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

module NAS_TrackingArea_GERAN {

  import from CommonDefs all;
  import from GERAN_Parameters all;
  import from UTRAN_Parameters all;
  import from Parameters all;
  import from GERAN_Component all;
  import from CommonIratDefs all;
  // import from GERAN_CellInfo all;
  import from GERAN_CommonFunctions all;
  import from NAS_AuxiliaryDefsAndFunctions all;
  import from NAS_24008TypeDefs all;
  import from NAS_CommonTypeDefs all;
  import from NAS_CommonTemplates all;
  import from NAS_24008Templates all;
  import from GERAN_TypeDefs all;
  import from GERAN_Templates all;
  import from UpperTesterFunctions all;
  import from UTRANGERAN_CommonFunctions all;

template LLCUnitDataIndType cr_G_RAUReq_Ids (template (present) UpdateType p_UpdateType,
                                        template (present) RoutingAreaId p_RAI,
                                        template PTMSI_Signature p_PTMSISig,
                                        template (present) KeySeq p_KeySeq,
                                        template MobileIdentity p_PTMSIMobileId,
                                        template MobileIdentity p_AddMobileId,
                                        template RoutingAreaId2 p_AddOldRAI) :=
  {
    rauReq := cr_RAURequest_Common(p_UpdateType,
                        p_RAI,
                        p_PTMSISig,
                        cr_TMSI_Status ifpresent,
                        p_KeySeq,
                        cr_MS_RadioAccessCapLVAny,
                        cr_GPRS_TimerAny ifpresent,
                        cr_DRXparameter_Any('27'O) ifpresent,
                        p_PTMSIMobileId,
                        cr_MS_NetworkCap_Any ifpresent,
                        cr_PDP_ContextStatusAny ifpresent,
                        cr_PS_LCS_CapabilityAny ifpresent,
                        cr_MBMS_ContextStatusAny ifpresent,
                        cr_UENetworkCap_Any ('58'O),
                        p_AddMobileId,
                        p_AddOldRAI,
                        cdr_MS_Clsmk2_Any ifpresent,
                        cr_MSCLSMK3_Any ifpresent,
                        cr_CodecListAny ifpresent)
  };

  template LLCUnitDataIndType cdr_G_RA_UpdCompleteWithIRInfo
  modifies cr_G_RA_UpdComplete :=
  {
    rauComplete := {
      eutranInterRAT_HO_Info := cr_EUTRAN_HO_InfoAny
    }
  };

  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_GERAN () runs on GERAN_PTC
  {
        fl_TC_9_2_3_1_10_11_AND_12_Body ();
  }

function f_TC_9_2_3_1_11_GERAN () runs on GERAN_PTC
  {
        fl_TC_9_2_3_1_10_11_AND_12_Body ();
  }

function f_TC_9_2_3_1_12_GERAN () runs on GERAN_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 GERAN_PTC
{

  var boolean v_TriggerRxd := false;

  if (pc_GERAN and not pc_UTRA) { // UE supports GERAN but not UTRAN
    f_GERAN_Init(EUTRA_GERAN); // This is still only a 2 PTC test

    f_GERAN_CreateCell (geran_Cell24);
    f_GERAN_Pre_Preamble (geran_Cell24);
    f_GERAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params
    f_GERAN_TestBody_Set( true );

   f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_NonSuitableCell);
    
    //@siclog "Step 13" siclog@
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger (EUTRA);
    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_ServingCell);

    //@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 or 24?
    f_GERAN_CheckNoAttachOnCell (geran_Cell24, 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_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_NonSuitableCell);

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

    f_GERAN_SS_CellRelease ( geran_Cell24 );

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

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

// @desc Normal tracking area update / Rejected / PLMN not allowed
function f_TC_9_2_3_1_15_GERAN () runs on GERAN_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_GERAN and not pc_UTRA) { // UE supports GERAN but not UTRAN
    f_GERAN_Init(EUTRA_GERAN); // This is still only a 2 PTC test

    f_GERAN_CreateCell (geran_Cell24);

  // Pre-Preamble on GERAN cell first to set PTSMI, PTSMI Sig and TMSI in USIM
    f_GERAN_Pre_Preamble (geran_Cell24);
    f_GERAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params

    f_GERAN_TestBody_Set( true );

    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_NonSuitableCell);

    // First Trigger
    //@siclog "Step 12" siclog@
    // Set Cell 24 to "Serving Cell"
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger (EUTRA);
    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_ServingCell);

    //@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 or 24?
    f_GERAN_CheckNoAttachOnCell (geran_Cell24, 30.0, "Step 13a2");

    //+ Set the cell type of cell 5 or 24 to the ''Non-Suitable cell''.
    //@siclog "Step 15" siclog@
    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_NonSuitableCell);

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

    f_GERAN_SS_CellRelease ( geran_Cell24 );

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

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

