/******************************************************************************/
// @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 11:39:57 +0200 (Fri, 17 Sep 2010) $
// $Rev: 3955 $
/******************************************************************************/
module MAC_Functions {
//=========================================================================
// Import Part
//=========================================================================

  import from CommonDefs all;
  import from EUTRA_CellInfo all;
  import from EUTRA_ConfigurationSteps all;
  import from EUTRA_RRCSteps all;
  import from EUTRA_LoopBack all;
  import from EPS_NAS_Templates all;
  import from EUTRA_ASP_TypeDefs all;
  import from EUTRA_AspCommon_Templates all;
  import from EUTRA_LoopBack_TypeDefs all;
  import from EUTRA_CommonDefs all;
  import from EUTRA_RRC_ASN1_Definitions language "ASN.1:1997" all;
  import from EUTRA_RRC_Templates all;
  import from EUTRA_ASP_DrbDefs all;
  import from EUTRA_SRB_Templates all;
  import from EUTRA_DRB_Templates all;
  import from EUTRA_Component all;
  import from MAC_Templates all;
  import from L2_CommonTemplates all;
  import from L2_CommonFunctions all;
  import from EPS_NAS_Constants all;
  import from EUTRA_SecurityFunctions all;
  import from EUTRA_SecuritySteps all;
    import from EUTRA_Timing all;

  //import from EUTRA_ASP_SrbDefs all;
  //import from EUTRA_Timing all;
  import from EUTRA_CellCfg_Templates all;
  import from EPS_NAS_TypeDefs all;
  import from EUTRA_NASSteps  all;
  import from EUTRA_Paging all;
  import from EPS_NAS_MsgContainers all;

 //=========================================================================
  // MAC Specific Alt Steps group
  //=========================================================================
  group MAC_AltSteps {

  altstep a_EUTRA_MAC_PRACH_Preamble(CellId_Type p_CellId) runs on EUTRA_PTC {
    []SYSIND.receive ( car_PRACH_Preamble_IND_Any (p_CellId,?))
      {
        repeat;
      }
  };
  altstep a_EUTRA_MAC_ScheduligReq(CellId_Type p_CellId) runs on EUTRA_PTC {
    []SYSIND.receive ( car_SchedulingReq_IND (p_CellId, ?))
      {
        repeat;
      }
  };
  altstep a_EUTRA_MAC_PDCP_SDU_Receive(CellId_Type p_CellId,
                                       template (present) PDCP_SDU_Type p_PDCP_SDU) runs on EUTRA_PTC{
    [] DRB.receive (car_DRB_COMMON_IND_PDCP_SDUList (p_CellId, tsc_RbId_DRB1, ?, cr_PDCP_SDUList_1(p_PDCP_SDU)))
      {
        repeat;
      }
  };
  }// end of group MAC_AltSteps


  ////////////////////////////////////////////////////////////////////
  // These functions to be provided in common modules
  ////////////////////////////////////////////////////////////////////

  group CommonFunctions {
  /*
   * @desc      Assign the parameterised Preamble Transmission in the SIB2 of the cell
   * @param     p_CellId
   * @param     p_PreamblesGroupAConfig
   * @status    APPROVED
   */
  function f_EUTRA_CellInfo_SetPreambleGroup (CellId_Type p_CellId,
                                              template (value) RACH_ConfigCommon.preambleInfo.preamblesGroupAConfig p_PreamblesGroupAConfig) runs on EUTRA_PTC
  {
    var template (value) EUTRA_CellInfo_Type v_CellInfo := f_EUTRA_CellInfo_Get(p_CellId);

    v_CellInfo.Sysinfo.BCCH_Info.SIs[0].message_.c1.systemInformation.criticalExtensions.systemInformation_r8.sib_TypeAndInfo[0].sib2.radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig := p_PreamblesGroupAConfig;      /* @sic R5s100135 sic@ */
    f_EUTRA_CellInfo_Set (p_CellId, v_CellInfo );
  };

  /*
   * @desc      Assign the parameterised Preamble Transmission in the SIB2 of the cell
   * @param     p_CellId
   * @param     p_FDD_TDD
   * @status    APPROVED
   */
  function f_EUTRA_CellInfo_SetRootSeqInd (CellId_Type p_CellId,
                                           EUTRA_FDD_TDD_Mode_Type p_FDD_TDD) runs on EUTRA_PTC
  {
    var template (value) EUTRA_CellInfo_Type v_CellInfo := f_EUTRA_CellInfo_Get(p_CellId);
    if (p_FDD_TDD == FDD)
      {
        v_CellInfo.Sysinfo.BCCH_Info.SIs[0].message_.c1.systemInformation.criticalExtensions.systemInformation_r8.sib_TypeAndInfo[0].sib2.radioResourceConfigCommon.prach_Config.rootSequenceIndex:= 20;
        // u=2 [table 5.7.2-4 in TS 36.211] value selected to be different from default u=1
      }
    else if (p_FDD_TDD == TDD)
      {
        v_CellInfo.Sysinfo.BCCH_Info.SIs[0].message_.c1.systemInformation.criticalExtensions.systemInformation_r8.sib_TypeAndInfo[0].sib2.radioResourceConfigCommon.prach_Config.rootSequenceIndex:= 2;
        // u=2 [table 5.7.2-5 in TS 36.211] value selected to be different from default u=1
      }
    f_EUTRA_CellInfo_Set (p_CellId, v_CellInfo);
  };

  /*
   * @desc      Shall configure 1 DRB with RLC in special mode of TM, and MAC to have no header manipulation in DL
   * @param     p_CellId
   * @param     p_RBID
   * @param     p_MAC_TestModeInfo
   * @status    APPROVED
   */
  function f_SS_Config1TM_DRB_NoMACHeader (CellId_Type p_CellId,
                                           RadioBearerId_Type   p_RBID,
                                           template (value) MAC_TestModeInfo_Type p_MAC_TestModeInfo) runs on EUTRA_PTC
  {
    var template (value) RadioBearerList_Type v_RbList1 := {
      cs_RB_Reconfig_MACDRBTestMode( p_RBID,p_MAC_TestModeInfo )
    };
    f_EUTRA_SS_CommonRadioBearerConfig(p_CellId, v_RbList1);
  };
  /*
   * @desc      Shall configure 1 RB with RLC in special mode of  to not ACK the next PDU received; TTCN shall use this for AM RB only
   * @param     p_CellId
   * @param     p_RBID
   * @status
   */
  function f_SS_RB_Reconfig_NotAck_NextPDU (CellId_Type p_CellId,
                                           RadioBearerId_Type   p_RBID) runs on EUTRA_PTC
  {
    var template (value) RadioBearerList_Type v_RbList1 := {
      cs_RB_Reconfig_NotAck_NextPDU( p_RBID )
    };
    f_EUTRA_SS_CommonRadioBearerConfig(p_CellId, v_RbList1);
  };

  function f_SS_Config1TM_DRB_NoMACHeader_TimingInfo (CellId_Type p_CellId,
                                                      template (value) TimingInfo_Type p_TimingInfo,
                                                      RadioBearerId_Type   p_RBID,
                                                      template (value) MAC_TestModeInfo_Type p_MAC_TestModeInfo) runs on EUTRA_PTC
  {
    // Shall configure 1 DRB with RLC in special mode of TM, and MAC to have no header manipulation in DL
    var template (value) RadioBearerList_Type v_RbList1 := {
      cs_RB_Reconfig_MACDRBTestMode( p_RBID,p_MAC_TestModeInfo )
    };
    f_EUTRA_SS_CommonRadioBearerConfig(p_CellId,v_RbList1, p_TimingInfo);
  };

  } // end of group CommonFunctions

