/******************************************************************************/
// @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 03:16:03 +0200 (Thu, 19 Aug 2010) $
// $Rev: 3730 $
/******************************************************************************/

module L2_CommonFunctions {

  import from CommonDefs all;
  import from EUTRA_ASP_TypeDefs all;
  import from EUTRA_ASP_DrbDefs all;
  import from EUTRA_AspCommon_Templates all;
  import from EUTRA_Component all;
  import from EUTRA_CommonDefs all;
  import from EUTRA_CellCfg_Templates all;
  import from EUTRA_DRB_Templates all;
  import from L2_CommonTemplates all;
  import from EUTRA_ConfigurationSteps all;
  import from EUTRA_RRC_ASN1_Definitions language "ASN.1:1997" all;
  import from EUTRA_CommonProcedures all;
  import from EPS_NAS_Templates all;
  import from EUTRA_NASSteps all;
  import from EUTRA_LoopBack_TypeDefs all;
  import from EUTRA_LoopBack all;

  group SubframeTiming {

  /*
   * @desc      function to calculate subframe numbers for PDU/SDUs to be sent in subsequent TTIs
   *            This function shall be used to calculate subframe offsets used in the timing info of ASPs;
   *            the offset is the absolute index of a subframe (in contrast to f_EUTRA_DataListSubframeOffset where relative values are calculated).
   *            for FDD that are simply subsequent subframes but for TDD not all subframes can be used.
   *            This function is not suitable for sending UL grants requiring subframes 4, 9, 14, 19, ..
   *            but it can can be used for this by employing even indices.
   * @param     p_EUTRA_FDD_TDD_Mode  ... FDD/TDD
   * @param     p_Index               ... index of the PDU/SUDs
   * @return    integer
   * @status    APPROVED
   */
  function f_EUTRA_TimingInfoSubframeOffset(EUTRA_FDD_TDD_Mode_Type p_EUTRA_FDD_TDD_Mode,
                                            integer p_Index)
    return integer
  {
    var integer j;
    var integer v_SubframeOffset;
    
    if (p_EUTRA_FDD_TDD_Mode == TDD)
      {
        // index  = 0, 1, 2, 3,  4,  5,  6, .. =>
        // offset = 4, 5, 9, 10, 14, 15, ..
        p_Index := p_Index+1;
        j := ((p_Index+1) / 2);
        v_SubframeOffset := p_Index + j * 3;
      }
    else // FDD
      {
        v_SubframeOffset := p_Index + tsc_EUTRA_SN4;
      }
    return v_SubframeOffset;
  } // f_EUTRA_CalcSubframeOffset_NoList

  /*
   * @desc      function to calculate subframe numbers for PDU/SDUs to be sent in subsequent TTIs.
   *            This function shall be used to calculate subframe offsets used in PDU/SDU lists (DRB_DataPerSubframeList_DL_Type);
   *            the offset is relative to the subframe given in the timing info of the ASP.
   *            For FDD that are simply subsequent subframes but for TDD not all subframes can be used.
   *            Note: This function shall not be used to calculate the subfame being used in the timing info of the ASP which is an absolute value (as e.g. for UL grants).
   * @param     p_EUTRA_FDD_TDD_Mode  ... FDD/TDD
   * @param     p_Index               ... index of the PDU/SUDs
   * @return    integer
   * @status    APPROVED
   */
  function f_EUTRA_DataListSubframeOffset(EUTRA_FDD_TDD_Mode_Type p_EUTRA_FDD_TDD_Mode,
                                          integer p_Index) return integer
  {
    var integer j;
    var integer v_SubframeOffset;
    
    if (p_EUTRA_FDD_TDD_Mode == TDD)
      {
        // index  = 0, 1, 2, 3,  4,  5,  6, .. =>
        // offset = 0, 1, 5, 6, 10, 11, ..
        j := ((p_Index) / 2);
        v_SubframeOffset := p_Index + j * 3;
      }
    else // FDD
      {
        v_SubframeOffset := p_Index;
      }
    return v_SubframeOffset;
  } // f_EUTRA_CalcSubframeOffset_DataList
  
  } // end of group SubframeTiming

