/******************************************************************************/
// @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:01:56 +0200 (Fri, 17 Sep 2010) $
// $Rev: 3947 $
/******************************************************************************/
module Idle_PLMNSelection
{
//=========================================================================
// Imports
//=========================================================================

  import from EUTRA_RRC_ASN1_Definitions language "ASN.1:1997" all;

  import from UpperTesterFunctions all;

  import from EUTRA_Component all;
  import from EUTRA_CommonDefs all;
  import from EUTRA_ConfigurationSteps all;
  import from EUTRA_CellInfo all;
  import from EUTRA_IdleMode all;
  import from EUTRA_CommonProcedures all;
  import from EUTRA_NASSteps all;
  import from EUTRA_Timing all;
  import from EUTRA_AspCommon_Templates all;
  import from EUTRA_SRB_Templates all;
  import from EUTRA_RRC_Templates all;
  import from EUTRA_AuxiliaryFunctions all;
  import from EUTRA_ASP_SrbDefs all;
  import from EUTRA_RRCSteps all;

  import from Parameters all;
  import from CommonDefs all;

  import from EPS_NAS_MsgContainers all;
  import from EPS_NAS_TypeDefs all;
  import from EPS_NAS_Templates all;
  import from EPS_NAS_Constants all;

  import from NAS_CommonTypeDefs all;
  import from EUTRA_NASCommonFunctions all;
  
/*
==============================================================================
 Open issue for test case 6.1.1.6
==============================================================================

  New function to cause UE to perfomr Automatic PLMN scan needs to be implemented
  
  The following is suggested:
  
  1. New template
  template (value) Ut_System_Cmd_Type cs_AT_AUTOMATIC_PLMN_SCAN :=
    cs_AT_Cmd("AT+COPS=0");
    
  2. New case added in function fl_UT_HandleCmd
      case (AUTOMATIC_PLMN_SCAN)  {
        v_SystemCmd := cs_AT_AUTOMATIC_PLMN_SCAN;
    }
    
  3. New function f_UT_AutomaticPLMNScan needs to be implemened
  function f_UT_AutomaticPLMNScan (UT_PTC_MTC_PORT p_Port)
  {
    fl_UT_ApplyCommand(p_Port, cas_UT_Req(AUTOMATIC_PLMN_SCAN, NO_CNF_REQUIRED, omit));
  }
  
  4. type enumerated Ut_Common_Req_Type must be extended with AUTOMATIC_PLMN_SCAN
*/

//==============================================================================
// Functions
//==============================================================================