  group MAC_SpecialModes {


  /***************************************************************************************************/
  /*
   * @desc      Function to Config MAC Test mode to use Different Logical Channel ID in MAC header for a RB ID
   * @param     p_CellId
   * @param     p_RBID
   * @param     p_DiffLCHID
   * @status    APPROVED
   */
  function f_SS_ReconfigForDiffLCHID (CellId_Type p_CellId,
                                      RadioBearerId_Type   p_RBID,
                                      TestLogicalChannelId_Type p_DiffLCHID) runs on EUTRA_PTC
  {
    var template (value) RadioBearerList_Type v_RbList1 := {
      cs_RB_Reconfig_DiffLCHID( p_RBID, p_DiffLCHID )
    };
    f_EUTRA_SS_CommonRadioBearerConfig(p_CellId, v_RbList1);
  };

  /*******************************************************************************************/
  /*
   * @desc      Function to disable any MAC Test mode for a RB ID
   * @param     p_CellId
   * @param     p_RBID
   * @status    APPROVED
   */
  function f_SS_DisableMACTestMode (CellId_Type p_CellId,
                                    RadioBearerId_Type   p_RBID) runs on EUTRA_PTC
  {
    var template (value) RadioBearerList_Type v_SrbList1 := {
      cs_RB_Reconfig_DisableMACtestMode( p_RBID )
    };
    f_EUTRA_SS_CommonRadioBearerConfig(p_CellId, v_SrbList1);
  };

  /***************************************************************************************************/
  /*
   * @desc      Function to Config SS for reporting C-RNTI MCE Reception
   * @param     p_CellId
   * @param     p_C_RNTI
   * @status    APPROVED
   */
  function f_SS_ConfigC_RNTI_IndMode (CellId_Type p_CellId,
                                      L1Mac_IndicationMode_Type p_C_RNTI) runs on EUTRA_PTC
  {
    f_EUTRA_SS_CommonL1MacIndCtrlConfig(p_CellId, cas_C_RNTI_Config_REQ (p_CellId, p_C_RNTI));
  };
  /***************************************************************************************************/
  /*
   * @desc      Function to Config SS for reporting RLC PDU Discarded
   * @param     p_CellId
   * @param     p_IndMode
   * @status
   */
  function f_SS_ConfigRLCPDU_Discard (CellId_Type p_CellId,
                                      RadioBearerId_Type p_RB_Id,
                                      template (value) TimingInfo_Type p_TimingInfo :=cs_TimingInfo_Now,
                                      Rlc_IndicationMode_Type p_IndMode) runs on EUTRA_PTC
  {
    f_EUTRA_SS_CommonCellConfig(p_CellId, cas_RLCPDU_DiscardConfig_REQ (p_CellId,p_RB_Id,p_TimingInfo, p_IndMode));
  };
  /***************************************************************************************************/
  /*
   * @desc      Function to Config SS to use a sub set of DL HARQ process
   * @param     p_CellId
   * @param     p_HarqProcessList
   * @status
   */
  function f_SS_ConfigDLHARQProcess_Subset (CellId_Type p_CellId,
                                      template (value) TimingInfo_Type p_TimingInfo :=cs_TimingInfo_Now,
                                      template (value) HarqProcessList_Type p_HarqProcessList) runs on EUTRA_PTC
  {
    f_EUTRA_SS_CommonCellConfig(p_CellId, cas_DLHARQProcess_Config (p_CellId,p_TimingInfo, cs_HarqProcessConfigDL_Subset(p_HarqProcessList)));
  };
  /***************************************************************************************************/
  /*
   * @desc      Function to Config SS to use all DL HARQ processes
   * @param     p_CellId
   * @status
   */
  function f_SS_ConfigDLHARQProcess_All (CellId_Type p_CellId,
                                      template (value) TimingInfo_Type p_TimingInfo :=cs_TimingInfo_Now) runs on EUTRA_PTC
  {
    f_EUTRA_SS_CommonCellConfig(p_CellId, cas_DLHARQProcess_Config (p_CellId,p_TimingInfo, cs_HarqProcessConfigDL_All));
  };

  /***************************************************************************************************/
  /*
   * @desc      Cell Configuration: L1 test mode
   * @param     p_CellId
   * @param     p_SYSTEM_CTRL_REQ
   * @status    APPROVED
   */
  function f_EUTRA_SS_L1_TestModeConfig(CellId_Type p_CellId,
                                        template (value) SYSTEM_CTRL_REQ p_SYSTEM_CTRL_REQ) runs on EUTRA_PTC
  {
    SYS.send( p_SYSTEM_CTRL_REQ );
    if (valueof(p_SYSTEM_CTRL_REQ.Common.ControlInfo.CnfFlag) == true) {
      SYS.receive ( car_SYSTEM_CTRL_L1_TestMode_CNF( p_CellId ) );
    }
  };

  /*
   * @desc      Function to Config SS for CRC Errors
   * @param     p_CellId
   * @param     p_DL_SCH_CRC
   * @param     p_TimingInfo        (default value: cs_TimingInfo_Now)
   * @status    APPROVED
   */
  function f_SS_ConfigCRC_ErrorMode (CellId_Type p_CellId,
                                     template (value) DL_SCH_CRC_Type p_DL_SCH_CRC,
                                     template (value) TimingInfo_Type p_TimingInfo := cs_TimingInfo_Now) runs on EUTRA_PTC
  {
    f_EUTRA_SS_L1_TestModeConfig(p_CellId, cas_L1_Test_DL_SCH_CRC_REQ (p_CellId, p_DL_SCH_CRC, p_TimingInfo));
  };

  /***************************************************************************************************/
  /*
   * @desc      SS Configuration: SPS
   * @param     p_CellId
   * @param     p_SYSTEM_CTRL_REQ
   * @status
   */
  function f_EUTRA_SS_SPS_Config(CellId_Type p_CellId,
                                 template (value) SYSTEM_CTRL_REQ p_SYSTEM_CTRL_REQ) runs on EUTRA_PTC
  {
    SYS.send( p_SYSTEM_CTRL_REQ );
    if (valueof(p_SYSTEM_CTRL_REQ.Common.ControlInfo.CnfFlag) == true) {
      SYS.receive ( car_SYSTEM_CTRL_SPS_Config_CNF( p_CellId ) );
    }
  };


  /***************************************************************************************************/
  // Function to Config SS for PHICH mode
  /////////////////////////////////////////////////////////////////////////////////////////////////////
  function f_SS_ConfigPhich_TestMode (CellId_Type p_CellId,
                                      template (value) PhichTestMode_Type p_PhichTestMode) runs on EUTRA_PTC
  {
    f_EUTRA_SS_L1_TestModeConfig(p_CellId, cas_L1_Test_PhichMode_REQ (p_CellId, p_PhichTestMode));
  };
  /***************************************************************************************************/
  /*
   * @desc      Function to Config SS for reporting Power head room Reception
   * @param     p_CellId
   * @param     p_PHR_Mode
   * @status    APPROVED
   */
  function f_SS_ConfigPowerHeadRoomIndMode (CellId_Type p_CellId,
                                            L1Mac_IndicationMode_Type p_PHR_Mode) runs on EUTRA_PTC
  {
    f_EUTRA_SS_CommonL1MacIndCtrlConfig(p_CellId,  cas_PHR_IndConfig_REQ (p_CellId, p_PHR_Mode));// To be completed after corresponding ASP changes are completed.
  };

  }// end of group MAC_SpecialModes

  group GenericFunctions {

  /*
   * @desc      function to convert BI_Index to the value of Back off timer
   * @param     p_BI_Index
   * @return    float
   * @status    APPROVED
   */
  function f_BI_IndexToValueMap (integer p_BI_Index) return float
  {
    select (p_BI_Index)
    {
      case (0)
        {
          return (0.0); // timer =0
        }
      case (1)
        {
          return (0.01); // timer =10ms
        }
      case (2)
        {
          return (0.02); // timer =20ms
        }
      case (3)
        {
          return (0.03); // timer =30ms
        }
      case (4)
        {
          return (0.04); // timer =40ms
        }
      case (5)
        {
          return (0.06); // timer =60
        }
      case (6)
        {
          return (0.08); // timer =80ms
        }
      case (7)
        {
          return (0.12); // timer =120ms
        }
      case (8)
        {
          return (0.16); // timer =160ms

        }
      case (9)
        {
          return (0.24); // timer =240ms
        }
      case (10)
        {
          return (0.32); // timer =320ms
        }
      case (11)
        {
          return (0.48); // timer =480ms
        }
      case (12)
        {
          return (0.96); // timer =960ms
        }
      case else
             {
               FatalError(__FILE__, __LINE__, "Back Off Indicator index out of range");
               return (-1.0); /// dummy statement added for satisfying the compiler
             }
    }

  };

  function f_EvaluateNext_UL_TTI ( SubFrameTiming_Type p_Timing,
                                   EUTRA_FDD_TDD_Mode_Type  p_EUTRA_FDD_TDD) return SubFrameTiming_Type
  {
    var SubFrameTiming_Type v_Timing := p_Timing;

    if (p_EUTRA_FDD_TDD == FDD)
      {
        v_Timing.Subframe.Number := (v_Timing.Subframe.Number + 1) mod 10;
        if (v_Timing.Subframe.Number == 0) // increment the Frame number
          {
            v_Timing.SFN.Number := (v_Timing.SFN.Number + 1) mod 1024;
          }
      }
    else if (p_EUTRA_FDD_TDD == TDD) // caters only for default UL DL Mode of 1.
      {
        select (v_Timing.Subframe.Number)
          {
            case (2)
              {
                v_Timing.Subframe.Number := 3;
              }
            case (3)
              {
                v_Timing.Subframe.Number := 7;
              }
            case (7)
              {
                v_Timing.Subframe.Number := 8;
              }
            case (8)
              {
                v_Timing.Subframe.Number := 2;
                v_Timing.SFN.Number := (v_Timing.SFN.Number + 1) mod 1024;
              }
            case else
                   {
                     FatalError(__FILE__, __LINE__, "UL Sub frame used not according combination s1");
                   }
          }
      }
    return (v_Timing);
  };
  function f_EvaluateNext_UL_TransmissionForHARQ_Process( SubFrameTiming_Type p_Timing,
                                                          EUTRA_FDD_TDD_Mode_Type  p_EUTRA_FDD_TDD) return SubFrameTiming_Type
  {
    var SubFrameTiming_Type v_Timing := p_Timing;

    if (p_EUTRA_FDD_TDD == FDD)
      {
        // From UL TX, PHICH and Grant = 4 sub frame and next Tx =4 Subframe total 8 SF;
        v_Timing.SFN.Number := (v_Timing.SFN.Number + ((v_Timing.Subframe.Number + 8) / 10)) mod 1024;
        v_Timing.Subframe.Number := (v_Timing.Subframe.Number + 8) mod 10;

      }
    else  // caters only for TDD default UL DL Mode of 1.
      {
        v_Timing.SFN.Number := (v_Timing.SFN.Number + 1 ) mod 1024;
        //     36.213  Table 8.3-1    Table 8-2
        // UL SF =2 => PHICH/Grant = 6 => Next Tx(6) = 2
        // UL SF= 3 => PHICH/Grant = 9 => Next Tx(4) =3
        // UL SF= 7 => PHICH/Grant = 1 => Next Tx(6) =7
        // UL SF= 8 => PHICH/Grant = 4 => Next Tx (4) =8
      }
    return (v_Timing);
  };

  /*
   * @desc      send RLC status PDU
   * @param     p_LchId
   * @param     p_SN
   * @status    APPROVED
   */
  function f_RLC_Status_PDU_Tx ( B5_Type p_LchId,
                                 integer p_SN ) runs on EUTRA_PTC
  {
    //cs_MAC_PDU_1RLCPDU_NoPad(p_MAC_SDU)
    DRB.send ( cas_DRB_COMMOM_REQ_MAC_PDU (eutra_Cell1,
                                           tsc_RbId_DRB1,
                                           cs_TimingInfo_Now,
                                           cs_MAC_PDUList_1(cs_MAC_PDU_NoPadding_RLCPDU_LCID(p_LchId,
                                                                                             f_RLC_PDU_Encvalue(cs_RLC_Status_1PDU(p_SN)) ))));
    //sent MAC PDU (with RLC Status PDU)
  }// end of f_RLC_Status_PDU_Tx

  /*
   * @desc      To receive an MAC PDU containing RLC Status PDU on a Logical channel
   * @param     p_LchId
   * @param     p_SN
   * @status    APPROVED
   */
  function f_RLC_Status_PDU_Rx (B5_Type p_LchId,
                                integer p_SN) runs on EUTRA_PTC
  {
    var DRB_COMMON_IND v_DRB_COMMON_IND;
    var MAC_SDU_Type v_MAC_SDU;
    var RLC_PDU_Type v_RLC_PDU;
    timer t_Watchdog := 5.0;              // Local wait Timer

    t_Watchdog.start;
    alt {

      []DRB.receive ( car_DRB_COMMON_IND_MAC (eutra_Cell1,
                                              tsc_RbId_DRB1,
                                              cr_TimingInfo_Any,
                                              cr_MAC_PDUList_1(cr_MAC_PDU_NoPadding_RLCPDU_LCID(p_LchId, ?)))) // received UL RLC Status PDU
        -> value v_DRB_COMMON_IND
        {
          v_MAC_SDU := v_DRB_COMMON_IND.U_Plane.SubframeData.PduSduList.MacPdu[0].SduList[0];
          v_RLC_PDU := f_MAC_SDU_Decode(v_MAC_SDU);
          if (match(v_RLC_PDU, cr_RLC_Status_1PDU(p_SN))) {
            f_EUTRA_PreliminaryPass(__FILE__, __LINE__, "Status PDU Received"); // R5-104796
          } else {
            f_EUTRA_SetVerdictFailOrInconc(__FILE__, __LINE__, "RLC Status PDU does not match");
          }
          t_Watchdog.stop;
        }
      [] t_Watchdog.timeout
        {
          f_EUTRA_SetVerdictFailOrInconc(__FILE__, __LINE__, "UE is not sending RLC Status PDU");
        }
    };
  }// end of f_RLC_Status_PDU_Rx

  }// End of Group Generic Functions

