/******************************************************************************/
// @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-08 19:00:20 +0200 (Wed, 08 Sep 2010) $
// $Rev: 3836 $
/******************************************************************************/
module InterRat_CellReSelection_EtoG
{
//=========================================================================
// Imports
//=========================================================================

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

  import from EUTRA_Component all;
  import from EUTRA_CommonDefs all;
  import from EUTRA_CellInfo all;
  import from EUTRA_ConfigurationSteps all;
  import from EUTRA_CommonProcedures all;
  import from EUTRA_AspCommon_Templates all;
  import from EUTRA_ASP_TypeDefs all;
  import from EUTRA_SysInfo_Templates all;
  import from EUTRA_IdleMode all;
  import from EUTRA_NASSteps all;
  import from EUTRA_IRATFunctions all;

  template (value) SystemInformationBlockType7 cds_SystemInformationBlockType7_T_ReselectionGeran(template (omit) CarrierFreqsInfoListGERAN p_CarrierFreqsInfoListGERAN,
                                                                                                      T_Reselection p_T_ReselectionGeran)
  modifies cs_508_SystemInformationBlockType7_Def:=
  {
    t_ReselectionGERAN      := p_T_ReselectionGeran,
    carrierFreqsInfoList    := p_CarrierFreqsInfoListGERAN
  };


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

  //* @ desc Test case 6.2.3.1 Inter-RAT Cell Reselection /
  //* @ from E-UTRA RRC_IDLE to GSM_Idle/GPRS Packet_Idle
  function f_TC_6_2_3_1_EUTRA ( ) runs on EUTRA_PTC {

    var boolean v_TriggerRxd := false;
    var float v_WaitTime := 5.0;
    var IRAT_CoOrd_SysInfo_Type v_GERANSysInfo;
    var CellRes_Prio_Type v_CellRes_Prio_initial := 4;
    var ReselectionThreshold v_ThreshServingLow_Cell1 := 10;

    //@sic Created T3 and removed T0 from CR R5-104784 @sic
    var AbsoluteCellPower_Type v_T2_Cell_Specific_RS_EPRE_Cell1 := -60;
    var AbsoluteCellPower_Type v_T1_Cell_Specific_RS_EPRE_Cell1 := -70;
    var AbsoluteCellPower_Type v_T3_Cell_Specific_RS_EPRE_Cell1 := -100;

    timer t_IdleMode_GenericTimer := tsc_IdleMode_GenericTimer;

    //* @desc Initialise all cells, security and mobile parameters
    f_EUTRA_Init( c5 );//Combination 5 in TS 36.508 section 4.4.3.1.1

    //* @desc Set maximum cell power level for Cell 1
    f_EUTRA_CellInfo_InitMaxReferencePower ( eutra_Cell1, -60 );

    //* @desc Coordinate with GERAN component to receive GERAN frequencies
    v_GERANSysInfo := f_WaitForIRATCoOrd_SysInfo (GERAN);

    // default values before start
    //* @desc Set Sys. info for Cell 1 to be used in creation (according to Table 6.2.3.1.3.2-1)
    f_EUTRA_CellInfo_SetSIB7 ( eutra_Cell1,
                               cds_SystemInformationBlockType7_T_ReselectionGeran (
                                  { cds_CarrierFreqsInfoGERAN_CellReselectionPriority (
                                           cs_CarrierFreqsGERAN( //Geran[0] is cell24
                                               v_GERANSysInfo.Geran[0].Arfcn,
                                               f_ConvertGERAN_Band(v_GERANSysInfo.Geran[0].BandIndicator),
                                               fl_ConvertGERANNeighCell(v_GERANSysInfo.Geran[0].NeighCells)
                                           ), 5
                                    ),
                                    cds_CarrierFreqsInfoGERAN_CellReselectionPriority (
                                           cs_CarrierFreqsGERAN(//Geran[1] is cell25
                                               v_GERANSysInfo.Geran[1].Arfcn,
                                               f_ConvertGERAN_Band(v_GERANSysInfo.Geran[1].BandIndicator),
                                               fl_ConvertGERANNeighCell(v_GERANSysInfo.Geran[1].NeighCells)
                                           ), 3
                                    )
                                  },
                                  7  // t_ReselectionGeran parameter updated as Table 6.2.3.1.3.3-2
                               )
                             );

    // --- Update SIB3 ---
    //* @desc Set system information according to specific message contents
    f_EUTRA_CellInfo_SetSysInfo_CellRes_Prio ( eutra_Cell1, v_CellRes_Prio_initial );
    f_EUTRA_CellInfo_SetSysInfo_ThreshServingLow ( eutra_Cell1, v_ThreshServingLow_Cell1 );

    //* @desc Create and configure Cell 1
    f_EUTRA_CellConfig_Def ( eutra_Cell1 );

    //* @desc Preamble to ensure USIM is updated with valid TAI and to bring UE to initial state
    f_EUTRA_Preamble_InterRAT(eutra_Cell1, STATE2_IDLEUPDATE, GERAN);

    f_EUTRA_TestBody_Set ( true );

    //@siclog "Step 1" siclog@
    //Set cell1 paramters according to T1
    f_EUTRA_SetCellPower ( eutra_Cell1, v_T1_Cell_Specific_RS_EPRE_Cell1, cs_TimingInfo_Now );

    //* @desc Trigger 1: GERAN component steps
    f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);