// @desc Normal tracking area update / Rejected / Roaming not allowed in this tracking area
function f_TC_9_2_3_1_17_GERAN () runs on GERAN_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 G_LLC_DATAMESSAGE_IND v_LLCDataInd;
  var B3_Type v_UpdateType;
  timer t_Wait30s := f_UG_SetTimerToleranceMax (30.0);

  if (pc_GERAN and not pc_UTRA) { // UE supports GERAN but not UTRAN
    f_GERAN_Init(EUTRA_GERAN); // This is still only a 2 PTC test

    f_GERAN_CreateCell (geran_Cell24);
    f_GERAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params
    f_GERAN_TestBody_Set( true );
    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_NonSuitableCell);

    // First Trigger:
    //@siclog "Step 10" siclog@
    // Set Cell 24 to "Serving Cell"
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger (EUTRA);
    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_ServingCell);

    //+ Step
    //@siclog "Step 11a1" siclog@
    // Check: Does the UE transmit a ROUTING AREA UPDATE REQUEST message in the next 30 seconds on cell 24?
    f_UplinkTBFOnePhase (geran_Cell24);
    t_Wait30s.start;
    alt {
    [] t_Wait30s.timeout { // Can't arrive too late
      f_GERAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "Step 11a1");
       }
    []    G_LLC.receive(car_G_LLC_UnitData_IND ( cr_G_RA_UpdReqAny (cr_GMM_UpdateType('0'B, '001'B), cr_RAI_Any (omit), cr_PTMSI_SignatureAny ifpresent, ?)))
      -> value v_LLCDataInd
      {
        v_UpdateType := v_LLCDataInd.unit.msg.rauReq.updateType.updateValue;
        t_Wait30s.stop;
        f_GERAN_PreliminaryPass (__FILE__, __LINE__, "Step 9a2");
      }
    }

    //@siclog "Step 11a2" siclog@
    // Send ROUTING AREA UPDATE REJECT message with cause "Roaming not allowed in this area"
    G_LLC.send(cas_G_LLC_UnitData_Req (f_GERAN_TLLI_Get(geran_Cell24), tsc_LLCSapi_GMM, tsc_LLC_PM, px_GSM_CipheringOnOff,
                          cs_G_RAUpdReject(cs_GMM_Cause('00001101'B)))); // cause 'Roaming not allowed in this area'


    //+ Set the cell type of cell 24 to the ''Non-Suitable cell''.
    //@siclog "Step 12" siclog@
    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_NonSuitableCell);

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

    f_GERAN_SS_CellRelease ( geran_Cell24 );

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

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

// @desc Normal tracking area update / Rejected / EPS services not allowed in this PLMN
function f_TC_9_2_3_1_18_GERAN () runs on GERAN_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_GERAN and not pc_UTRA) { // UE supports GERAN but not UTRAN
    f_GERAN_Init(EUTRA_GERAN); // This is still only a 2 PTC test

    f_GERAN_CreateCell (geran_Cell24);
    f_GERAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params
    f_GERAN_TestBody_Set( true );
    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_NonSuitableCell);

    // First Trigger
    //@siclog "Step 9" siclog@
    // Set Cell 24 to "Serving Cell"
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger (EUTRA);
    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_ServingCell);

    //@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 24?
    f_GERAN_CheckNoAttachOnCell (geran_Cell24, 30.0, "Step 10a2");

    //+  Set the cell type of cell 24 to the ''Non-Suitable cell''.
    //@siclog "Step 11" siclog@
    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_NonSuitableCell);

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

    f_GERAN_SS_CellRelease ( geran_Cell24 );

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

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