  group Grant_Functions {
  function f_EUTRA_OneULGrantTransmission_RV( CellId_Type p_CellId,
                                              template (value) TimingInfo_Type p_TimingInfo ,
                                              ImcsValue_Type  p_Imcs,
                                              integer p_Nprb,
                                              template (value) UL_TransRetransmissionList_Type p_TransRetransmissionList) runs on EUTRA_PTC
  {
    // Configures SS to start periodic UL grant transmission
    // Suitable for RLC and MAC test cases.
    f_EUTRA_ULGrantConfiguration_Common(p_CellId,
                                        p_TimingInfo,
                                        cs_DciInfo_CcchDcchDtchUL_Explicit_RV(p_Imcs,  p_Nprb, p_TransRetransmissionList),
                                        f_EUTRA_PUCCH_Synch_Auto(),  // @sic R5-101177, R5-101178, R5-101050 sic@
                                        cs_UL_GrantConfig_OneTime);
  };
  function f_EUTRA_PeriodicCyclicULGrantTransmission_RV( CellId_Type p_CellId,
                                                         template (value) TimingInfo_Type p_TimingInfo ,
                                                         ImcsValue_Type  p_Imcs,
                                                         integer p_Nprb,
                                                         integer p_Period,
                                                         integer p_Cycles,
                                                         template (value) UL_TransRetransmissionList_Type p_TransRetransmissionList) runs on EUTRA_PTC
  {
    // Configures SS to start periodic UL grant transmission
    // Suitable for RLC and MAC test cases.
    f_EUTRA_ULGrantConfiguration_Common(p_CellId,
                                        p_TimingInfo,
                                        cs_DciInfo_CcchDcchDtchUL_Explicit_RV(p_Imcs,  p_Nprb, p_TransRetransmissionList),
                                        f_EUTRA_PUCCH_Synch_Auto(),  // @sic R5-101177, R5-101178, R5-101050 sic@
                                        cs_UL_GrantConfig_NoOfGrants(p_Period, p_Cycles));
  };
  //----------------------------------------------------------------------------
  /*
   * @desc      Basic function used in various types of explicit UL grant with PUSCH Hopping configuration
   * @param     p_CellId
   * @param     p_TimingInfo
   * @param     p_DciUlInfo
   * @param     p_PUCCH_Synch
   * @param     p_UL_GrantConfig
   * @param     p_PucchHoppingBits
   * @status
   */
  function f_EUTRA_ULHopingGrantConfiguration_Common(CellId_Type   p_CellId,
                                               template (value) TimingInfo_Type p_TimingInfo,
                                               template (omit)  DciUlInfo_Type p_DciUlInfo,
                                               template (omit)  PUCCH_Synch_Type p_PUCCH_Synch,
                                               template (value) UL_GrantConfig_Type p_UL_GrantConfig,
                                               template (value) PucchHoppingBits_Type p_PucchHoppingBits) runs on EUTRA_PTC
  {
    f_EUTRA_SS_CommonCellConfig(p_CellId, cas_ULHoppingGrantAllocation_REQ(p_CellId, p_TimingInfo, p_DciUlInfo, p_PUCCH_Synch, p_UL_GrantConfig,p_PucchHoppingBits));
  };
  //----------------------------------------------------------------------------
  /*
   * @desc      Function to start configurable UL grant allocation and keep PUCCH synchronisation unchanged
   *            with period and num of cycles configured
   * @param     p_CellId
   * @param     p_TimingInfo
   * @param     p_Imcs
   * @param     p_Nprb
   * @param     p_Period
   * @param     p_Cycles
   * @param     p_PucchHoppingBits
   * @status
   */
  function f_EUTRA_PeriodicCyclicULHoppingGrantTransmission( CellId_Type p_CellId,
                                                      template (value) TimingInfo_Type p_TimingInfo ,
                                                      ImcsValue_Type  p_Imcs,
                                                      integer p_Nprb,
                                                      integer p_Period,
                                                      integer p_Cycles,
                                                      template (value) PucchHoppingBits_Type p_PucchHoppingBits) runs on EUTRA_PTC
  {
    // Configures SS to start periodic UL grant transmission
    // Suitable for RLC and MAC test cases.
    f_EUTRA_ULHopingGrantConfiguration_Common(p_CellId,
                                        p_TimingInfo,
                                        cs_DciInfo_CcchDcchDtchUL_Explicit(p_Imcs, p_Nprb),
                                        f_EUTRA_PUCCH_Synch_Auto(),  // @sic R5-101177, R5-101178, R5-101050 sic@
                                        cs_UL_GrantConfig_NoOfGrants(p_Period, p_Cycles),
                                        p_PucchHoppingBits);
  };
  } // end of group Grant_Functions
  group Functions_71411 {

  function f_UpdateRedundencyVersion_Def ( RedundancyVersion_Type p_RV) return RedundancyVersion_Type
  {
    if (p_RV == 0)
      {
        return (2);
      }
    else if (p_RV == 2)
      {
        return (3);
      }
    else if (p_RV == 3)
      {
        return (1);
      }
    else // case p_RV == 1
      {
        FatalError(__FILE__, __LINE__, "Redundency version out of range");
        return (0); /// dummy statement added for satisfying the compiler
      }

  };
  function f_GetSubFrameNumForULGrant ( EUTRA_FDD_TDD_Mode_Type p_EUTRA_FDD_TDD_Mode,
                                        SubFrameTiming_Type p_TimingInfo) return SubFrameTiming_Type
  {
    var SubFrameTiming_Type v_TimingInfo := p_TimingInfo;

    if ( p_EUTRA_FDD_TDD_Mode == FDD)
      {
        v_TimingInfo.SFN.Number := (p_TimingInfo.SFN.Number + (( p_TimingInfo.Subframe.Number +4)/10)) mod 1024;
        v_TimingInfo.Subframe.Number:= (p_TimingInfo.Subframe.Number +4)mod 10;

        return (v_TimingInfo );
      }
    else // case TDD Caters only for def UL/DL Type of 1
      {
        select (p_TimingInfo.Subframe.Number)
          {
            case (2)
              {
                v_TimingInfo.Subframe.Number:=6;
                return (v_TimingInfo);
              }
            case (3)
              {
                v_TimingInfo.Subframe.Number:=9;
                return (v_TimingInfo);
              }
            case (7)
              {
                v_TimingInfo.Subframe.Number:=1;
                v_TimingInfo.SFN.Number := (p_TimingInfo.SFN.Number + 1 )mod 1024;
                return (v_TimingInfo);
              }
            case (8)
              {
                v_TimingInfo.Subframe.Number:=4;
                v_TimingInfo.SFN.Number := (p_TimingInfo.SFN.Number + 1 )mod 1024;
                return (v_TimingInfo);
              }
            case else
                   {
                     FatalError(__FILE__, __LINE__, "subframe number out of range");
                     return (v_TimingInfo); /// dummy statement added for satisfying the compiler
                   }

          }
      }

  };// end of function f_GetFrameNumForULGrant

  function f_GetSubFrameNumForULGrant_DiffHarqProcess ( EUTRA_FDD_TDD_Mode_Type p_EUTRA_FDD_TDD_Mode,
                                                        SubFrameTiming_Type p_TimingInfo) return SubFrameTiming_Type
  {
    var SubFrameTiming_Type v_TimingInfo := p_TimingInfo;
    if ( p_EUTRA_FDD_TDD_Mode == FDD)
      {
        v_TimingInfo.SFN.Number := (p_TimingInfo.SFN.Number + (( p_TimingInfo.Subframe.Number +4)/10)) mod 1024;
        v_TimingInfo.Subframe.Number:= (p_TimingInfo.Subframe.Number +4)mod 10;

        return (v_TimingInfo );
        // 4 arbitrarily selected in middle
      }
    else // case TDD Caters only for def UL/DL Type of 1
      {
        select (p_TimingInfo.Subframe.Number) // 2 HARQ process arbitrarily selected in middle
          {
            case (1)
              {
                v_TimingInfo.Subframe.Number:=6;
                return (v_TimingInfo);
              }
            case (4)
              {
                v_TimingInfo.Subframe.Number:=9;
                return (v_TimingInfo);
              }
            case (6)
              {
                v_TimingInfo.Subframe.Number:=1;
                v_TimingInfo.SFN.Number := (p_TimingInfo.SFN.Number + 1 ) mod 1024;
                return (v_TimingInfo);
              }
            case (9)
              {
                v_TimingInfo.Subframe.Number:=4;
                v_TimingInfo.SFN.Number := (p_TimingInfo.SFN.Number + 1 ) mod 1024;
                return (v_TimingInfo);
              }
            case else
                   {
                     FatalError(__FILE__, __LINE__, "subframe number out of range");
                     return (v_TimingInfo); /// dummy statement added for satisfying the compiler
                   }

          }
      }

  };// end of function f_GetFrameNumForULgrant_DiffHarqProcess
  function f_GetSubFrameNumForULData ( EUTRA_FDD_TDD_Mode_Type p_EUTRA_FDD_TDD_Mode,
                                       SubFrameTiming_Type p_TimingInfo) return SubFrameTiming_Type
  {
    var SubFrameTiming_Type v_TimingInfo := p_TimingInfo;
    if ( p_EUTRA_FDD_TDD_Mode == FDD)
      {
        v_TimingInfo.SFN.Number := (p_TimingInfo.SFN.Number + (( p_TimingInfo.Subframe.Number +4)/10)) mod 1024;
        v_TimingInfo.Subframe.Number:= (p_TimingInfo.Subframe.Number +4)mod 10;

        return (v_TimingInfo );
      }
    else // case TDD Caters only for def UL/DL Type of 1
      {
        select (p_TimingInfo.Subframe.Number)
          {
            case (6)
              {
                v_TimingInfo.Subframe.Number:=2;
                v_TimingInfo.SFN.Number := (p_TimingInfo.SFN.Number + 1 )mod 1024;
                return (v_TimingInfo);
              }
            case (9)
              {
                v_TimingInfo.Subframe.Number:=3;
                v_TimingInfo.SFN.Number := (p_TimingInfo.SFN.Number + 1 )mod 1024;
                return (v_TimingInfo);
              }
            case (1)
              {
                v_TimingInfo.Subframe.Number:=7;
                return (v_TimingInfo);
              }
            case (4)
              {
                v_TimingInfo.Subframe.Number:=8;
                return (v_TimingInfo);
              }
            case else
                   {
                     FatalError(__FILE__, __LINE__, "subframe number out of range");
                     return (v_TimingInfo); /// dummy statement added for satisfying the compiler
                   }

          }
      }

  };// end of function f_GetFrameNumForULData
  }// end of group Functions_71411