  group ULGRant_DLAllocation {
  //============================================================================
  // local common function
  //----------------------------------------------------------------------------

  //----------------------------------------------------------------------------
  /*
   * @desc      Basic function used in various types of explicit UL grant configuration
   * @param     p_CellId
   * @param     p_TimingInfo
   * @param     p_DciUlInfo
   * @param     p_PUCCH_Synch
   * @param     p_UL_GrantConfig
   * @status    APPROVED
   */
  function f_EUTRA_ULGrantConfiguration_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) runs on EUTRA_PTC
  {
    f_EUTRA_SS_CommonCellConfig(p_CellId, cas_ULGrantAllocation_REQ(p_CellId, p_TimingInfo, p_DciUlInfo, p_PUCCH_Synch, p_UL_GrantConfig));
  }

  //============================================================================
  //
  //----------------------------------------------------------------------------
  /*
   * @desc      Function to start configurable periodic UL grant allocation and  auto PUCCH synchronisation
   *            Configures SS to start periodic UL grant transmission
   *            Suitable for RLC and MAC test cases.
   * @param     p_CellId
   * @param     p_TimingInfo
   * @param     p_Imcs
   * @param     p_Nprb
   * @param     p_Period
   * @status    APPROVED
   */
  function f_EUTRA_PeriodicULGrantTransmission( CellId_Type p_CellId,
                                                template (value) TimingInfo_Type p_TimingInfo ,
                                                ImcsValue_Type  p_Imcs,
                                                integer p_Nprb,
                                                integer p_Period) runs on EUTRA_PTC
  {
    f_EUTRA_ULGrantConfiguration_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_ContPeriodic(p_Period));
  };
  //============================================================================
  /*
   * @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
   * @status    APPROVED
   */
  function f_EUTRA_PeriodicCyclicULGrantTransmission( CellId_Type p_CellId,
                                                      template (value) TimingInfo_Type p_TimingInfo ,
                                                      ImcsValue_Type  p_Imcs,
                                                      integer p_Nprb,
                                                      integer p_Period,
                                                      integer p_Cycles) 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(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));
  };
  //============================================================================
  /*
   * @desc      Function to start configurable one time grant allocation and keep PUCCH synchronisation unchanged
   * @param     p_CellId
   * @param     p_TimingInfo
   * @param     p_Imcs
   * @param     p_Nprb
   * @status    APPROVED
   */
  function f_EUTRA_OneULGrantTransmission( CellId_Type p_CellId,
                                           template (value) TimingInfo_Type p_TimingInfo ,
                                           ImcsValue_Type  p_Imcs,
                                           integer p_Nprb) 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(p_Imcs,  p_Nprb),
                                        f_EUTRA_PUCCH_Synch_Auto(),  // @sic R5-101177, R5-101178, R5-101050 sic@
                                        cs_UL_GrantConfig_OneTime);
  };

  function f_EUTRA_OneULGrantTransmission_DCI( CellId_Type p_CellId,
                                               template (value) TimingInfo_Type p_TimingInfo ,
                                               template (value) DciUlInfo_Type  p_ULDCIInfo ) 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,
                                        p_ULDCIInfo,
                                        f_EUTRA_PUCCH_Synch_Auto(),  // @sic R5-101177, R5-101178, R5-101050 sic@
                                        cs_UL_GrantConfig_OneTime);
  };
  //============================================================================
  /*
   * @desc      Function to start configurable UL grant allocation on SR reception and PUCCH synchronisation:
   *            starts UL grant transmission on SI reception
   *            configures SS to maintain UE in PUCCH synchronised state
   *            needs to be called when UE enters connected mode in a cell (after reception of RRCConnectionReq or HandoverComplete)
   * @param     p_CellId
   * @param     p_TimingInfo
   * @param     p_ULDCIInfo
   * @status    APPROVED
   */
  function f_EUTRA_StartULGrantTransmissionOnSR_Reception ( CellId_Type p_CellId,
                                                            template (value) TimingInfo_Type p_TimingInfo,
                                                            template (value) DciUlInfo_Type  p_ULDCIInfo ) runs on EUTRA_PTC
  {
    f_EUTRA_ULGrantConfiguration_Common(p_CellId,
                                        p_TimingInfo,
                                        p_ULDCIInfo,
                                        cs_PUCCH_Synch_KeepAsItIs,
                                        cs_UL_GrantConfig_Def);
  };
  //============================================================================
  /*
   * @desc      Function to start configurable UL grant allocation on SR reception and No PUCCH synchronisation
   *            suitable when time alignment timer is configured as infinity
   * @param     p_CellId
   * @param     p_TimingInfo
   * @param     p_ULDCIInfo
   * @status    APPROVED
   */
  function f_EUTRA_StartULGrantTransmissionOnSR_Reception_No_PUCCH_Sync ( CellId_Type p_CellId,
                                                            template (value) TimingInfo_Type p_TimingInfo,
                                                            template (value) DciUlInfo_Type  p_ULDCIInfo  ) runs on EUTRA_PTC
  { /* starts UL grant transmission on SI reception
       configures SS to maintain UE in PUCCH synchronised state
       needs to be called when UE enters connected mode in a cell [after reception of RRCConnectionReq or HandoverComplete] */
    f_EUTRA_ULGrantConfiguration_Common(p_CellId,
                                        p_TimingInfo,
                                        p_ULDCIInfo,
                                        cs_PUCCH_Synch_None,
                                        cs_UL_GrantConfig_Def);
  };
  //============================================================================
  /*
   * @desc      Function to start configurable UL grant allocation on SR reception and PUCCH synchronisation
   * @param     p_CellId
   * @param     p_TimingInfo
   * @param     p_Imcs
   * @param     p_Nprb
   * @status    APPROVED
   */
  function f_EUTRA_StartExplicitULGrantTransmissionOnSR_Reception ( CellId_Type p_CellId,
                                                                    template (value) TimingInfo_Type p_TimingInfo,
                                                                    ImcsValue_Type  p_Imcs,
                                                                    integer p_Nprb) runs on EUTRA_PTC {
    // starts UL grant transmission on SI reception
    // configures SS to maintain UE in PUCCH synchronised state
    //  needs to be called when UE enters connected mode in a cell [after reception of RRCConnectionReq or HandoverComplete]
    f_EUTRA_ULGrantConfiguration_Common(p_CellId,
                                        p_TimingInfo,
                                        cs_DciInfo_CcchDcchDtchUL_Explicit(p_Imcs,  p_Nprb),
                                        cs_PUCCH_Synch_KeepAsItIs,
                                        cs_UL_GrantConfig_Def);
  };
  //============================================================================
  /*
   * @desc      Function to stop UL Grant transmision but keep PUCCH synchronisation unchanged
   * @param     p_CellId
   * @param     p_TimingInfo
   * @status    APPROVED
   */
  function f_EUTRA_StopULGrantTransmission_PUCCH_Sync ( CellId_Type p_CellId,
                                                        template (value) TimingInfo_Type p_TimingInfo ) runs on EUTRA_PTC
  { // stops UL grant transmission
    // configures SS to not maintain UE in PUCCH synchronised state
    //  needs to be called when UE enters idle mode in a cell [after RRCConnectionRelease]
    f_EUTRA_ULGrantConfiguration_Common(p_CellId,
                                        p_TimingInfo,
                                        omit,   // no DCI info
                                        f_EUTRA_PUCCH_Synch_Auto(),  // @sic R5-101177, R5-101178, R5-101050 sic@
                                        cs_UL_GrantConfig_Stop);
  };

  //============================================================================
  /*
   * @desc      Function to stop UL Grant transmision and not maintain PUCCH synchronisation
   * @param     p_CellId
   * @param     p_TimingInfo
   * @status    APPROVED
   */
  function f_EUTRA_StopULGrantTransmission_No_PUCCH_Sync ( CellId_Type p_CellId,
                                                           template (value) TimingInfo_Type p_TimingInfo ) runs on EUTRA_PTC
  { // stops UL grant transmission
    // configures SS to not maintain UE in PUCCH synchronised state
    //  needs to be called when UE enters idle mode in a cell [after RRCConnectionRelease]
    //JKS NOTE:used in tc 7.1.2.6 step 8
    f_EUTRA_ULGrantConfiguration_Common(p_CellId,
                                        p_TimingInfo,
                                        omit,   // no DCI info
                                        cs_PUCCH_Synch_None,
                                        cs_UL_GrantConfig_Stop);
  };
  } // end of group ULGRant_DLAllocation
  group L2_EncodeDecode {

  /*
   * @desc      To PER encode and DL CCCH ASN.1 type message
   * @param     p_CCCH_Message
   * @return    octetstring
   * @status    APPROVED
   */
  function f_RRC_DL_CCCH_Encvalue(template (value) DL_CCCH_Message p_CCCH_Message) return octetstring
  {
    var bitstring v_Bitstring := encvalue(p_CCCH_Message);
    var octetstring v_Octetstring := bit2oct(f_OctetAlignedBitString(v_Bitstring));
    return v_Octetstring;
  };

  /*
   * @desc      encode PDCP PDU
   * @param     p_PDCP_PDU
   * @return    octetstring
   * @status    APPROVED
   */
  function f_PDCP_PDU_Encvalue(template (value) PDCP_PDU_Type p_PDCP_PDU) return octetstring
  {
    var bitstring v_Bitstring := encvalue(p_PDCP_PDU);
    var octetstring v_Octetstring := bit2oct(f_OctetAlignedBitString(v_Bitstring));
    return v_Octetstring;
  };

  /*
   * @desc      encode RLC PDU
   * @param     p_RLC_PDU
   * @return    octetstring
   * @status    APPROVED
   */
  function f_RLC_PDU_Encvalue(template (value) RLC_PDU_Type p_RLC_PDU) return octetstring {
    var bitstring v_Bitstring := encvalue(p_RLC_PDU);
    var octetstring v_Octetstring := bit2oct(f_OctetAlignedBitString(v_Bitstring));
    return v_Octetstring;
  };

  function f_MAC_PDU_Encvalue(template (value) MAC_PDU_Type p_MAC_PDU) return octetstring {
    var bitstring v_Bitstring := encvalue(p_MAC_PDU);
    var octetstring v_Octetstring := bit2oct(f_OctetAlignedBitString(v_Bitstring));
    return v_Octetstring;
  };

  /*
   * @desc      decode MAC PDU
   * @param     p_MAC_SDU
   * @return    RLC_PDU_Type
   * @status    APPROVED
   */
  function f_MAC_SDU_Decode(MAC_SDU_Type p_MAC_SDU) return RLC_PDU_Type
  {
    var RLC_PDU_Type v_RLC_PDU;
    var bitstring v_Bitstring := oct2bit(p_MAC_SDU);
    var integer v_Result := decvalue(v_Bitstring, v_RLC_PDU);
    if (v_Result != 0) {
      FatalError(__FILE__, __LINE__, "RLC PDU cannot be decoded");
    }
    return v_RLC_PDU;
  };

  } // end of group L2_Encode

  /***************************************************************************************************/
  // Function to Config SS for reporting Scheduling Request Reception
  /////////////////////////////////////////////////////////////////////////////////////////////////////
  /*
   * @desc      To configure Scheduling Request MAC indication Mode
   * @param     p_CellId
   * @param     p_SR_Mode
   * @status    APPROVED
   */
  function f_SS_ConfigSchedulingRequestIndMode ( CellId_Type p_CellId,
                                                 L1Mac_IndicationMode_Type p_SR_Mode) runs on EUTRA_PTC
  {
    f_EUTRA_SS_CommonL1MacIndCtrlConfig(p_CellId, cas_SchedulingReqIndConfig_REQ (p_CellId, p_SR_Mode));
  };

  group DRB_UM {
  
  /*
   * @desc      Readio Bearer configuration for one DRB (UM bearer in TM mode)
   * @param     p_CellId
   * @param     p_UM_SN_Size
   * @status    APPROVED
   */
  function f_EUTRA_SS_DRB2_ConfigUM_TM_Mode(CellId_Type p_CellId,
                                            integer p_UM_SN_Size)
    runs on EUTRA_PTC
  { // @sic R5w100002r1 sic@
    if (p_UM_SN_Size == tsc_UM_SN_Size_5) {
      f_EUTRA_SS_CommonRadioBearerConfig_SingleDRB ( p_CellId, cds_DRB2_ConfigUM_TM_Mode_SN5 );
      
    } else {
      f_EUTRA_SS_CommonRadioBearerConfig_SingleDRB ( p_CellId, cs_DRB2_ConfigUM_TM_Mode_SN10 );
    }
  }
  } // end of group DRB_UM

  group L1_MAC_Ind_Functions {  // Functions to configure SS in special reporting modes
  /*
   * @desc      Function to Config SS for reporting Buffer Status Report Reception
   * @param     p_CellId
   * @param     p_BSR_Mode
   * @param     p_TimingInfo        (default value: cs_TimingInfo_Now)
   * @status    APPROVED
   */
  function f_SS_ConfigBufferStatusReportIndMode (CellId_Type p_CellId,
                                                 L1Mac_IndicationMode_Type p_BSR_Mode,
                                                 template (value) TimingInfo_Type p_TimingInfo := cs_TimingInfo_Now) runs on EUTRA_PTC
  {
    f_EUTRA_SS_CommonL1MacIndCtrlConfig(p_CellId, cas_BSR_IndConfig_REQ(p_CellId, p_BSR_Mode, p_TimingInfo));
  };
  
  /*----------------------------------------------------------------------------------------------*/
  /*
   * @desc      Function to Config SS for reporting UL HAR ACK/NACK Reception
   * @param     p_CellId
   * @param     p_UL_HARQ_Mode
   * @status    APPROVED
   */
  function f_SS_ConfigUL_HARQ_IndMode (CellId_Type p_CellId,
                                       L1Mac_IndicationMode_Type p_UL_HARQ_Mode) runs on EUTRA_PTC
  {
    f_EUTRA_SS_CommonL1MacIndCtrlConfig(p_CellId, cas_UL_HARQ_IndConfig_REQ (p_CellId, p_UL_HARQ_Mode));
  };


  }// end of group L1_MAC_Ind_Functions

  group Generic_L2_RRC_ReconfigSteps {
  ///***************************************************************************************************/
  // This group duplicates generic functions for L2 as a result of R5-096458
  /////////////////////////////////////////////////////////////////////////////////////////////////////

  //***************************************************************************************************/
  /*
   * @desc      This function is same as  fl_EUTRA_GenericRbEst except for no_periodic_BSR_or_PHR branch of table
   *            Table 4.8.2.1.5-1 as a result of R5-096458
   * @param     p_CellId
   * @param     p_NoOfAddDRBs_AM
   * @param     p_NoOfAddDRBs_UM
   * @param     p_QoS
   * @param     p_Tft
   * @param     p_PDCP_StatusReportRequired (default value: true)
   * @status    APPROVED
   */
  function fl_EUTRA_GenericRbEst_DisableBSR_PHR( CellId_Type p_CellId,
                                                 integer p_NoOfAddDRBs_AM,
                                                 integer p_NoOfAddDRBs_UM,
                                                 template (omit) EPS_QoSList_Type p_QoS,
                                                 template (omit) Tft_List_Type p_Tft,
                                                 boolean p_PDCP_StatusReportRequired := true ) 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 (value) MAC_MainConfig_Type v_MAC_MainConfig ;
    var template (omit) PhysicalConfigDedicated v_PhysicalConfigDedicated := omit;  // => apply default setting acc. 36.508 cl. 4.8.2.1.6 */
    if (p_NoOfAddDRBs_UM > 0) {
      v_MAC_MainConfig := cs_508_MAC_MainConfig_Explicit_RBC_DrxS_DisableBSR_PHR; // short DRX cycle acc. to note in 36.508 table 4.6.3-16
    } else {
      v_MAC_MainConfig := cs_508_MAC_MainConfig_Explicit_RBC_DrxL_DisableBSR_PHR; // long DRX cycle acc. to note in 36.508 table 4.6.3-16
    };
    f_EUTRA_GenericRbEst_Common(p_CellId,
                                p_NoOfAddDRBs_AM,
                                p_NoOfAddDRBs_UM,
                                v_DRB_ToAddModList,
                                v_MAC_MainConfig,
                                v_PhysicalConfigDedicated,
                                p_QoS,
                                p_Tft,
                                p_PDCP_StatusReportRequired);
  };

  /***************************************************************************************************/
  /*
   * @desc      This function is same as  f_EUTRA_RbEst_Def except for no_periodic_BSR_or_PHR branch of table
   *            Table 4.8.2.1.5-1 as a result of R5-096458
   * @param     p_CellId
   * @param     p_PDCP_StatusReportRequired (default value: true)
   * @status    APPROVED
   */
  function f_EUTRA_RbEst_Def_DisableBSR_PHR(CellId_Type p_CellId,
                                            boolean p_PDCP_StatusReportRequired := true) runs on EUTRA_PTC
  {
    fl_EUTRA_GenericRbEst_DisableBSR_PHR(p_CellId, 0, 0, omit, omit, p_PDCP_StatusReportRequired);
  };

  ///***************************************************************************************************/
  /*
   * @desc      This function is same as  f_EUTRA_RbEst_508_UM except for no_periodic_BSR_or_PHR branch
   *            of table Table 4.8.2.1.5-1 as a result of R5-096458
   * @param     p_CellId
   * @status    APPROVED
   */
  function f_EUTRA_RbEst_508_UM_DisableBSR_PHR(CellId_Type p_CellId) runs on EUTRA_PTC
  { /* additional UM bearer will be established */
    var template (value) EPS_QoSList_Type v_Qos_List := {cs_508_EPS_QoS_Dedicated_1};
    var template (value) Tft_List_Type v_Tft_List := {cs_508_Tft_Dedicated_1};
    fl_EUTRA_GenericRbEst_DisableBSR_PHR(p_CellId, 0, 1, v_Qos_List, v_Tft_List);
  };

  /***************************************************************************************************/
  /*
   * @desc      This function is same as f_EUTRA_LoopBackActivation_State4_Def except for no_periodic_BSR_or_PHR branch of Table 4.8.2.1.5-1 as a result of R5-096458
   * @param     p_CellId
   * @param     p_UE_TestLoopModeA_LB_Setup
   * @status    APPROVED
   */
  function f_EUTRA_LoopBackActivation_State4_Def_DisableBSR_PHR(CellId_Type p_CellId,
                                                 template (value) UE_TestLoopModeA_LB_Setup_Type p_UE_TestLoopModeA_LB_Setup) runs on EUTRA_PTC
  {
    f_EUTRA_RbEst_Def_DisableBSR_PHR(p_CellId);                                       // bring UE to State 3
    f_EUTRA_CloseUE_TestLoopModeA(p_CellId, p_UE_TestLoopModeA_LB_Setup);             // Step 1-2
  };

  ///***************************************************************************************************/
  // This function is wrapper for as  f_EUTRA_GenericRbEst_Common except for no_periodic_BSR_or_PHR branch of table
  // Table 4.8.2.1.5-1 as a result of R5-096458
  /////////////////////////////////////////////////////////////////////////////////////////////////////
  /*
   * @desc      Genric function to establsih SRB2 and DRB's but with special L2 option to disable BSR and PHR
   *            according to the condition no_periodic_BSR_or_PHR as specified in TS 36.508 subclause 4.8.2.1.5
   * @param     p_CellId
   * @param     p_NoOfAddDRBs_AM
   * @param     p_NoOfAddDRBs_UM
   * @param     p_DRB_ToAddModList
   * @param     p_MAC_MainConfig
   * @param     p_PhysicalConfigDedicated
   * @param     p_QoS
   * @param     p_Tft
   * @status    APPROVED
   */
   function f_EUTRA_GenericRbEst_DisableBSR_PHR ( 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 )
    runs on EUTRA_PTC
  {
   var template (value) MAC_MainConfig_Type v_MAC_MainConfig ;
   if (isvalue(p_MAC_MainConfig)) {
      v_MAC_MainConfig := p_MAC_MainConfig;
    } else {
     if (p_NoOfAddDRBs_UM > 0) {
       v_MAC_MainConfig := cs_508_MAC_MainConfig_Explicit_RBC_DrxS_DisableBSR_PHR; // short DRX cycle acc. to note in 36.508 table 4.6.3-16
     } else {
       v_MAC_MainConfig := cs_508_MAC_MainConfig_Explicit_RBC_DrxL_DisableBSR_PHR; // long DRX cycle acc. to note in 36.508 table 4.6.3-16
     }
   }
   f_EUTRA_GenericRbEst_Common(p_CellId,
                               p_NoOfAddDRBs_AM,
                               p_NoOfAddDRBs_UM,
                               p_DRB_ToAddModList,
                               v_MAC_MainConfig,
                               p_PhysicalConfigDedicated,
                               p_QoS,
                               p_Tft);
  };

  /*
   * @desc      Generic function to establish DRB(1,1) combination with parameterised DRB list, MAC and Physical config
   * @param     p_CellId
   * @param     p_DRB_ToAddModList
   * @param     p_MAC_MainConfig    (default value: omit)
   * @param     p_PhysicalConfigDedicated (default value: omit)
   * @status    APPROVED
   */
  function f_EUTRA_GenericRbEst_WithRLC_UM_Params(CellId_Type p_CellId,
                                                  template (omit) DRB_ToAddModList p_DRB_ToAddModList,
                                                  template (omit) MAC_MainConfig_Type p_MAC_MainConfig := omit,
                                                  template (omit) PhysicalConfigDedicated p_PhysicalConfigDedicated := omit) runs on EUTRA_PTC
  {
    var template (value) EPS_QoSList_Type v_Qos_List := {cs_508_EPS_QoS_Dedicated_1};
    var template (value) Tft_List_Type v_Tft_List := {cs_508_Tft_Dedicated_1};

    f_EUTRA_GenericRbEst_DisableBSR_PHR(p_CellId,
                                        0,
                                        1,
                                        p_DRB_ToAddModList,
                                        p_MAC_MainConfig,
                                        p_PhysicalConfigDedicated,
                                        v_Qos_List,
                                        v_Tft_List);
  };  // f_EUTRA_GenericRbEst_WithRLC_UM_Params

  /*
   * @desc     Generic step to config DRB[1,1] combination with parameterised RLC MAC and physical
   * @param     p_CellId
   * @param     p_PDCP_Config
   * @param     p_UL_UM_RLC
   * @param     p_DL_UM_RLC
   * @param     p_MAC_MainConfig    (default value: omit)
   * @param     p_PhysicalConfigDedicated (default value: omit)
   * @status    APPROVED
   */
  function f_EUTRA_GenericRbEst_UM_Params (CellId_Type p_CellId,
                                           template (value) PDCP_Config  p_PDCP_Config,
                                           template (value) UL_UM_RLC p_UL_UM_RLC,
                                           template (value) DL_UM_RLC p_DL_UM_RLC,
                                           template (omit) MAC_MainConfig_Type p_MAC_MainConfig := omit,
                                           template (omit) PhysicalConfigDedicated p_PhysicalConfigDedicated := omit) runs on EUTRA_PTC
  {
    var template (omit) DRB_ToAddModList v_DRB_ToAddModList:= omit;

    v_DRB_ToAddModList[0] := cs_508_DRB_ToAddMod_DEFAULT_AM (tsc_DRB1);
    v_DRB_ToAddModList[1] := cs_DRB_ToAddMod_RLC_UM (tsc_DRB2,
                                                     p_PDCP_Config,
                                                     p_UL_UM_RLC,
                                                     p_DL_UM_RLC);
    f_EUTRA_GenericRbEst_WithRLC_UM_Params (p_CellId,
                                            v_DRB_ToAddModList,
                                            p_MAC_MainConfig,
                                            p_PhysicalConfigDedicated);
  }  // f_EUTRA_GenericRbEst_UM_Params
  
  } // end of group Generic_L2_RBSteps

  group Common_L2Functions {

  /*
   * @desc      to configure SS to transmit a PDCCH order
   * @param     p_CellId
   * @param     p_TimingInfo
   * @param     p_RA_PDCCH_Order
   * @status    APPROVED
   */
  function f_Send_PDCCH_Order (CellId_Type p_CellId,
                               template (value) TimingInfo_Type p_TimingInfo,
                               template (value) RA_PDCCH_Order_Type p_RA_PDCCH_Order) runs on EUTRA_PTC
  {
    SYS.send ( cas_RA_PDCCH_Order(p_CellId, p_TimingInfo, p_RA_PDCCH_Order) ); //@sic Baseline R5s100135: cas_RA_PDCCH_Order does not require a confirmation sic@
  };


  } // end of group Common_L2Functions


} // module
