/******************************************************************************/
// @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-08-19 00:48:00 +0200 (Thu, 19 Aug 2010) $
// $Rev: 3727 $
/******************************************************************************/

module RRC_Measurement_C2K {

  import from EUTRA_RRC_ASN1_Definitions language "ASN.1:1997" all;
  import from EUTRA_Component all;
  //import from Parameters all;
  //import from CommonDefs all;
  import from CommonIratDefs all;
  import from EUTRA_CommonDefs all;
  import from EUTRA_RRC_Templates all;
  import from EUTRA_SRB_Templates all;
  import from EUTRA_AspCommon_Templates all;
  import from EUTRA_CellInfo all;
  import from EUTRA_CommonProcedures all;
  import from EUTRA_ConfigurationSteps all;
  import from EUTRA_Measurement_Templates all;
  import from EUTRA_Measurement_Specific_Templates all;
  import from EUTRA_Timing all;
  
  type integer CDMA2000_PilotPnPhase (0..32767);  //
  type integer CDMA2000_PilotStrength (0..63);    //
  const integer tsc_IdMeasObject_f14 := 14; // Meas object Id for CDMA2000    //
  const integer tsc_IdReportConfig_B2_CDMA2000 := 13;  // Report Config Id for CDMA2000  //
  
  //----------------------------------------------------------------------------
  /* TO BE MOVED - Copied from RRC_Measurement
   * @desc      Check that no measurement report is received within certain time1
   * @param     p_CellId
   * @param     p_Timer
   * @param     p_MeasurementReport
   * @status
   */
  function fl_NoMeasurementReport(CellId_Type p_CellId,
                                  float p_Timer,
                                  template (present) UL_DCCH_Message p_MeasurementReport) runs on EUTRA_PTC
  {
    timer t_Wait;
    t_Wait.start(p_Timer);
    alt {
      [] t_Wait.timeout
        {
        }
      [] SRB.receive( car_SRB1_RrcPdu_IND( p_CellId, p_MeasurementReport ) )
        {
          f_EUTRA_SetVerdictFailOrInconc( __FILE__, __LINE__, "" );
        }
    }
  }; // end of function fl_NoMeasurementReport
  
  
  group SpecificTemplates{
  //------------------------------------------------
  //8.3.2.7_start Step1
  template (value) DL_DCCH_Message cs_RRCConnectionReconfiguration_8_3_2_7_Step1 (RRC_TransactionIdentifier p_RRC_TI,
                                                                                  CDMA2000_Type p_CDMA2000_Type,
                                                                                  ARFCN_ValueCDMA2000 p_ARFCNCDMA2000,
                                                                                  BandclassCDMA2000 p_BandClassCDMA2000,
                                                                                  SearchWindowSize_Type p_SearchWindowSize) :=
    cs_508_RRCConnectionReconfiguration_ConditionMEAS(p_RRC_TI,
                                                      cs_MeasConfig(omit,
                                                                    cs_MeasObjectToAddModList_1Entry(tsc_IdMeasObject_f14,
                                                                                                     cs_MeasObject_measObjectCDMA2000(p_CDMA2000_Type,
                                                                                                                                      p_ARFCNCDMA2000,
                                                                                                                                      p_BandClassCDMA2000,
                                                                                                                                      p_SearchWindowSize,
                                                                                                                                      0,
                                                                                                                                      omit,
                                                                                                                                      omit,
                                                                                                                                      omit ) ),
                                                                    omit,
                                                                    cs_ReportConfigToAddModList_1Entry(tsc_IdReportConfig_B2_CDMA2000, // why isin't tsc_IdReportConfig_B2_GERAN used in 8.3.2.1?
                                                                                                       cs_508_ReportConfigInterRAT_B2_CDMA2000( -69 ) ),
                                                                    omit,
                                                                    cs_MeasIdToAddModList_1Entry( 1, tsc_IdMeasObject_f14, tsc_IdReportConfig_B2_CDMA2000 ), // why isin't tsc_IdReportConfig_B2_GERAN used in 8.3.2.1?
                                                                    cs_QuantityConfig( omit, omit, omit, cs_QuantityConfigCDMA2000( pilotStrength ) ),  // 0 is just put here for compiling, this value is measQuantityCDMA2000 and is currently FFS as per 36508
                                                                    cs_508_MeasGapConfig_GP2 // currently using this since the MeasGapConfig for CDMA2000 is not defined and the MeasGapConfig given in 36523 in test case prose cannot be found
                                                                    ) );
  // 8.3.2.7_end
  
  //8.3.2.8, Step1
  template (value) DL_DCCH_Message cs_RRCConnectionReconfiguration_8_3_2_8_Step1(RRC_TransactionIdentifier p_RRC_TI,
                                                                                 CDMA2000_Type p_CDMA2000_Type,
                                                                                 ARFCN_ValueCDMA2000 p_ARFCNCDMA2000,
                                                                                 BandclassCDMA2000 p_BandClassCDMA2000,
                                                                                 SearchWindowSize_Type p_SearchWindowSize ) :=
    cs_508_RRCConnectionReconfiguration_ConditionMEAS(p_RRC_TI,
                                                      cs_MeasConfig(omit,
                                                                    cs_MeasObjectToAddModList_1Entry(tsc_IdMeasObject_f14,
                                                                                                     cs_MeasObject_measObjectCDMA2000(p_CDMA2000_Type,
                                                                                                                                      p_ARFCNCDMA2000,
                                                                                                                                      p_BandClassCDMA2000,
                                                                                                                                      p_SearchWindowSize,
                                                                                                                                      0,
                                                                                                                                      omit,
                                                                                                                                      omit,
                                                                                                                                      omit ) ),
                                                                    omit,
                                                                    cs_ReportConfigToAddModList_1Entry(tsc_IdReportConfig_B2_CDMA2000, // why isin't tsc_IdReportConfig_B2_GERAN used in 8.3.2.1?
                                                                                                       cs_508_ReportConfigInterRAT_Periodical ),
                                                                    omit,
                                                                    cs_MeasIdToAddModList_1Entry( 1, tsc_IdMeasObject_f14, tsc_IdReportConfig_B2_CDMA2000 ), // why isin't tsc_IdReportConfig_B2_GERAN used in 8.3.2.1?
                                                                    cs_QuantityConfig( omit, omit, omit, cs_QuantityConfigCDMA2000( pilotStrength ) ),  // 0 is just put here for compiling, this value is measQuantityCDMA2000 and is currently FFS as per 36508
                                                                    cs_508_MeasGapConfig_GP2 // currently using this since the MeasGapConfig for CDMA2000 is not defined and the MeasGapConfig given in 36523 in test case prose cannot be found
                                                                    ) );
  
  //8.3.2.8, Step10
  template (value) DL_DCCH_Message cs_RRCConnectionReconfiguration_8_3_2_8_Step10(RRC_TransactionIdentifier p_RRC_TI ) :=
    cs_508_RRCConnectionReconfiguration_ConditionMEAS(p_RRC_TI,
                                                      cs_MeasConfig(omit,
                                                                    omit,
                                                                    omit,
                                                                    omit,
                                                                    cs_MeasIdToRemoveList_1Entry( 1 ),
                                                                    omit ) );
  //------------------------------------------------
  
  //8.3.2.8_start, Meas report Parallel to Steps 3,4 and steps 9, 10
  template UL_DCCH_Message cr_MeasurementReport_8_3_2_8_Step3_Step4_Step9_Step10(integer p_PhysCellId ) :=
  cr_MeasurementReport(
    1, ?, ?,
    cr_MeasResultNeighCells_measResultsCDMA2000_1Entry( false, p_PhysCellId, omit, ?, ? ) );
  //8.3.2.8_end
  
  //------------------------------------------------
  
  //------------------------------------------------
  
  //8.3.2.8_start, Meas report parallel to steps 6,7
  template UL_DCCH_Message cr_MeasurementReport_8_3_2_8_Step6_Step7(integer p_PhysCellId15,
                                                                    integer p_PhysCellId16) :=
  cr_MeasurementReport(
    1, ?, ?,
    cr_MeasResultNeighCells_measResultsCDMA2000_2Entries( false, p_PhysCellId15, p_PhysCellId16, omit, omit, ?, ?, ?, ? ) );
  //8.3.2.8_end
  
  //8.3.2.7_start, Step5
  template UL_DCCH_Message cr_MeasurementReport_8_3_2_7_Step5(integer p_PhysCellId) :=
  cr_MeasurementReport(
    1, ?, ?,
    cr_MeasResultNeighCells_measResultsCDMA2000_1Entry( false, p_PhysCellId, omit, ?, ? ) );
  //8.3.2.7_end
  //------------------------------------------------
  //measObjectToAddMod.measObject(CHOICE: measObjectCDMA2000)
  
  //cs_MeasObject_measObjectCDMA2000
  template (value) MeasObjectToAddMod.measObject cs_MeasObject_measObjectCDMA2000(CDMA2000_Type p_CDMA2000_Type,
                                                                                  ARFCN_ValueCDMA2000 p_ARFCN,
                                                                                  BandclassCDMA2000 p_BandClass,
                                                                                  SearchWindowSize_Type p_SearchWindowSize,
                                                                                  template (omit) Q_OffsetRangeInterRAT p_OffsetFreq,
                                                                                  template (omit) CellIndexList p_CellsToRemoveList,
                                                                                  template (omit) MeasObjectCDMA2000.cellsToAddModList p_CellsToAddModList,
                                                                                  template (omit) MeasObjectCDMA2000.cellForWhichToReportCGI p_CellForWhichToReportCGI ) := {
    measObjectCDMA2000 := {
      cdma2000_Type := p_CDMA2000_Type,
      carrierFreq := {
        bandClass := p_BandClass,
        arfcn := p_ARFCN
      },
      searchWindowSize := p_SearchWindowSize,
      offsetFreq := p_OffsetFreq,
      cellsToRemoveList := p_CellsToRemoveList,
      cellsToAddModList := p_CellsToAddModList,
      cellForWhichToReportCGI := p_CellForWhichToReportCGI
    }
  };
  
  //------------------------------------------------
  //quantityConfig.quantityConfigCDMA2000

  //cs_QuantityConfigCDMA2000
  template (value) QuantityConfigCDMA2000 cs_QuantityConfigCDMA2000 (QuantityConfigCDMA2000.measQuantityCDMA2000 p_MeasQuantityCDMA2000 ) :=
  {
    measQuantityCDMA2000 := p_MeasQuantityCDMA2000
  };

  //------------------------------------------------
  //measurementReport_r8.measResultNeighCells(CHOICE: MeasResultListCDMA2000)

  //cr_MeasResultNeighCells_measResultListCDMA2000_1Entry
  template MeasResults.measResultNeighCells cr_MeasResultNeighCells_measResultsCDMA2000_1Entry(template boolean p_PreRegistrationStatusHRPD,
                                                                                               template PhysCellIdCDMA2000 p_PhysCellId,
                                                                                               template MeasResultCDMA2000.cgi_Info p_Cgi_Info,
                                                                                               template CDMA2000_PilotPnPhase p_PilotPnPhase,
                                                                                               template CDMA2000_PilotStrength p_PilotStrength ) := {
    measResultsCDMA2000 := {
      preRegistrationStatusHRPD := p_PreRegistrationStatusHRPD,
      measResultListCDMA2000 := {
        {
          physCellId := p_PhysCellId,
          cgi_Info := p_Cgi_Info,
          measResult := {
            pilotPnPhase := p_PilotPnPhase,
            pilotStrength := p_PilotStrength
          }
        }
      }
    }
  };

  //cr_MeasResultNeighCells_measResultListCDMA2000_2Entries
  template MeasResults.measResultNeighCells cr_MeasResultNeighCells_measResultsCDMA2000_2Entries(template boolean p_PreRegistrationStatusHRPD,
                                                                                                 template PhysCellIdCDMA2000 p_PhysCellId15,
                                                                                                 template PhysCellIdCDMA2000 p_PhysCellId17,
                                                                                                 template MeasResultCDMA2000.cgi_Info p_Cgi_Info_cell15,
                                                                                                 template MeasResultCDMA2000.cgi_Info p_Cgi_Info_cell17,
                                                                                                 template CDMA2000_PilotPnPhase p_PilotPnPhase_cell15,
                                                                                                 template CDMA2000_PilotPnPhase p_PilotPnPhase_cell17,
                                                                                                 template CDMA2000_PilotStrength p_PilotStrength_cell15,
                                                                                                 template CDMA2000_PilotStrength p_PilotStrength_cell17 ) := {
    measResultsCDMA2000 := {
      preRegistrationStatusHRPD := p_PreRegistrationStatusHRPD,
      measResultListCDMA2000 := {
        {
          physCellId := p_PhysCellId15,
          cgi_Info := p_Cgi_Info_cell15,
          measResult := {
            pilotPnPhase := p_PilotPnPhase_cell15,
            pilotStrength := p_PilotStrength_cell15
          }
        },
        {
          physCellId := p_PhysCellId17,
          cgi_Info := p_Cgi_Info_cell17,
          measResult := {
            pilotPnPhase := p_PilotPnPhase_cell17,
            pilotStrength := p_PilotStrength_cell17
          }
        }
      }
    }
  };
  
  template (value) ReportConfigToAddMod.reportConfig cs_508_ReportConfigInterRAT_B2_CDMA2000( EUTRA_RS_EPRE_Type p_EUTRA_Thres ) :=
  {
    reportConfigInterRAT := {
      triggerType := {
        event := {
          eventId := {
            eventB2 := {
              b2_Threshold1 := {
                threshold_RSRP := p_EUTRA_Thres + 140 //Changed back from 141 (CR R5-0904639) to formerly 140, CR R5-100111
              },
              b2_Threshold2 := {
                b2_Threshold2CDMA2000 := 30 // fixed to 30 (-15 DB as per 36508 9.0.0)
              }
            }
          },
          hysteresis := 2,
          timeToTrigger := ms0
        }
      },
      maxReportCells := 8,
      reportInterval := ms2048,
      reportAmount := r1
    }
  };

  template (value) ReportConfigToAddMod.reportConfig cs_508_ReportConfigInterRAT_Periodical :=
  {
    reportConfigInterRAT := {
      triggerType := {
        periodical := {
          purpose := reportStrongestCells // purpose is CHOICE in 36508 whereas it is ENUMERATED in ASN1 file??
        }
      },
      maxReportCells := 8,
      reportInterval := ms2048,
      reportAmount := r1
    }
  };
  
  
  } // End of group specifictemplates
  