  group SPS_Functions
  {
  /***************************************************************************************************/
  // Function to Activate Deactivate SPS GRANT
  /////////////////////////////////////////////////////////////////////////////////////////////////////
  function f_SS_ActivateSPS_Grant (CellId_Type p_CellId,
                                   template (value) TimingInfo_Type p_TimingInfo,
                                   template (value) SpsActivateInfo_Type p_SpsInfo) runs on EUTRA_PTC
  {
    f_EUTRA_SS_SPS_Config(p_CellId, cas_SPS_Activate_REQ (p_CellId, p_TimingInfo, p_SpsInfo));
  };

  function f_SS_DeactivateSPS_Grant (CellId_Type p_CellId,
                                     template (value) TimingInfo_Type p_TimingInfo) runs on EUTRA_PTC
  {
    f_EUTRA_SS_SPS_Config(p_CellId, cas_SPS_Deactivate_REQ (p_CellId, p_TimingInfo));
  };

  function f_SS_SPS_PDCCH_ExplicitRelease(CellId_Type p_CellId,
                                          template (value) TimingInfo_Type p_TimingInfo,
                                          template (value) C_RNTI p_SPS_CRNTI,
                                          template (value) PdcchDciFormat_Type p_DCI_Format) runs on EUTRA_PTC
  {
    f_EUTRA_SS_SPS_Config(p_CellId, cas_SPS_PDCCH_ExplicitRelease_REQ (p_CellId, p_TimingInfo, p_SPS_CRNTI, p_DCI_Format));
  };
  /***************************************************************************************************/
  // Function to Config SPS Grant at UE
  /////////////////////////////////////////////////////////////////////////////////////////////////////
  function f_RRC_ConnectionReconfiguration_SPS_Config (CellId_Type p_CellId,
                                                       RRC_TransactionIdentifier p_RRC_TI,
                                                       template (value) TimingInfo_Type p_TimingInfo,
                                                       template (value) SPS_Config p_SPS_Config) runs on EUTRA_PTC
  {

    //timer t_Watchdog :=0;
    f_SendRRC_ConnectionReconfiguration_SPS_Config( p_CellId,p_RRC_TI,p_TimingInfo,p_SPS_Config);

    SRB.receive ( car_SRB1_RrcPdu_IND ( p_CellId, cr_508_RRCConnectionReconfigurationComplete ( p_RRC_TI ) ) );


  };
  function f_SendRRC_ConnectionReconfiguration_SPS_Config (CellId_Type p_CellId,
                                                           RRC_TransactionIdentifier p_RRC_TI,
                                                           template (value) TimingInfo_Type p_TimingInfo,
                                                           template (value) SPS_Config p_SPS_Config) runs on EUTRA_PTC
  {
    //timer t_Watchdog :=0;
    SRB.send ( cas_SRB1_RrcPdu_REQ ( p_CellId,
                                     p_TimingInfo,
                                     cs_RRCConnectionReconfiguration_Common ( p_RRC_TI,
                                                                              omit,
                                                                              omit,
                                                                              cs_RadioResourceConfigDedicated_MAC(omit,p_SPS_Config,omit),
                                                                              omit) ) );
  }
  }// end of SPS_Functions
  function f_SS_TTI_Bundle_Configure (CellId_Type p_CellId,
                                      template (value) TimingInfo_Type p_TimingInfo,
                                      boolean p_TTI_Bundle,
                                      Dl_Bandwidth_Type p_Dl_Bandwidth, // @sic R5-103846 sic@
                                      Combination_Type    p_Combination)  runs on EUTRA_PTC// @sic R5-103846 sic@
  {
    f_EUTRA_SS_CommonCellConfig(p_CellId, cas_TTI_Bundle_REQ (p_CellId, p_TimingInfo,p_TTI_Bundle,p_Dl_Bandwidth,p_Combination));
  };
  function f_RRC_ConnectionReconfiguration_MAC_MainConfig (CellId_Type p_CellId,
                                                           RRC_TransactionIdentifier p_RRC_TI,
                                                           template (value) TimingInfo_Type p_TimingInfo,
                                                           template (value) MAC_MainConfig_Type p_MAC_MainConfig) runs on EUTRA_PTC
  {
    //timer t_Watchdog :=0;
    SRB.send ( cas_SRB1_RrcPdu_REQ ( p_CellId,
                                     p_TimingInfo,
                                     cs_RRCConnectionReconfiguration_Common( p_RRC_TI,
                                                                             omit,
                                                                             omit,
                                                                             cs_RadioResourceConfigDedicated_MAC (p_MAC_MainConfig, omit, omit),
                                                                             omit) ) );

    SRB.receive ( car_SRB1_RrcPdu_IND ( p_CellId, cr_508_RRCConnectionReconfigurationComplete ( p_RRC_TI ) ) );
  };

  function f_RRC_ConnectionReconfiguration_MAC_Physical_Reconfig (CellId_Type p_CellId,
                                                                  RRC_TransactionIdentifier p_RRC_TI,
                                                                  template (value) TimingInfo_Type p_TimingInfo,
                                                                  template (value) MAC_MainConfig_Type p_MAC_MainConfig,
                                                                  template (value) PhysicalConfigDedicated p_PhysicalConfigDedicated) runs on EUTRA_PTC
  {
    //timer t_Watchdog :=0;
    SRB.send ( cas_SRB1_RrcPdu_REQ ( p_CellId,
                                     p_TimingInfo,
                                     cs_RRCConnectionReconfiguration_Common( p_RRC_TI,
                                                                             omit,
                                                                             omit,
                                                                             cs_RadioResourceConfigDedicated_MAC (p_MAC_MainConfig, omit, p_PhysicalConfigDedicated),
                                                                             omit) ) );

    SRB.receive ( car_SRB1_RrcPdu_IND ( p_CellId, cr_508_RRCConnectionReconfigurationComplete ( p_RRC_TI ) ) );
  };

  /***************************************************************************************************/
  /*
   * @desc      Function to Bring UE in PUCCH Synchronous after desynchronising (due to Time alignment timer expiry)
   *            Configures PUCCH for SR
   * @param     p_CellId
   * @param     p_RRC_TI
   * @param     p_TimingInfo
   * @param     p_PRACH_PreambleIndication (default value: true)
   * @status    (APPROVED)
   */
  function f_RRC_ConnectionReconfiguration_PUCCH_Resync_SRS_Config (CellId_Type p_CellId,
                                                                    RRC_TransactionIdentifier p_RRC_TI,
                                                                    template (value) TimingInfo_Type p_TimingInfo,
                                                                    Dl_Bandwidth_Type p_Dl_Bandwidth , // @sic R5-103846 sic@
                                                                    boolean p_PRACH_PreambleIndication := true) runs on EUTRA_PTC
  {
    var template (value) EUTRA_FDD_TDD_CellInfo_Type v_EUTRA_FDD_TDD_CellInfo := f_EUTRA_CellInfo_GetFDD_TDD_Info ( p_CellId );
    var SR_PUCCH_ResourceIndex_Type v_Sr_PUCCH_ResourceIndex := f_EUTRA_CellInfo_GetSR_PUCCH_ResourceIndex ( p_CellId );
    var template (value) PhysicalConfigDedicated_AntennaInfo_Type v_AntennaInfo := f_EUTRA_CellInfo_GetAntennaInfoDedicated (p_CellId);
    var SR_ConfigIndex_Type v_SR_ConfigIndex := f_EUTRA_CellInfo_GetSR_ConfigIndex (p_CellId ); //@sic R5-102177 sic@


    // UE is not time aligned hence PDCCH order needs to be sent and RACH procedure configuration is needed
    f_EUTRA_SS_ConfigRachProcedure (p_CellId,
                                    omit,
                                    cs_RachProcedureConfig_CRNTI(f_EUTRA_CellInfo_GetRAR_TA(p_CellId),p_Dl_Bandwidth));
    f_Send_PDCCH_Order(p_CellId,
                       cs_TimingInfo_Now,
                       cs_RA_PDCCH_Order);

    if (p_PRACH_PreambleIndication) // SS is configured to report PRACH preambles received
      {
        SYSIND.receive ( car_PRACH_Preamble_IND_Any (p_CellId,?));
      }
        SRB.send ( cas_SRB1_RrcPdu_REQ ( p_CellId,
                                     p_TimingInfo,
                                     cs_RRCConnectionReconfiguration_Common( p_RRC_TI,
                                                                             omit,
                                                                             omit,
                                                                             cs_RadioResourceConfigDedicated_PhyConfig (
                                                                                cds_PhysicalConfigDedicated_PUCCH_Resync(v_EUTRA_FDD_TDD_CellInfo.cqi_ReportConfig,
                                                                                                                         v_EUTRA_FDD_TDD_CellInfo.soundingRS_UL_Config,
                                                                                                                         v_AntennaInfo,
                                                                                                                         v_Sr_PUCCH_ResourceIndex,
                                                                                                                         v_SR_ConfigIndex
                                                                                                                         )),
                                                                             omit) ) );

    SRB.receive ( car_SRB1_RrcPdu_IND ( p_CellId, cr_508_RRCConnectionReconfigurationComplete ( p_RRC_TI ) ) );
  };
  /***************************************************************************************************/
  /*
   * @desc      function to  Configures PUCCH for SR which gets deleated due to
   *            1. dsr_Trans max transmission of Scheduling Request
   *            2. Time alignment timer expiry.
   *            Note it expects the UE is still PUCCH synchronised
   *            Default grant/allocation is assumed
   * @param     p_CellId
   * @param     p_RRC_TI            (default value: tsc_RRC_TI_Def)
   * @status    APPROVED
   */
  function f_RRC_ConnectionReconfiguration_SRS_Config (CellId_Type p_CellId,
                                                       RRC_TransactionIdentifier p_RRC_TI := tsc_RRC_TI_Def) runs on EUTRA_PTC
  {
    var template (value) EUTRA_FDD_TDD_CellInfo_Type v_EUTRA_FDD_TDD_CellInfo := f_EUTRA_CellInfo_GetFDD_TDD_Info ( p_CellId );
    var SR_PUCCH_ResourceIndex_Type v_Sr_PUCCH_ResourceIndex := f_EUTRA_CellInfo_GetSR_PUCCH_ResourceIndex ( p_CellId );
   var template (value) PhysicalConfigDedicated_AntennaInfo_Type v_AntennaInfo := f_EUTRA_CellInfo_GetAntennaInfoDedicated (p_CellId);
   var SR_ConfigIndex_Type v_SR_ConfigIndex := f_EUTRA_CellInfo_GetSR_ConfigIndex (p_CellId ); //@sic R5-102177 sic@
    f_EUTRA_RRCConnectionReconfiguration_RadioResConfig(p_CellId,
                                                        p_RRC_TI,
                                                        cs_RadioResourceConfigDedicated_PhyConfig (cds_PhysicalConfigDedicated_PUCCH_Resync(v_EUTRA_FDD_TDD_CellInfo.cqi_ReportConfig,
                                                                                                                                            v_EUTRA_FDD_TDD_CellInfo.soundingRS_UL_Config,
                                                                                                                                            v_AntennaInfo,
                                                                                                                                            v_Sr_PUCCH_ResourceIndex,
                                                                                                                                            v_SR_ConfigIndex)));
  };

