/******************************************************************************/
// @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_GERAN
{
//=========================================================================
// Imports
//=========================================================================

  import from GERAN_Component all;
  import from GERAN_CommonFunctions all;
  import from CommonDefs all;
  import from CommonIratDefs all;
  import from GERAN_Templates all;
  import from GERAN_TypeDefs all;

  //==============================================================================
  // Templates
  //==============================================================================
  template (value) EUTRANMeasParams_SI2 cs_EUTRAN_MeasParams_SI2_6232 (template (value) RptdEARFCN_BW p_RptdARFCNs) := {
    eutranCCNActive := '0'B,
    eutranMask      := '1'B,
    eutranMeasParams := cs_EUTRAN_MeasParams,
    gprsEutranMeasMask := '0'B,
    gprsEutranMeasParams := omit,
    neighCells := cs_RptdEARFCNNeighCell_6232 (p_RptdARFCNs),
    notAllowedCells := cs_EUTRANNotAllowedCellsNone,
    pcidToTA := cs_TAMappingNone
  };
  
  template (value) RptdEUTRANNeighCells cs_RptdEARFCNNeighCell_6232 (template (value) RptdEARFCN_BW p_RptdARFCNs) := {
    {
      prefix  := '1'B,
      cell := cs_EARFCNNeighCell_6232 (p_RptdARFCNs)
    },
    {
      prefix := '0'B,
      cell   := omit
    }
  };
  
  template (value) EUTRANNeighCell cs_EARFCNNeighCell_6232 (template (value) RptdEARFCN_BW p_RptdARFCNs) :=
  {
    earfcnBW := p_RptdARFCNs,
    pMask    := '1'B,
    priority := '100'B,
    threshHigh := '00010'B,
    lowMask := '1'B,
    threshLow := '00010'B,
    qMask := '1'B,
    eutranQrxLevelMin := '00000'B // -140 dBm FFS
  };
  
  template (value) RptdEARFCN_BW cs_RptdEARFCNList1 (B16_Type p_ARFCN1) := {
    cs_EARFCN_BWList (p_ARFCN1),
    cs_EARFCN_BWEmpty
  };
  
  
  //==============================================================================
  // Constants
  //==============================================================================
  
  //constant to use as dummy value
  const B16_Type tsc_B16_SQN0 := int2bit(0,16);
  
  //==============================================================================
  // 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_GERAN ( ) runs on GERAN_PTC
  {
    var boolean v_TriggerRxd := false;
    //@sic Created T3 and removed T0 from CR R5-104784 @sic
    var integer v_T2_T3_RF_SignalLevel_Cell24 := tsc_GERAN_ChPwrLvl_Off;
    var integer v_T1_RF_SignalLevel_Cell24 := -80;
    var integer v_T3_RF_SignalLevel_Cell25 := -80;
    var float v_WaitTime := 5.0;
    
    //* @desc Initialise all cells
    f_GERAN_Init (EUTRA_GERAN);
    
    // Create GERAN cells
    f_GERAN_CreateCell (geran_Cell24);
    f_GERAN_CreateCell (geran_Cell25);
    
    //* @desc Coordinate with E-UTRA component to send GERAN frequencies
    f_GERAN_Send_IR_SysInfoToEUTRA ( 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 );
    
    //@siclog "Step 1" siclog@
    //* @desc Trigger 1: Wait for completion of preamble in EUTRA and then
    //* set cell parameters according to T1 in Table 6.2.3.1.3.2-2
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger ( EUTRA );
    f_GERAN_SetCellPowerLevel ( geran_Cell24, v_T1_RF_SignalLevel_Cell24 );
    
    //@siclog "Step 2" siclog@
    //does the test result of generic test procedure in 36.508
    //subclause 6.4.2.9 indicate that the UE is camped on GERAN Cell 24?
    f_GERAN_IdleMode_RAU( geran_Cell24 );

    //@siclog "Step 3 Void" siclog@

    //@siclog "Step 4" siclog@
    //Wait for 5 seconds */
    f_Delay ( v_WaitTime );
    
    //@siclog "Step 5" siclog@
    //and Trigger 2: set cell24 parameters according to T2 in Table 6.2.3.1.3.2-2
    f_GERAN_SetCellPowerLevel( geran_Cell24, v_T2_T3_RF_SignalLevel_Cell24 );
    f_SendIRATCoOrd (EUTRA, cms_IRAT_Trigger);
    
    //@siclog "Step 8" siclog@
    //Trigger 3:
    //* set cell parameters for Cell25 according to T3 in Table 6.2.3.1.3.2-2
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger ( EUTRA );
    f_GERAN_SetCellPowerLevel ( geran_Cell25, v_T3_RF_SignalLevel_Cell25 );

    //@siclog "Step 9 Void" siclog@
    
    //@siclog "Step 10" siclog@
    //does the test result of generic test procedure in 36.508
    //subclause 6.4.2.9 indicate that the UE is camped on GERAN Cell 25?
    f_GERAN_IdleMode_RAU( geran_Cell25 );
    
    //* @desc Trigger4: Tell the EUTRA component that the test is over
    f_SendIRATCoOrd ( EUTRA, cms_IRAT_Trigger );
    
    f_GERAN_TestBody_Set ( false );
    
    //* @desc Release GERAN Cells
    f_GERAN_SS_CellRelease ( geran_Cell24 );
    f_GERAN_Postamble (geran_Cell25, G1_IDLE);
  }
  
  //* @ 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_GERAN ( ) runs on GERAN_PTC
  {
    var boolean v_TriggerRxd := false;
    //@sic Removed T0 from CR R5-104785 @sic
    //var integer v_T0_RF_SignalLevel_Cell24 := -80;
    var template(value) SYSTEMINFORMATIONTYPE2quater v_SI2quater;
    var IRAT_CoOrd_SysInfo_Type v_EUTRA_SysInfo;
    
    //* @desc Initialise all cells
    f_GERAN_Init (EUTRA_GERAN);
    
    //* @desc Wait for EUTRA cell information to configure in GERAN cell
    v_EUTRA_SysInfo := f_WaitForIRATCoOrd_SysInfo (EUTRA);
    
    //Configure Repeated E-UTRA Neighbour Cells specific message contents,
    //change SI2q according to test case
    v_SI2quater := cs_SysInfoType2quater(cs_SI2quaterRO('0001'B, '0001'B,'0'B, omit,
                                                        '1'B, cs_SI2quaterMeasParams3G_ISHO,
                                                        '0'B, omit,
                                                        cs_EUTRAN_MeasParams_SI2_6232 (cs_RptdEARFCNList1(int2bit(v_EUTRA_SysInfo.Eutra[0].Arfcn,16)))));
    
    // valueof cannot be avoided here
    //* @desc Set the SI2 with the information provided from E-UTRA
    f_GERAN_SysInfo_SetSI2q_2 (geran_Cell24, valueof(v_SI2quater));
    
    // Create GERAN cell and broadcast modified System Infomation
    f_GERAN_CreateCell (geran_Cell24);
    
    // Registered, Idle Mode (state 2) on a GERAN cell
    f_GERAN_Preamble (geran_Cell24);

    f_GERAN_TestBody_Set( true );
    
    //@siclog "Step 1" siclog@
    //* @desc Trigger 1: Tell the EUTRA component that Cell 24 is configured
    f_SendIRATCoOrd (EUTRA, cms_IRAT_Trigger);
    
    //@siclog "Step 2" siclog@
    //* @desc Trigger 2: Wait for completion of test case
    v_TriggerRxd := f_WaitForIRATCoOrd_Trigger ( EUTRA );
    
    f_GERAN_TestBody_Set ( false );
    
    //* @desc Release Cell 5
    f_GERAN_SS_CellRelease ( geran_Cell24 );
  }
}