/// @desc Combined tracking area update / Successful for EPS services only / MSC temporarily not reachable
function f_TC_9_2_3_2_3_GERAN () runs on GERAN_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:
    -   The UE is configured to initiate EPS attach
    Preamble:
    -   The UE is in state Switched OFF (state 1) according to [18].

    */

  var boolean v_TriggerRxd := false;

  f_GERAN_Init(EUTRA_GERAN); // This is still only a 2 PTC test

  f_GERAN_CreateCell (geran_Cell24);
  f_GERAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params
  f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_NonSuitableCell);
  f_GERAN_TestBody_Set( true );

  //@siclog "Step 20b1" siclog@
  v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(EUTRA); // Wait 2nd trigger from  EUTRAN side
  f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_ServingCell);

  // Steps : RAU procedure
  //@siclog "Step 20b2 - 20b51" siclog@
  f_GERAN_RAU (geran_Cell24, '0'B, '001'B);

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

  // Test case now finished on GERAN side
  f_GERAN_TestBody_Set( false );
  f_GERAN_SwitchPowerOff ( geran_Cell24 );
  f_GERAN_SS_CellRelease ( geran_Cell24 );

} // f_TC_9_2_3_2_3_GERAN

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

/// @desc tracking area update / Rejected / Illegal ME
function f_TC_9_2_3_2_6_GERAN () runs on GERAN_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_GERAN


/// @desc Combined tracking area update / Rejected / EPS services and non-EPS services not allowed
function f_TC_9_2_3_2_7_GERAN () runs on GERAN_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_GERAN

function fl_TC_9_2_3_2_6_AND_7_Body () runs on GERAN_PTC
{

  var boolean v_TriggerRxd := false;

  if (pc_GERAN and not pc_UTRA) { // UE supports GERAN but not UTRAN
    f_GERAN_Init(EUTRA_GERAN); // This is still only a 2 PTC test

    f_GERAN_CreateCell (geran_Cell24);
    f_GERAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params
    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_NonSuitableCell);

    f_GERAN_TestBody_Set( true );

    // First Trigger
    //@siclog "Step 7a1" siclog@
    // Set Cell 24 to "Serving Cell"
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger (EUTRA);
    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_ServingCell);
    
    //@siclog "Step 7a3" siclog@
    // Check: Does the UE transmit an ATTACH REQUEST message in the next 30 seconds on cell 24?
    f_GERAN_CheckNoAttachOnCell ( geran_Cell24, 30.0, "Step 7a3");

    //+  Set the cell type of cell 24 to the ''Non-Suitable cell''.
    //@siclog "Step 8" siclog@
    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_NonSuitableCell);

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

    f_GERAN_SS_CellRelease ( geran_Cell24 );

    } // UE doesn't support GERAN, or supports UTRAN too, so do nothing
 
} // 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_GERAN () runs on GERAN_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 G_LLC_DATAMESSAGE_IND v_LLCDataInd;
  var B3_Type v_AttachType;
  var octetstring v_PLMN := f_GERAN_PLMN_Get(geran_Cell24);
  var O1_Type v_RAC := f_GERAN_RAC_Get(geran_Cell24);
  var O2_Type v_LAC := f_GERAN_LAC_Get(geran_Cell24);

  f_GERAN_Init(EUTRA_GERAN); // This is still only a 2 PTC test

  f_GERAN_CreateCell (geran_Cell24);
  f_GERAN_Pre_Preamble (geran_Cell24);
  f_GERAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params
  f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_NonSuitableCell);
  f_GERAN_TestBody_Set( true );

  // Step 5a1.
  //@siclog "Step 5a1" siclog@
  v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(EUTRA); // Wait 2nd trigger from  EUTRAN side
  f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_ServingCell);

  // The UE transmits an ATTACH REQUEST message on Cell 24
  //@siclog "Step 5a3" siclog@
  // Check: Does the UE send an ATTACH REQUEST?
  f_UplinkTBFOnePhase (geran_Cell24);
  alt { // Receive GPRS Attach Request Message
  [] G_LLC.receive(car_G_LLC_UnitData_IND ( cr_G_AttachReqWithIMSI (cr_AttachType(?, tsc_I_AttachTypeCombined),
                                                                    f_Imsi2MobileIdentity(px_IMSI_Def),
                                                                    cr_RAI (omit, cr_LAI(omit, v_PLMN, 'FFFE'O), ?),
                                                                    '111'B)))  -> value v_LLCDataInd
    {
      f_GERAN_PreliminaryPass (__FILE__, __LINE__, "Step 15a5");
      v_AttachType := v_LLCDataInd.unit.msg.attReq.attachType.attachType;
      f_GERAN_SplitPGCycle_Set(geran_Cell24, v_LLCDataInd.unit.msg.attReq.drxParameter);
    }
  }

  // The SS transmits an AUTHENTICATION REQUEST and CIPHERING REQUEST message.
  //The UE transmits an AUTHENTICATION AND CIPHERING RESPONSE message.
  //@siclog "Step 5a4 - 5a5" siclog@
  f_GERAN_GPRS_Authentication (geran_Cell24);

  // SS responds with ATTACH ACCEPT message including valid TMSI, P-TMSI (TIN set to P-TMSI) and RAI
  //  Editor's Note: the default message contents in 51.010 clause 40.2.4.3 allocate a Negotiated READY timer value of 32 seconds.
  // Send GPRS Attach Accept
  //@siclog "Step 5a6" siclog@
  f_DownlinkTBFEstablishment(geran_Cell24, 1);
  G_LLC.send(cas_G_LLC_UnitData_Req (f_GERAN_TLLI_Get(geran_Cell24), tsc_LLCSapi_GMM, tsc_LLC_PM, px_GSM_CipheringOnOff,
                cs_G_AttachAccept (cs_GMM_AttachResult(v_AttachType), 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))));

  // The UE transmits an ATTACH COMPLETE message.
  //Receive GPRS Attach Complete Message
  //@siclog "Step 5a7" siclog@
  f_UplinkTBFOnePhase (geran_Cell24);
  G_LLC.receive(car_G_LLC_UnitData_IND (cr_G_AttachComplete));