  group SpecificPreambles {
  /*
   * @desc      Brings UE to state 4, with one DRB established in AM Mode both on SS and UE side
   *            Put UE in Loop Back Mode A. Configures SS in normal mode
   * @param     p_CellId
   * @param     p_UE_TestLoopModeA_LB_Setup
   * @status    APPROVED
   */
  function f_EUTRA_LoopBackActivation_State4_DSR_TransMax(CellId_Type p_CellId,
                                                          template (value) UE_TestLoopModeA_LB_Setup_Type p_UE_TestLoopModeA_LB_Setup) runs on EUTRA_PTC
  {
    var template (omit) DRB_ToAddModList v_DRB_ToAddModList := omit;                // => apply default setiing acc. 36.508 cl. 4.8.2.1.7 */
    var template (omit) MAC_MainConfig_Type v_MAC_MainConfig := omit;
    var template (value) EUTRA_FDD_TDD_CellInfo_Type v_EUTRA_FDD_TDD_Info := f_EUTRA_CellInfo_GetFDD_TDD_Info (p_CellId);// => apply default setting acc. 36.508 cl. 4.8.2.1.5 */
    var SR_PUCCH_ResourceIndex_Type v_Sr_PUCCH_ResourceIndex := f_EUTRA_CellInfo_GetSR_PUCCH_ResourceIndex ( p_CellId );
    var template (value) PhysicalConfigDedicated_AntennaInfo_Type v_AntennaInfo := f_EUTRA_CellInfo_GetAntennaInfoDedicated (p_CellId);
    var SR_ConfigIndex_Type v_SR_ConfigIndex := f_EUTRA_CellInfo_GetSR_ConfigIndex (p_CellId ); //@sic R5-102177 sic@
    var template (omit) PhysicalConfigDedicated v_PhysicalConfigDedicated :=
      cds_PhysicalConfigDedicated_Dsr_TransMax(v_EUTRA_FDD_TDD_Info.cqi_ReportConfig,
                                               v_EUTRA_FDD_TDD_Info.soundingRS_UL_Config,
                                               v_AntennaInfo,
                                               v_Sr_PUCCH_ResourceIndex,
                                               v_SR_ConfigIndex);
    f_EUTRA_GenericRbEst_DisableBSR_PHR(p_CellId,
                                        0,
                                        0,
                                        v_DRB_ToAddModList,
                                        v_MAC_MainConfig,
                                        v_PhysicalConfigDedicated,
                                        omit,
                                        omit);                                               // bring UE to State 3
    f_EUTRA_CloseUE_TestLoopModeA(p_CellId, p_UE_TestLoopModeA_LB_Setup);             // Step 1-2
  };

  /*function f_EUTRA_LoopBackActivation_State4_MaxHarq_Tx(CellId_Type p_CellId,
    template (value) UE_TestLoopModeA_LB_Setup_Type p_UE_TestLoopModeA_LB_Setup,
    MaxHARQ_Tx_Type p_MaxHARQ_Tx) runs on EUTRA_PTC
    { // Brings UE to state 4, with one DRB established in AM Mode both on SS and UE side
    //   Put UE in Loop Back Mode A.
    //  Configures SS in normal mode
    var template (omit) DRB_ToAddModList v_DRB_ToAddModList := omit;                // => apply default setiing acc. 36.508 cl. 4.8.2.1.7
    var template (omit) MAC_MainConfig_Type v_MAC_MainConfig := cds_MAC_MainConfig_Explicit_MaxHarq_Tx(p_MaxHARQ_Tx);
    var template (omit) PhysicalConfigDedicated v_PhysicalConfigDedicated :=omit;  //
    f_EUTRA_GenericRbEst_DisableBSR_PHR(p_CellId,
    0,
    0,
    v_DRB_ToAddModList,
    v_MAC_MainConfig,
    v_PhysicalConfigDedicated,
    omit,
    omit);                                               // bring UE to State 3
    f_EUTRA_CloseUE_TestLoopModeA(p_CellId, p_UE_TestLoopModeA_LB_Setup);             // Step 1-2
    };*/


  function f_EUTRA_LoopBackActivation_State4_7143() runs on EUTRA_PTC
  { /* Function to allow the specific combination of AM and UM bearers for TC7143*/

    var template (omit) MAC_MainConfig_Type v_MAC_MainConfig := omit;
     var template (value) EUTRA_FDD_TDD_CellInfo_Type v_EUTRA_FDD_TDD_Info := f_EUTRA_CellInfo_GetFDD_TDD_Info (eutra_Cell1);// => apply default setting acc. 36.508 cl. 4.8.2.1.5 */
    var SR_PUCCH_ResourceIndex_Type v_Sr_PUCCH_ResourceIndex := f_EUTRA_CellInfo_GetSR_PUCCH_ResourceIndex ( eutra_Cell1 );
    var template (value) PhysicalConfigDedicated_AntennaInfo_Type v_AntennaInfo := f_EUTRA_CellInfo_GetAntennaInfoDedicated (eutra_Cell1);
    var SR_ConfigIndex_Type v_SR_ConfigIndex := f_EUTRA_CellInfo_GetSR_ConfigIndex (eutra_Cell1 ); //@sic R5-102177 sic@
    var template (omit) PhysicalConfigDedicated v_PhysicalConfigDedicated :=
      cds_PhysicalConfigDedicated_Dsr_TransMax(v_EUTRA_FDD_TDD_Info.cqi_ReportConfig,
                                               v_EUTRA_FDD_TDD_Info.soundingRS_UL_Config,
                                               v_AntennaInfo,
                                               v_Sr_PUCCH_ResourceIndex,
                                               v_SR_ConfigIndex, n16);//@sic R5-104798 dsr transmax sic@
    var template (omit) DRB_ToAddModList v_DRB_ToAddModList:= omit;

    v_DRB_ToAddModList[0] := cs_DRB_ToAddMod_NoPDCP_StatusReport (tsc_DRB1); //@sic R5s100473 sic@
    v_DRB_ToAddModList[1] := cs_508_DRB_ToAddMod_Common(tsc_DRB2,
                                                        cds_DRB_PDCP_Conf_UM_ModifyDiscardTime(ms1500), //@sic R5-104798 discard timer sic@
                                                        cs_508_RLC_Config_DRB_UM,
                                                        cds_LogicalChannelConfig_PrioritizedBitRate_DRB_AM ( 6, kBps8, 1));
    v_DRB_ToAddModList[2] := cs_508_DRB_ToAddMod_Common(tsc_DRB3,
                                                        cds_DRB_PDCP_Conf_UM_ModifyDiscardTime(ms1500),//@sic R5-104798 discard timer sic@
                                                        cs_508_RLC_Config_DRB_UM,
                                                        cds_LogicalChannelConfig_PrioritizedBitRate_DRB_AM ( 7, kBps16, 1));

    v_DRB_ToAddModList[3] := cs_508_DRB_ToAddMod_Common(tsc_DRB4,
                                                        cds_DRB_PDCP_Conf_UM_ModifyDiscardTime(ms1500),//@sic R5-104798 discard timer sic@
                                                        cs_508_RLC_Config_DRB_UM,
                                                        cds_LogicalChannelConfig_PrioritizedBitRate_DRB_AM ( 8, kBps32, 1));

    f_EUTRA_GenericRbEst_DisableBSR_PHR(eutra_Cell1,
                                        0,
                                        3,
                                        v_DRB_ToAddModList,
                                        v_MAC_MainConfig,
                                        v_PhysicalConfigDedicated,
                                        { cs_508_EPS_QoS_Dedicated_1,cs_508_EPS_QoS_Dedicated_1,cs_508_EPS_QoS_Dedicated_1},
                                        { cs_508_Tft_Dedicated_1,cs_508_Tft_Dedicated_2,cs_508_Tft_Dedicated_1(tsc_EpsDedicatedBearerId3)} );     // bring UE to State 3
    f_EUTRA_CloseUE_TestLoopModeA(eutra_Cell1, cs_UE_TestLoopModeA_LB_Setup_NoScaling);             // Step 1-2
  };

  

  /*
   * @desc      To move to state 4 as required for test cases 7.1.4.7 and 7.1.4.13
   * @status    APPROVED
   */
  function f_EUTRA_LoopBackActivation_State4_7147_71413() runs on EUTRA_PTC
  {

    var template (omit) MAC_MainConfig_Type v_MAC_MainConfig := omit;   // BSR_timer is infinity            // => apply default setting acc. 36.508 cl. 4.8.2.1.5 */
    var template (omit) PhysicalConfigDedicated v_PhysicalConfigDedicated := omit;
    var template (omit) DRB_ToAddModList v_DRB_ToAddModList:= omit;
    v_DRB_ToAddModList[0] :=  cs_508_DRB_ToAddMod_Common(tsc_DRB1,
                                                         cs_508_PDCP_Config_DRB_AM,
                                                         cs_508_RLC_Config_DRB_AM,
                                                         cds_LogicalChannelConfig_DRB_AM ( 7, 2));
    v_DRB_ToAddModList[1] := cs_508_DRB_ToAddMod_Common(tsc_DRB2,
                                                        cs_508_PDCP_Config_DRB_AM,
                                                        cs_508_RLC_Config_DRB_AM,
                                                        cds_LogicalChannelConfig_DRB_AM ( 6, 1));
    f_EUTRA_GenericRbEst_DisableBSR_PHR(eutra_Cell1,
                                        1,
                                        0,
                                        v_DRB_ToAddModList,
                                        v_MAC_MainConfig,
                                        v_PhysicalConfigDedicated,
                                        { cs_508_EPS_QoS_Dedicated_1},
                                        { cs_508_Tft_Dedicated_1} );     // bring UE to State 3
    f_EUTRA_CloseUE_TestLoopModeA(eutra_Cell1, cs_UE_TestLoopModeA_LB_Setup_NoScaling);             // Step 1-2
  };

  /*
   * @desc      To move to state 4 as required for test cases 7.1.4.8
   * @status    APPROVED
   */
  function f_EUTRA_LoopBackActivation_State4_7148() runs on EUTRA_PTC
  {

    var template (omit) MAC_MainConfig_Type v_MAC_MainConfig := cds_MAC_MainConfig_Explicit_PeriodicBSR_Timer(sf10);
    var template (omit) PhysicalConfigDedicated v_PhysicalConfigDedicated := omit;
    var template (omit) DRB_ToAddModList v_DRB_ToAddModList:= omit;
    v_DRB_ToAddModList[0] :=  cs_508_DRB_ToAddMod_Common(tsc_DRB1,
                                                         cs_508_PDCP_Config_DRB_AM,
                                                         cs_508_RLC_Config_DRB_AM,
                                                         cds_LogicalChannelConfig_PrioritizedBitRate_DRB_AM  ( 7, kBps0, 2)); //@sic R5s100274
    v_DRB_ToAddModList[1] := cs_508_DRB_ToAddMod_Common(tsc_DRB2,
                                                        cs_508_PDCP_Config_DRB_AM,
                                                        cs_508_RLC_Config_DRB_AM,
                                                        cds_LogicalChannelConfig_PrioritizedBitRate_DRB_AM  ( 6, kBps0, 1)); //@sic R5s100274

    f_EUTRA_GenericRbEst_DisableBSR_PHR(eutra_Cell1,
                                        1,
                                        0,
                                        v_DRB_ToAddModList,
                                        v_MAC_MainConfig,
                                        v_PhysicalConfigDedicated,
                                        { cs_508_EPS_QoS_Dedicated_1},
                                        { cs_508_Tft_Dedicated_1} );     // bring UE to State 3
    f_EUTRA_CloseUE_TestLoopModeA(eutra_Cell1, cs_UE_TestLoopModeA_LB_Setup_NoScaling);             // Step 1-2
  };

  /*
   * @desc      To move to state 4 with a different Poll Retransmit timer
   * @status    APPROVED
   */
  function f_EUTRA_LoopBackActivation_State4_7123() runs on EUTRA_PTC
  { /* @sic R5s090349 sic@*/
    var template (omit) MAC_MainConfig_Type v_MAC_MainConfig := cds_MAC_MainConfig_Explicit_PeriodicBSR_Timer(sf10);
    var template (omit) PhysicalConfigDedicated v_PhysicalConfigDedicated := omit;
    var template (omit) DRB_ToAddModList v_DRB_ToAddModList:= omit;

    v_DRB_ToAddModList[0] := cs_508_DRB_ToAddMod_Common(tsc_DRB1,
                                                        cs_508_PDCP_Config_DRB_AM,
                                                        cs_508_RLC_Config_DRB_AM(cds_TX_AM_RLC_t_PollRetransmit(ms200)),
                                                        cs_508_LogicalChannelConfig_DRB_AM);

    f_EUTRA_GenericRbEst_DisableBSR_PHR(eutra_Cell1,
                                        0,
                                        0,
                                        v_DRB_ToAddModList,
                                        v_MAC_MainConfig,
                                        v_PhysicalConfigDedicated,
                                        omit,
                                        omit );     // bring UE to State 3
    f_EUTRA_CloseUE_TestLoopModeA(eutra_Cell1, cs_UE_TestLoopModeA_LB_Setup_NoScaling);             // Step 1-2
  };

  /*
   * @desc      To move to state 4 as required for test case 7.1.4.6
   * @status    APPROVED
   */
  function f_EUTRA_LoopBackActivation_State4_7146() runs on EUTRA_PTC
  {
    var template (omit) MAC_MainConfig_Type v_MAC_MainConfig := cds_MAC_MainConfig_Explicit_RetxBSR_Timer(sf320);
    var template (omit) PhysicalConfigDedicated v_PhysicalConfigDedicated := omit;
    var template (omit) DRB_ToAddModList v_DRB_ToAddModList:= omit;
    v_DRB_ToAddModList[0] :=  cs_508_DRB_ToAddMod_Common(tsc_DRB1,
                                                         cs_508_PDCP_Config_DRB_AM,
                                                         cs_508_RLC_Config_DRB_AM,
                                                         cds_LogicalChannelConfig_DRB_AM ( 8, 2));
    v_DRB_ToAddModList[1] := cs_508_DRB_ToAddMod_Common(tsc_DRB2,
                                                        cs_508_PDCP_Config_DRB_AM,
                                                        cs_508_RLC_Config_DRB_AM,
                                                        cds_LogicalChannelConfig_DRB_AM ( 7, 2));
    v_DRB_ToAddModList[2] := cs_508_DRB_ToAddMod_Common(tsc_DRB3,
                                                        cs_508_PDCP_Config_DRB_AM,
                                                        cs_508_RLC_Config_DRB_AM,
                                                        cds_LogicalChannelConfig_DRB_AM ( 6, 1));
    f_EUTRA_GenericRbEst_DisableBSR_PHR(eutra_Cell1,
                                        2,
                                        0,
                                        v_DRB_ToAddModList,
                                        v_MAC_MainConfig,
                                        v_PhysicalConfigDedicated,
                                        { cs_508_EPS_QoS_Dedicated_1,cs_508_EPS_QoS_Dedicated_1},
                                        { cs_508_Tft_Dedicated_1, cs_508_Tft_Dedicated_1(tsc_EpsDedicatedBearerId2)} );     // bring UE to State 3
                                         //@sic R5s100301 sic@
    f_EUTRA_CloseUE_TestLoopModeA(eutra_Cell1, cs_UE_TestLoopModeA_LB_Setup_NoScaling);             // Step 1-2
  };

  /*
   * @desc      To move to state 4 as required for test case 7.1.3.1
   * @status    APPROVED
   */
  function f_EUTRA_LoopBackActivation_State4_7131() runs on EUTRA_PTC
  {
    var template (omit) MAC_MainConfig_Type v_MAC_MainConfig := cs_MAC_MainConfig_Explicit_DisableBSR_TA_Infinity;   // time alignment timer is infinity
    var template (omit) PhysicalConfigDedicated v_PhysicalConfigDedicated := omit;
    var template (omit) DRB_ToAddModList v_DRB_ToAddModList:= omit;

    f_EUTRA_GenericRbEst_DisableBSR_PHR(eutra_Cell1,
                                        0,
                                        0,
                                        v_DRB_ToAddModList,
                                        v_MAC_MainConfig,
                                        v_PhysicalConfigDedicated,
                                        omit,
                                        omit);     // bring UE to State 3
    f_EUTRA_CloseUE_TestLoopModeA(eutra_Cell1, cs_UE_TestLoopModeA_LB_Setup_1DRB(0,tsc_DRB1));             // Step 1-2
  };

  
  /*
   * @desc      To move to state 4 as required for test case
   * @status    APPROVED
   */
  function f_EUTRA_LoopBackActivation_State4_717() runs on EUTRA_PTC
  { // @sic R5-100263 sic@
    var template (omit) MAC_MainConfig_Type v_MAC_MainConfig := cds_MAC_MainConfig_Explicit_RetxBSR_Timer(sf320);   // time alignment timer is infinity
    var template (value) EUTRA_FDD_TDD_CellInfo_Type v_EUTRA_FDD_TDD_Info := f_EUTRA_CellInfo_GetFDD_TDD_Info (eutra_Cell1);
    var template (value) PhysicalConfigDedicated_AntennaInfo_Type v_AntennaInfo := f_EUTRA_CellInfo_GetAntennaInfoDedicated (eutra_Cell1);
    var template (omit) PhysicalConfigDedicated v_PhysicalConfigDedicated := cds_PhysicalConfigDedicated_TBS_Test(v_EUTRA_FDD_TDD_Info.cqi_ReportConfig,
                                                                                                                  v_EUTRA_FDD_TDD_Info.soundingRS_UL_Config,
                                                                                                                  v_AntennaInfo);
    var template (omit) DRB_ToAddModList v_DRB_ToAddModList:= omit;
    
    f_EUTRA_GenericRbEst_DisableBSR_PHR(eutra_Cell1,
                                        0,
                                        0,
                                        v_DRB_ToAddModList,
                                        v_MAC_MainConfig,
                                        v_PhysicalConfigDedicated,
                                        omit,
                                        omit);     // bring UE to State 3
    f_EUTRA_CloseUE_TestLoopModeA(eutra_Cell1, cs_UE_TestLoopModeA_LB_Setup_NoScaling);             // Step 1-2
  };

  /*
   * @desc      To move to state 4 as required for test case 7.1.3.4
   * @status    APPROVED
   */
  function f_EUTRA_LoopBackActivation_State4_TA_Infinity_LB_NoScaling() runs on EUTRA_PTC
  //@sic R5-101183
  {
    var template (omit) MAC_MainConfig_Type v_MAC_MainConfig := cs_MAC_MainConfig_Explicit_DisableBSR_TA_Infinity;   // time alignment timer is infinity
    var template (omit) PhysicalConfigDedicated v_PhysicalConfigDedicated := omit;
    var template (omit) DRB_ToAddModList v_DRB_ToAddModList:= omit;

    f_EUTRA_GenericRbEst_DisableBSR_PHR(eutra_Cell1,
                                        0,
                                        0,
                                        v_DRB_ToAddModList,
                                        v_MAC_MainConfig,
                                        v_PhysicalConfigDedicated,
                                        omit,
                                        omit);     // bring UE to State 3
    f_EUTRA_CloseUE_TestLoopModeA(eutra_Cell1, cs_UE_TestLoopModeA_LB_Setup_NoScaling);             // Step 1-2
  };
  } // end of group SpecificPreambles