  /*
   * @desc      Sets 3 PLMN idendities
   * @status
   */
  function f_EUTRA_CellInfo_SetPLMN_3Entries ( CellId_Type                    p_CellId,
                                               template (value) PLMN_Identity p_PLMN1,
                                               template (value) PLMN_Identity p_PLMN2,
                                               template (value) PLMN_Identity p_PLMN3 ) runs on EUTRA_PTC  {
    /* Set the parameterised PLMN value in EUTRA Cellinfo */
    var EUTRA_CellInfo_Type v_CellInfo := f_EUTRA_CellInfo_Get ( p_CellId );
    var template (value) EUTRA_CellInfo_Type v_NewCellInfo := v_CellInfo;

    if (v_CellInfo.Frequency.FrequencyBandIndicator == 6 ) {
      // For Band 6: set MCC to the Japan MCC value
      v_NewCellInfo.NAS_Parameters.Guti_Parameters.PLMN_Identity.mcc := f_ConvertMCC_Nas2Asn(px_eJapanMCC_Band6);
      v_NewCellInfo.NAS_Parameters.Guti_Parameters.PLMN_Identity.mnc := p_PLMN1.mnc;
      v_NewCellInfo.Sysinfo.BCCH_Info.SIB1.message_.c1.systemInformationBlockType1.cellAccessRelatedInfo.plmn_IdentityList[0].plmn_Identity.mcc := f_ConvertMCC_Nas2Asn(px_eJapanMCC_Band6);
      v_NewCellInfo.Sysinfo.BCCH_Info.SIB1.message_.c1.systemInformationBlockType1.cellAccessRelatedInfo.plmn_IdentityList[0].plmn_Identity.mnc := p_PLMN1.mnc;
      v_NewCellInfo.Sysinfo.BCCH_Info.SIB1.message_.c1.systemInformationBlockType1.cellAccessRelatedInfo.plmn_IdentityList[1].plmn_Identity.mcc := f_ConvertMCC_Nas2Asn(px_eJapanMCC_Band6);
      v_NewCellInfo.Sysinfo.BCCH_Info.SIB1.message_.c1.systemInformationBlockType1.cellAccessRelatedInfo.plmn_IdentityList[1].plmn_Identity.mnc := p_PLMN2.mnc;
      v_NewCellInfo.Sysinfo.BCCH_Info.SIB1.message_.c1.systemInformationBlockType1.cellAccessRelatedInfo.plmn_IdentityList[2].plmn_Identity.mcc := f_ConvertMCC_Nas2Asn(px_eJapanMCC_Band6);
      v_NewCellInfo.Sysinfo.BCCH_Info.SIB1.message_.c1.systemInformationBlockType1.cellAccessRelatedInfo.plmn_IdentityList[2].plmn_Identity.mnc := p_PLMN3.mnc;
    }
    else {
      v_NewCellInfo.NAS_Parameters.Guti_Parameters.PLMN_Identity := p_PLMN1;
      v_NewCellInfo.Sysinfo.BCCH_Info.SIB1.message_.c1.systemInformationBlockType1.cellAccessRelatedInfo.plmn_IdentityList[0].plmn_Identity.mcc := p_PLMN1.mcc;
      v_NewCellInfo.Sysinfo.BCCH_Info.SIB1.message_.c1.systemInformationBlockType1.cellAccessRelatedInfo.plmn_IdentityList[0].plmn_Identity.mnc := p_PLMN1.mnc;
      v_NewCellInfo.Sysinfo.BCCH_Info.SIB1.message_.c1.systemInformationBlockType1.cellAccessRelatedInfo.plmn_IdentityList[1].plmn_Identity.mcc := p_PLMN2.mcc;
      v_NewCellInfo.Sysinfo.BCCH_Info.SIB1.message_.c1.systemInformationBlockType1.cellAccessRelatedInfo.plmn_IdentityList[1].plmn_Identity.mnc := p_PLMN2.mnc;
      v_NewCellInfo.Sysinfo.BCCH_Info.SIB1.message_.c1.systemInformationBlockType1.cellAccessRelatedInfo.plmn_IdentityList[2].plmn_Identity.mcc := p_PLMN2.mcc;
      v_NewCellInfo.Sysinfo.BCCH_Info.SIB1.message_.c1.systemInformationBlockType1.cellAccessRelatedInfo.plmn_IdentityList[2].plmn_Identity.mnc := p_PLMN2.mnc;
    }
    f_EUTRA_CellInfo_Set ( p_CellId, v_NewCellInfo );
  };

