/******************************************************************************/
// @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-15 18:29:22 +0200 (Wed, 15 Sep 2010) $
// $Rev: 3910 $
/******************************************************************************/

module L2_CommonTemplates {
import from CommonDefs all;
import from EUTRA_ASP_TypeDefs all;
import from EUTRA_ASP_DrbDefs all;
import from EUTRA_RRC_ASN1_Definitions language "ASN.1:1997" all;
import from EUTRA_CommonDefs all;
import from EUTRA_AspCommon_Templates all;
import from EUTRA_RRC_Templates all;
import from EUTRA_DRB_Templates all;

group L2_PRBS_Functions {

//----------------------------------------------------------------------------
/*
 * @desc      function to extract output string  from random test pattern of a certain length and at a starting point
 * @param     p_Start
 * @param     p_N
 * @return    octetstring
 * @status    APPROVED
 */
function f_GetN_OctetsFromPRBS(UInt_Type p_Start,
                               UInt_Type p_N)
  return octetstring
{
  var integer i;
  var integer k;
  var octetstring v_Noctets :=''O; // output string to be extracted from random test pattern

  for (i:= 0; i< p_N; i := i+1) {
    k := p_Start + i;
    k := k mod 2047;
    v_Noctets := v_Noctets & tsc_RandomPRBS[k];
  }
  return v_Noctets;
} // f_GetN_OctetsFromPRBS

} // L2_PRBS_Functions

/******************************************************************************/
/******************************************************************************/

group L2_CommonTypesAndConstants {

//=========================================================================
//Constants
//=========================================================================

const octetstring tsc_RandomPRBS :=                      /* @status    APPROVED */
    'FFE665A5C5CA3452085408ABEECE4B0B813FD337873F2CD1E29AE91BD6C8E14F'O
  & 'DE630F8195688EBE465F09816A8EEB1B83953DD362DAE3B06D5B76D8E3E53087'O
  & 'EA645A09017FD99C3CACBB46DF1CD61DA9C435F89943DF9CC34ADEE31AD6E24F'O
  & 'A1903D53778D949742750DD49DE9CE9E430AD448A14575D89C16025508814020'O //octets 0 .. 127
  & '0555DDC9CBCB9EC31F833F866A5BA390680EAB11282EAE44F5E7658F6B247A0C'O
  & '54A21057F73278595C235077F267A59097E8CEB4EDE49A16FDB36D2485EA3107'O
  & 'D59DC360700D5488BEB9B96C24AF44DF498BC135788C14A8BBEC64A5EF64DA1C'O
  & '5608FEB312D7B738D3E2CFB4C74A7458A3EF9B3C79F3CD348740DFE330780C01'O //octets 128 .. 255
  & 'FFCCCB4B8B9468A410A81157DD9C9617027FA66F0E7E59A3C535D237AD91C29F'O
  & 'BCC61F032AD11D7C8CBE1302D51DD637072A7BA6C5B5C760DAB6EDB1C7CA610F'O
  & 'D4C8B41202FFB3387959768DBE39AC3B53886BF13287BF398695BDC635ADC49F'O
  & '43207AA6EF1B292E84EA1BA93BD39D3C8615A891428AEBB1382C04AA11028040'O //octets 256 .. 383
  & '0AABBB9397973D863F067F0CD4B74720D01D5622505D5C89EBCECB1ED648F418'O
  & 'A94420AFEE64F0B2B846A0EFE4CF4B212FD19D69DBC9342DFB66DA490BD4620F'O
  & 'AB3B86C0E01AA9117D7372D8495E89BE9317826AF118295177D8C94BDEC9B438'O
  & 'AC11FD6625AF6E71A7C59F698E94E8B147DF3678F3E79A690E81BFC660F01803'O //octets 384 .. 511
  & 'FF9996971728D148215022AFBB392C2E04FF4CDE1CFCB3478A6BA46F5B23853F'O
  & '798C3E0655A23AF9197C2605AA3BAC6E0E54F74D8B6B8EC1B56DDB638F94C21F'O
  & 'A991682405FF6670F2B2ED1B7C735876A710D7E2650F7E730D2B7B8C6B5B893E'O
  & '8640F54DDE36525D09D4375277A73A790C2B51228515D7627058095422050080'O //octets 512 .. 639
  & '155777272F2E7B0C7E0CFE19A96E8E41A03AAC44A0BAB913D79D963DAC91E831'O
  & '5288415FDCC9E165708D41DFC99E96425FA33AD3B792685BF6CDB49217A8C41F'O
  & '56770D81C0355222FAE6E5B092BD137D262F04D5E23052A2EFB19297BD936871'O
  & '5823FACC4B5EDCE34F8B3ED31D29D1628FBE6CF1E7CF34D21D037F8CC1E03007'O //octets 640 .. 767
  & 'FF332D2E2E51A29042A0455F7672585C09FE99BC39F9668F14D748DEB6470A7E'O
  & 'F3187C0CAB4475F232F84C0B547758DC1CA9EE9B16D71D836ADBB6C71F29843F'O
  & '5322D0480BFECCE1E565DA36F8E6B0ED4E21AFC4CA1EFCE61A56F718D6B7127D'O
  & '0C81EA9BBC6CA4BA13A86EA4EF4E74F21856A2450A2BAEC4E0B012A8440A0100'O //octets 768 .. 895
  & '2AAEEE4E5E5CF618FC19FC3352DD1C834075588941757227AF3B2C7B5923D062'O
  & 'A51082BFB993C2CAE11A83BF933D2C84BF4675A76F24D0B7ED9B69242F51883E'O
  & 'ACEE1B03806AA445F5CDCB61257A26FA4C5E09ABC460A545DF63252F7B26D0E2'O
  & 'B047F59896BDB9C69F167DA63A53A2C51F7CD9E3CF9E69A43A06FF1983C0600F'O //octets 896 .. 1023
  & 'FE665A5C5CA3452085408ABEECE4B0B813FD337873F2CD1E29AE91BD6C8E14FD'O
  & 'E630F8195688EBE465F09816A8EEB1B83953DD362DAE3B06D5B76D8E3E53087E'O
  & 'A645A09017FD99C3CACBB46DF1CD61DA9C435F89943DF9CC34ADEE31AD6E24FA'O
  & '1903D53778D949742750DD49DE9CE9E430AD448A14575D89C160255088140200'O //octets 1024 .. 1151
  & '555DDC9CBCB9EC31F833F866A5BA390680EAB11282EAE44F5E7658F6B247A0C5'O
  & '4A21057F73278595C235077F267A59097E8CEB4EDE49A16FDB36D2485EA3107D'O
  & '59DC360700D5488BEB9B96C24AF44DF498BC135788C14A8BBEC64A5EF64DA1C5'O
  & '608FEB312D7B738D3E2CFB4C74A7458A3EF9B3C79F3CD348740DFE330780C01F'O //octets 1152 .. 1279
  & 'FCCCB4B8B9468A410A81157DD9C9617027FA66F0E7E59A3C535D237AD91C29FB'O
  & 'CC61F032AD11D7C8CBE1302D51DD637072A7BA6C5B5C760DAB6EDB1C7CA610FD'O
  & '4C8B41202FFB3387959768DBE39AC3B53886BF13287BF398695BDC635ADC49F4'O
  & '3207AA6EF1B292E84EA1BA93BD39D3C8615A891428AEBB1382C04AA110280400'O //octets 1280 .. 1407
  & 'AABBB9397973D863F067F0CD4B74720D01D5622505D5C89EBCECB1ED648F418A'O
  & '94420AFEE64F0B2B846A0EFE4CF4B212FD19D69DBC9342DFB66DA490BD4620FA'O
  & 'B3B86C0E01AA9117D7372D8495E89BE9317826AF118295177D8C94BDEC9B438A'O
  & 'C11FD6625AF6E71A7C59F698E94E8B147DF3678F3E79A690E81BFC660F01803F'O //octets 1408 .. 1535
  & 'F9996971728D148215022AFBB392C2E04FF4CDE1CFCB3478A6BA46F5B23853F7'O
  & '98C3E0655A23AF9197C2605AA3BAC6E0E54F74D8B6B8EC1B56DDB638F94C21FA'O
  & '991682405FF6670F2B2ED1B7C735876A710D7E2650F7E730D2B7B8C6B5B893E8'O
  & '640F54DDE36525D09D4375277A73A790C2B51228515D76270580954220500801'O //octets 1536 .. 1663
  & '55777272F2E7B0C7E0CFE19A96E8E41A03AAC44A0BAB913D79D963DAC91E8315'O
  & '288415FDCC9E165708D41DFC99E96425FA33AD3B792685BF6CDB49217A8C41F5'O
  & '6770D81C0355222FAE6E5B092BD137D262F04D5E23052A2EFB19297BD9368715'O
  & '823FACC4B5EDCE34F8B3ED31D29D1628FBE6CF1E7CF34D21D037F8CC1E03007F'O //octets 1664 .. 1791
  & 'F332D2E2E51A29042A0455F7672585C09FE99BC39F9668F14D748DEB6470A7EF'O
  & '3187C0CAB4475F232F84C0B547758DC1CA9EE9B16D71D836ADBB6C71F29843F5'O
  & '322D0480BFECCE1E565DA36F8E6B0ED4E21AFC4CA1EFCE61A56F718D6B7127D0'O
  & 'C81EA9BBC6CA4BA13A86EA4EF4E74F21856A2450A2BAEC4E0B012A8440A01002'O //octets 1792 .. 1919
  & 'AAEEE4E5E5CF618FC19FC3352DD1C834075588941757227AF3B2C7B5923D062A'O
  & '51082BFB993C2CAE11A83BF933D2C84BF4675A76F24D0B7ED9B69242F51883EA'O
  & 'CEE1B03806AA445F5CDCB61257A26FA4C5E09ABC460A545DF63252F7B26D0E2B'O
  & '047F59896BDB9C69F167DA63A53A2C51F7CD9E3CF9E69A43A06FF1983C0600'O; //octets 1920 .. 2046


const B2_Type  tsc_B2_Reserved := '00'B;                      /* @status    APPROVED */
const B3_Type  tsc_B3_Reserved := '000'B;                     /* @status    APPROVED */
                                                         

/***** RLC: *****/
const integer         tsc_AM_SN_Size := 10;             /* @status   APPROVED */

const integer         tsc_UM_SN_Size_5 := 5;            /* @desc     The number of bits used to represent a 5 bits UM sequence number.
                                                         *           Ref 3G TS 25.322 clause 6.2.2.3
                                                         * @status   APPROVED */

const integer         tsc_UM_SN_Size_10 := 10;          /* @desc     The number of bits used to represent a 10 bits UM sequence number.
                                                         *           Ref 3G TS 36.322 clause 6.2.2.3
                                                         * @status   APPROVED */

const B1_Type         tsc_D_C_Control:= '0'B;           /* @desc     Value for D/C field within an AMD Control PDU.
                                                         *           Ref 3G TS 36.322 clause 6.2.2.9
                                                         * @status   APPROVED */

const B3_Type         tsc_CPT_STATUSPDU := '000'B;      /* @desc     Value for CPT field to indicate that RLC Control PDU is a STATUS PDU.
                                                         *           Ref 3G TS 36.322 clause 6.2.2.13
                                                         * @status   APPROVED */

const B1_Type         tsc_E1_NoNACK_Follows := '0'B;    /* @desc     Value to indicate that a set of NACK_SN, E1 and E2 does not follow.
                                                         *           Ref 3G TS 36.322 clause 6.2.2.15
                                                         * @status   APPROVED */

const B1_Type         tsc_E_Data := '0'B;               /* @desc     Value for ExtBit in UMDPDU/AMDPDU/AMDPDUsegment when the next field is data.
                                                         *           Ref 3G TS 36.322 clause 6.2.2.4
                                                         * @status   APPROVED */

const RLC_FramingInfo_Type tsc_FI_FullSDU := '00'B;     /* @desc     Value to indicate that PDU contains a complete SDU. Ref 3G TS
                                                         *           36.322 clause 6.2.2.6
                                                         * @status   APPROVED */

/***** PDCP: *****/
const B1_Type         tsc_D_C_CtrlPDU := '0'B;          /* @desc    Value for D/C field within an PDCP Control PDU.
                                                         *          Ref 3G TS 36.323 clause 6.3.7
                                                         * @status  APPROVED */

const B1_Type         tsc_D_C_DataPDU := '1'B;          /* @desc    Value for D/C field within an PDCP Data PDU.
                                                         *          Ref 3G TS 36.323 clause 6.3.7
                                                         * @status  APPROVED */

const B1_Type         tsc_R_Bit := '0'B;                /* @desc    Value for R field within an PDCP Data PDU.
                                                         *          Ref 3G TS 36.323 clause 6.3.6
                                                         * @status  APPROVED */

const integer         tsc_PDCP_SN_Size_12 := 12;        /* @desc    The number of bits used to represent a PDCP sequence number.
                                                         *          Ref 3G TS 36.323 clause 6.2.2.3
                                                         * @status  APPROVED */
const integer         tsc_PDCP_SN_Size_7 := 7;          /* @desc    The number of bits used to represent a PDCP sequence number.
                                                         *          Ref 3G TS 36.323 clause 6.2.2.3
                                                         * @status  APPROVED */
const integer         tsc_Maximum_PDCP_SN_12 := 4095;   /* @status  APPROVED */
const integer         tsc_Maximum_PDCP_SN_7 := 127;     /* @status  APPROVED */
const integer         tsc_Maximum_PDCP_SN_5 := 31;      /* @status  APPROVED */

const B3_Type         tsc_PDU_Type_StatusRep := '000'B; /* @desc    Value for PDU type field to indicate that Control PDU is a STATUS REPORT
                                                         *          Ref 3G TS 36.323 clause 6.3.8
                                                         * @status  APPROVED */

const B3_Type         tsc_PDU_Type_ROHC_Fdbk := '001'B; /* @desc    Value for PDU type field to indicate that Control PDU is a ROHC Feedback packet
                                                         *          Ref 3G TS 36.323 clause 6.3.8
                                                         * @status   */

template (value) PDCP_SDU_Type crs_PDCP_SDU_16B   := f_GetN_OctetsFromPRBS(0,16);     /* @status    APPROVED */

} // end of group L2_CommonTypesAndConstants

/******************************************************************************/
/******************************************************************************/

group Layer2_CommonTemplates {

template (value) PDCP_Configuration_Type cs_PDCP_Configuration_None :=
{ /* @status    APPROVED */
  None  := true  //PDCP layer is not configured for the RB
};

template (value) HarqProcessAssignment_Type cs_HarqProcessAssignment_Specific(HarqProcessId_Type p_HarqProcessId) :=
{ /* @status    APPROVED */
  Id := p_HarqProcessId
};

template (value) DRB_COMMON_REQ cas_DRB_PDCP_PDU_Req(CellId_Type p_CellId,
                                                     template (value) TimingInfo_Type p_TimingInfo,
                                                     RadioBearerId_Type p_RB_Id,
                                                     template (value) PDCP_PDU_Type p_PDU) :=
{ /* @status    APPROVED */
  Common := cs_ReqAspCommonPart_RB (p_CellId, p_RB_Id, p_TimingInfo),
  U_Plane := {
    SubframeDataList := {
      {
        SubframeOffset := 0,
        HarqProcess := {Automatic := true},
        PduSduList := { PdcpPdu := {p_PDU}}
      }
    }
  }, // U_Plane
  SuppressPdcchForC_RNTI := omit
}; // cas_PDCPDataReq

template DRB_COMMON_IND car_DRB_PDCP_PDU_Ind(CellId_Type p_CellId,
                                             RadioBearerId_Type p_RB_Id,
                                             template (present) PDCP_PDU_Type p_PDU) :=
{ /* @status    APPROVED */
  Common := cr_IndAspCommonPart_RB (p_CellId, p_RB_Id),
  U_Plane := {
    SubframeData := {
      PduSduList := { PdcpPdu := {p_PDU}},
      NoOfTTIs := 1
      // @sic R5w100222 slide 4 - RedundancyVersion removed sic@
    }
  } // U_Plane
}; // car_PDCPDataInd

template (value) PDCP_SDUList_Type cs_PDCP_SDUList_1 (template (value) PDCP_SDU_Type p_PDCP_SDU) :=
{ /* @status    APPROVED */
  p_PDCP_SDU
};

template  PDCP_SDUList_Type cr_PDCP_SDUList_1 (template (present) PDCP_SDU_Type p_PDCP_SDU) :=
{ /* @status    APPROVED */
  p_PDCP_SDU
};

template (value) PDCP_PDU_Type cs_PDCP_PDU_LongSN (template (value) PDCP_DataPdu_LongSN_Type p_PDCPPDU_LongSN):=
{ /* @status    APPROVED */
  DataLongSN  := p_PDCPPDU_LongSN
};

template (value) PDCP_DataPdu_LongSN_Type cs_PDCP_DataPdu_LongSN(B12_Type p_PDCP_SN_12B,
                                                                 template (value) PDCP_SDU_Type p_PDCP_SDU) :=
{ /* @status    APPROVED */
  D_C             := tsc_D_C_DataPDU,         /* * 1 .......... Data PDU */
  Reserved        := tsc_B3_Reserved,
  SequenceNumber  := p_PDCP_SN_12B,           /* 12 bit sequence number */
  SDU             := p_PDCP_SDU               /* content (octetstring) */
};

template (value) PDCP_PDU_Type cs_PDCP_DataLongSN ( integer p_SN,
                                                    PDCP_SDU_Type p_PdcpSdu) :=
  /* @desc Template used for sending a PDCP PDU with long SN */
  /* @status    APPROVED */
  cs_PDCP_PDU_LongSN ( cs_PDCP_DataPdu_LongSN(int2bit(p_SN, 12), p_PdcpSdu) );

template (value) PDCP_PDU_Type cs_PDCP_DataShortSN ( integer p_SN,
                                                     PDCP_SDU_Type p_PdcpSdu) :=
{ /* @desc Template used for sending a PDCP PDU with short SN */
  /* @status    APPROVED */
  DataShortSN := {
    D_C := tsc_D_C_DataPDU,
    SequenceNumber := int2bit(p_SN, tsc_PDCP_SN_Size_7),
    SDU := p_PdcpSdu
  }
};

template PDCP_PDU_Type cr_PDCP_DataLongSN ( template (present) B12_Type p_SN,
                                            template (present) octetstring p_PdcpSdu) :=
{ /* @desc Template used for receiving a PDCP PDU with long SN */
  /* @status    APPROVED */
  DataLongSN := {
    D_C := tsc_D_C_DataPDU,
    Reserved := tsc_R_Bit & tsc_R_Bit & tsc_R_Bit,
    SequenceNumber := p_SN,
    SDU := p_PdcpSdu
  }
};

template SYSTEM_IND car_SchedulingReq_IND (CellId_Type p_CellId,
                                           template (present) TimingInfo_Type p_TimingInfo) :=
{ /* @status    APPROVED */
  Common        := cr_IndAspCommonPart_SysInd (p_CellId,p_TimingInfo ),
  Indication    := {
    SchedReq := true
  }
};

} // end of group Layer2_CommonTemplates

/******************************************************************************/
/******************************************************************************/

group MAC_Constraints {

template (value) L1Mac_IndicationControl_Type cs_EnableSR_Req(L1Mac_IndicationMode_Type p_SR_Mode) :=
{ /* @status    APPROVED */
  RachPreamble := omit,
  SchedReq  := p_SR_Mode,       /* To enable/disable reporting of Scheduling Request received. */
  BSR       := omit,
  UL_HARQ   := omit,
  C_RNTI    := omit,
  PHR       := omit,
  HarqError := omit
};

template (value) SYSTEM_CTRL_REQ cas_SchedulingReqIndConfig_REQ(CellId_Type p_CellId,
                                                                L1Mac_IndicationMode_Type p_SR_Mode) :=
{ /* @status    APPROVED */
  Common := cs_ReqAspCommonPart_CellCfg(p_CellId, cs_TimingInfo_Now),
  Request := {
    L1MacIndCtrl := cs_EnableSR_Req ( p_SR_Mode)
  }
};
}; // end of group MAC_Constraints

/******************************************************************************/
/******************************************************************************/

group UL_Grant_DL_Allocation {

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

template (value) ULGrant_Period_Type cs_ULGrant_Period_Duration (integer p_Period) :=
{ /* @desc      Configured UL Grant transmission periodic */
  /* @status    APPROVED */
  Duration := p_Period     /* duration of the grant period (TTI=1ms) */
};

template (value) ULGrant_Period_Type cs_ULGrant_EverySubFrame :={
  Duration := 1       /* duration of the grant period (TTI=1ms) */
};

template (value) ULGrant_Period_Type cs_ULGrant_OneTime :=
{ /* @status    APPROVED */
  OnlyOnce := true
};

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

template (value) TransmissionRepetition_Type cs_TransmissionRepetitionContinous :=
{ /* @status    APPROVED */
  Continuous := true
};

template (value) TransmissionRepetition_Type cs_TransmissionRepetitionCyclic(integer p_Cycles) :=
{ /* @status    APPROVED */
  NumOfCycles := p_Cycles
};

template (value) TransmissionRepetition_Type cs_TransmissionCycleOneTime := cs_TransmissionRepetitionCyclic(1); /* @status    APPROVED */

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

template (value) UL_GrantConfig_Type cs_UL_GrantConfig_OneTime  :=
{ /* @status    APPROVED */
  Periodic := {
    Period          := cs_ULGrant_OneTime,
    NoOfRepetitions := cs_TransmissionCycleOneTime
  }
};

template (value) UL_GrantConfig_Type cs_UL_GrantConfig_ContPeriodic(integer p_Period)  :=
{ /* @status    APPROVED */
  Periodic := {
    Period          := cs_ULGrant_Period_Duration(p_Period),
    NoOfRepetitions := cs_TransmissionRepetitionContinous
  }
};

template (value) UL_GrantConfig_Type cs_UL_GrantConfig_NoOfGrants (integer p_Period,
                                                                   integer p_Number) :=
{ /* @status    APPROVED */
  Periodic := {
    Period          := cs_ULGrant_Period_Duration(p_Period),
    NoOfRepetitions := cs_TransmissionRepetitionCyclic(p_Number)
  }
};

//============================================================================


} // end of group UL_Grant_DL_Allocation

/******************************************************************************/
/******************************************************************************/

group RLC_CommonTemplates {

template (value) RLC_AM_StatusPDU_Type cs_RLC_AM_StatusPDU_ACK_SN (integer p_AckSN) :=
{ /* @desc      serves to transmit one STATUS PDU without NackList */
  /* @status    APPROVED */
  D_C           :=  tsc_D_C_Control,            /* 0 .......... Control PDU
                                                 * 1 .......... Data PDU */
  Type          :=  tsc_CPT_STATUSPDU,          /* 000 ........ STATUS PDU
                                                 * 001-111 .... Reserved (=> PDU to be discarded by the receiving entity
                                                 *                           for this release of the protocol) */
  Ack           := {
    ACK_SN      := int2bit (p_AckSN, tsc_AM_SN_Size),
    Extn1       := tsc_E1_NoNACK_Follows
  },
  NackList := omit,                       /* presence depends on Extn1 bit of Ack filed (RLC_Status_ACK_Type) */
  Padding := '1'B                         /* 1..7 bit padding if needed for octet alignment */
};


template RLC_AM_StatusPDU_Type cr_RLC_AM_StatusPDU_ACK_SN_Bit (template (present) B10_Type p_AckSN_Bits) :=
{ /* @desc      serves to receive one STATUS PDU without NackList and Padding */
  /* @status    APPROVED */
  D_C           :=  tsc_D_C_Control,            /* 0 .......... Control PDU
                                                 * 1 .......... Data PDU */
  Type          :=  tsc_CPT_STATUSPDU,          /* 000 ........ STATUS PDU
                                                 * 001-111 .... Reserved (=> PDU to be discarded by the receiving entity
                                                 *                           for this release of the protocol) */
  Ack           := {
    ACK_SN      := p_AckSN_Bits,
    Extn1       := tsc_E1_NoNACK_Follows
  },
  NackList := omit,
  Padding := '?'B
};

template RLC_AM_StatusPDU_Type cr_RLC_AM_StatusPDU_ACK_SN (integer p_AckSN) :=
  /* @status    APPROVED */
  cr_RLC_AM_StatusPDU_ACK_SN_Bit (int2bit (p_AckSN, tsc_AM_SN_Size));


template (value) UL_AM_RLC cds_TX_AM_RLC_t_PollRetransmit (T_PollRetransmit p_T_PollRetransmit)
  modifies cs_508_DRB_UL_AM_RLC :=
{ /* @status    APPROVED */
  t_PollRetransmit := p_T_PollRetransmit
};


} // end of group RLC_CommonTemplates

/******************************************************************************/
/******************************************************************************/

group DRB_UM {

template (value) RadioResourceConfigDedicated cds_DRB2_Config_UM_PDCP_Discard_Time_500ms(template (omit) CQI_ReportPeriodic p_CQI_ReportingPeriodic,
                                                                                         template (omit) SoundingRS_UL_ConfigDedicated p_SoundingRsUl_ConfigDedicated,
                                                                                         template (value) PhysicalConfigDedicated_AntennaInfo_Type p_AntennaInfo)
  modifies cs_DRB2_Config_UM_Def :=
{
  drb_ToAddModList := {
    [0] := cs_508_DRB_ToAddMod_Common(tsc_DRB2,
                                      cds_DRB_PDCP_Conf_UM_ModifyDiscardTime(ms500),
                                      cs_508_RLC_Config_DRB_UM,
                                      cs_508_LogicalChannelConfig_DRB_UM) }
};

template (value) PDCP_Config cds_DRB_PDCP_Conf_UM_ModifyDiscardTime (PDCP_Config.discardTimer p_DiscardTimer)
modifies cs_508_PDCP_Config_DRB_UM :=
{ /* @status    APPROVED */
  discardTimer := p_DiscardTimer
};

template (value) DRB_ToAddMod cs_508_DRB_ToAddMod_UM_DiscardTimer_300ms (DRB_Identity p_DRB_Id) :=
  /* According to 36.508 cl. 4.8.2.1.7 Table 4.8.2.1.7-1 (using condition UM) */
  /* @status    APPROVED */
  cs_508_DRB_ToAddMod_Common(p_DRB_Id,
                             cds_DRB_PDCP_Conf_UM_ModifyDiscardTime(ms300),
                             cs_508_RLC_Config_DRB_UM,
                             cs_508_LogicalChannelConfig_DRB_UM);

template (value) RadioResourceConfigDedicated cs_DRB2_Config_UM_Def(template (omit) CQI_ReportPeriodic p_CQI_ReportingPeriodic,
                                                                    template (omit) SoundingRS_UL_ConfigDedicated p_SoundingRsUl_ConfigDedicated,
                                                                    template (value) PhysicalConfigDedicated_AntennaInfo_Type p_AntennaInfo):=
{
  srb_ToAddModList := omit,
  drb_ToAddModList := { cs_508_DRB_ToAddMod_DEFAULT_UM(tsc_DRB2) },
  drb_ToReleaseList := omit,
  mac_MainConfig := cs_508_MAC_MainConfig_Explicit_RBC_DrxS_L2,  /* @sic R5-101178 sic@ */
  sps_Config := omit,
  physicalConfigDedicated :=  cs_508_PhysicalConfigDedicated_Default_RBC(p_CQI_ReportingPeriodic, p_SoundingRsUl_ConfigDedicated, p_AntennaInfo)
};

template (value) RadioBearer_Type cs_DRB2_ConfigUM_TM_Mode_SN10 :=
{ /* @status    APPROVED */
  Id := {
    Drb := tsc_DRB2
  },
  Config := {
    AddOrReconfigure := {
      Pdcp := cs_PDCP_Configuration_None,
      Rlc := {
        Rb := {
          TM := true
        },
        TestMode := {
          Info := {
            TransparentMode_UMDwith10BitSN := true   // @sic R5w100002r1 sic@
          }
        }
      },
      LogicalChannelId := tsc_DRB2+2,
      Mac := cs_MAC_Configuration_UM       // @sic R5s090314: Additional comments sic@
    }
  }
};

template (value) RadioBearer_Type cds_DRB2_ConfigUM_TM_Mode_SN5 modifies cs_DRB2_ConfigUM_TM_Mode_SN10 :=
{ /* @status    APPROVED */
  Config := {
    AddOrReconfigure := {
      Rlc := {
        TestMode := {
          Info := {
            TransparentMode_UMDwith5BitSN := true   // @sic R5w100002r1 sic@
          }
        }
      }
    }
  }
};

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

template (value) RadioResourceConfigDedicated cds_DRB2_Config_UM_SN5(
          template (omit) CQI_ReportPeriodic p_CQI_ReportingPeriodic,
          template (omit) SoundingRS_UL_ConfigDedicated p_SoundingRsUl_ConfigDedicated,
          template (value) PhysicalConfigDedicated_AntennaInfo_Type p_AntennaInfo)
modifies cs_DRB2_Config_UM_Def :=
{
  drb_ToAddModList := {
    [0] := {
      pdcp_Config := cds_PDCP_Config_DRB_UM_SN7, // @sic R5s100302 sic@
      rlc_Config := {
        um_Bi_Directional := {
          ul_UM_RLC := cds_TX_UM_RLC_DRB_SN5,
          dl_UM_RLC := cds_RX_UM_RLC_DRB_SN5
        }
      }
    }
  }
};
//
template (value) PDCP_Config cds_PDCP_Config_DRB_UM_SN7
modifies cs_508_PDCP_Config_DRB_UM :=
{ /* @status    APPROVED */
  /* @sic R5s100302 sic@ */
  rlc_UM := {
    pdcp_SN_Size := len7bits
  }
};
//
template (value) UL_UM_RLC cds_TX_UM_RLC_DRB_SN5 modifies cs_508_DRB_UL_UM_RLC :=
{ /* for the UE the tx direction is the UL, for SS it is the DL */
  /* @status    APPROVED */
  sn_FieldLength := size5
};

template (value) DL_UM_RLC cds_RX_UM_RLC_DRB_SN5 modifies cs_508_DRB_DL_UM_RLC :=
{ /* for the UE the rx direction is the DL, for SS it is the UL */
  /* @status    APPROVED */
  sn_FieldLength := size5
};


template (value) RLC_UMD_PDU_Type cs_UMD_PDU_NoLIs_SN10(integer p_SN,
                                                        RLC_FramingInfo_Type p_FramingInfo,
                                                        RLC_DataFieldList_Type p_Data) :=
{ /* serves to transmit one UMD PDU without Length Indicators */
  /* @status    APPROVED */
  LongSN := {
    Header := {
      FixPart := {
        Reserved := tsc_B3_Reserved,
        FramingInfo :=  p_FramingInfo,
        Extension := tsc_E_Data,
        SequenceNumber := int2bit (p_SN, tsc_UM_SN_Size_10)
      },
      FlexPart := omit
    },
    Data := p_Data
  }
};

template (value) RLC_UMD_PDU_Type cs_UMD_PDUoneSDU_SN10(integer p_SN,
                                                        RLC_DataFieldList_Type p_RLC_SduData) :=
  /* serves to transmit one SDU in one UMD PDU */
  /* @status    APPROVED */
  cs_UMD_PDU_NoLIs_SN10(p_SN, tsc_FI_FullSDU, p_RLC_SduData);


template (value) DRB_ToAddMod cs_DRB_ToAddMod_RLC_UM (DRB_Identity p_DRB_Id,
                                                      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) :=
  /* According to 36.508 cl. 4.8.2.1.7 Table 4.8.2.1.7-1 (using condition AM) */
  /* @status    APPROVED */
  cs_508_DRB_ToAddMod_Common(p_DRB_Id,
                             p_PDCP_Config,
                             cs_RLC_Config_DRB_UM (p_UL_UM_RLC,
                                                   p_DL_UM_RLC),
                             cs_508_LogicalChannelConfig_DRB_UM);

template (value) RLC_Config cs_RLC_Config_DRB_UM (template (value) UL_UM_RLC p_UL_UM_RLC,
                                                  template (value) DL_UM_RLC p_DL_UM_RLC):=
{ /* @status    APPROVED */
  um_Bi_Directional := {
    ul_UM_RLC := p_UL_UM_RLC,
    dl_UM_RLC := p_DL_UM_RLC
  }
};

} // end of group DRB_UM

/******************************************************************************/
/******************************************************************************/

group L1_MAC_Indication {

template (value) L1Mac_IndicationControl_Type cs_EnableBSR_Req(L1Mac_IndicationMode_Type p_BSR_Mode) :=
{ /* @status    APPROVED */
  RachPreamble := omit,
  SchedReq     := omit,       /* To enable/disable reporting of Scheduling Request received. */
  BSR          := p_BSR_Mode,
  UL_HARQ      := omit,
  C_RNTI       := omit,
  PHR          := omit,
  HarqError    := omit
};

template (value) SYSTEM_CTRL_REQ cas_BSR_IndConfig_REQ(CellId_Type p_CellId,
                                                       L1Mac_IndicationMode_Type p_BSR_Mode,
                                                       template (value) TimingInfo_Type p_TimingInfo := cs_TimingInfo_Now) :=
{ /* @status    APPROVED */
  Common := cs_ReqAspCommonPart_CellCfg(p_CellId, p_TimingInfo),
  Request := {
    L1MacIndCtrl := cs_EnableBSR_Req(p_BSR_Mode)
  }
};

template (value) SYSTEM_CTRL_REQ cas_PHR_IndConfig_REQ(CellId_Type p_CellId,
                                                       L1Mac_IndicationMode_Type p_PHR_Mode) :=
{ /* @status    APPROVED */
  Common := cs_ReqAspCommonPart_CellCfg(p_CellId, cs_TimingInfo_Now),
  Request := {
    L1MacIndCtrl := cs_EnablePHR_Req ( p_PHR_Mode)
  }
};

template (value) SYSTEM_CTRL_REQ cas_UL_HARQ_IndConfig_REQ(CellId_Type p_CellId,
                                                           L1Mac_IndicationMode_Type p_UL_HARQ_Mode) :=
{ /* @status    APPROVED */
  Common := cs_ReqAspCommonPart_CellCfg(p_CellId, cs_TimingInfo_Now),
  Request := {
    L1MacIndCtrl := cs_EnableUL_HARQ_Req ( p_UL_HARQ_Mode)
  }
};

template (value) L1Mac_IndicationControl_Type cs_EnableUL_HARQ_Req(L1Mac_IndicationMode_Type p_HARQ_Mode) :=
{ /* @status    APPROVED */
  RachPreamble := omit,
  SchedReq  := omit,
  BSR       := omit,
  UL_HARQ   := p_HARQ_Mode,
  C_RNTI    := omit,
  PHR       := omit,
  HarqError := omit
};

template (value) L1Mac_IndicationControl_Type cs_EnablePHR_Req(L1Mac_IndicationMode_Type p_PHR_Mode) :=
{ /* @status    APPROVED */
  RachPreamble := omit,
  SchedReq  := omit,
  BSR       := omit,
  UL_HARQ   := omit,
  C_RNTI    := omit,
  PHR       := p_PHR_Mode,
  HarqError := omit
};

template BSR_Type cr_LongBSR_Ind ( template (present) integer p_BS1,
                                   template (present) integer p_BS2,
                                   template (present) integer p_BS3,
                                   template (present) integer p_BS4) :=
{ /* @status    APPROVED */
  Long :={
    Value_LCG1 := p_BS1,             /* BSR value for LCG 1 */
    Value_LCG2 := p_BS2,             /* BSR value for LCG 2 */
    Value_LCG3 := p_BS3,             /* BSR value for LCG 3 */
    Value_LCG4 := p_BS4              /* BSR value for LCG 4 */
  }
};
template BSR_Type cr_ShortBSR_Ind ( template (present) integer p_LCG,
                                      template (present) integer p_BSR_Value) :=
  { /* @status    APPROVED */
    Short := {
      LCG  :=  p_LCG,          /* Logical channel Group */
      Value := p_BSR_Value     /* BSR value */
    }
  };
template SYSTEM_IND car_BSR_IND(CellId_Type p_CellId,
                                template (present) TimingInfo_Type p_TimingInfo,
                                template (present) BSR_Type p_BSR_Type) :=
{ /* @status    APPROVED */
  Common := cr_IndAspCommonPart_SysInd (p_CellId,p_TimingInfo ),
  Indication := {
    BSR := p_BSR_Type
  }
};

template SYSTEM_IND car_UL_HARQ_IND(CellId_Type p_CellId,
                                    template (present) TimingInfo_Type p_TimingInfo,
                                    template (present)  HARQ_Type p_HARQ_Type) :=
{ /* @status    APPROVED */
  Common        := cr_IndAspCommonPart_SysInd (p_CellId, p_TimingInfo),
  Indication    := {
    UL_HARQ := p_HARQ_Type
  }
};

};// end of group L1_MAC_Indication

/******************************************************************************/
/******************************************************************************/

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

template (value) UL_SCH_Config_Type cs_UL_SCH_Config_DisableBSR :=
{ /* no_periodic_BSR_or_PHR for table  Table 4.8.2.1.5-1 as a result of R5-096458 */
  /* @status    APPROVED */
  maxHARQ_Tx := n5,
  periodicBSR_Timer := infinity_,
  retxBSR_Timer := sf10240,
  ttiBundling := false
};

template (value) MAC_MainConfig cs_MAC_MainConfig_RBC_DisableBSR_PHR(template (omit) DRX_Config p_DRX_Config) :=
{ /* Default values according to 36.508 cl. 4.8.2.1.5 Table 4.8.2.1.5-1;
     no_periodic_BSR_or_PHR for table  Table 4.8.2.1.5-1 as a result of R5-096458 */
  /* @status    APPROVED */
  ul_SCH_Config := cs_UL_SCH_Config_DisableBSR,
  drx_Config := p_DRX_Config,
  timeAlignmentTimerDedicated := sf750,
  phr_Config := {
    release := NULL
  }
};


template (value) MAC_MainConfig_Type cs_508_MAC_MainConfig_Explicit_RBC_DrxL_DisableBSR_PHR :=
{ /* Depending on PICS pc_FeatrGrp_5 function returns:
     pc_FeatrGrp_5 supported: DRX_L
     pc_FeatrGrp_5 not supported: DRX not configured/released */
  /* @status    APPROVED */
  explicitValue := cs_MAC_MainConfig_RBC_DisableBSR_PHR ( f_GetUeDrxConfig ( DRX_L ) )
};

template (value) MAC_MainConfig_Type cs_508_MAC_MainConfig_Explicit_RBC_DrxS_DisableBSR_PHR :=
{ /* Depending on PICS pc_FeatrGrp_5 function returns:
     pc_FeatrGrp_5 supported: DRX_S
     pc_FeatrGrp_5 not supported: DRX not configured/released */
  /* @status    APPROVED */
  explicitValue := cs_MAC_MainConfig_RBC_DisableBSR_PHR ( f_GetUeDrxConfig ( DRX_S_L2 ) )  // @sic R5-101177, R5-101178
};
} // end of group Generic_L2_RRC_ReconfigTemplates
template (value) PhysicalConfigDedicated cds_PhysicalConfigDedicated_Dsr_TransMax (template (omit) CQI_ReportPeriodic p_CQI_ReportingPeriodic,
                                                                                     template (omit) SoundingRS_UL_ConfigDedicated p_SoundingRsUl_ConfigDedicated,
                                                                                     template (value) PhysicalConfigDedicated_AntennaInfo_Type p_AntennaInfo,
                                                                                     SR_PUCCH_ResourceIndex_Type      p_SR_PUCCH_ResourceIndex,
                                                                                     SR_ConfigIndex_Type p_SR_ConfigIndex,
                                                                                     Dsr_TransMax_Type p_Dsr_TransMax :=n64 )    // @sic R5-102177 R5-104798 sic@
    modifies cs_508_PhysicalConfigDedicated_Default_RBC :=
  { /* @status    APPROVED */
    schedulingRequestConfig := cs_508_SchedulingRequest_Config_Default (p_SR_PUCCH_ResourceIndex, p_SR_ConfigIndex, p_Dsr_TransMax)
  };
  template (value) PDCP_Config cds_508_PDCP_Config_DRB_AM_NoStatusRep modifies cs_508_PDCP_Config_DRB_AM:=
  { /* Default values according to 36.508 cl. 4.8.2.1.2.2 Table 4.8.2.1.2.2-1
     except Status Required is set as  false*/
    /* @status    APPROVED */
    //@sic R5-103816 PDCP Status report made as false sic@
     rlc_AM := {
      statusReportRequired := false
    }
  };
  template (value) DRB_ToAddMod cs_508_DRB_ToAddMod_AM_NoStatusRep (DRB_Identity p_DRB_Id) :=
    /* According to 36.508 cl. 4.8.2.1.7 Table 4.8.2.1.7-1 (using condition AM)
    except Status Required is set as  false*/
    /* @status    APPROVED */
    //@sic R5-103816 PDCP Status report made as false sic@
    cs_508_DRB_ToAddMod_Common(p_DRB_Id,
                               cds_508_PDCP_Config_DRB_AM_NoStatusRep,
                               cs_508_RLC_Config_DRB_AM,
                               cs_508_LogicalChannelConfig_DRB_AM);

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

} // module