//  f_GERAN_GPRSAttach (geran_Cell24); // old stuff!!!!

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

  // Test case now finished on GERAN side
  f_GERAN_TestBody_Set( false );
  f_GERAN_Postamble ( geran_Cell24, G1_IDLE );

} // f_TC_9_2_3_2_9_GERAN

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

/**
  * @desc Periodic Routing Area Update (multi RAT test)
*/
function f_TC_9_2_3_3_5_GERAN () runs on GERAN_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 octetstring v_PLMN := f_GERAN_PLMN_Get(geran_Cell26);
  var O1_Type v_RAC := f_GERAN_RAC_Get(geran_Cell26);
  var O2_Type v_LAC := f_GERAN_LAC_Get(geran_Cell26);
  var G_LLC_DATAMESSAGE_IND v_LLCDataInd;
  var template (value) LLCUnitDataReqType v_RAUAccept;
  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%
  timer t_Wait30s := f_UG_SetTimerToleranceMax (30.0);

  if (pc_GERAN and not pc_UTRA) { // UE supports GERAN but not UTRAN
    f_GERAN_Init(EUTRA_GERAN); // This is still only a 2 PTC test

    f_GERAN_CreateCell (geran_Cell24);
    f_GERAN_Pre_Preamble (geran_Cell24);
    f_GERAN_InterRAT_InitialiseAuthParams();  // The UE starts in EUTRA, so wait for it to send the Auth Params
    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_NonSuitableCell);
    f_GERAN_TestBody_Set( true );

    //@siclog "Step 1a1" siclog@
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger(EUTRA);
    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_ServingCell);

    // Routing Area Update on GERAN side
    //@siclog "Step 1a2 - 1a4" siclog@
    f_UplinkTBFOnePhase (geran_Cell24);
    alt{
    [] G_LLC.receive(car_G_LLC_UnitData_IND ( cr_G_RAUReq_Ids ( cr_GMM_UpdateType ( ?, '000'B),
                                                                cr_RAI_Any (omit),
                                                                cr_PTMSI_SignatureAny ifpresent,
                                                                ?,
                                                                omit, // Hellen TO DO PTMSI mapped from GUTI, if required
                                                                cr_MobileIdAny('1A'O) ifpresent,
                                                                cr_RoutingAreaId2_Any ifpresent)))
          -> value v_LLCDataInd {
    }}
    // Check ISR support
    if (v_LLCDataInd.unit.msg.rauReq.msNetworkCap.isrSupport != '1'B) {
      f_GERAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "Step 1a2");
    }
    v_RAUAccept := cs_G_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),
                    omit );
    // 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_RAUAccept.rauAccept.periodicRAupdateTimer:= cs_GprsTimer_v('001'B, '00111'B);
    f_DownlinkTBFEstablishment(geran_Cell24, 1);
    G_LLC.send (cas_G_LLC_UnitData_Req (f_GERAN_TLLI_Get(geran_Cell24), tsc_LLCSapi_GMM, tsc_LLC_PM, px_GSM_CipheringOnOff, v_RAUAccept));

    f_UplinkTBFOnePhase (geran_Cell24);
    G_LLC.receive(car_G_LLC_UnitData_IND (cr_G_RA_UpdComplete));

   // 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_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_NonSuitableCell);
    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_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_ServingCell);

    t_T3312_low.timeout; // RAU can't be too early
    // Steps 9a2 to 9a4  Routing Area Update on UTRAN side
    f_UplinkTBFOnePhase (geran_Cell24);
    alt{
    [] t_T3312_high.timeout { // Can't arrive too late
      f_GERAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "Step 9a2");
       }
    [] G_LLC.receive(car_G_LLC_UnitData_IND ( cr_G_RAUReq_Ids ( cr_GMM_UpdateType ( ?, '000'B),
                                                                cr_RAI_Any (omit),
                                                                cr_PTMSI_SignatureAny ifpresent,
                                                                ?,
                                                                omit, // Hellen TO DO PTMSI mapped from GUTI, if required
                                                                cr_MobileIdAny('1A'O) ifpresent,
                                                                cr_RoutingAreaId2_Any ifpresent)))
          -> value v_LLCDataInd {
      t_T3312_high.stop;
      f_GERAN_PreliminaryPass (__FILE__, __LINE__, "Step 9a2");
    }}
    // Check ISR support
    if (v_LLCDataInd.unit.msg.rauReq.msNetworkCap.isrSupport != '1'B) {
      f_GERAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "Step 9a2");
    }
    f_DownlinkTBFEstablishment(geran_Cell24, 1);
    G_LLC.send (cas_G_LLC_UnitData_Req (f_GERAN_TLLI_Get(geran_Cell24), tsc_LLCSapi_GMM, tsc_LLC_PM, px_GSM_CipheringOnOff, v_RAUAccept));

    f_UplinkTBFOnePhase (geran_Cell24);
    G_LLC.receive(car_G_LLC_UnitData_IND (cr_G_RA_UpdComplete));

    //@siclog "Step 9a5" siclog@
    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_NonSuitableCell);
    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_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_ServingCell);
    t_Wait30s.start;

    // Steps  Routing Area Update on UTRAN side
    //@siclog "Step 21a2 - 21a4 " siclog@
    alt{
    [] t_Wait30s.timeout{
       f_GERAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "Step 21a2");
       }
    [] G_LLC.receive(car_G_LLC_UnitData_IND ( cr_G_RAUReq_Ids ( cr_GMM_UpdateType ( ?, '000'B),
                                                                cr_RAI_Any (omit),
                                                                cr_PTMSI_SignatureAny ifpresent,
                                                                ?,
                                                                omit, // Hellen TO DO PTMSI mapped from GUTI, if required
                                                                cr_MobileIdAny('1A'O) ifpresent,
                                                                cr_RoutingAreaId2_Any ifpresent)))
          -> value v_LLCDataInd {
      t_Wait30s.stop;
      f_GERAN_PreliminaryPass (__FILE__, __LINE__, "Step 21a2");
    }}
    // Check ISR support
    if (v_LLCDataInd.unit.msg.rauReq.msNetworkCap.isrSupport == '1'B) {
      f_GERAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "Step 21a2");
    }
    f_DownlinkTBFEstablishment(geran_Cell24, 1);
    G_LLC.send (cas_G_LLC_UnitData_Req (f_GERAN_TLLI_Get(geran_Cell24), tsc_LLCSapi_GMM, tsc_LLC_PM, px_GSM_CipheringOnOff, v_RAUAccept));

    f_UplinkTBFOnePhase (geran_Cell24);
    G_LLC.receive(car_G_LLC_UnitData_IND (cr_G_RA_UpdComplete));

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

    // Test case now finished on GERAN side
    f_GERAN_TestBody_Set( false );
    f_GERAN_Postamble ( geran_Cell24, G1_IDLE );
 } // GERAN not supported, so do nothing
} // f_TC_9_2_3_3_5_GERAN