  /*
   * @desc      REFERENCE TS 36.523-1 clause 6.1.1.1
   * @status
   */
  function f_TC_6_1_1_1_EUTRA ( ) runs on EUTRA_PTC {

    var template (value) CellPowerList_Type v_CellPowerList_AtT1, v_CellPowerList_AtT2;
    var float v_WaitTime := 720.0;
    timer t_HpPlmn_lower;
    timer t_HpPlmn_upper;
    timer t_IdleMode_GenericTimer := tsc_IdleMode_GenericTimer;
    
    v_CellPowerList_AtT1 := {
      cs_CellPower ( eutra_Cell1, tsc_ServingCellRS_EPRE ),
      cs_CellPower ( eutra_Cell13, tsc_ServingCellRS_EPRE )
    };
    v_CellPowerList_AtT2 := {
      cs_CellPower ( eutra_Cell1, tsc_NonSuitableOffCellRS_EPRE ),
      cs_CellPower ( eutra_Cell14, tsc_NonSuitableOffCellRS_EPRE )
    };

    //Initialise all cell, security and mobile parameters
    //1. c3 initialises SIB2, SIB3 and SIB5 for all cells on same PLMN => no SIB5 would be initialised for cell 12, 13 & 14
    //2. Prose does not specify any non default combination
    //=> combination 1 will be used
    f_EUTRA_Init(c1);//SIB2 & SIB3 are transmitted

    //Set Sys info and cell infor for cell 12, 13 & 14 to be used @ creation
    f_EUTRA_CellInfo_SetPLMN_1Entry ( eutra_Cell12, cs_HPLMN_001_11 );//PLMN1
    f_EUTRA_CellInfo_SetPLMN_1Entry ( eutra_Cell13, cs_HPLMN_001_21 );//PLMN2
    f_EUTRA_CellInfo_SetPLMN_1Entry ( eutra_Cell14, cs_HPLMN_001_31 );//PLMN3

    //Set TAC for Cell1, Cell12, Cell13 & Cell14
    //TAC for Cell1 is set to 1 in f_EUTRA_Init
    f_EUTRA_CellInfo_SetTAC ( eutra_Cell12, tsc_IdleMode_TAC_Cell12 );
    f_EUTRA_CellInfo_SetTAC ( eutra_Cell13, tsc_IdleMode_TAC_Cell13 );
    f_EUTRA_CellInfo_SetTAC ( eutra_Cell14, tsc_IdleMode_TAC_Cell14 );

    //Configure and activate all cells
    //Cell power level will be -85 dBm/15kHz & attenuation set so that cell is seen as OFF
    f_EUTRA_CellConfig_Def ( eutra_Cell12 );
    f_EUTRA_CellConfig_Def ( eutra_Cell1 );
    f_EUTRA_CellConfig_Def ( eutra_Cell13 );
    f_EUTRA_CellConfig_Def ( eutra_Cell14 );//As postamble will be executed on this cell

    //Equip UE with a USIM containing default values except for those shown in Table 6.1.1.1.3.1-2
    f_UT_USIM_Insert ( UT, "36.523-1 Table 6.1.1.1.3.1-2" );

    //Preamble to ensure USIM is updated
    f_EUTRA_Preamble ( eutra_Cell12, STATE2_IDLEUPDATE );
    f_EUTRA_UE_Detach_SwitchOffUe ( eutra_Cell12, RRC_IDLE );

    f_EUTRA_TestBody_Set ( true );

    //@siclog "Step 1" siclog@
    //Adjust cell configuration according to T1
    f_EUTRA_SetCellPowerList ( v_CellPowerList_AtT1, cs_TimingInfo_Now );

    //@siclog "Step 2" siclog@
    //Power on UE
    f_UT_SwitchOnUE (UT, false);
    t_HpPlmn_lower.start ( f_EUTRA_SetTimerToleranceMin ( eutra_Cell12, 120.0 ) );
    t_HpPlmn_upper.start ( f_EUTRA_SetTimerToleranceMax ( eutra_Cell12, 360.0 ) ) ;
    t_IdleMode_GenericTimer.start;

    //@siclog "Step 3" siclog@
    //Receive RRCConnectionRequest on Cell 12
    SRB.receive( car_SRB0_RrcPdu_IND ( eutra_Cell12, cr_508_RRCConnectionRequest ) );
    t_IdleMode_GenericTimer.stop;
    //* @verdict pass RRCConnectionRequest message received on Cell 1
    f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "Test Case 6.1.1.1 Step 3");

    //@siclog "Step 4 - 18" siclog@
    //Perform step 3 to 17 of registration procedure on cell 12
    f_EUTRA_IdleUpdated_WithoutRRCConnReq ( eutra_Cell12, STATE2_IDLEUPDATE );