  group CommonFunctions {
  //----------------------------------------------------------------------------
  function fl_ConvertFromBoolToCDMA2000_Type (boolean p_IsHRPD)  return CDMA2000_Type
  {
    if (p_IsHRPD == true) {
      return (typeHRPD);
    } else {
      return ( type1XRTT);
    };
  }
  
  function fl_ConvertFromIntegerToBandClass (integer p_Integer) runs on EUTRA_PTC return BandclassCDMA2000
  {
    var BandclassCDMA2000 v_Value;
    select (p_Integer) {
      case (0) {
        v_Value := bc0;
      } case (1) {
        v_Value := bc1;
      } case (2) {
        v_Value := bc2;
      } case (3) {
        v_Value := bc3;
      } case (4) {
        v_Value := bc4;
      } case (5) {
        v_Value := bc5;
      } case (6) {
        v_Value := bc6;
      } case (7) {
        v_Value := bc7;
      } case (8) {
        v_Value := bc8;
      } case (9) {
        v_Value := bc9;
      } case (10) {
        v_Value := bc10;
      } case (11) {
        v_Value := bc11;
      } case (12) {
        v_Value := bc12;
      } case (13) {
        v_Value := bc13;
      } case (14) {
        v_Value := bc14;
      } case (15) {
        v_Value := bc15;
      } case (16) {
        v_Value := bc16;
      } case (17){
        v_Value := bc17;
      } case else {
        f_EUTRA_SetVerdictFailOrInconc (__FILE__, __LINE__, "wrong Band Class");
      }
    }
    return v_Value;
  }
  } // end of group CommonFunctions
  