  /*
   * @desc      return the Transport block size from 36.213 Table 7.1.7.2.1-1
   * @param     p_N_PRB   ...  nPRB value
   * @param     p_I_TBS   ...  iTBS value
   * @return    integer   ...  Transport block size
   * @status    APPROVED
   */
  function f_EUTRA_LookUp_TB_Size (integer p_N_PRB,
                                   integer p_I_TBS) return integer
  {
    if ((p_N_PRB>=1 and p_N_PRB<=110) and (p_I_TBS>=0 and p_I_TBS<=26))  //check array bound
      {
        return tsc_Nprb_Itbs[p_N_PRB][p_I_TBS];
      }
    else
      {
        FatalError(__FILE__, __LINE__, "Out of Bound Value for nPRB or iTBS");
        return (0); /// dummy statement added for satisfying the compiler
      }
  }

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

  



  /*
   * @desc      return MaxDLSCH TB Bits Per TTI acc. Table 7.1.7.1.1.3.2-1
   * @param     p_UE_Category
   * @return    integer
   * @status    APPROVED
   */
  function f_EUTRA_GetMaxDLSCH_TB_Bits_Per_TTI (integer p_UE_Category) return integer
  {
    select (p_UE_Category)
    {  // Table 7.1.7.1.1.3.2-1: Maximum DL SCH TBsize for different UE categories
      case (1) {
        return (10296);
      }
      case (2) {
        return (51024);
      }
      case (3) {
        return (75376);
      }
      case (4) {
        return (75376);
      }
      case (5) {
        return (149776); // @sic R5-0966421 sic@
      }
      case else {
        FatalError(__FILE__, __LINE__, "invalid UE Category");
        return (10296); /// dummy statement added for satisfying the compiler
      }
    }
  }