    //@siclog "Step 19" siclog@
    //Check if PLMN1 is indicated by UE
    f_UT_PLMN_Check ( UT, "00111" );
    //* @verdict pass PLMN1 indicated by UE
    f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "Test Case 6.1.1.1 Step 19");

    //@siclog "Step 20" siclog@
    //Check for RRCConnectionRequest on Cell1 / PLMN4
    alt {
      [] SRB.receive( car_SRB0_RrcPdu_IND ( eutra_Cell1, cr_508_RRCConnectionRequest ) )
      {
        //* @verdict fail RRCConnectionRequest received on PLMNN4 / Cell 1 within t_HpPlmn_lower time
        f_EUTRA_SetVerdictFailOrInconc (__FILE__, __LINE__, "Test Case 6.1.1.1 Step 20");
      }
      [] t_HpPlmn_lower.timeout
      {
        alt {
          [] SRB.receive( car_SRB0_RrcPdu_IND ( eutra_Cell1, cr_508_RRCConnectionRequest ) )
          {
            t_HpPlmn_upper.stop;
            //* @verdict pass RRC Connection request received on PLMN4 / Cell 1 after t_HpPlmn_lower time but before t_HpPlmn_upper
             f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "Test Case 6.1.1.1 Step 20");
          }
          [] t_HpPlmn_upper.timeout
          {
            //* @verdict fail No RRCConnectionRequest received
            f_EUTRA_SetVerdictFailOrInconc (__FILE__, __LINE__, "Test Case 6.1.1.1 Step 20");
          }
        }
      }
    }

    //@siclog "Step 21 - 25" siclog@
    //Perform TAU procedure steps 2 to 6
    f_EUTRA_TrackingAreaUpdate_WithoutRrcConnReq ( eutra_Cell1 );

    //@siclog "Step 26" siclog@
    //Check if PLMN4 is indicated by UE
    f_UT_PLMN_Check ( UT, "00101" );
    //* @verdict pass PLMN4 is indicated by UE
    f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "Test Case 6.1.1.1 Step 26");

    //@siclog "Step 27" siclog@
    //Check for no RRCConnectionRequest message on any active cell
    f_EUTRA_CheckNoAttachOn3Cells ( eutra_Cell1,
                                    eutra_Cell12,
                                    eutra_Cell13,
                                    v_WaitTime,//Tolerance is taken care of inside function f_EUTRA_CheckNoAttachOn3Cells
                                    "Test Case 6.1.1.1 Step 27 : RRCConnectionRequest message received within no-response-time");

    //@siclog "Step 28" siclog@
    //Adjusts cell power level according to T2
    f_EUTRA_SetCellPowerList ( v_CellPowerList_AtT2, cs_TimingInfo_Now );
    t_HpPlmn_upper.start ( f_EUTRA_SetTimerToleranceMin ( eutra_Cell13, 360.0 ) );

    //@siclog "Step 29" siclog@
    //Check if UE camps on Cell13
    f_EUTRA_IdleMode_TAU ( eutra_Cell13 );

    //@siclog "Step 30" siclog@
    //Check if PLMN2 is indicated by UE
    f_UT_PLMN_Check ( UT, "00121" );
    //* @verdict pass PLMN2 is indicated by UE
    f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "Test Case 6.1.1.1 Step 30");

    //@siclog "Step 31" siclog@
    //Adjusts cell power level according to T3
    f_EUTRA_SetCellPower ( eutra_Cell14, tsc_ServingCellRS_EPRE, cs_TimingInfo_Now );

    //@siclog "Step 32" siclog@
    //Check for RRCConnectionRequest on Cell 14
    alt {
      [] SRB.receive( car_SRB0_RrcPdu_IND ( eutra_Cell14, cr_508_RRCConnectionRequest ) )
      {
        //* @verdict fail RRCConnectionRequest received within t_HpPlmn_upper time
        f_EUTRA_SetVerdictFailOrInconc (__FILE__, __LINE__, "Test Case 6.1.1.1 Step 32");
      }
      [] t_HpPlmn_upper.timeout
      {
        SRB.receive( car_SRB0_RrcPdu_IND ( eutra_Cell14, cr_508_RRCConnectionRequest ) );
        //* @verdict pass RRC Connection Request received on PLMN3 / Cell 4 after t_HpPlmn_upper time
        f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "Test Case 6.1.1.1 Step 32");
      }
    }
    
    //@siclog "Step 33 - 37" siclog@
    //Perform TAU procedure steps 2 to 6
    f_EUTRA_TrackingAreaUpdate_WithoutRrcConnReq ( eutra_Cell14 );

    //@siclog "Step 38" siclog@
    //Check if PLMN3 is indicated by UE
    f_UT_PLMN_Check ( UT, "00131" );
    //* @verdict PLMN3 is indicated by UE
    f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "Test Case 6.1.1.1 Step 38");

    //@siclog "Step 39" siclog@
    //Check for no RRCConnectionRequest message on any active cell
    f_EUTRA_CheckNoAttachOn3Cells ( eutra_Cell12,
                                    eutra_Cell13,
                                    eutra_Cell14,
                                    v_WaitTime,//Tolerance is taken care of inside function f_EUTRA_CheckNoAttachOn3Cells
                                    "Test Case 6.1.1.1 Step 39 : RRCConnectionRequest message received within no-response-time");

    f_EUTRA_TestBody_Set ( false );

    //Switch/power off UE
    f_EUTRA_Postamble ( eutra_Cell14, E1_IDLE );
  }

  /*
   * @desc      REFERENCE TS 36.523-1 clause 6.1.1.4
   * @status
   */
  function f_TC_6_1_1_4_EUTRA ( ) runs on EUTRA_PTC {
  
    var NAS_MSG_Indication_Type v_NAS_Ind;
    var SRB_COMMON_IND v_ReceivedAsp;
    var template (value) CellPowerList_Type v_CellPowerList_AtT0, v_CellPowerList_AtT1;
    var NAS_AttDetValue_Type v_AttachType := f_GetEAttachType();
    var template AdditionalUpdateType v_AdditionalUpdateType := f_GetAdditionalUpdateType();
    var B3_Type v_PDNType := f_GetPdnType();
    timer t_IdleMode_GenericTimer := tsc_IdleMode_GenericTimer;

    v_CellPowerList_AtT0 := {
      cs_CellPower (eutra_Cell1, tsc_NonSuitableOffCellRS_EPRE),
      cs_CellPower (eutra_Cell12, tsc_ServingCellRS_EPRE)
    };
    
    v_CellPowerList_AtT1 := {
      cs_CellPower (eutra_Cell12, tsc_NonSuitableOffCellRS_EPRE),
      cs_CellPower (eutra_Cell13, tsc_ServingCellRS_EPRE)
    };

    //Initialise all cell, security and mobile parameters
    //1. c3 initialises SIB2, SIB3 and SIB5 for all cells on same PLMN => no SIB5 would be initialised for cell 12 & 13
    //2. Since cell 12 & cell 13 are on different PLMN than cell 1 => cell 12 and cell 13 will not be present in SIB5 of cell 1
    //3. Prose does not specify any non default combination
    //=> combination 1 will be used
    f_EUTRA_Init(c1);//SIB2 & SIB3 are transmitted

    //Set Sys info and cell infor for cell 12, 13 & 14 to be used @ creation
    f_EUTRA_CellInfo_SetPLMN_1Entry (eutra_Cell1, cs_HPLMN_004_31);//PLMN4
    f_EUTRA_CellInfo_SetPLMN_2Entries (eutra_Cell12, cs_HPLMN_001_11, cs_HPLMN_Def);//PLMN15, PLMN1
    f_EUTRA_CellInfo_SetPLMN_3Entries (eutra_Cell13, cs_HPLMN_001_11, cs_HPLMN_Def, cs_HPLMN_001_21);//PLMN15, PLMN1, PLMN16

    //Set TAC for Cell1, Cell12, Cell13 & Cell14
    //TAC for Cell1 is set to 1 in f_EUTRA_Init
    f_EUTRA_CellInfo_SetTAC (eutra_Cell12, tsc_IdleMode_TAC_Cell12);
    f_EUTRA_CellInfo_SetTAC (eutra_Cell13, tsc_IdleMode_TAC_Cell13);

    //Configure and activate all cells
    f_EUTRA_CellConfig_Def (eutra_Cell1);//Cell 1 is only needed for preamble to set EFLOCI to PLMN4
    f_EUTRA_CellConfig_Def (eutra_Cell12);
    f_EUTRA_CellConfig_Def (eutra_Cell13);

    //Equip UE with a USIM containing default values except for those shown in Table 6.1.1.4.3.1-2
    f_UT_USIM_Insert (UT, "36.523-1 Table 6.1.1.4.3.1-2");
    
    //Make sure the UE is in automatic PLMN selection mode
    f_UT_AutomaticPLMN_Select (UT);

    //Preamble to ensure USIM is updated
    f_EUTRA_Preamble (eutra_Cell1, STATE2_IDLEUPDATE);
    f_EUTRA_UE_Detach_SwitchOffUe (eutra_Cell12, RRC_IDLE);
    
    f_EUTRA_TestBody_Set (true);
    
    //@siclog "Step 1" siclog@
    //Adjust cell configuration according to T0
    f_EUTRA_SetCellPowerList (v_CellPowerList_AtT0, cs_TimingInfo_Now);
    
    //@siclog "Step 2" siclog@
    //Power on UE
    f_UT_SwitchOnUE (UT, false);
    t_IdleMode_GenericTimer.start;

    //@siclog "Step 3" siclog@
    //Receive RRCConnectionRequest on Cell 12
    SRB.receive(car_SRB0_RrcPdu_IND (eutra_Cell12, cr_508_RRCConnectionRequest));
    t_IdleMode_GenericTimer.stop;
    //* @verdict pass RRCConnectionRequest message received on Cell 12
    f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "Test Case 6.1.1.1 Step 3");

    //@siclog "Step 4" siclog@
    //Transmits RRCConnectionSetup
    f_EUTRA_RRC_ConnectionSetup_Def (eutra_Cell1, cs_TimingInfo_Now, tsc_RRC_TI_Def);
    
    //@siclog "Step 5" siclog@
    //Receive RRCConnectionSetupComplete
    SRB.receive(car_SRB1_RrcNasPdu_IND (eutra_Cell12,
                                        cdr_RRCConnectionSetupComplete_2ndSelPlmnId (tsc_RRC_TI_Def, ?),
                                        cr_NAS_IndicationWithPiggybacking(tsc_SHT_IntegrityProtected,
                                                                          cr_508_ATTACH_REQUEST(v_AttachType,
                                                                                                v_AdditionalUpdateType),
                                                                          cr_508_PDN_CONNECTIVITY_REQUEST(tsc_PdnRequest_InitialAttach, v_PDNType))))
      -> value v_ReceivedAsp;
    v_NAS_Ind := v_ReceivedAsp.Signalling.Nas[0];
    
    //@siclog "Step 6-18" siclog@
    //Perform steps 5 to 17 of the registration procedure
    f_EUTRA_IdleUpdated_Step5_17 (eutra_Cell12, STATE2_IDLEUPDATE, NORMAL, v_NAS_Ind);
    
    //@siclog "Step 19" siclog@
    //Check if PLMN1 is indicated by UE
    f_UT_PLMN_Check (UT, "00101");
    //* @verdict pass PLMN1 indicated by UE
    f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "Test Case 6.1.1.4 Step 19");

    //@siclog "Step 20" siclog@
    //Adjust cell configuration according to T1
    f_EUTRA_SetCellPowerList (v_CellPowerList_AtT1, cs_TimingInfo_Now);

    //@siclog "Step 22 - 26" siclog@
    //Perform TAU procedure steps 2 to 6
    f_EUTRA_TrackingAreaUpdate_WithoutRrcConnReq (eutra_Cell13);

    //@siclog "Step 27" siclog@
    //Check if PLMN1 is indicated by UE
    f_UT_PLMN_Check (UT, "00101");
    //* @verdict pass PLMN1 is indicated by UE
    f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "Test Case 6.1.1.4 Step 27");

    f_EUTRA_TestBody_Set (false);

    //Switch/Power off UE
    f_EUTRA_Postamble (eutra_Cell13, E1_IDLE);
  }
  
  /*
   * @desc      REFERENCE TS 36.523-1 clause 6.1.1.6
   * @status
   */
  function f_TC_6_1_1_6_EUTRA ( ) runs on EUTRA_PTC {
  
    var float v_RRC_NoResponseTime := 30.0;//Value according to 36.523-1 Table 6.1.1.6.3.2-1 Step 12.
    var template (value) CellPowerList_Type v_CellPowerList_AtT1, v_CellPowerList_T1toT2, v_CellPowerList_T2toT1, v_CellPowerList_T1toT3;
    timer t_IdleMode_GenericTimer := tsc_IdleMode_GenericTimer;
    
    v_CellPowerList_AtT1 := {
      cs_CellPower (eutra_Cell12, tsc_ServingCellRS_EPRE),
      cs_CellPower (eutra_Cell14, tsc_ServingCellRS_EPRE)
    };
    v_CellPowerList_T1toT2 := {
      cs_CellPower (eutra_Cell1, tsc_NonSuitableOffCellRS_EPRE),
      cs_CellPower (eutra_Cell14, tsc_NonSuitableOffCellRS_EPRE)
    };
    v_CellPowerList_T2toT1 := {
      cs_CellPower (eutra_Cell1, tsc_ServingCellRS_EPRE),
      cs_CellPower (eutra_Cell14, tsc_ServingCellRS_EPRE)
    };
    v_CellPowerList_T1toT3 := {
      cs_CellPower (eutra_Cell12, tsc_NonSuitableOffCellRS_EPRE),
      cs_CellPower (eutra_Cell13, tsc_ServingCellRS_EPRE)
    };
    
    //Initialise all cell, security and mobile parameters
    //1. c3 initialises SIB2, SIB3 and SIB5 for all cells on same PLMN => no SIB5 would be initialised for cell 12, 13 & 14
    //2. Since cells 12, 13 & 14 are on different PLMN than cell 1 => cell 12, 13 & 14 will not be present in SIB5 of cell 1
    //3. Prose does not specify any non default combination
    //=> combination 1 will be used
    f_EUTRA_Init(c1);//SIB2 & SIB3 are transmitted
    
    //PLMNs will be according to 36.508 Table 4.4.2-2. i.e.:
    //Cell1 PLMN1 : 00101
    //Cell12 PLMN2  : 00211
    //Cell13 PLMN3 : 00321
    //Cell14 PLMN4 : 00431
    
    //Set TAC for Cell1, Cell12 & Cell13
    //TAC for Cell1 is set to 1 in f_EUTRA_Init
    f_EUTRA_CellInfo_SetTAC (eutra_Cell12, tsc_IdleMode_TAC_Cell12);
    f_EUTRA_CellInfo_SetTAC (eutra_Cell13, tsc_IdleMode_TAC_Cell13);
    f_EUTRA_CellInfo_SetTAC (eutra_Cell14, tsc_IdleMode_TAC_Cell14);
    
    //Create and configure all cells
    f_EUTRA_CellConfig_Def (eutra_Cell1);
    f_EUTRA_CellConfig_Def (eutra_Cell12);
    f_EUTRA_CellConfig_Def (eutra_Cell13);
    f_EUTRA_CellConfig_Def (eutra_Cell14);
  
    //Equip UE with a USIM containing default values except for those shown in Table 6.1.1.6.3.1-2
    f_UT_USIM_Insert (UT, "36.523-1 Table 6.1.1.6.3.1-2");
    
    //Make sure the UE is in automatic PLMN selection mode
    f_UT_AutomaticPLMN_Select (UT);
    
    //Bring UE to initial state
    f_EUTRA_Preamble (eutra_Cell1, STATE2_IDLEUPDATE);
    
    f_EUTRA_TestBody_Set (true);
    
    //@siclog "Step 1" siclog@
    //Set power level setting according to the row "T1" in table 6.1.1.6.3.2-1
    f_EUTRA_SetCellPowerList ( v_CellPowerList_AtT1, cs_TimingInfo_Now );
    t_IdleMode_GenericTimer.start;
    
    //@siclog "Step 2" siclog@
    //Cause the UE in Automatic network selection mode to initiate reselection and registration onto an available PLMN
    //FFS - See open isse
    
    //@siclog "Step 3" siclog@
    //Start Idle Mode generic timer and wait for RRCConnectionRequest on Cell 12
    SRB.receive(car_SRB0_RrcPdu_IND (eutra_Cell12, cr_508_RRCConnectionRequest));
    t_IdleMode_GenericTimer.stop;
    //* @verdict pass RRCConnectionRequest message received on Cell 12
    f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "Test Case 6.1.1.6 Step 3");
    
    //@siclog "Step 4-8" siclog@
    //Perform steps 2-6 of TAU procedure (36.508 cl. 6.4.2.7)
    f_EUTRA_TrackingAreaUpdate_WithoutRrcConnReq (eutra_Cell12);
    
    //@siclog "Step 9" siclog@
    //Check if PLMN2 is indicated by UE
    f_UT_PLMN_Check (UT, "00211");
    
    //@siclog "Step 10" siclog@
    //Set power level setting according to the row "T2" in table 6.1.1.6.3.2-1
    f_EUTRA_SetCellPowerList (v_CellPowerList_T1toT2, cs_TimingInfo_Now);
    
    //@siclog "Step 11" siclog@
    //Cause the UE in Automatic network selection mode to initiate reselection and registration onto an available PLMN
    //FFS - See open isse
    
    //@siclog "Step 12" siclog@
    //Start wait timer and wait for RRCConnectionRequest on Cell 12
    f_EUTRA_CheckNoAttachOn1Cell (eutra_Cell12,
                                  v_RRC_NoResponseTime,
                                  "Test Case 6.1.1.6 Step 12 : RRCConnectionRequest message received on Cell 12 within wait time");
    
    //@siclog "Step 13" siclog@
    //Check if PLMN2 is indicated by UE
    f_UT_PLMN_Check (UT, "00211");
    //* @verdict pass PLMN2 is indicated by UE
    f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "Test Case 6.1.1.6 Step 13");
    
    //@siclog "Step 14" siclog@
    //Set power level setting according to the row "T1" in table 6.1.1.6.3.2-1
    f_EUTRA_SetCellPowerList (v_CellPowerList_T2toT1, cs_TimingInfo_Now);
    t_IdleMode_GenericTimer.start;
    
    //@siclog "Step 15" siclog@
    //Cause the UE in Automatic network selection mode to initiate reselection and registration onto an available PLMN
    //FFS - See open isse
    
    //@siclog "Step 16" siclog@
    //Start Idle Mode generic timer and wait for RRCConnectionRequest on Cell 1
    SRB.receive(car_SRB0_RrcPdu_IND (eutra_Cell1, cr_508_RRCConnectionRequest));
    t_IdleMode_GenericTimer.stop;
    //* @verdict pass RRCConnectionRequest message received on Cell 1
    f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "Test Case 6.1.1.6 Step 16");
    
    //@siclog "Step 17-21" siclog@
    //Perform steps 2-6 of TAU procedure (36.508 cl. 6.4.2.7)
    f_EUTRA_TrackingAreaUpdate_WithoutRrcConnReq (eutra_Cell1);
    
    //@siclog "Step 22" siclog@
    //Check if PLMN1 is indicated by UE
    f_UT_PLMN_Check (UT, "00101");
    //* @verdict pass PLMN1 is indicated by UE
    f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "Test Case 6.1.1.6 Step 22");
    
    //@siclog "Step 23" siclog@
    //Set power level setting according to the row "T3" in table 6.1.1.6.3.2-1
    f_EUTRA_SetCellPowerList (v_CellPowerList_T1toT3, cs_TimingInfo_Now);
    t_IdleMode_GenericTimer.start;
    
    //@siclog "Step 24" siclog@
    //Cause the UE in Automatic network selection mode to initiate reselection and registration onto an available PLMN
    //FFS - See open isse
    
    //@siclog "Step 25" siclog@
    //Start Idle Mode generic timer and wait for RRCConnectionRequest on Cell 13
    SRB.receive( car_SRB0_RrcPdu_IND ( eutra_Cell13, cr_508_RRCConnectionRequest ) );
    t_IdleMode_GenericTimer.stop;
    //* @verdict pass RRCConnectionRequest message received on Cell 13
    f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "Test Case 6.1.1.6 Step 25");
    
    //@siclog "Step 26-30" siclog@
    //Perform steps 2-6 of TAU procedure (36.508 cl. 6.4.2.7)
    f_EUTRA_TrackingAreaUpdate_WithoutRrcConnReq (eutra_Cell13);
    
    //@siclog "Step 31" siclog@
    //Check if PLMN3 is indicated by UE
    f_UT_PLMN_Check (UT, "00321");
    //* @verdict pass PLMN1 is indicated by UE
    f_EUTRA_PreliminaryPass (__FILE__, __LINE__, "Test Case 6.1.1.6 Step 31");
    
    f_EUTRA_TestBody_Set (false);
    
    //Switch/Power off UE
    f_EUTRA_Postamble (eutra_Cell13, E1_IDLE);
  }
  
}