  //testcase 8.3.2.7_start:
  //Measurement configuration control and reporting / Inter-RAT measurements / Event B2 / Measurement of HRPD cells
  function f_TC_8_3_2_7_EUTRA () runs on EUTRA_PTC
  {
    var integer v_T0_T2_T4_RS_EPRE_Cell1 := -60;
    var integer v_T1_T3_RS_EPRE_Cell1 := -80;
    
    var RRC_TransactionIdentifier v_RRC_TI := tsc_RRC_TI_Def;
    
    var IRAT_CoOrd_SysInfo_Type v_CDMA2000SysInfo;
    var CDMA2000_Type  v_CDMA2000_Type_Cell15 ;
    
    var PhysCellIdCDMA2000  v_PNOffset_Cell15 ;
    var ARFCN_ValueCDMA2000 v_Arfcn_CDMA2000_Cell15 ;
    
    var BandclassCDMA2000 v_BandClass_CDMA2000_Cell15;
    var SearchWindowSize_Type v_SearchWindowSize_Cell15;
    
    var float v_TimerValue_1;
    var float v_TimerValue_2;
    
    //Initialize testcase
    f_EUTRA_Init ( c6 );
    
    v_TimerValue_1 := f_EUTRA_SetTimerToleranceMax ( eutra_Cell1, 10.0 );
    v_TimerValue_2 := f_EUTRA_SetTimerToleranceMax ( eutra_Cell1, 5.0 );
    
    //Set EPRE for T0
    f_EUTRA_CellInfo_InitMaxReferencePower ( eutra_Cell1, v_T0_T2_T4_RS_EPRE_Cell1 );
    
    //Create and configure Cell1
    f_EUTRA_CellConfig_Def ( eutra_Cell1 );
    
    f_EUTRA_Preamble ( eutra_Cell1, STATE2_IDLEUPDATE );
    f_EUTRA_RbEst_Def (eutra_Cell1);
    
    // Get Cell Parameters for CDMA2000 cell
    
    v_CDMA2000SysInfo := f_WaitForIRATCoOrd_SysInfo ( CDMA2000 );
    // Initialise locol parameters for
    v_CDMA2000_Type_Cell15 :=  fl_ConvertFromBoolToCDMA2000_Type(v_CDMA2000SysInfo.Cdma2000[0].IsHRPD);
    v_PNOffset_Cell15 := v_CDMA2000SysInfo.Cdma2000[0].PNOffset;
    v_Arfcn_CDMA2000_Cell15 := v_CDMA2000SysInfo.Cdma2000[0].Arfcn;
    v_BandClass_CDMA2000_Cell15 := fl_ConvertFromIntegerToBandClass(v_CDMA2000SysInfo.Cdma2000[0].BandClass);
    v_SearchWindowSize_Cell15 := v_CDMA2000SysInfo.Cdma2000[0].SearchWindowSize;
    
    // First Cor-ordination message to power up HRPD Cells;
    f_SendIRATCoOrd ( CDMA2000, cms_IRAT_Trigger );
    
    f_EUTRA_TestBody_Set ( true );
    
    //------------------------------------------------
    //Start TestBody
    
    //@siclog "Step 1" siclog@
    //The SS transmits an RRCConnectionReconfiguration message to setup inter RAT measurement on Cell 1.
    SRB.send ( cas_SRB1_RrcPdu_REQ ( eutra_Cell1,
                                     cs_TimingInfo_Now,
                                     cs_RRCConnectionReconfiguration_8_3_2_7_Step1 ( v_RRC_TI,
                                                                                     v_CDMA2000_Type_Cell15,
                                                                                     v_Arfcn_CDMA2000_Cell15,
                                                                                     v_BandClass_CDMA2000_Cell15,
                                                                                     v_SearchWindowSize_Cell15 ) ) );
    
    //@siclog "Step 2" siclog@
    //The UE transmits an RRCConnectionReconfigurationComplete message to confirm the setup of inter RAT measurement on Cell 1.
    SRB.receive ( car_SRB1_RrcPdu_IND ( eutra_Cell1, cr_508_RRCConnectionReconfigurationComplete ( v_RRC_TI ) ) );
    
    //@siclog "Step 3" siclog@
    //Check: Does the UE transmit a MeasurementReport message to report the event B2 during the next 10s?
    fl_NoMeasurementReport ( eutra_Cell1, v_TimerValue_1, cr_MeasurementReport_CheckAny);
    
    //@siclog "Step 4" siclog@
    //The SS changes Cell 1 and Cell 16 parameters according to the row "T1" in table 8.3.2.7.3.2-1.
    f_SendIRATCoOrd ( CDMA2000, cms_IRAT_Trigger );
    f_EUTRA_SetCellPower ( eutra_Cell1, v_T1_T3_RS_EPRE_Cell1, cs_TimingInfo_Now );
    
    //@siclog "Step 5" siclog@
    //Check: Does the UE transmit a MeasurementReport message to report the event B2 for Cell 16 and not Cell 17?
    SRB.receive ( car_SRB1_RrcPdu_IND ( eutra_Cell1,
                                        cr_MeasurementReport_8_3_2_7_Step5 ( v_PNOffset_Cell15) ) );
    f_EUTRA_PreliminaryPass ( __FILE__, __LINE__, "Step 5" );
    
    //@siclog "Step 7" siclog@
    //The SS changes Cell 1 and Cell 15 parameters according to the row "T2" in table 8.3.2.7.3.2-1.
    f_SendIRATCoOrd ( CDMA2000, cms_IRAT_Trigger );
    f_EUTRA_SetCellPower ( eutra_Cell1, v_T0_T2_T4_RS_EPRE_Cell1, cs_TimingInfo_Now );
    
    //Activate the default to receive measurement reports for Cell 15
    //( Step 7 )
    // v_DefaultRef := activate ( a_EUTRA_AddDefault_PeriodicalMeasurmentReport ( eutra_Cell1,
    //                                                                           cr_MeasurementReport_CheckAny ) );
    
    //@siclog "Step 8" siclog@
    //Check: Does the UE transmit a MeasurementReport message to report the event B2 during the next 10s?
    fl_NoMeasurementReport ( eutra_Cell1, v_TimerValue_1, cr_MeasurementReport_CheckAny);
    
    //Step 7: Wait and ignore MeasurementReport messages for 5 s to allow change of power levels for Cells 1 and Cell 24.
    // t_Wait.start ( v_TimerValue_2 );
    // t_Wait.timeout;
    // deactivate ( v_DefaultRef );
    
    //@siclog "Step 9" siclog@
    //The SS changes Cell 1 and Cell 15 parameters according to the row "T3" in table 8.3.2.7.3.2-1.
    f_SendIRATCoOrd ( CDMA2000, cms_IRAT_Trigger );
    f_EUTRA_SetCellPower ( eutra_Cell1, v_T1_T3_RS_EPRE_Cell1, cs_TimingInfo_Now );
    
    //@siclog "Step 10" siclog@
    //Check: Does the UE transmit a MeasurementReport message to report the event B2 for Cell 16 and not Cell 17?
    SRB.receive ( car_SRB1_RrcPdu_IND ( eutra_Cell1,
                                        cr_MeasurementReport_8_3_2_7_Step5 ( v_PNOffset_Cell15 ) ) );
    f_EUTRA_PreliminaryPass ( __FILE__, __LINE__, "Step 10" );
    
    //@siclog "Step 12" siclog@
    //The SS changes Cell 1 and Cell 15 parameters according to the row "T4" in table 8.3.2.7.3.2-1.
    f_SendIRATCoOrd ( CDMA2000, cms_IRAT_Trigger );
    f_EUTRA_SetCellPower ( eutra_Cell1, v_T0_T2_T4_RS_EPRE_Cell1, cs_TimingInfo_Now );
    
    //@siclog "Step 13" siclog@
    //Check: Does the UE transmit a MeasurementReport message to report the event B2 during the next 10s?
    fl_NoMeasurementReport ( eutra_Cell1, v_TimerValue_1, cr_MeasurementReport_CheckAny);
    
    //@siclog "Step 14" siclog@
    //Check: Does the test result of CALL generic procedure indicate that the UE is in E-UTRA RRC_CONNECTED state on Cell 1?
    f_EUTRA_508Check_ConnectedState ( eutra_Cell1 );
    
    //End TestBody
    //------------------------------------------------
    
    f_EUTRA_TestBody_Set ( false );
    
    //tell the CDMA2000 component that the test is over
    f_SendIRATCoOrd ( CDMA2000, cms_IRAT_Trigger );
    
    f_EUTRA_Postamble ( eutra_Cell1, E2_CONNECTED, v_RRC_TI );
    
  }; //end of testcase 8.3.2.7_end
  
  
  //testcase 8.3.2.8:
  // Measurement configuration control and reporting / Inter-RAT measurements / Periodic reporting / Measurement of HRPD cells
  function f_TC_8_3_2_8_EUTRA () runs on EUTRA_PTC
  {
    var integer v_T0_T1_T2_RS_EPRE_Cell1 := -60;
    
    var RRC_TransactionIdentifier v_RRC_TI := tsc_RRC_TI_Def;
    
    var IRAT_CoOrd_SysInfo_Type v_CDMA2000SysInfo;
    var CDMA2000_Type  v_CDMA2000_Type_Cell15;
    var CDMA2000_Type  v_CDMA2000_Type_Cell16;
    
    var integer v_PNOffset_Cell15;
    var integer v_PNOffset_Cell16;
    
    var ARFCN_ValueCDMA2000 v_Arfcn_CDMA2000_Cell15;
    var ARFCN_ValueCDMA2000 v_Arfcn_CDMA2000_Cell16;
    
    var BandclassCDMA2000 v_BandClass_CDMA2000_Cell15;
    var BandclassCDMA2000 v_BandClass_CDMA2000_Cell16;
    
    var integer v_SearchWindowSize_Cell15;
    var integer v_SearchWindowSize_Cell16;
    
    var float v_TimerValue_1;
    var float v_TimerValue_2;
    
    var default v_DefaultRef := null;
    
    timer t_Wait;
    timer t_CheckTimer_1;
    
    //Initialize testcase
    f_EUTRA_Init ( c6 );
    
    v_TimerValue_1 := f_EUTRA_SetTimerToleranceMax ( eutra_Cell1, 30.0 );
    v_TimerValue_2 := f_EUTRA_SetTimerToleranceMax ( eutra_Cell1, 5.0 );
    
    //Set EPRE for T0
    f_EUTRA_CellInfo_InitMaxReferencePower ( eutra_Cell1, v_T0_T1_T2_RS_EPRE_Cell1 );
    
    //Create and configure Cell1
    f_EUTRA_CellConfig_Def ( eutra_Cell1 );
    
    f_EUTRA_Preamble ( eutra_Cell1, STATE2_IDLEUPDATE );
    f_EUTRA_RbEst_Def (eutra_Cell1);
    
    // First Get Cell Parameters for CDMA2000 cell15
    v_CDMA2000SysInfo := f_WaitForIRATCoOrd_SysInfo ( CDMA2000 );
    
    v_CDMA2000_Type_Cell15 := fl_ConvertFromBoolToCDMA2000_Type(v_CDMA2000SysInfo.Cdma2000[0].IsHRPD);
    v_PNOffset_Cell15 := v_CDMA2000SysInfo.Cdma2000[0].PNOffset;
    
    v_Arfcn_CDMA2000_Cell15 := v_CDMA2000SysInfo.Cdma2000[0].Arfcn;
    v_BandClass_CDMA2000_Cell15 := fl_ConvertFromIntegerToBandClass(v_CDMA2000SysInfo.Cdma2000[0].BandClass);
    v_SearchWindowSize_Cell15 := v_CDMA2000SysInfo.Cdma2000[0].SearchWindowSize;
    
    // Next Get Cell Parameters for CDMA2000 cell16
    v_CDMA2000SysInfo := f_WaitForIRATCoOrd_SysInfo ( CDMA2000 );
    
    v_CDMA2000_Type_Cell16 := fl_ConvertFromBoolToCDMA2000_Type(v_CDMA2000SysInfo.Cdma2000[1].IsHRPD);
    v_PNOffset_Cell16 := v_CDMA2000SysInfo.Cdma2000[1].PNOffset;
    
    v_Arfcn_CDMA2000_Cell16 := v_CDMA2000SysInfo.Cdma2000[1].Arfcn;
    v_BandClass_CDMA2000_Cell16 := fl_ConvertFromIntegerToBandClass(v_CDMA2000SysInfo.Cdma2000[1].BandClass);
    v_SearchWindowSize_Cell16 := v_CDMA2000SysInfo.Cdma2000[1].SearchWindowSize;
    
    f_EUTRA_TestBody_Set ( true );
    
    //------------------------------------------------
    //Start TestBody
    
    //@siclog "Step 1" siclog@
    //The SS transmits an RRCConnectionReconfiguration message including measConfig to setup measurements and periodical reporting for HRPD cells.
    SRB.send ( cas_SRB1_RrcPdu_REQ ( eutra_Cell1,
                                     cs_TimingInfo_Now,
                                     cs_RRCConnectionReconfiguration_8_3_2_8_Step1 ( v_RRC_TI,
                                                                                     v_CDMA2000_Type_Cell15,
                                                                                     v_Arfcn_CDMA2000_Cell15,
                                                                                     v_BandClass_CDMA2000_Cell15,
                                                                                     v_SearchWindowSize_Cell15 ) ) );
    
    //@siclog "Step 2" siclog@
    //The UE transmits an RRCConnectionReconfigurationComplete message to confirm measurement on Cell 15.
    SRB.receive ( car_SRB1_RrcPdu_IND ( eutra_Cell1, cr_508_RRCConnectionReconfigurationComplete ( v_RRC_TI ) ) );
    
    //@siclog "Step 3" siclog@
    //Wait for 30 s to ensure that the UE performs a periodical reporting of HRPD cells
    t_Wait.start ( v_TimerValue_1 );
    
    // In parallel to steps 3 and 4, the steps specified in table 8.3.2.8.3.2-3 shall take place
    //Parallel behaviour Check: Does the UE transmit a MeasurementReport message to perform periodical intra frequency reporting for HRPD Cell 15?
    t_CheckTimer_1.start( v_TimerValue_2 );
    alt {
      [] t_Wait.timeout{}
      [] t_CheckTimer_1.timeout
        {
          f_EUTRA_SetVerdictFailOrInconc( __FILE__, __LINE__, "" );
        }
      
      [] SRB.receive( car_SRB1_RrcPdu_IND ( eutra_Cell1, cr_MeasurementReport_8_3_2_8_Step3_Step4_Step9_Step10(v_PNOffset_Cell15) ) )
        {
          f_EUTRA_PreliminaryPass( __FILE__, __LINE__, "Measurement Report for cell 15, Parallel behaviour to Step 3 and Step 4" );
          t_CheckTimer_1.stop;
          t_CheckTimer_1.start( v_TimerValue_2 );
          repeat;
        }
    }
    
    //Activate the default to receive periodical reports.
    v_DefaultRef := activate( a_EUTRA_AddDefault_PeriodicalMeasurmentReport( eutra_Cell1, cr_MeasurementReport_CheckAny ) );
    
    
    //@siclog "Step 4" siclog@
    //SS sets the cell-specific reference signal levels for Cell 1, Cell 15 and Cell 16 according to row "T1" in table 8.3.2.8.3.2-1.
    f_SendIRATCoOrd ( CDMA2000, cms_IRAT_Trigger );
    
    
    //@siclog "Step 5" siclog@
    //Wait and ignore MeasurementReport messages for 5 s to allow for the switching of cells
    t_Wait.start( v_TimerValue_2 );
    t_Wait.timeout;
    
    //Deactivate the default.
    deactivate( v_DefaultRef );
    
    //@siclog "Step 6" siclog@
    //Wait for 30 s to ensure that the UE performs a periodical reporting of HRPD cells
    t_Wait.start ( v_TimerValue_1 );
    
    // In parallel to steps 6 and 7, the steps specified in table 8.3.2.8.3.2-4 shall take place
    //Parallel behaviour Check: Does the UE transmit a MeasurementReport message to perform periodical intra frequency reporting for Cell 15 and Cell 17 ?
    t_CheckTimer_1.start( v_TimerValue_2 );
    
    alt {
      [] t_Wait.timeout{}
      [] t_CheckTimer_1.timeout
        {
          f_EUTRA_SetVerdictFailOrInconc( __FILE__, __LINE__, "" );
        }
      
      [] SRB.receive( car_SRB1_RrcPdu_IND ( eutra_Cell1, cr_MeasurementReport_8_3_2_8_Step6_Step7(v_PNOffset_Cell15, v_PNOffset_Cell16 ) ) )
        {
          f_EUTRA_PreliminaryPass( __FILE__, __LINE__, "Measurement Report for cell 15, cell 16, Parallel behaviour to Step 6 and Step 7" );
          t_CheckTimer_1.stop;
          t_CheckTimer_1.start( v_TimerValue_2 );
          repeat;
        }
    }
    
    //Activate the default to receive periodical reports.
    v_DefaultRef := activate( a_EUTRA_AddDefault_PeriodicalMeasurmentReport( eutra_Cell1, cr_MeasurementReport_CheckAny ) );
    
    //@siclog "Step 7" siclog@
    //The SS changes Cell 1 and Cell 15 parameters according to the row "T2" in table 8.3.2.8.3.2-1.
    f_SendIRATCoOrd ( CDMA2000, cms_IRAT_Trigger );
    
    //@siclog "Step 8" siclog@
    //Wait and ignore MeasurementReport messages for 5 s to allow for the switching of cells
    t_Wait.start( v_TimerValue_2 );
    t_Wait.timeout;
    
    //Deactivate the default.
    deactivate( v_DefaultRef );
    
    //@siclog "Step 9" siclog@
    //Wait for 30 s to ensure that the UE performs a periodical reporting of HRPD cells
    t_Wait.start ( v_TimerValue_1 );
    
    // In parallel to steps 9 and 10, the steps specified in table 8.3.2.8.3.2-5 shall take place
    //Parallel behaviour Check: Does the UE transmit a MeasurementReport message to perform periodical intra frequency reporting for Cell 16?
    t_CheckTimer_1.start( v_TimerValue_2 );
    alt {
      [] t_Wait.timeout{}
      [] t_CheckTimer_1.timeout
        {
          f_EUTRA_SetVerdictFailOrInconc( __FILE__, __LINE__, "" );
        }
      
      [] SRB.receive( car_SRB1_RrcPdu_IND ( eutra_Cell1, cr_MeasurementReport_8_3_2_8_Step3_Step4_Step9_Step10 (v_PNOffset_Cell16)) )
        {
          f_EUTRA_PreliminaryPass( __FILE__, __LINE__, "Measurement Report for cell 16, Parallel behaviour to Step 9 and Step 10" );
          t_CheckTimer_1.stop;
          t_CheckTimer_1.start( v_TimerValue_2 );
          repeat;
        }
    }
    
    //@siclog "Step 10" siclog@
    //SS transmits an RRCConnectionReconfiguration message including measConfig to remove measId for periodic reporting.
    SRB.send( cas_SRB1_RrcPdu_REQ( eutra_Cell1,
                                   cs_TimingInfo_Now,
                                   cs_RRCConnectionReconfiguration_8_3_2_8_Step10( v_RRC_TI ) ) );
    
    //@siclog "Step 11" siclog@
    //The UE transmits an RRCConnectionReconfigrationComplete message
    SRB.receive ( car_SRB1_RrcPdu_IND ( eutra_Cell1, cr_508_RRCConnectionReconfigurationComplete ( v_RRC_TI ) ) );
    
    
    //End TestBody
    //------------------------------------------------
    
    f_EUTRA_TestBody_Set ( false );
    
    //tell the CDMA2000 component that the test is over
    f_SendIRATCoOrd ( CDMA2000, cms_IRAT_Trigger );
    
    f_EUTRA_Postamble ( eutra_Cell1, E2_CONNECTED, v_RRC_TI );
    
  }; //end of testcase 8.3.2.8
  
  
} // end of Module