//---------------------------------------------------------------------
function f_TC_9_2_3_4_1_GERAN () runs on GERAN_PTC
{

    /*
    System Simulator:
    NOTE:   while this test describes the uses of 3 cells, it is intended that this test only requires 2 cells to be active at any one instant.
    -   Cell A (E-UTRAN), Cell 24 and Cell 26 (GERAN)
        With the exception of the MCC and MNC, cell 24 and cell 26 take the default parameters of the GERAN cells as defined in clause 6.3.1 of TS 36.508 [18], Cells 24 and 26 are configured with the same MCC and MNC as cell A. Cells 24 and 26 are in the same Routeing Area.
    As defined in table 4.4.2-1 of TS 36.508 [18], cell 24 and cell 26 are GERAN cells.
    -
    -   -   As defined in clause 40.1 of TS 51.010 [23], the GERAN cells are configured to use Network Mode of Operation I.
    -   The power level of Cell 24 is the Serving Cell level defined in table 6.2.2.1-1 of TS 36.508 [18].
    -   The power levels of Cells A and 26 are set to the Non-suitable "Off" level defined in table 6.2.2.1-1 of TS 36.508 [18].
    UE:
    -   The test USIM contains a valid GUTI = GUTIx (stored in EFEPSLOCI), valid EPS security parameters (stored in EFEPSNSC), and EPS update status is "EU1: UPDATED". GUTIx has MNC=987, MCC= 65, MMEGI = 'fedc' hex, MMEC = 'ba' hex, and arbitrary M-TMSI.
    Preamble:
    -   The UE is in state Switched OFF (state 1) according to [18].

    */

    var boolean v_TriggerRxd := false;
    var IRAT_CoOrd_Auth_Type v_CoOrd_AuthParams;
    var octetstring v_PLMN := f_U_Asn2Nas_PlmnId({ mcc := {9, 8, 7},  mnc := {6, 5} });
    var template (value) CoOrd_GUTIParam_Type v_GTUIParams;
    var G_LLC_DATAMESSAGE_IND v_LLCDataInd;
    var B3_Type v_UpdateType;
    var B32_Type v_TLLIBits;
    var O1_Type v_RAC := f_GERAN_RAC_Get(geran_Cell26);
    var O2_Type v_LAC := f_GERAN_LAC_Get(geran_Cell26);
    var B32_Type v_M_TMSIIn, v_M_TMSIOut;
    f_GERAN_Init(EUTRA_GERAN);

    f_GERAN_PLMN_Set(geran_Cell24, v_PLMN);
    f_GERAN_PLMN_Set(geran_Cell26, v_PLMN);

    f_GERAN_CreateCell (geran_Cell24);
    f_GERAN_CreateCell (geran_Cell26);

    f_GERAN_InterRAT_InitialiseAuthParams (); // Get and store Auth Params from EUTRA
    f_GERAN_TestBody_Set( true );

    // First Trigger
    //@siclog "Step 1" siclog@
    v_CoOrd_AuthParams := f_ReceiveAuthCoOrdParameters (EUTRA);
    v_M_TMSIIn := v_CoOrd_AuthParams.GutiParams.M_TMSI;
    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_ServingCell);

    //+   The UE is switched on.
    f_UT_SwitchOnUE(UT, false); /* no USIM insertion */

    // The UE transmits an ATTACH REQUEST message on Cell 24
    // Step 3
    //The SS transmits an AUTHENTICATION REQUEST message.
    // Step 4
    //The UE transmits an AUTHENTICATION RESPONSE message.
    // Step 8
    // SS responds with ATTACH ACCEPT message including valid TMSI, P-TMSI (TIN set to P-TMSI) and RAI.
    //  Editor's Note: the default message contents in 51.010 clause 40.2.4.3 allocate a Negotiated READY timer value of 32 seconds.
    // Step 9
    // The UE transmits an ATTACH COMPLETE message.
    //@siclog "Step 3 - 9" siclog@
    f_GERAN_GPRSAttach (geran_Cell24);

    // 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_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_SuitableNeighbourCell);
    f_GERAN_SendAuthCoOrdParameters (EUTRA, v_GTUIParams);

    // Step 10 to step 20 is implementated in EUTRA side.

    // Second Trigger:
    //  Cell 24 is switched off
    //@siclog "Step 21" siclog@
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger (EUTRA);
    f_GERAN_SetCellPowerLevel (geran_Cell24, tsc_GERAN_ChPwrLvl_Off);

    //@siclog "Step 22" siclog@
    // The signal strength of Cell 26 is raised to that of the Serving Cell and that of Cell A is lowered to that of a Suitable Neighbour Cell as defined in table 6.2.2.1-1 of TS 36.508 [18].
    // Note: Cell A is still suitable but the UE is expected to select Cell 26.
     f_GERAN_SetCellPowerLevel (geran_Cell26, tsc_GERAN_ServingCell);

    //+Check: does the UE send on Cell 26 an RLC/MAC header with the TLLI derived from the P-TMSI that is derived from the GUTI allocated in step 18? [4,P]
    //@siclog "Step 23" siclog@
    f_UplinkTBFOnePhase (geran_Cell26);
    v_TLLIBits := oct2bit(f_GERAN_TLLI_Get(geran_Cell26));
    if ((substr(v_M_TMSIIn, 24, 6) == substr(v_TLLIBits, 24, 6)) and (substr(v_M_TMSIIn, 0, 16) == substr(v_TLLIBits, 0, 16)))
    {
       f_GERAN_PreliminaryPass(__FILE__, __LINE__, "Step 23");
    } else {
       f_GERAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "PTMSI doesn't correlate to M-TMSI, Step 23");
    }

    //+ Check: does the UE send on Cell 26 a ROUTING AREA UPDATE REQUEST with the correct parameters? [5,P]
    //@siclog "Step 24" siclog@
    alt { // Receive RAU Request Message
    []    G_LLC.receive(car_G_LLC_UnitData_IND ( cr_G_RAUReq_Ids (cr_GMM_UpdateType( ?, ?), cr_RAI_Any (omit), cr_PTMSI_SignatureAny ifpresent,
                                        v_CoOrd_AuthParams.AuthPS.KeySeq,  // Get value from Authentication done on EUTRA during Preamble
                                        omit,
                                        cs_MobileIdTMSIorPTMSI ('18'O, px_PTMSI_Def),
                                        cr_RoutingAreaId2(v_PLMN&v_LAC&v_RAC))))
                    -> value v_LLCDataInd
        {
            v_UpdateType := v_LLCDataInd.unit.msg.rauReq.updateType.updateValue;
        }
    }
    if (v_UpdateType != '000'B){
      v_UpdateType := '001'B;
    }
    //+The SS sends ROUTING AREA UPDATE ACCEPT (without the allocated P-TMSI IE, but with the Requested MS Information IE indicating "E-UTRAN inter RAT information container IE requested").
    // TODO
    //@siclog "Step 25" siclog@
    f_DownlinkTBFEstablishment(geran_Cell26, 1);
    G_LLC.send(cas_G_LLC_UnitData_Req (bit2oct(v_TLLIBits), tsc_LLCSapi_GMM, tsc_LLC_PM, px_GSM_CipheringOnOff,
                  cs_G_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), cs_RequestedMS_Info)));

    //+ UE sends ROUTING AREA UPDATE COMPLETE message
    //@siclog "Step 26" siclog@
    f_UplinkTBFOnePhase (geran_Cell26);
    G_LLC.receive(car_G_LLC_UnitData_IND (cdr_G_RA_UpdCompleteWithIRInfo));

    //+  The signal strength of Cell A is raised to that of the Serving Cell and that of Cell 26 is lowered to that of a Suitable Neighbour Cell as defined in table 6.2.2.1-1 of TS 36.508 [18].
    //   Note: Cell 26 is still suitable but the UE is expected to select Cell A.
    //@siclog "Step 27" siclog@
    f_GERAN_SetCellPowerLevel (geran_Cell26, tsc_GERAN_SuitableNeighbourCell);

    // Finished here for now
    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 GERAN side
    f_GERAN_TestBody_Set( false );

    f_GERAN_SS_CellRelease ( geran_Cell24 );
    f_GERAN_SS_CellRelease ( geran_Cell26 );

} // f_TC_9_2_3_4_1_GERAN

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


} // module NAS_TrackingArea_GERAN