    //* @desc Wait for trigger2
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger ( GERAN );
    
    //@siclog "Step 5" siclog@
    //Set cell1 paramters according to T2 in Table 6.2.3.1.3.2-1
    f_EUTRA_SetCellPower ( eutra_Cell1, v_T2_Cell_Specific_RS_EPRE_Cell1, cs_TimingInfo_Now );

    //@siclog "Step 6" siclog@
    //UE reselects cell1 and completes tracking area update procedure
    t_IdleMode_GenericTimer.start;
    f_EUTRA_TrackingAreaUpdate (eutra_Cell1, tsc_RRC_TI_Def);
    t_IdleMode_GenericTimer.stop;

    //@siclog "Step 7" siclog@
    // Wait for 5 seconds */
    f_Delay ( v_WaitTime );

    //@siclog "Step 8" siclog@
    //Set cell1 paramters according to T3
    f_EUTRA_SetCellPower ( eutra_Cell1, v_T3_Cell_Specific_RS_EPRE_Cell1, cs_TimingInfo_Now );
    //* @desc Trigger 3: Set cell25 parameters according to T2 in the GERAN component
    f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);

    //* @desc Wait for the end of the test case
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger ( GERAN );

    f_EUTRA_TestBody_Set ( false );

    //* @desc Remove the non-camping cell
    f_EUTRA_ReleaseAllCells( );
  }


  //* @ desc Test case 6.2.3.2 Inter-RAT Cell Reselection /
  //* @ from GSM_Idle/GPRS Packet_Idle to E-UTRA
  function f_TC_6_2_3_2_EUTRA ( ) runs on EUTRA_PTC {

    var boolean v_TriggerRxd := false;
    var Q_Rxlevmin_Type v_Q_Rxlevmin := -55;
    var AbsoluteCellPower_Type v_T1_Cell_Specific_RS_EPRE_Cell1 := -70;

    //* @desc Initialise all cells, security and mobile parameters
    f_EUTRA_Init( c5 );//EUTRA-GERAN configuration

    //* @desc Set maximum cell power level for Cell 1
    f_EUTRA_CellInfo_InitMaxReferencePower ( eutra_Cell1, -70 );

    //* @desc Set Sys. info for Cell 1 to be used in creation (according to Table 6.2.3.2.3.2-1)
    f_EUTRA_CellInfo_SetSysInfo_Q_Rxlevmin ( eutra_Cell1, v_Q_Rxlevmin );

    //* @desc Create and configure Cell 1
    f_EUTRA_CellConfig_Def ( eutra_Cell1 );

    //* @desc Send cell information to Geran side to update SI
    f_IRAT_Send_EUTRA_SysInfoToOtherPort(GERAN, f_EUTRA_CellInfo_GetEARFCN_DL(eutra_Cell1));

    f_EUTRA_TestBody_Set ( true );

    //* @desc Trigger 1: Wait for GERAN configuration
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger ( GERAN );

    //@siclog "Step 1" siclog@
    //Set cell1 paramters according to T1
    f_EUTRA_SetCellPower ( eutra_Cell1, v_T1_Cell_Specific_RS_EPRE_Cell1, cs_TimingInfo_Now );

    //@siclog "Step 2" siclog@
    //Check that UE camps on Cell 1 with the generic test procedure TS 36.508 subclause 6.4.2.7A
    f_EUTRA_IdleMode_TAU_UponMobility_FromOtherRAT ( eutra_Cell1 );

    //* @desc Trigger 2: Tell the GERAN component that the test case is over
    f_SendIRATCoOrd (GERAN, cms_IRAT_Trigger);

    f_EUTRA_TestBody_Set ( false );

    //* @desc Switch off UE and expect Detach Request
    f_EUTRA_Postamble ( eutra_Cell1, E1_IDLE ); //@sic R5-103875 sic@
  }
}