  /*
   * @desc      Implements 36.213 Table 7.1.7.1-1: Modulation and TBS index table for PDSCH
   * @param     p_I_MCS
   * @return    integer
   * @status    APPROVED
   */
  function f_EUTRA_Get_iTBS_For_iMCS (integer p_I_MCS) return integer
  {
    var integer v_I_TBS := 0;

    if (p_I_MCS <= 9)
      {
        v_I_TBS := p_I_MCS;
      }
    else if (p_I_MCS <= 16)
      {
        v_I_TBS := p_I_MCS - 1;
      }
    else if (p_I_MCS <= 28)
      {
        v_I_TBS := p_I_MCS - 2;
      }
    else // case 29,30,31
      {
        FatalError(__FILE__, __LINE__, "Reserved or Invalid I_MCS");
      }
    return v_I_TBS;
  }

  /*
   * @desc      Implements 36.213 Table 8.6.1-1: Modulation, TBS index table for PUSCH
   * @param     p_I_MCS
   * @return    integer  .. v_I_TBS
   * @status    APPROVED
   */
  function f_EUTRA_Get_iTBS_For_iMCS_PUSCH (integer p_I_MCS) return integer
  {
    var integer v_I_TBS := 0;

    if (p_I_MCS <= 10)
      {
        v_I_TBS := p_I_MCS;
      }
    else if (p_I_MCS <= 20)
      {
        v_I_TBS := p_I_MCS - 1;
      }
    else if (p_I_MCS <= 28)
      {
        v_I_TBS := p_I_MCS - 2;
      }
    else // case 29,30,31
      {
        FatalError(__FILE__, __LINE__, "Reserved or Invalid I_MCS");
      }
    return v_I_TBS;
  }

  group ConsecutiveTTI {

  /*
   * @desc      function to build list of subframe data for subsequent TTIs;
   *            for FDD all subframes are suitable resulting in subframe offsets of 0, 1, 2 ...
   *            for TDD not subframes can be used therefore subframe offsets of 0, 4, 5 .. shall be used
   * @param     p_PDCP_SDUList        .. list of PDCP SDUs which is repeated in each suitable TTI
   * @param     p_NumTTI              .. number of repititions
   * @param     p_EUTRA_FDD_TDD_Mode  .. FDD/TDD
   * @return    template (value) DRB_DataPerSubframeList_DL_Type
   * @status
   */
  function f_BuildPDCPSDUsToBeSentInConsecutiveTTI (template (value) PDCP_SDUList_Type p_PDCP_SDUList,
                                                    integer p_NumTTI,
                                                    EUTRA_FDD_TDD_Mode_Type  p_EUTRA_FDD_TDD_Mode)
    return template (value) DRB_DataPerSubframeList_DL_Type
  {
    var template (value) DRB_DataPerSubframeList_DL_Type v_DataList;
    var integer i;
    var integer v_SubframeOffset;

    for (i:=0; i<p_NumTTI; i:=i+1)
      {
        v_SubframeOffset := f_EUTRA_DataListSubframeOffset(p_EUTRA_FDD_TDD_Mode, i);
        v_DataList[i] := {
          SubframeOffset  := v_SubframeOffset,
          HarqProcess := { Automatic := true},
          PduSduList   :=
          {
            PdcpSdu  := p_PDCP_SDUList
          }
        };
      }
    return v_DataList;

  };  // End of function

  /*
   * @desc      setup list of PDCP SDUs
   * @param     p_PDCP_SDU_Type
   * @param     p_NumSDU
   * @return    template (value) PDCP_SDUList_Type
   * @status
   */
  function f_BuildPDCPSDUsToBeSentInSingleTTI (template (value) PDCP_SDU_Type p_PDCP_SDU_Type,
                                               integer p_NumSDU)
    return template (value) PDCP_SDUList_Type
  {
    var template (value) PDCP_SDUList_Type v_SDUList;
    var integer i;
    
    for (i:=0; i<p_NumSDU; i:=i+1)
      {
        v_SDUList[i] := p_PDCP_SDU_Type;
      };
    
    return v_SDUList;
  };

  } // end of group ConsecutiveTTI
  group Functions716 {
      /* functions for Group 7.1.6 test cases */
      //----------------------------------------------------------------------------
  /*
   * @desc      Generic Radio Bearer Establishment (State 3)
   *            If no Dedicated bearers are required, set p_NoOfAddDRBs_AM and p_NoOfAddDRBs_UM to 0 and p_QoS and p_Tft to omit
   *            Otherwise, at least 1 AM DRB will be configured
   * @param     p_CellId
   * @param     p_NoOfAddDRBs_AM
   * @param     p_NoOfAddDRBs_UM
   * @param     p_DRB_ToAddModList              p_NoOfAddDRBs_AM+p_NoOfAddDRBs_UM+1 elements or omit;
   *                                            omit => default setting acc. 36.508 cl. 4.8.2.1.7
   * @param     p_MAC_MainConfig                omit => default setting acc. 36.508 cl. 4.8.2.1.5
   * @param     p_PhysicalConfigDedicated       omit => default setting acc. 36.508 4.8.2.1.6
   * @param     p_QoS
   * @param     p_Tft
   * @param     p_GrantPeriod shall be approxiately 80% of inactivity timer
   * @param     p_PDCP_StatusReportRequired     (default value: true)
   * @status    APPROVED
   */
      function f_EUTRA_GenericRbEst_Common_716 ( CellId_Type p_CellId,
                                         integer p_NoOfAddDRBs_AM,
                                         integer p_NoOfAddDRBs_UM,
                                         template (omit) DRB_ToAddModList p_DRB_ToAddModList,
                                         template (omit) MAC_MainConfig_Type p_MAC_MainConfig,
                                         template (omit) PhysicalConfigDedicated p_PhysicalConfigDedicated,
                                         template (omit) EPS_QoSList_Type p_QoS,
                                         template (omit) Tft_List_Type p_Tft,
                                         integer p_GrantPeriod,
                                         boolean p_PDCP_StatusReportRequired := true )
    runs on EUTRA_PTC
  {
    var GutiParameters_Type v_GutiParameters := f_EUTRA_CellInfo_GetGuti ( p_CellId );

    /* Step 2 */
    f_EUTRA_UE_Page ( p_CellId,
                    cs_NasPaging_OneRecord ( cs_PagingUE_Identity_S_TMSI ( v_GutiParameters.MME_Code, v_GutiParameters.M_TMSI )) ); //@sic R5s100398 sic@

    // Steps 3 - 10
    f_EUTRA_ServiceRequestAndActivate_SRB2_DRB_716 ( p_CellId,
                                                 p_NoOfAddDRBs_AM,
                                                 p_NoOfAddDRBs_UM,
                                                 p_DRB_ToAddModList,
                                                 p_MAC_MainConfig,
                                                 p_PhysicalConfigDedicated,
                                                 p_QoS,
                                                 p_Tft,
                                                 p_GrantPeriod,
                                                 p_PDCP_StatusReportRequired);
  }

  /*
   * @desc       Establishment of SRB1 + default DRB + n AM DRBs + m UM DRBs acc. to 36.508 cl. 4.5.3.2;
   *             This function starts by setting up an RRC Connection to receive a Service Request,
   *             then performs RRC Security and sends RRC Connection Reconfiguration to configure SRB2 and at least 1 AM DRB,
   *             with optionally activating up to 8 Dedictated Bearers
   *             This function DOES NOT configure the SS, but expects the appropriate DRBs to be already configured
   *             @params
   *               If no Dedicated bearers are required, set p_NoOfAddDRBs_AM and p_NoOfAddDRBs_UM to 0 and p_QoS and p_Tft to omit
   *               in this case only SRB2 and 1 AM DRB (for the already activated Default Bearer) are configured
   *               Otherwise, SRB2 and 1 AM DRB will be configured + p_NoOfAddDRBs_AMs and p_NoOfAddDRBs_UMs
   *             Note:
   *               usage of n and N in 36.508 is confusing:
   *               - acc. to Table 4.6.3-16 n is the total number of AM DRBs - including the default DRB;
   *               - in cl. 4.5.3.2 N is the number of add. DRBs (UM and AM), n = no of add. AM bearers, m = no of add. UM bearers (=> N = n+m; 0<=N<=7)
   *                 but here the default DRB is not taken into account
   *                 Periodic UL grant allocation is configured so that UE does not go in DRX
   * @param     p_CellId
   * @param     p_NoOfAddDRBs_AM             no of add. AM bearers not including the default DRB
   * @param     p_NoOfAddDRBs_UM             no of add. UM bearers
   * @param     p_DRB_ToAddModList           p_NoOfAddDRBs_AM+p_NoOfAddDRBs_UM+1 elements or omit;
   *                                         omit => default setiing acc. 36.508 cl. 4.8.2.1.7
   * @param     p_MAC_MainConfig             omit => default setting acc. 36.508 cl. 4.8.2.1.5
   * @param     p_PhysicalConfigDedicated    omit => default setting acc. 36.508 4.8.2.1.6
   * @param     p_QoS
   * @param     p_Tft
   * @param     p_GrantPeriod shall be approxiately 80% of inactivity timer
   * @param     p_PDCP_StatusReportRequired (default value: true)
   * @status    APPROVED
   */
  function f_EUTRA_ServiceRequestAndActivate_SRB2_DRB_716(CellId_Type p_CellId,
                                                      UInt_Type p_NoOfAddDRBs_AM,
                                                      UInt_Type p_NoOfAddDRBs_UM,
                                                      template (omit) DRB_ToAddModList p_DRB_ToAddModList,
                                                      template (omit) MAC_MainConfig_Type p_MAC_MainConfig,
                                                      template (omit) PhysicalConfigDedicated p_PhysicalConfigDedicated,
                                                      template (omit) EPS_QoSList_Type p_QoS,
                                                      template (omit) Tft_List_Type p_Tft,
                                                      integer p_GrantPeriod,
                                                      boolean p_PDCP_StatusReportRequired := true ) runs on EUTRA_PTC
  {
    var RRC_TransactionIdentifier v_RRC_TI := tsc_RRC_TI_Def;
    var NAS_MSG_Indication_Type v_NAS_Ind;
    var NAS_KsiValue v_KsiValue;
    
    // =====================================================
    // step 3-10 of procedure in 36.508 cl. 4.5.3.3

    // Step 3 - 5 of Generic RB establishment procedure
    //Check the Service Request message
    v_KsiValue := f_EUTRA_SecurityKSIasme_Get ( );
    v_NAS_Ind := f_EUTRA_RRC_ConnEst_DefWithNas ( p_CellId,
                                                  v_RRC_TI,
                                                  cr_EstablishmentCause_mt_Access,
                                                  cr_NAS_Indication(tsc_SHT_IntegrityProtected,
                                                                    cr_508_SERVICE_REQUEST ( v_KsiValue )));
   /* Over write def grant transmission with perioidc grant so as to stop UE entering DRX
    36.321 clause 5.7
    if the PDCCH indicates a new transmission (DL or UL):
        -   start or restart drx-InactivityTimer. */
    f_EUTRA_ULGrantConfigNoDRX ( p_CellId, p_GrantPeriod, cs_TimingInfo_Now, f_EUTRA_PUCCH_Synch_Auto());


   /* Step 6 - 8 */
    f_EUTRA_Activate_SRB2_DRB_SendRrcMsg ( p_CellId,
                                           v_RRC_TI,
                                           v_NAS_Ind.SecurityProtection.NasCount,
                                           p_NoOfAddDRBs_AM,
                                           p_NoOfAddDRBs_UM,
                                           p_DRB_ToAddModList,
                                           p_MAC_MainConfig,
                                           p_PhysicalConfigDedicated,
                                           p_QoS,
                                           p_Tft,
                                           p_PDCP_StatusReportRequired);      /* @sic R5s100315 sic@ */
    
    /* Step 9 - 10 */
    f_EUTRA_Activate_SRB2_DRB_ReceiveRrcAndNasMsg(p_CellId,
                                                  v_RRC_TI,
                                                  p_NoOfAddDRBs_AM,
                                                  p_NoOfAddDRBs_UM);          /* @sic R5s100315 sic@ */
  }

  /*
   * @desc      To configure continous periodic UL grants with given period so as to prevent UE entering DRX
   * @param     p_CellId
   * @param     p_GrantPeriod shall be approxiately 80% of inactivity timer
   * @param     p_TimingInfo
   * @param     p_PUCCH_Synch
   */
  function f_EUTRA_ULGrantConfigNoDRX (  CellId_Type p_CellId,
                                         integer p_GrantPeriod,
                                         template (value) TimingInfo_Type p_TimingInfo,
                                         template (value) PUCCH_Synch_Type p_PUCCH_Synch) runs on EUTRA_PTC // @sic R5s100520
  {
    // @sic R5s100520
    /* f_EUTRA_PeriodicULGrantTransmission( p_CellId,
                                         p_TimingInfo ,// immediate effect
                                         4, // Imcs = Itbs =4
                                         4, // Nprb Results in TB size of 328 selected to be neither too big nor too small
                                         p_GrantPeriod);  // period */
    f_EUTRA_ULGrantConfiguration_Common(p_CellId,
                                        p_TimingInfo,
                                        cs_DciInfo_CcchDcchDtchUL_Explicit(4,  4), // Imcs = Itbs =4, Nprb Results in TB size of 328 selected to be neither too big nor too small
                                        p_PUCCH_Synch,
                                        cs_UL_GrantConfig_ContPeriodic(p_GrantPeriod)); // period */
  }
  
  }
/* @desc      Function for performing SS and UE configuration at IntraLTE IntraCell handover. The function will:
   *             1. configure C-RNTI based contention resolution in SS with minimal grant
   *                i.e. the UE will have to raise SR to send additional/user data.
   *             2. activate security at target cell according to 36.508 cl. 4.6.4 Table 4.6.4-1
   *                with keyChangeIndicator set to FALSE and nextHopChainingCount set to 0
   *             3. send the RRCConnectionReconfiguration to UE. This message will include
   *               3a. Measurement configuration if specified.
   *               3b. MobilityControlInfo according to 36.508 cl. 4.6.5 Table 4.6.5-1
   *                   with newUE-Identity set to tsc_C_RNTI_Def2 or p_C_R_NTI
   *               3c. RadioResourceConfigDedicated according to 36.508 cl. 4.6.3 Table 4.6.3-19
   *               3d. SecurityConfigHO according to 36.508 cl. 4.6.4 Table 4.6.4-1
   *                   with keyChangeIndicator set to FALSE and nextHopChainingCount set to 0
   *             4. Receive the RRCConnectionReconfigurationComplete message
   *             5. Reset and re-establish SRBs and DRB(s) at source cell.
   *             NOTE: Steps above may not happen in the listed order as it depends on whether target and source cell are the same or not.
   * @param     p_CellId
   * @param     p_TimingInfo      (default value: cs_TimingInfo_Now)
   * @param     p_DrbConfigList   (default value: cs_DrbConfigList_Def)
   * @param     p_C_RNTI          (default value: tsc_C_RNTI_Def2)
   * @param     p_MeasConfig      (default value: p_MeasConfig)
   * @param     p_Dsr_TransMax    (default value: n4)
   * @status    (APPROVED)
   */
  function f_EUTRA_508RRC_IntraLTE_HO_IntraCell_DSR_Transmax ( CellId_Type                           p_CellId,
                                                  template (value) TimingInfo_Type      p_TimingInfo    := cs_TimingInfo_Now,
                                                  template (value) RadioBearerList_Type p_DrbConfigList := cs_DrbConfigList_Def,
                                                  C_RNTI                                p_C_RNTI        := tsc_C_RNTI_Def2,
                                                  template (omit)  MeasConfig           p_MeasConfig    := omit,
                                                  Dsr_TransMax_Type p_Dsr_TransMax :=n4)  runs on EUTRA_PTC
  { /* @sic R5s100491: enhancement to support MeasConfig sic@ */
    /* @sic R5s100524: common change of HO functions sic@ */
    var DRB_IdentityList_Type v_DRB_IdentityList;
    var integer k;
    var SubFrameTiming_Type v_Timing;
    var EUTRA_SecurityParams_Type v_Auth_Params := f_EUTRA_Security_Get();
    var NextHopChainingCount v_NextHopChainingCount := 0; //According to 36.508 cl. 4.6.1 RRCConnectionReestablishment
    var Frequency_IE_Type v_Frequency_IE := f_EUTRA_CellInfo_GetFrequencyIEs (p_CellId);
    var CarrierFreqEUTRA v_CarrierFreqEutra := v_Frequency_IE.UL_DL_Earfcn;
    var template (value) MobilityControlInfo v_MobilityControlInfo := f_Generate_cs_MobilityControlInfo_HO_CRNTI(p_CellId, v_CarrierFreqEutra, p_C_RNTI);
    var template (value) RadioResourceConfigDedicated v_RadioResourceConfigDedicated := f_Generate_cs_508_RadioResourceConfigDedicated_HO (p_CellId);
    v_RadioResourceConfigDedicated.physicalConfigDedicated.schedulingRequestConfig.setup.dsr_TransMax := p_Dsr_TransMax;
    //Build DRB identity list from inputed radiobearer config list
    for (k:=0; k < lengthof(p_DrbConfigList); k:= k+1) {
      v_DRB_IdentityList[k] := valueof ( p_DrbConfigList[k].Id.Drb );
    }
    
    /* for intra cell HO the HO procedure and the SS configuration must be executed with timing info.
     * This is to make sure SS reconfiguration is done properly and in time before UE access the new cell.
     * The timing info used is based on the information provided in TTCN CR R5s100178 */
    if ( ischosen ( p_TimingInfo.SubFrame ) )
      {
        //Use the provided timing iformation
        v_Timing := valueof(p_TimingInfo.SubFrame);
      }
    else //i.e. p_TimingInfo is "now" (either not provided or provided as "now")
      {
        //Get next sending occassion
        v_Timing := f_EUTRA_GetNextSendOccasion ( p_CellId );
      }
    
    //Transmit RRCConnectionReconfiguration/HO command to UE
    f_EUTRA_RRC_ConnReconfigHO_Common(p_CellId,
                                      p_MeasConfig,
                                      v_MobilityControlInfo,
                                      v_RadioResourceConfigDedicated,
                                      cs_508SecurityConfigHO_IntraLTE,
                                      cs_TimingInfo (v_Timing.SFN.Number, v_Timing.Subframe.Number));
    
    /* Note: current implementation releases SRBs and reconfigures C-RNTI 5ms after sending the RRCConnectionReconfiguration
       => RLC ACK is not taken into consideration */
    
    v_Timing := f_EUTRA_TimingInfoAdd(v_Timing, 5);   // add 5ms
    
    //Release SRBs and DRBs
    f_EUTRA_SS_SRBs_DRBs_Release ( p_CellId,
                                   cs_TimingInfo(v_Timing.SFN.Number, v_Timing.Subframe.Number),
                                   v_DRB_IdentityList );
    
    //Configure C-RNTI based contention resolution in target cell 1 and assign new C-RNTI to the cell
    f_EUTRA_SS_ConfigRachProcedure_HO(p_CellId, cs_TimingInfo(v_Timing.SFN.Number, v_Timing.Subframe.Number), p_C_RNTI);
      
    //Save new C-RNTI in cell configuration for target cell (which is also source cell)
    f_EUTRA_CellInfo_SetC_RNTI ( p_CellId, p_C_RNTI );
    
    //Setup SRBs and DRBs again
    v_Timing := f_EUTRA_TimingInfoAdd(v_Timing, 5);   // add 5ms
    f_EUTRA_SS_SRBs_DRBs_Config ( p_CellId,
                                  cs_TimingInfo(v_Timing.SFN.Number, v_Timing.Subframe.Number),
                                  p_DrbConfigList );
    
    //Enable RRC Integrity and Ciphering at SS target cell
    v_Auth_Params := f_EUTRA_SS_AS_ActivateSecurity_HO_Reest ( p_CellId,
                                                               v_Auth_Params,
                                                               v_NextHopChainingCount,
                                                               cs_TimingInfo(v_Timing.SFN.Number, v_Timing.Subframe.Number),
                                                               v_DRB_IdentityList );
    
    f_EUTRA_Security_Set ( v_Auth_Params );
    
    SRB.receive(car_SRB1_RrcPdu_IND(p_CellId, cr_508_RRCConnectionReconfigurationComplete(tsc_RRC_TI_Def)));       // @sic R5s100430  Change 2 sic@

    // configure RACH procedure for target cell back to default    @sic R5s100520 change 11 sic@
    f_EUTRA_SS_ConfigRachProcedure (p_CellId,
                                    omit,
                                    cs_RachProcedureConfig_Def(omit, f_EUTRA_CellInfo_GetRAR_TA(p_CellId), f_EUTRA_CellInfo_GetDL_ChBandwidth(p_CellId)));
  }

}
