/******************************************************************************/
// @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 14:25:12 +0200 (Thu, 19 Aug 2010) $
// $Rev: 3749 $
/******************************************************************************/

module UTRAN_RAB_Functions {
  
  //----------------------------------------------------------------------
  // Import part
  //----------------------------------------------------------------------
  
  import from UTRAN_RRC_ASN1_Definitions language "ASN.1:1997" all;
  import from UTRAN_ASP_Definitions language "ASN.1:1997" all;
  import from UTRAN_Parameters all;
  import from UTRAN_Component all;
  import from UTRAN_RAB_Templates all;
  import from UTRAN_RAB_TemplatesFDD all;
  import from UTRAN_RAB_TemplatesTDD all;
  import from UTRAN_CellInfo all;
  import from UTRAN_CommonFunctions all;
  import from UTRANGERAN_CommonFunctions all;
  import from UTRAN_Templates all;
  import from UTRAN_ASN1_Templates all;
  import from UTRAN_TypeDefs all;
  import from UTRAN_ConfigurationSteps all;
  
  import from CommonDefs all;
  import from Parameters all;
  import from UpperTesterFunctions all;
  
  import from NAS_24008TypeDefs all;
  import from NAS_24008Templates all;
  import from NAS_CommonTypeDefs all;
  import from NAS_CommonTemplates all;
  
  //----------------------------------------------------------------------
  // Init functions
  //----------------------------------------------------------------------
  
  function fl_GetMoEstCause ( ) return template (value) EstablishmentCause {
    
    var template (value) EstablishmentCause v_EstablishmentCause;
    
    if ( pc_Interactive and ( px_RRC_PS_ServTested == ps_Interactive ) ) {
      v_EstablishmentCause := originatingInteractiveCall;
    }
    else if ( pc_Background and ( px_RRC_PS_ServTested == ps_Background ) ) {
      v_EstablishmentCause := originatingBackgroundCall;
    }
    else if ( pc_Streaming and ( px_RRC_PS_ServTested == ps_Streaming ) ) {
      v_EstablishmentCause := originatingStreamingCall;
    }
    else {
      FatalError(__FILE__, __LINE__, "Configuration not supported");
    };
    
    return v_EstablishmentCause;
  }
  
  /*
   * @desc      Initialise QoS, Delay and Traffic Class
   * @param    p_CellId
   * @param    p_RB_Configuration
   * @return   template (value) QualityOfService
   * @status
   */
  function f_UTRAN_InitialiseQoS ( UTRAN_CellId_Type p_CellId,
                                   RB_ConfigType     p_RB_Configuration := cell_DCH_64kPS_RAB_SRB )
  runs on UTRAN_PTC return template (value) QualityOfService
  {
    var B3_Type v_DlyClass, v_TrafficClass;
    var template (value) QualityOfService v_QualityOfService;
    var B8_Type v_MaxSDU_Size := '00100000'B;//maxSDU_Size is 320
    var B8_Type v_MaxBitRateUL, v_MaxBitRateDL;
    var B4_Type v_PeakThroughput;
    var template (omit) B8_Type v_BitRateExt := omit;
    var B8_Type v_BitRateUL_64kbps := '01000000'B;//64kbps
    var UTRAN_FDD_TDD v_FDD_TDD_Mode := f_UTRAN_CellInfo_GetFDD_TDD ( p_CellId );
    
    if ( pc_Interactive and ( px_RRC_PS_ServTested == ps_Interactive ) ) {
      v_DlyClass := '011'B;
      v_TrafficClass := '011'B;
    }
    else if ( pc_Background and ( px_RRC_PS_ServTested == ps_Background ) ) {
      v_DlyClass := '100'B;
      v_TrafficClass := '100'B;
    }
    else {//Default values for all other cases
      v_DlyClass := '011'B;
      v_TrafficClass := '011'B;
    }

    if ( v_FDD_TDD_Mode == UTRAN_FDD ) {//Cell is FDD
      //* @desc px_HSDSCH_UE_Category_FDD is used to determine the QoS as MAC-ehs and dual cell configuration
      //is not configured. Ref: 25.331 cl. 10.3.3.25 Note 5, 6 and 12
      if ( ( px_HSDSCH_UE_Category_FDD == 1 ) or ( px_HSDSCH_UE_Category_FDD == 2 ) ) {
        v_PeakThroughput := '1000'B;//PTC=8
        v_MaxBitRateDL := '10001001'B;//Downlink bit rate=1173 kbps
        if ( ( px_EDCH_UE_Category_FDD == 4 ) or ( px_EDCH_UE_Category_FDD == 6 ) ) {
          v_PeakThroughput := '1001'B;//PTC=9
        }
      }
      else if ( ( px_HSDSCH_UE_Category_FDD == 3 ) or ( px_HSDSCH_UE_Category_FDD == 4 ) ) {
        v_PeakThroughput := '1000'B;//PTC=8
        v_MaxBitRateDL := '10010010'B;//Downlink bit rate=1759 kbps
        if ( ( px_EDCH_UE_Category_FDD == 4 ) or ( px_EDCH_UE_Category_FDD == 6 ) ) {
          v_PeakThroughput := '1001'B;//PTC=9
        }
      }
      else if ( ( px_HSDSCH_UE_Category_FDD == 5 ) or ( px_HSDSCH_UE_Category_FDD == 6 ) ) {
        v_PeakThroughput := '1001'B;//PTC=9
        v_MaxBitRateDL := '10101110'B;//Downlink bit rate=3520 kbps
      }
      else if ( ( px_HSDSCH_UE_Category_FDD == 7 ) or ( px_HSDSCH_UE_Category_FDD == 8 ) ) {
        v_PeakThroughput := '1001'B;//PTC=9
        v_MaxBitRateDL := '11100000'B;//Downlink bit rate=6720 kbps
      }
      else if ( px_HSDSCH_UE_Category_FDD == 9 ) {
        v_PeakThroughput := '1001'B;//PTC=9
        v_MaxBitRateDL := '11100000'B;//Downlink bit rate=9600 kbps
        v_BitRateExt := '00001010'B;
      }
      else if ( px_HSDSCH_UE_Category_FDD == 10 ) {
        v_PeakThroughput := '1001'B;//PTC=9
        v_MaxBitRateDL := '11111110'B;//Downlink bit rate=13400 kbps
        v_BitRateExt := '00110000'B;
      }
      else if ( px_HSDSCH_UE_Category_FDD == 11 ) {
        v_PeakThroughput := '0111'B;//PTC=7
        v_MaxBitRateDL := '10000011'B;//Downlink bit rate=800 kbps
        if ( ( px_EDCH_UE_Category_FDD == 2 ) or
             ( px_EDCH_UE_Category_FDD == 3 ) or
             ( px_EDCH_UE_Category_FDD == 4 )) {
          v_PeakThroughput := '1000'B;//PTC=8
        }
        else if ( ( px_EDCH_UE_Category_FDD == 4 ) or ( px_EDCH_UE_Category_FDD == 6 ) ) {
          v_PeakThroughput := '1001'B;//PTC=9
        }
      }
      else if ( px_HSDSCH_UE_Category_FDD == 12 ) {
        v_PeakThroughput := '1000'B;//PTC=8
        v_MaxBitRateDL := '10010000'B;//Downlink bit rate=1600 kbps
        if ( ( px_EDCH_UE_Category_FDD == 4 ) or ( px_EDCH_UE_Category_FDD == 6 ) ) {
          v_PeakThroughput := '1001'B;//PTC=9
        }
      }
      else {
        FatalError(__FILE__, __LINE__, "Invalid HSDSCH UE Category");
      }

      // px_EDCH_UE_Category is used to determine the QoS for UL
      if ( px_EDCH_UE_Category_FDD == 1 ) {
        v_MaxBitRateUL := oct2bit('81'O);//640 kbps for EDCH category 1 UE
      }
      else if ( px_EDCH_UE_Category_FDD == 2 ) {
        v_MaxBitRateUL := oct2bit('8B'O);//1280 kbps for EDCH category 2 UE
      }
      else if ( px_EDCH_UE_Category_FDD == 3 ) {
        v_MaxBitRateUL := oct2bit('8C'O);//1344 kbps for EDCH category 3 UE
      }
      else if ( px_EDCH_UE_Category_FDD == 4 ) {
        v_MaxBitRateUL := oct2bit('A1'O);//2688 kbps for EDCH category 4 UE
      }
      else if ( px_EDCH_UE_Category_FDD == 5 ) {
        v_MaxBitRateUL := oct2bit('94'O);//1856 kbps for EDCH category 5 UE
      }
      else if ( px_EDCH_UE_Category_FDD == 6 ) {
        v_MaxBitRateUL := oct2bit('CC'O);//5440 kbps for EDCH category 6 UE
      }
      else {
        FatalError(__FILE__, __LINE__, "Incorrect value of px_EDCH_UE_Category_FDD");
      }
    }
    else {//Cell is TDD
      v_PeakThroughput := '0100'B;

      if ( ( px_HSDSCH_UE_Category_TDD == 1 ) or ( px_HSDSCH_UE_Category_TDD == 2 ) or ( px_HSDSCH_UE_Category_TDD == 3 ) or ( px_HSDSCH_UE_Category_TDD == 4 ) or ( px_HSDSCH_UE_Category_TDD == 5 ) or ( px_HSDSCH_UE_Category_TDD == 6 ) ) {
        v_MaxBitRateDL := '10001100'B;//Downlink bit rate=1216 kbps
      }
      else if ( ( px_HSDSCH_UE_Category_TDD == 7 ) or ( px_HSDSCH_UE_Category_TDD == 8 ) or ( px_HSDSCH_UE_Category_TDD == 9 ) or ( px_HSDSCH_UE_Category_TDD == 10 ) or ( px_HSDSCH_UE_Category_TDD == 11 ) or ( px_HSDSCH_UE_Category_TDD == 12 ) ) {
        v_MaxBitRateDL := '10010110'B;//Downlink bit rate=1792 kbps
      }
      else if ( ( px_HSDSCH_UE_Category_TDD == 13 ) or ( px_HSDSCH_UE_Category_TDD == 14 ) or ( px_HSDSCH_UE_Category_TDD == 15 ) ) {
        v_MaxBitRateDL := '10100010'B;//Downlink bit rate=3648 kbps
      }
      else {
        FatalError(__FILE__, __LINE__, "Invalid HSDSCH UE Category");
      }

      // px_EDCH_UE_Category is used to determine the QoS for UL
      if ( px_EDCH_UE_Category_TDD == 1 ) {
        v_MaxBitRateUL := oct2bit('7D'O);//551 kbps for EDCH category 1 UE
      }
      else if ( px_EDCH_UE_Category_TDD == 2 ) {
        v_MaxBitRateUL := oct2bit('84'O);//832 kbps for EDCH category 2 UE
      }
      else if ( px_EDCH_UE_Category_TDD == 3 ) {
        v_MaxBitRateUL := oct2bit('89'O);//1106 kbps for EDCH category 3 UE
      }
      else if ( px_EDCH_UE_Category_TDD == 4 ) {
        v_MaxBitRateUL := oct2bit('8A'O);//1170 kbps for EDCH category 4 UE
      }
      else if ( px_EDCH_UE_Category_TDD == 5 ) {
        v_MaxBitRateUL := oct2bit('9A'O);//2232 kbps for EDCH category 5 UE
      }
      else if ( px_EDCH_UE_Category_TDD == 6 ) {
        v_MaxBitRateUL := oct2bit('9A'O);//2232 kbps for EDCH category 6 UE
      }
      else {
        FatalError(__FILE__, __LINE__, "Incorrect value of px_EDCH_UE_Category_TDD");
      }
    }
    
    if ( p_RB_Configuration == cell_DCH_64kPS_RAB_SRB ) {
      v_QualityOfService := cs_QoS_InteractiveOrBackgroundMT ( v_DlyClass, v_TrafficClass );
    }
    else if ( p_RB_Configuration == cell_DCH_HS_DSCH ) {
      v_QualityOfService := cs_QoS_InteractiveOrBackgroundMT_HS ( v_DlyClass,
                                                                  v_TrafficClass,
                                                                  v_PeakThroughput,
                                                                  v_MaxSDU_Size,
                                                                  v_BitRateUL_64kbps,
                                                                  v_MaxBitRateDL,
                                                                  v_BitRateExt );
    }
    else if ( p_RB_Configuration == cell_DCH_E_HS ) {
      v_QualityOfService := cs_QoS_InteractiveOrBackgroundMT_HS ( v_DlyClass,
                                                                  v_TrafficClass,
                                                                  v_PeakThroughput,
                                                                  v_MaxSDU_Size,
                                                                  v_MaxBitRateUL,
                                                                  v_MaxBitRateDL,
                                                                  v_BitRateExt );
    }
    else {
      FatalError(__FILE__, __LINE__, "RAB Configuration not supported");
    }
    return v_QualityOfService;
  }
  
  //----------------------------------------------------------------------
  // Functions
  //----------------------------------------------------------------------
  
  //* @desc To set up physical channel DPCH1 and connect DCH1and DCH5 to the physical channel.
  //* Then map DCCH1-4 on to the DCH5 transport channel and map DTCH1 to the DCH1 transport channel.
  function f_SS_Config_64kPS_FDD ( UTRAN_CellId_Type                       p_CellId,
                                   template (value) CphyTrchConfigReq      p_UL_TrChConfig,
                                   template (value) CphyTrchConfigReq      p_DL_TrChConfig,
                                   template (value) TrCHInfo               p_UL_TrCHInfo,
                                   template (value) TrCHInfo               p_DL_TrCHInfo,
                                   template (value) TrCH_LogCHMappingList1 p_UL_TrLogMapping,
                                   template (value) TrCH_LogCHMappingList1 p_DL_TrLogMapping,
                                   template (value) DL_DPCHInfo_r8         p_DL_DPCHInfo,
                                   template (value) UL_DPCH_Info_r7        p_UL_DPCH_Info,
                                   template (value) SS_ActivationTime      p_ActivationTime ) runs on UTRAN_PTC
  {
    f_CPHY_RL_Modify ( cas_DL_DPCH_ModifyInfo_FDD ( p_CellId,
                                                    tsc_DL_DPCH1,
                                                    p_DL_DPCHInfo,
                                                    omit,
                                                    p_ActivationTime ) );
    
    f_CPHY_TrCH_Config ( cas_TrChCfgInfo_FDD ( p_CellId,
                                               tsc_DL_DPCH1,
                                               cs_TrChConfigTypeDCH_NoSHO,
                                               p_DL_TrChConfig ) );
    
    f_CMAC_Config ( cas_CMAC_ReconfigInfo_FDD ( p_CellId,
                                                tsc_DL_DPCH1,
                                                cs_UE_Info ( omit, omit ),
                                                p_DL_TrCHInfo,
                                                p_DL_TrLogMapping,
                                                p_ActivationTime ) );
    
    f_CPHY_RL_Modify ( cas_UL_DPCH_ModifyInfo_FDD ( p_CellId,
                                                    tsc_UL_DPCH1,
                                                    p_UL_DPCH_Info,
                                                    omit,
                                                    p_ActivationTime ) );
    
    f_CPHY_TrCH_Config ( cas_TrChCfgInfo_FDD ( p_CellId,
                                               tsc_UL_DPCH1,
                                               cs_TrChConfigTypeDCH_NoSHO,
                                               p_UL_TrChConfig ) );
    
    f_CMAC_Config ( cas_CMAC_ReconfigInfo_FDD ( p_CellId,
                                                tsc_UL_DPCH1,
                                                cs_UE_Info ( omit, omit ),
                                                p_UL_TrCHInfo,
                                                p_UL_TrLogMapping,
                                                p_ActivationTime ) );
  }
  
  //* @desc To set up physical channel DPCH1 and connect DCH1and DCH5 to the physical channel.
  //* Then map DCCH1-4 on to the DCH5 transport channel and map DTCH1 to the DCH1 transport channel.
  function f_SS_Config_64kPS_TDD ( UTRAN_CellId_Type                       p_CellId,
                                   template (value) CphyTrchConfigReq_TDD  p_UL_TrChConfig,
                                   template (value) CphyTrchConfigReq_TDD  p_DL_TrChConfig,
                                   template (value) TrCHInfo_TDD           p_UL_TrCHInfo,
                                   template (value) TrCHInfo_TDD           p_DL_TrCHInfo,
                                   template (value) TrCH_LogCHMappingList1 p_UL_TrLogMapping,
                                   template (value) TrCH_LogCHMappingList1 p_DL_TrLogMapping,
                                   template (value) DL_DPCHInfo_r8         p_DL_DPCHInfo,
                                   template (value) UL_DPCH_Info_r7        p_UL_DPCH_Info,
                                   template (value) SS_ActivationTime      p_ActTime ) runs on UTRAN_PTC
  {
    f_CPHY_RL_Modify ( cas_DL_DPCH_ModifyInfo_TDD ( p_CellId,
                                                    tsc_DL_DPCH1,
                                                    p_DL_DPCHInfo,
                                                    omit,
                                                    p_ActTime ) );
    
    f_CPHY_TrCH_Config (cas_TrChCfgInfo_TDD ( p_CellId,
                                              tsc_DL_DPCH1,
                                              cs_TrChConfigTypeDCH_NoSHO,
                                              p_DL_TrChConfig ) );
    
    f_CMAC_Config ( cas_CMAC_ReconfigInfo_TDD ( p_CellId,
                                                tsc_DL_DPCH1,
                                                cs_UE_Info ( omit, omit ),
                                                p_DL_TrCHInfo,
                                                p_DL_TrLogMapping,
                                                p_ActTime ) );
    
    f_CPHY_RL_Modify ( cas_UL_DPCH_ModifyInfo_TDD ( p_CellId,
                                                    tsc_UL_DPCH1,
                                                    p_UL_DPCH_Info,
                                                    omit,
                                                    p_ActTime ) );
    
    f_CPHY_TrCH_Config ( cas_TrChCfgInfo_TDD ( p_CellId,
                                               tsc_UL_DPCH1,
                                               cs_TrChConfigTypeDCH_NoSHO,
                                               p_UL_TrChConfig ) );
    
    f_CMAC_Config ( cas_CMAC_ReconfigInfo_TDD ( p_CellId,
                                                tsc_UL_DPCH1,
                                                cs_UE_Info ( omit, omit ),
                                                p_UL_TrCHInfo,
                                                p_UL_TrLogMapping,
                                                p_ActTime ) );
  }
  
  //* @desc If now activation time is specified "now" will be used. This is to be used for HOs to UTRAN.
  function f_SS_Config_64kPS_RAB ( UTRAN_CellId_Type                  p_CellId,
                                   template (value) SS_ActivationTime p_ActTime := cs_ActivateNow ) runs on UTRAN_PTC
  {
    var UL_ScramblingCode v_UL_ScramblingCode;
    var RB_ConfigType v_CellConfig := f_UTRAN_CellInfo_GetConfigType(p_CellId);
    var UTRAN_FDD_TDD v_FDD_TDD_Mode := f_UTRAN_CellInfo_GetFDD_TDD ( p_CellId );
    
    if ( v_CellConfig == cell_DCH_StandAloneSRB ) {
      if ( v_FDD_TDD_Mode == UTRAN_FDD ) {
        
        v_UL_ScramblingCode := f_UTRAN_CellInfo_GetULScrmCode_FDD ( p_CellId );
        
        // Configure SS for cell_DCH_64kPS_RAB_SRB configuration
          f_SS_Config_64kPS_FDD ( p_CellId,
                                  cs_CphyTrchConfigReq_Common_FDD  ( p_ActTime,
                                                                     cs_DCH_336_148_UL_Info_FDD,
                                                                     cs_TFCS_Cmpl0_1_2_3_4_5_6_7_8_9_Rx,
                                                                     omit, omit, omit, omit, omit, omit ),
                                  cs_CphyTrchConfigReq_Common_FDD  ( p_ActTime, omit, omit,
                                                                     cs_DCH_336_148_DL_Info_FDD,
                                                                     cs_TFCS_Cmpl0_1_2_3_4_5_6_7_8_9_Tx ( cs_PowerOffsetInfo64k_FDD ),
                                                                     omit, omit, omit, omit ),
                                  cs_TrCHInfo_Common_FDD ( cs_TrChInfoUL_336_148_FDD,
                                                           cs_TFCS_Cmpl0_1_2_3_4_5_6_7_8_9_Rx,
                                                           omit, omit, omit, omit, omit ),
                                  cs_TrCHInfo_Common_FDD ( omit, omit, cs_TrChInfoDL_336_148_FDD,
                                                           cs_TFCS_Cmpl0_1_2_3_4_5_6_7_8_9_Tx ( cs_PowerOffsetInfo64k_FDD ),
                                                           omit, omit, omit ),
                                  cs_TrLogMappingUL_4DCCH_1DTCH ( tsc_RB20 ),
                                  cs_TrLogMappingDL_4DCCH_1DTCH_PS,
                                  cs_DL_DPCH_FDD ( cs_DL_CommonInformationRB_SetUp_FDD ( tsc_DL_DPCH1_SFP_64k_PS, flexible),
                                                   tsc_DL_DPCH1_ChC_64k_PS,
                                                   tsc_DL_TxPower_DPCH_64k ),
                                  cs_UL_DPCH_Info_FDD ( tsc_UL_DPDCH_SF_64k_PS,
                                                        pl0_96,
                                                        v_UL_ScramblingCode ), p_ActTime );
      }
      else if ( v_FDD_TDD_Mode == UTRAN_TDD ) {
        // Step 1: Configure a dedicated channel in the UTRAN TDD configuration according to 34.108 cl. 6.11.5.4.1.26
        f_SS_Config_64kPS_TDD ( p_CellId,
                                cs_CphyTrchConfigReq_Common_TDD ( p_ActTime,
                                                                  cs_DCH_336_148_UL_Info_TDD,
                                                                  cs_TFCS_Cmpl0_1_2_3_4_5_6_7_8_9_Rx,
                                                                  omit, omit, omit, omit ),
                                cs_CphyTrchConfigReq_Common_TDD ( p_ActTime, omit, omit,
                                                                  cs_DCH_336_148_DL_Info_TDD,
                                                                  cs_TFCS_Cmpl0_1_2_3_4_5_6_7_8_9_Tx ( cs_PowerOffsetInfo_TDD ),
                                                                  omit, omit ),
                                cs_TrChInfoUL_336_148_TDD,
                                cs_TrChInfoDL_336_148_TDD,
                                cs_TrLogMappingUL_4DCCH_1DTCH ( tsc_RB20 ),
                                cs_TrLogMappingDL_4DCCH_1DTCH_PS,
                                cs_DL_DPCH_64K_PS_TDD ( cs_DL_CommonInfoDCH_initialise_TDD ),
                                cs_UL_DPCH_64K_PS_TDD,
                                p_ActTime );
      }
      else {
        FatalError(__FILE__, __LINE__, "Cell is neither FDD or TDD");
      }
    }
    else {
      FatalError(__FILE__, __LINE__, "Configuration not supported");
    }
    
    // Setup radio bearer B20.
    //* Default values from 34.108  cl. 6.10.2.4.4 and 6.10.2.4.3.3
    f_SS_RB20_AM_PS_Cfg ( p_CellId, cs_OctetModeRLC_Size336 );
    
    f_UTRAN_CellInfo_SetConfigType ( p_CellId, cell_DCH_64kPS_RAB_SRB );
  }
  
  //* @desc Function to receive the Service Request message
  //* @param p_CellId
  //* @param p_CN_Domain
  function f_UTRAN_GMM_ServReq ( UTRAN_CellId_Type p_CellId, CN_DomainIdentity p_CN_Domain ) runs on UTRAN_PTC
  {
    var START_Value v_START_Value := '00000000000000000000'B;
    var RRC_DATA_IND v_RRC_DataInd;
    var UTRAN_SecurityInfo_Type v_SecurityInfo := f_UTRAN_Security_Get( );
    var KeySeq v_KeySeqPs := v_SecurityInfo.authKeys.AuthPS.KeySeq;
    
    alt {
      [p_CN_Domain == cs_domain] U_Dc.receive ( car_InitDirectTransfer ( p_CellId,
                                                                         tsc_RB3,
                                                                         cr_U_ServReqAny_Common (?) ) )
        -> value v_RRC_DataInd {}
      [p_CN_Domain == ps_domain] U_Dc.receive ( car_PS_InitDirectTransfer ( p_CellId,
                                                                            tsc_RB3,
                                                                            cr_U_ServiceRequest ( cr_ServiceType ( ? ),
                                                                                                  cs_MobileIdTMSIorPTMSI ('18'O, px_PTMSI_Def),
                                                                                                  v_KeySeqPs ) ) )
        -> value v_RRC_DataInd {}
    }
    v_START_Value := v_RRC_DataInd.ttcn_start;
    f_SS_SecurityDownloadStart ( p_CN_Domain, v_START_Value );
  }
  
  function f_UTRAN_PS_SessionAct_ReceivePDP_Req ( UTRAN_CellId_Type                 p_CellId,
                                                  RB_ConfigType                     p_RB_Config,
                                                  template (value) QualityOfService p_QualityOfService ) runs on UTRAN_PTC return ACTIVATEPDPCONTEXTREQUESTul {
    var RRC_DATA_IND v_RRC_DataInd;
    
    // Call is initiated by AT command, check QoS
    if ( p_RB_Config == cell_DCH_64kPS_RAB_SRB ) {
      if ( pc_GERAN ) {
        U_Dc.receive ( car_PS_UplinkDirectTransfer ( p_CellId,
                                                     tsc_RB3,
                                                     cr_U_ActPDP_ContextReqMo ( cr_QoS_InteractiveOrBackgroundMO ( p_QualityOfService.delayClass, p_QualityOfService.trafficClass ) ) ) )
          -> value v_RRC_DataInd;
      }
      if ( not pc_GERAN ) {
        U_Dc.receive ( car_PS_UplinkDirectTransfer ( p_CellId,
                                                     tsc_RB3,
                                                     cr_U_ActPDP_ContextReqMo ( cr_QoS_InteractiveOrBackgroundMO_UMTS ( p_QualityOfService.trafficClass ) ) ) )
          -> value v_RRC_DataInd;
      }
    }
    else if ( p_RB_Config == cell_DCH_HS_DSCH ) {
      alt {
        // px_HSDSCH_UE_Category_FDD == 9 ) or px_HSDSCH_UE_Category_FDD == 10
        [] U_Dc.receive ( car_PS_UplinkDirectTransfer ( p_CellId,
                                                        tsc_RB3,
                                                        cr_U_ActPDP_ContextReqMo ( cdr_QoS_InteractiveOrBackgroundMO_HSDPA_Ext ( p_QualityOfService.trafficClass,
                                                                                                                                 p_QualityOfService.maxSduSize,
                                                                                                                                 p_QualityOfService.maxBitRateDL,
                                                                                                                                 p_QualityOfService.maxBitRateDL_Ext ) ) ) )
          -> value v_RRC_DataInd {}
        
        [] U_Dc.receive ( car_PS_UplinkDirectTransfer ( p_CellId,
                                                        tsc_RB3,
                                                        cr_U_ActPDP_ContextReqMo ( cr_QoS_InteractiveOrBackgroundMO_HSDPA ( p_QualityOfService.trafficClass,
                                                                                                                            p_QualityOfService.maxSduSize,
                                                                                                                            p_QualityOfService.maxBitRateDL ) ) ) )
          -> value v_RRC_DataInd {}
      }
    }
    else if ( p_RB_Config == cell_DCH_E_HS ) {
      FatalError(__FILE__, __LINE__, "Configuration not supported");
    }
    else {
      FatalError(__FILE__, __LINE__, "Wrong configuration handed in to the function");
    }
    
    /*
      @desc If by MMI call, then not check the QoS
      else {
      U_Dc.receive ( car_PS_UplinkDirectTransfer ( p_CellId,
      tsc_RB3,
      cr_U_ActPDP_ContextReqMo ( cr_QualityOfService_Any ) ) )
      -> value v_RRC_DataInd;
      }
    */
    return v_RRC_DataInd.msg.activatePDPContextRequestul;
  }
  
  function f_UTRAN_CalculateTGCFN ( integer p_FrameNumber, integer p_TtiValue) return TGCFN
  {
    //p_ttiValue : is equal to tti/10
    return (p_FrameNumber+(256-p_TtiValue )) mod 256;
  }
  
  //* @desc To calculate the activation time with the tti value corresponding to the actual SS configuration.
  //* The tti value passed as parameter to ts_CPHY_ActTime is equal to tti/10 (e.g. tti 40 -> 4)
  //* Based on 34.108 on SRB tti.
  function f_CalculateActTime ( UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return UTRAN_CFN_Info_Type
  {
    var RB_ConfigType v_Rb_ConfigType := f_UTRAN_CellInfo_GetConfigType ( p_CellId );
    var UTRAN_CFN_Info_Type v_CFN_Info;
    var PhysicalChannelIdentity v_PhyChId;
    var integer v_TtiValue;
    
    select (v_Rb_ConfigType) {
      case (cell_DCH_Speech,
            cell_DCH_64kPS_RAB_SRB,
            cell_DCH_StandAloneSRB,
            cell_DCH_HS_DSCH,
            cell_DCH_E_HS) {
        /* An RRC connection is established. Use DCCH on DL DPCH1 */
        v_PhyChId := tsc_DL_DPCH1;
        v_TtiValue := 4;
      }
      case (cell_DCH_StandAloneSRB_NoConn,
            cell_FACH_NoConn) {
        /* No RRC connection is established. Use CCCH configuration */
        v_PhyChId := tsc_S_CCPCH1;
        v_TtiValue := 1;
      }
      case ( cell_FACH ) {
        /*One RRC connection established on FACH*/
        v_PhyChId := tsc_S_CCPCH1;
        v_TtiValue := 1;
      }
      case (cell_E_HS) {
        v_PhyChId := tsc_F_DPCH;
        v_TtiValue := 4;
      }
      case else {
        FatalError(__FILE__, __LINE__, "Configuration not supported");
      }
    }
    v_CFN_Info.frameNumber := f_CPHY_GetFrameNumber ( p_CellId, v_PhyChId );
    v_CFN_Info.actTime     := f_UTRAN_CalculateActTime ( v_CFN_Info.frameNumber );
    v_CFN_Info.tGCFN       := f_UTRAN_CalculateTGCFN ( v_CFN_Info.frameNumber, v_TtiValue );
    return v_CFN_Info;
  }
  
  function f_UTRAN_ReceiveRB_SetupCmpl_SS_CipheringAM_RAB_UL_DL ( UTRAN_CellId_Type            p_CellId,
                                                                  CN_DomainIdentity            p_Cn_DomainIdentity,
                                                                  RB_ConfigType                p_RbType,
                                                                  template (omit) KeyCiphering p_KC ) runs on UTRAN_PTC
  {
    var RLC_SequenceNumber v_RLC_SNs := 0;
    var template (value) RB_ActivationTimeInfoList v_RB_ActivationTimeInfoList;
    var UTRAN_SecurityInfo_Type v_SecurityInfo := f_UTRAN_Security_Get ( );
    
    select (p_RbType) {
      case (cell_DCH_64kPS_RAB_SRB) {
        v_RB_ActivationTimeInfoList := cs_RB_ActTimeInfoList20 ( v_RLC_SNs );
      }
      // HSD configurations:
      case (cell_DCH_HS_DSCH) {
        v_RB_ActivationTimeInfoList := cs_RB_ActTimeInfoList25 ( v_RLC_SNs );
      }
      // HSU configurations:
      case (cell_DCH_E_HS,
            cell_E_HS) {
        v_RB_ActivationTimeInfoList := cs_RB_ActTimeInfoList25 ( v_RLC_SNs );
      }
      case else {
        FatalError(__FILE__, __LINE__, "Configuaration not supported");
      }
    }
    
    f_CMAC_SecurityMode_Config ( v_SecurityInfo.recentSecureDomain,
                                 v_SecurityInfo.start_PS,
                                 p_KC, omit, omit );
    
    f_UTRAN_CRLC_DL_CipherCfgRB ( p_CellId,
                                  p_Cn_DomainIdentity,
                                  v_SecurityInfo.dL_CipherMode,
                                  p_RbType,
                                  false );//Do not suspend RLC since RB is established only
    
    f_CRLC_CipheringActivate ( cas_CRLC_UL_CipherActReq ( p_CellId,
                                                          ps_domain,
                                                          v_RB_ActivationTimeInfoList,
                                                          notInc ) );
  }
  
  function f_UTRAN_ReceiveRB_SetupCmpl_CipheringStartedAM_RAB ( UTRAN_CellId_Type p_CellId,
                                                                CN_DomainIdentity p_Cn_DomainIdentity,
                                                                RB_ConfigType     p_RbType ) runs on UTRAN_PTC
  {
    var UTRAN_SecurityInfo_Type v_SecurityInfo := f_UTRAN_Security_Get ( );
    var U_RLC_AM_IND v_U_RLC_AM_IND;
    
    U_AM.receive ( car_RLC_Data_Ind ( p_CellId,
                                      tsc_RB2,
                                      cr_108_RB_SetUpCmpl ( tsc_RRC_TI ) ) ) -> value v_U_RLC_AM_IND;
    
    // A new start value is provided; A RB UL cipher is not present
    v_SecurityInfo.start_PS := v_U_RLC_AM_IND.data.aM_message.uL_DCCH_Message.message_.radioBearerSetupComplete.start_Value;
    f_UTRAN_Security_Set ( v_SecurityInfo );
    
    f_UTRAN_ReceiveRB_SetupCmpl_SS_CipheringAM_RAB_UL_DL ( p_CellId,
                                                           p_Cn_DomainIdentity,
                                                           p_RbType,
                                                           v_SecurityInfo.authKeys.AuthCS.CKey );
  }
  
  function f_UTRAN_ReceiveRB_SetupCmpl_CipheringNotStartedAM_RAB ( UTRAN_CellId_Type p_CellId,
                                                                   CN_DomainIdentity p_Cn_DomainIdentity,
                                                                   RB_ConfigType p_RbType ) runs on UTRAN_PTC
  {
    var UTRAN_SecurityInfo_Type v_SecurityInfo := f_UTRAN_Security_Get ( );
    var U_RLC_AM_IND v_U_RLC_AM_IND;
    
    alt {
      [] U_AM.receive ( car_RLC_Data_Ind ( p_CellId,
                                           tsc_RB2,
                                           cdr_RRC_RB_SetUpCmplNoStartVal ( tsc_RRC_TI ) ) )
        -> value v_U_RLC_AM_IND {
        // No start value, no RB UL cipher
        f_UTRAN_ReceiveRB_SetupCmpl_SS_CipheringAM_RAB_UL_DL ( p_CellId, p_Cn_DomainIdentity, p_RbType, omit );
      }
      [] U_AM.receive ( car_RLC_Data_Ind ( p_CellId,
                                           tsc_RB2,
                                           cr_108_RB_SetUpCmpl ( tsc_RRC_TI ) ) )
        -> value v_U_RLC_AM_IND {
        
        //A new start value is provided
        v_SecurityInfo.start_PS := v_U_RLC_AM_IND.data.aM_message.uL_DCCH_Message.message_.radioBearerSetupComplete.start_Value;
        f_UTRAN_Security_Set ( v_SecurityInfo );
        f_UTRAN_ReceiveRB_SetupCmpl_SS_CipheringAM_RAB_UL_DL ( p_CellId, p_Cn_DomainIdentity, p_RbType, omit );
      }
    }
  }
  
  //* @desc To receive the RB Setup complete message and perform associated Security operations on SS
  function f_UTRAN_RRC_ReceiveRB_SetupCmpl ( UTRAN_CellId_Type p_CellId,
                                             RB_ConfigType     p_RbType
                                             /* ActivationTime    p_ActTime */
                                             ) runs on UTRAN_PTC
  {
    //FFS - Opend Issue #3
    //CS Branch not yet implemented
    
    var UTRAN_SecurityInfo_Type v_SecurityInfo := f_UTRAN_Security_Get ( );
    if (p_RbType == cell_DCH_Speech) {
      
      if ( ( v_SecurityInfo.cs_cipheringStarted == true ) and
           ( v_SecurityInfo.recentSecureDomain == cs_domain ) ) {
        //LOCAL_ReceiveRB_SetupCmpl_CipheringStartedTM_RAB ( p_ActTime );
        //FFS - ToDo
      }
      else if ( ( v_SecurityInfo.cs_cipheringStarted == true ) and
                ( p_RbType == cell_DCH_Speech ) ) {
        //LOCAL_ReceiveRB_SetupCmpl_CipheringStartedTM_RAB ( p_ActTime );
        //FFS - ToDo
      }
      else if ( v_SecurityInfo.cs_cipheringStarted == false ) {
        //LOCAL_ReceiveRB_SetupCmpl_CipheringNotStartedTM_RAB();
        //FFS - ToDo
      }
      else {  /*AM/UM RAB*/
        if ( ( v_SecurityInfo.ps_cipheringStarted == true ) and
             ( v_SecurityInfo.recentSecureDomain == ps_domain ) ) {
          f_UTRAN_ReceiveRB_SetupCmpl_CipheringStartedAM_RAB ( p_CellId,
                                                               v_SecurityInfo.recentSecureDomain,
                                                               p_RbType );
        }
        else {
          f_UTRAN_ReceiveRB_SetupCmpl_CipheringNotStartedAM_RAB ( p_CellId,
                                                                  v_SecurityInfo.recentSecureDomain,
                                                                  p_RbType );
        }
      }
    }
  }
  
  function f_CPHY_RL_Modify (template (value) U_CPHY_CONFIG_REQ p_CPHY_RL_Modify_REQ ) runs on UTRAN_PTC
  {
    U_CPHY.send ( p_CPHY_RL_Modify_REQ );
    U_CPHY.receive ( car_RL_ModifyCnf );
  }
  
  function f_CMAC_MACHs_Config ( UTRAN_CellId_Type p_CellId,
                                 template (value) U_CMAC_CONFIG_REQ p_CMAC_MACHs_Config_REQ) runs on UTRAN_PTC
  {
    U_CMAC.send ( p_CMAC_MACHs_Config_REQ );
    U_CMAC.receive ( car_CMAC_MACHs_CfgCnf ( p_CellId ) );
  }

  /*
   * @desc      to modify physical channel DPCH1and connect DCH1, DCH2, DCH3 and DCH5  to the physical channel,
   *            then map DCCH1-4 on to the DCH5 transport channel and map DTCH(subflow#1), DTCH(subflow#2), DTCH(subflow#3)
   *            to the DCH1, DCH2, DCH3 transport channel respectively.
   *            Used for AMR speech.
   * @param     p_CellId
   * @param     p_ActTime
   * @param     p_DL_CommonInformation
   * @param     p_UL_DPCH_Info
   * @param     p_HS_DPCCHInfo
   * @status
   */
  function f_SS_4DCH_Modify_FDD ( UTRAN_CellId_Type                        p_CellId,
                                  ActivationTime                           p_ActTime,
                                  template (value) DL_CommonInformation_r8 p_DL_CommonInformation,
                                  template (omit)  UL_DPCH_Info_r7         p_UL_DPCH_Info,
                                  template (omit)  HS_DPCCHInfo            p_HS_DPCCHInfo ) runs on UTRAN_PTC {

    var template (value) SS_ActivationTime v_SS_ActivationTime := cas_ActivateCNF ( p_ActTime );
    
    f_CPHY_RL_Modify ( cas_DL_DPCH_ModifyInfo_FDD ( p_CellId,
                                                    tsc_DL_DPCH1,
                                                    cs_DL_DPCH_122_AMR_FDD ( p_DL_CommonInformation,
                                                                         tsc_DL_DPCH1_2ndScrC ),
                                                    omit,
                                                    v_SS_ActivationTime ) );
    f_CPHY_TrCH_Config (cas_DCH4_DL_Info_FDD ( p_CellId,
                                                tsc_DL_DPCH1,
                                                cs_TrChConfigTypeDCH_NoSHO,
                                                p_ActTime ) );
    f_CMAC_Config ( cas_CMAC_ReconfigInfo_FDD ( p_CellId,
                                               tsc_DL_DPCH1,
                                               cs_UE_Info(omit, omit),
                                               cs_TrChInfoDL_122_AMR_FDD,
                                               cs_TrLogMappingDL_4DCCH_3DTCH,
                                               v_SS_ActivationTime ) );
    f_CPHY_RL_Modify ( cas_UL_DPCH_ModifyInfo_FDD ( p_CellId,
                                                    tsc_UL_DPCH1,
                                                    p_UL_DPCH_Info,
                                                    p_HS_DPCCHInfo,
                                                    v_SS_ActivationTime ) );
    f_CPHY_TrCH_Config ( cas_DCH4_UL_Info_FDD ( p_CellId,
                                                tsc_UL_DPCH1,
                                                cs_TrChConfigTypeDCH_NoSHO,
                                                p_ActTime ) );
    f_CMAC_Config ( cas_CMAC_ReconfigInfo_FDD ( p_CellId,
                                                tsc_UL_DPCH1,
                                                cs_UE_Info(omit, omit),
                                                cs_TrChInfoUL_122_AMR_FDD,
                                                cs_TrLogMappingUL_4DCCH_3DTCH,
                                                v_SS_ActivationTime ) );
  }

  /*
   * @desc      to modify physical channel DPCH1and connect DCH1, DCH2, DCH3 and DCH5  to the physical channel,
   *            then map DCCH1-4 on to the DCH5 transport channel and map DTCH(subflow#1), DTCH(subflow#2), DTCH(subflow#3)
   *            to the DCH1, DCH2, DCH3 transport channel respectively.
   *            Used for AMR speech.
   * @param     p_CellId
   * @param     p_ActTime
   * @param     p_DL_CommonInformation
   * @param     p_UL_DPCH_Info
   * @param     p_HS_DPCCHInfo
   * @status
   */
  function f_SS_4DCH_Modify_TDD ( UTRAN_CellId_Type                        p_CellId,
                                  ActivationTime                           p_ActTime,
                                  template (value) DL_CommonInformation_r8 p_DL_CommonInformation,
                                  template (value) UL_DPCH_Info_r7         p_UL_DPCH_Info,
                                  template (omit)  HS_DPCCHInfo            p_HS_DPCCHInfo ) runs on UTRAN_PTC {

    var template (value) SS_ActivationTime v_SS_ActivationTime := cas_ActivateCNF ( p_ActTime );
    
    f_CPHY_RL_Modify ( cas_DL_DPCH_ModifyInfo_TDD ( p_CellId,
                                                    tsc_DL_DPCH1,
                                                    cs_DL_DPCH_122_AMR_TDD ( p_DL_CommonInformation ),
                                                    omit,
                                                    v_SS_ActivationTime ) );
    
    f_CPHY_TrCH_Config (cas_DCH4_DL_Info_TDD ( p_CellId,
                                                tsc_DL_DPCH1,
                                                cs_TrChConfigTypeDCH_NoSHO,
                                                p_ActTime ) );

    f_CMAC_Config ( cas_CMAC_ReconfigInfo_TDD ( p_CellId,
                                               tsc_DL_DPCH1,
                                               cs_UE_Info(omit, omit),
                                               cs_TrChInfoDL_122_AMR_TDD,
                                               cs_TrLogMappingDL_4DCCH_3DTCH,
                                               v_SS_ActivationTime ) );

    f_CPHY_RL_Modify ( cas_UL_DPCH_ModifyInfo_TDD ( p_CellId,
                                                    tsc_UL_DPCH1,
                                                    p_UL_DPCH_Info,
                                                    p_HS_DPCCHInfo,
                                                    v_SS_ActivationTime ) );
    f_CPHY_TrCH_Config ( cas_DCH4_UL_Info_TDD ( p_CellId,
                                                tsc_UL_DPCH1,
                                                cs_TrChConfigTypeDCH_NoSHO,
                                                p_ActTime ) );
    f_CMAC_Config ( cas_CMAC_ReconfigInfo_TDD ( p_CellId,
                                                tsc_UL_DPCH1,
                                                cs_UE_Info(omit, omit),
                                                cs_TrChInfoUL_122_AMR_TDD,
                                                cs_TrLogMappingUL_4DCCH_3DTCH,
                                                v_SS_ActivationTime ) );
  }
  
  //* @desc To configure SS to packet CELL_DCH / HS-DSCH.
  //* DL: [max bit rate depending on UE category] / PS RAB
  //* UL DCH: 64 kbps
  function f_SS_HS_DSCH_PDSCH_Cfg_DPCH_Modify_FDD ( UTRAN_CellId_Type                  p_CellId,
                                                    template (value) SS_ActivationTime p_ActTime ) runs on UTRAN_PTC
  {
    // to downgrade Signalling Channels in DL to 3.4
    f_CPHY_RL_Modify ( cas_DL_DPCH_ModifyInfo_FDD ( p_CellId,
                                                    tsc_DL_DPCH1,
                                                    cs_DL_DPCH_FDD ( cs_DL_CommonInformationRB_SetUp_FDD ( tsc_DL_DPCH1_SFP_SRB_3_4k, fixed ),
                                                                     tsc_Sfc256_C0,
                                                                     tsc_DL_TxPower_DPCH ),
                                                    omit,
                                                    p_ActTime ) );
    
    f_CPHY_TrCH_Config ( cas_TrChCfgInfo_FDD ( p_CellId,
                                               tsc_DL_DPCH1,
                                               cs_TrChConfigTypeDCH_NoSHO,
                                               cs_CphyTrchConfigReq_Common_FDD  ( p_ActTime, omit, omit,
                                                                                  cs_DCH_148_DL_FDD,
                                                                                  cs_TFCS_Cmpl0_1_Tx_FDD ( cs_PowerOffsetInfoBelow64k ),
                                                                                  omit, omit, omit, omit ) ) );
    
    f_CMAC_Config ( cas_CMAC_ReconfigInfo_FDD ( p_CellId,
                                                tsc_DL_DPCH1,
                                                cs_UE_Info( omit, omit ),
                                                cs_TrCHInfo_Common_FDD ( omit, omit, cs_TrChInfoDL_34_StandAlone_FDD,
                                                                         cs_TFCS_Cmpl0_1_Tx_FDD ( cs_PowerOffsetInfoBelow64k ),
                                                                         omit, omit, omit ),
                                                cs_TrLogMappingDL_4DCCH,
                                                p_ActTime ) );
    
    // Configure HSDPA channels
    f_CPHY_RL_Setup ( cas_HS_PDSCH_SetupInfo_FDD ( p_CellId,
                                                   tsc_HSPDSCH,
                                                   cs_DL_Cell_DCH_HS_DSCH_PS_RAB ( px_HSDSCH_UE_Category_FDD,
                                                                                   cs_DL_HSPDSCH_Information_FDD ( cs_HS_SCCH_Info_FDD,
                                                                                                                   cs_Measurement_Feedback_Info ),
                                                                                   false ),
                                                   p_ActTime ) );
    
    f_CPHY_TrCH_Config ( cas_TrChCfgInfo_FDD ( p_CellId,
                                               tsc_HSPDSCH,
                                               cs_TrChConfigTypeNonDCH,
                                               cs_CphyTrchConfigReq_Common_FDD ( p_ActTime, omit, omit, omit, omit,
                                                                                 cs_HS_DSCHMacdFlows ( cs_HARQ_Info_FDD,
                                                                                                       cs_SS_AddOrReconfMAC_dFlow ( cs_SS_MAC_hs_AddReconfQueue ( cs_MAC_hs_AddReconfQueue336 ) ) ),
                                                                                 omit, omit, omit ) ) );
    
    // To configure/Reconfigure MAC_HS in Explicit TFRC config mode.
    f_CMAC_MACHs_Config ( p_CellId, cas_CMAC_MAChs_TFRC_ExplicitConfigReq_FDD ( p_CellId ) );
    
    f_CMAC_Config ( cas_CMAC_CfgInfo_FDD ( p_CellId,
                                           tsc_HSPDSCH,
                                           cs_UE_Info (omit, omit),
                                           cs_TrCHInfo_Common_FDD ( omit, omit, omit, omit,
                                                                    cs_HS_DSCHMacdFlows ( cs_HARQ_Info_FDD,
                                                                                          cs_SS_AddOrReconfMAC_dFlow ( cs_SS_MAC_hs_AddReconfQueue ( cs_MAC_hs_AddReconfQueue336 ) ) ),
                                                                    omit, omit ),
                                           cs_TrLogMappingDL_MAC_HS ) );
    
    
    // to modify UL DPCH (ul_DataRate = r64)
    f_CPHY_RL_Modify ( cas_UL_DPCH_ModifyInfo_FDD ( p_CellId,
                                                    tsc_UL_DPCH1,
                                                    cds_UL_DPCH_InfoACK_HSDPA_FDD ( tsc_UL_DPDCH_SF_64k_PS,
                                                                                    pl0_96,
                                                                                    f_UTRAN_CellInfo_GetULScrmCode_FDD ( p_CellId ) ),
                                                    omit,
                                                    p_ActTime ) );
    
    f_CPHY_TrCH_Config (cas_TrChCfgInfo_FDD ( p_CellId,
                                              tsc_UL_DPCH1,
                                              cs_TrChConfigTypeDCH_NoSHO,
                                              cs_CphyTrchConfigReq_Common_FDD ( p_ActTime, cs_DCH_336_148_UL_Info_FDD,
                                                                                cs_TFCS_Cmpl0_1_2_3_4_5_6_7_8_9_Rx,
                                                                                omit, omit, omit, omit, omit, omit ) ) );
    
    f_CMAC_Config ( cas_CMAC_ReconfigInfo_FDD ( p_CellId,
                                                tsc_UL_DPCH1,
                                                cs_UE_Info( omit, omit ),
                                                cs_TrCHInfo_Common_FDD ( cs_TrChInfoUL_336_148_FDD,
                                                                         omit, omit, omit, omit, omit, omit ),
                                                cs_TrLogMappingUL_4DCCH_1DTCH ( tsc_RB25 ),
                                                p_ActTime ) );
    
  }
  
  //* @desc To configure SS to packet CELL_DCH / HS-DSCH.
  //* DL: [max bit rate depending on UE category] / PS RAB
  //* UL DCH: 64 kbps
  function f_SS_HS_DSCH_PDSCH_Cfg_DPCH_Modify_TDD ( UTRAN_CellId_Type p_CellId,
                                                    template (value) SS_ActivationTime p_ActTime ) runs on UTRAN_PTC
  {
    // to downgrade Signalling Channels in DL to 3.4
    f_CPHY_RL_Modify (cas_DL_DPCH_ModifyInfo_TDD ( p_CellId,
                                                   tsc_DL_DPCH1,
                                                   cs_DL_DPCH_SRB_StandAloneDPCH_TDD,
                                                   omit,
                                                   p_ActTime ) );
    
    f_CPHY_TrCH_Config ( cas_TrChCfgInfo_TDD ( p_CellId,
                                               tsc_DL_DPCH1,
                                               cs_TrChConfigTypeDCH_NoSHO,
                                               cs_CphyTrchConfigReq_Common_TDD ( p_ActTime, omit, omit,
                                                                                 cs_DCH_148_DL_TDD,
                                                                                 cs_TFCS_Cmpl0_1_Tx_TDD,
                                                                                 omit, omit) ) );
    
    f_CMAC_Config ( cas_CMAC_ReconfigInfo_TDD ( p_CellId,
                                                tsc_DL_DPCH1,
                                                cs_UE_Info( omit, omit ),
                                                cs_TrCHInfo_Common_TDD ( omit, omit, cs_TrChInfoDL_34_StandAlone_TDD,
                                                                         cs_TFCS_Cmpl0_1_Tx_TDD,
                                                                         omit ),
                                                cs_TrLogMappingDL_4DCCH,
                                                p_ActTime ) );
    
    // Configure HSDPA channels
    f_CPHY_RL_Setup ( cas_HS_PDSCH_SetupInfo_TDD ( p_CellId,
                                                   tsc_HSPDSCH,
                                                   cs_DL_Cell_DCH_HS_DSCH_PS_RAB ( px_HSDSCH_UE_Category_TDD,
                                                                                   cs_DL_HSPDSCH_Information_TDD ( cs_HS_SCCH_Info_TDD,
                                                                                                                   cs_HS_PDSCH_Midamble_Configuration_TDD128 ),
                                                                                   false ),
                                                   p_ActTime ) );
    
    f_CPHY_TrCH_Config ( cas_TrChCfgInfo_TDD ( p_CellId,
                                               tsc_HSPDSCH,
                                               cs_TrChConfigTypeNonDCH,
                                               cs_CphyTrchConfigReq_Common_TDD ( p_ActTime, omit, omit, omit, omit,
                                                                                 cs_HS_DSCHMacdFlows ( cs_HARQ_Info_TDD,
                                                                                                       cs_SS_AddOrReconfMAC_dFlow ( cs_SS_MAC_hs_AddReconfQueue ( cs_MAC_hs_AddReconfQueue336 ) ) ),
                                                                                 omit ) ) );
    
    // To configure/Reconfigure MAC_HS in Explicit TFRC config mode.
    f_CMAC_MACHs_Config ( p_CellId, cas_CMAC_MAChs_TFRC_ExplicitConfigReq_TDD ( p_CellId ) );
    
    f_CMAC_Config ( cas_CMAC_CfgInfo_TDD ( p_CellId,
                                           tsc_HSPDSCH,
                                           cs_UE_Info (omit, omit),
                                           cs_TrCHInfo_Common_TDD ( omit, omit, omit, omit,
                                                                    cs_HS_DSCHMacdFlows ( cs_HARQ_Info_TDD,
                                                                                          cs_SS_AddOrReconfMAC_dFlow ( cs_SS_MAC_hs_AddReconfQueue ( cs_MAC_hs_AddReconfQueue336 ) ) ) ),
                                           cs_TrLogMappingDL_MAC_HS ) );
    
    
    // to modify UL DPCH (ul_DataRate = r64)
    f_CPHY_RL_Modify ( cas_UL_DPCH_ModifyInfo_TDD ( p_CellId,
                                                    tsc_UL_DPCH1,
                                                    cs_UL_DPCH_64K_PS_TDD,
                                                    omit,
                                                    p_ActTime ) );
    
    f_CPHY_TrCH_Config ( cas_TrChCfgInfo_TDD ( p_CellId,
                                               tsc_UL_DPCH1,
                                               cs_TrChConfigTypeDCH_NoSHO,
                                               cs_CphyTrchConfigReq_Common_TDD ( p_ActTime, cs_DCH_336_148_UL_Info_TDD,
                                                                                 cs_TFCS_Cmpl0_1_2_3_4_5_6_7_8_9_Rx,
                                                                                 omit, omit, omit, omit ) ) );
    
    f_CMAC_Config ( cas_CMAC_ReconfigInfo_TDD ( p_CellId,
                                                tsc_UL_DPCH1,
                                                cs_UE_Info( omit, omit ),
                                                cs_TrChInfoUL_336_148_TDD,
                                                cs_TrLogMappingUL_4DCCH_1DTCH ( tsc_RB25 ),
                                                p_ActTime ) );
  }

  /*
   * @desc      setup radio bearers RB10, RB11, RB12 for radio beaer subflow#1, subflow#2, subflow#3
   *            Default values from 34.108  cl. 6.10.2.4.4 and 6.10.2.4.3.3
   * @param     p_CellId
   * @param     p_RB_Configuration The Radio Bearer type to be configured
   * @status
   */
  function f_SS_RB10_ToRB12_TM_Cfg ( UTRAN_CellId_Type p_CellId ) runs on UTRAN_PTC {
    
    var template (value) RB_LogCH_Mapping v_RB_LogCH_Mapping_RB10 := cs_RB_LogCH_Mapping(tsc_UL_DTCH1, tsc_DL_DTCH1);
    var template (value) RB_LogCH_Mapping v_RB_LogCH_Mapping_RB11 := cs_RB_LogCH_Mapping(tsc_UL_DTCH2, tsc_DL_DTCH2);
    var template (value) RB_LogCH_Mapping v_RB_LogCH_Mapping_RB12 := cs_RB_LogCH_Mapping(tsc_UL_DTCH3, tsc_DL_DTCH3);

    f_CRLC_Config ( cas_RB_TM_UL_Info_FDD ( p_CellId,
                                            tsc_RB10,
                                            81,
                                            v_RB_LogCH_Mapping_RB10 ) );

    f_CRLC_Config ( cas_RB_TM_UL_Info_FDD ( p_CellId,
                                            tsc_RB11,
                                            103,
                                            v_RB_LogCH_Mapping_RB11 ) );

    f_CRLC_Config ( cas_RB_TM_UL_Info_FDD ( p_CellId,
                                            tsc_RB12,
                                            60,
                                            v_RB_LogCH_Mapping_RB12 ) );
  }
  
  // cofigure radio bearers : RB25 DTCH on HS-DSCH and DTCH on DPCH associated HS-DSCH
  function f_SS_RB25_AM_PS_Cfg ( UTRAN_CellId_Type p_CellId,
                                 integer p_PayloadSize ) runs on UTRAN_PTC
  {
    
    if (f_UTRAN_CellInfo_GetFDD_TDD(p_CellId) == UTRAN_FDD)
      {
        f_CRLC_Config (cas_RB25_AM_Info_FDD ( p_CellId,
                                              tsc_RB25,
                                              cs_RB25_LogChMapping,
                                              p_PayloadSize ) );
      }
    else if (f_UTRAN_CellInfo_GetFDD_TDD(p_CellId) == UTRAN_TDD)
      {
        f_CRLC_Config ( cas_RB25_AM_Info_TDD ( p_CellId,
                                               tsc_RB25,
                                               cs_RB25_LogChMapping,
                                               p_PayloadSize ) );
      }
    else
      {
        FatalError(__FILE__, __LINE__, "Cell is neither FDD nor TDD");
      }
  }
  
  //* @desc If no activation time is specified "now" will be used. This is to be used for HOs to UTRAN.
  function f_SS_Config_HSDPA_64kUL_RAB ( UTRAN_CellId_Type                  p_CellId,
                                         template (value) SS_ActivationTime p_ActTime := cs_ActivateNow ) runs on UTRAN_PTC
  {
    if (f_UTRAN_CellInfo_GetFDD_TDD(p_CellId) == UTRAN_FDD) {
      // Configure SS
      f_SS_HS_DSCH_PDSCH_Cfg_DPCH_Modify_FDD ( p_CellId, p_ActTime );
    }
    else if (f_UTRAN_CellInfo_GetFDD_TDD(p_CellId) == UTRAN_TDD) {
      f_SS_HS_DSCH_PDSCH_Cfg_DPCH_Modify_TDD ( p_CellId, p_ActTime );
    }
    else {
      FatalError(__FILE__, __LINE__, "Cell is neither FDD nor TDD");
    }
    
    // Setup radio bearer RB25
    f_SS_RB25_AM_PS_Cfg ( p_CellId, 320 );
  }
  
  //* @desc To setup a RADIO BEARER and to reconfigure the SS accordingly.
  //* See TS 36.508 cl. 4.8.3 for more details what bearers are configured.
  function f_UTRAN_SendRB_SetUp ( UTRAN_CellId_Type p_CellId,
                                  RB_ConfigType     p_RbType,
                                  ActivationTime    p_ActTime ) runs on UTRAN_PTC
  {
    var UTRAN_SecurityInfo_Type v_SecurityInfo := f_UTRAN_Security_Get ( );
    var template (value) SS_ActivationTime v_SS_ActivationTime := cas_ActivateCNF ( p_ActTime );
    var UTRAN_FDD_TDD v_FDD_TDD_Mode := f_UTRAN_CellInfo_GetFDD_TDD ( p_CellId );
    
    if ( p_RbType == cell_DCH_64kPS_RAB_SRB ) {
      if ( v_FDD_TDD_Mode == UTRAN_FDD ) {
        // Send RB_Set Up for DCH 64k PS for FDD
        U_AM.send ( cas_RLC_Data_Req_Cnf ( p_CellId,
                                           tsc_RB2,
                                           tsc_Mui,
                                           cs_108_RB_SetUp64k_PS_FDD ( v_SecurityInfo.dl_IntegrityCheckInfo,
                                                                       tsc_RRC_TI,
                                                                       p_ActTime,
                                                                       f_UTRAN_CellInfo_GetPriScrmCode_FDD ( p_CellId ),
                                                                       f_UTRAN_CellInfo_GetULScrmCode_FDD ( p_CellId ) ) ) );
      }
      else if ( v_FDD_TDD_Mode == UTRAN_TDD ) {
        // Send RB_Set Up for DCH 64k PS for TDD
        U_AM.send ( cas_RLC_Data_Req_Cnf ( p_CellId,
                                           tsc_RB2,
                                           tsc_Mui,
                                           cs_108_RB_SetUp64k_PS_TDD ( v_SecurityInfo.dl_IntegrityCheckInfo,
                                                                       tsc_RRC_TI,
                                                                       p_ActTime,
                                                                       f_UTRAN_CellInfo_GetCellParametersID_TDD ( p_CellId ) ) ) );
      }
      else {
        FatalError(__FILE__, __LINE__, "Cell is neither FDD or TDD");
      }
      
      // Receive Acknowledgement on the RB Setup message
      U_AM.receive ( car_AM_DataMuiCnf ( p_CellId, tsc_RB2, tsc_Mui ) );
      
      // Configure 64k PS RAB at SS
      f_SS_Config_64kPS_RAB ( p_CellId, v_SS_ActivationTime );
    }
    else if ( p_RbType == cell_DCH_HS_DSCH ) {
      if ( v_FDD_TDD_Mode == UTRAN_FDD ) {
        // Send RB_Set Up with ul_DataRate = r64 for FDD
        U_AM.send ( cas_RLC_Data_Req_Cnf ( p_CellId,
                                           tsc_RB2,
                                           tsc_Mui,
                                           cs_108_RB_SetUpHS_FromDCH_UL_64k_FDD ( v_SecurityInfo.dl_IntegrityCheckInfo,
                                                                                  tsc_RRC_TI,
                                                                                  p_ActTime,
                                                                                  f_UTRAN_CellInfo_GetPriScrmCode_FDD ( p_CellId ),
                                                                                  f_UTRAN_CellInfo_GetULScrmCode_FDD ( p_CellId ) ) ) );
      }
      else if ( v_FDD_TDD_Mode == UTRAN_TDD ) {
        // Send RB_Set Up with ul_DataRate = r64 for TDD
        U_AM.send ( cas_RLC_Data_Req_Cnf ( p_CellId,
                                           tsc_RB2,
                                           tsc_Mui,
                                           cs_108_RB_SetUpHS_FromDCH_UL_64k_TDD ( v_SecurityInfo.dl_IntegrityCheckInfo,
                                                                                  tsc_RRC_TI,
                                                                                  p_ActTime,
                                                                                  f_UTRAN_CellInfo_GetCellParametersID_TDD ( p_CellId ) ) ) );
      }
      else {
        FatalError(__FILE__, __LINE__, "Cell is neither FDD or TDD");
      }
      
      // Receive Acknowledgement on the RB Setup message
      U_AM.receive ( car_AM_DataMuiCnf ( p_CellId, tsc_RB2, tsc_Mui ) );
      
      // Configure HSDPA (64k in UL) RAB at SS
      f_SS_Config_HSDPA_64kUL_RAB ( p_CellId, v_SS_ActivationTime );
    }
    else if ( p_RbType == cell_DCH_E_HS ) {
      FatalError(__FILE__, __LINE__, "Configuration not supported");
    }
    else {
      FatalError(__FILE__, __LINE__, "Wrong configuration passed in to functtion");
    }
    
    f_UTRAN_RRC_ReceiveRB_SetupCmpl ( p_CellId, p_RbType );
  }
  
  //* @desc To establish mobile originated PDP Context.
  //* This test step will send PDP Context Accept
  function f_UTRAN_SendActivatePDP_Accept_DCH ( UTRAN_CellId_Type                 p_CellId,
                                                template (value) PDP_TypeNo       p_IP_TypeNo,
                                                template (value) AddressInfo      p_Addr,
                                                template (value) Type4Length_Type p_LenOct,
                                                boolean                           p_StaticPDP_AddressReceived,
                                                TI                                p_Ti_S,
                                                template (value) QualityOfService p_QualityOfService,
                                                RB_ConfigType                     p_RB_ConfigType ) runs on UTRAN_PTC
  {
    if ( pc_GERAN ) {
      if ( p_StaticPDP_AddressReceived == false ) {// If Static PDP Address NOT Received, hence include PDP address
        if ( p_RB_ConfigType == cell_DCH_64kPS_RAB_SRB ) {
          // Send PDP Context Activation Accept, with LLC SAPI set as 3
          U_Dc.send ( cs_PS_DataReq ( p_CellId,
                                      tsc_RB3,
                                      {activatePDPContextAccept := cs_ActPDP_ContextAcpMT_Common ( p_Ti_S,
                                                                                                   cs_LLC_SAPI_UMTS_GSM,
                                                                                                   cs_QoS_InteractiveOrBackgroundMT ( p_QualityOfService.delayClass,
                                                                                                                                      p_QualityOfService.trafficClass ),
                                                                                                   cs_RadioPriorityHigh (omit),
                                                                                                   cs_PktDataProtoAddrMT ( p_LenOct, p_Addr, p_IP_TypeNo ),
                                                                                                   omit,
                                                                                                   omit ) } ) );
        }
        else if ( p_RB_ConfigType == cell_DCH_HS_DSCH ) {
          // Send PDP Context Activation Accept, with LLC SAPI set as 3
          U_Dc.send ( cs_PS_DataReq ( p_CellId,
                                      tsc_RB3,
                                      {activatePDPContextAccept := cs_ActPDP_ContextAcpMT_Common ( p_Ti_S,
                                                                                                   cs_LLC_SAPI_UMTS_GSM,
                                                                                                   cs_QoS_InteractiveOrBackgroundMT_HS ( p_QualityOfService.delayClass,
                                                                                                                                         p_QualityOfService.trafficClass,
                                                                                                                                         p_QualityOfService.peakThroughput,
                                                                                                                                         p_QualityOfService.maxSduSize,
                                                                                                                                         p_QualityOfService.maxBitRateUL,
                                                                                                                                         p_QualityOfService.maxBitRateDL,
                                                                                                                                         p_QualityOfService.maxBitRateDL_Ext ),
                                                                                                   cs_RadioPriorityHigh (omit),
                                                                                                   cs_PktDataProtoAddrMT ( p_LenOct, p_Addr, p_IP_TypeNo ),
                                                                                                   omit,
                                                                                                   omit ) } ) );
        }
        else if ( p_RB_ConfigType == cell_DCH_E_HS ) {
          // Send PDP Context Activation Accept, with LLC SAPI set as 3
          //FFS - Todo
        }
        else {
          FatalError(__FILE__, __LINE__, "Radio Bearar configuration not supported");
        }
      }
      else {// If Static PDP Address Received
        if ( p_RB_ConfigType == cell_DCH_64kPS_RAB_SRB ) {
          // Send PDP Context Activation Accept, with LLC SAPI set as 3
          U_Dc.send ( cs_PS_DataReq ( p_CellId,
                                      tsc_RB3,
                                      {activatePDPContextAccept := cs_ActPDP_ContextAcpMT_Common ( p_Ti_S,
                                                                                                   cs_LLC_SAPI_UMTS_GSM,
                                                                                                   cs_QoS_InteractiveOrBackgroundMT ( p_QualityOfService.delayClass, p_QualityOfService.trafficClass ),
                                                                                                   cs_RadioPriorityHigh (omit),
                                                                                                   omit,
                                                                                                   omit,
                                                                                                   omit ) } ) );
        }
        else if ( p_RB_ConfigType == cell_DCH_HS_DSCH ) {
          // Send PDP Context Activation Accept, with LLC SAPI set as 3
          U_Dc.send ( cs_PS_DataReq ( p_CellId,
                                      tsc_RB3,
                                      {activatePDPContextAccept := cs_ActPDP_ContextAcpMT_Common ( p_Ti_S,
                                                                                                   cs_LLC_SAPI_UMTS_GSM,
                                                                                                   cs_QoS_InteractiveOrBackgroundMT_HS ( p_QualityOfService.delayClass,
                                                                                                                                         p_QualityOfService.trafficClass,
                                                                                                                                         p_QualityOfService.peakThroughput,
                                                                                                                                         p_QualityOfService.maxSduSize,
                                                                                                                                         p_QualityOfService.maxBitRateUL,
                                                                                                                                         p_QualityOfService.maxBitRateDL,
                                                                                                                                         p_QualityOfService.maxBitRateDL_Ext ),
                                                                                                     cs_RadioPriorityHigh (omit),
                                                                                                   omit,
                                                                                                   omit,
                                                                                                   omit ) } ) );
        }
        else if ( p_RB_ConfigType == cell_DCH_E_HS ) {
          // Send PDP Context Activation Accept, with LLC SAPI set as 3
          //FFS - Todo
        }
        else {
          FatalError(__FILE__, __LINE__, "Radio Bearar configuration not supported");
        }
      }
    }
    
    else {// pc_GERAN == false
      if ( p_StaticPDP_AddressReceived == false ) {// If Static PDP Address  NOT Received, hence include PDP address
        if ( p_RB_ConfigType == cell_DCH_64kPS_RAB_SRB ) {
          // Send PDP Context Activation Accept, with LLC SAPI set as 0 (not assigned)
          U_Dc.send ( cs_PS_DataReq ( p_CellId,
                                      tsc_RB3,
                                      {activatePDPContextAccept := cs_ActPDP_ContextAcpMT_Common ( p_Ti_S,
                                                                                                   cs_LLC_SAPI_UMTS,
                                                                                                   cs_QoS_InteractiveOrBackgroundMT ( p_QualityOfService.delayClass,
                                                                                                                                      p_QualityOfService.trafficClass ),
                                                                                                   cs_RadioPriorityHigh (omit),
                                                                                                   cs_PktDataProtoAddrMT ( p_LenOct, p_Addr, p_IP_TypeNo ),
                                                                                                   omit,
                                                                                                   omit ) } ) );
        }
        else if ( p_RB_ConfigType == cell_DCH_HS_DSCH ) {
          // Send PDP Context Activation Accept, with LLC SAPI set as 0 (not assigned)
          U_Dc.send ( cs_PS_DataReq ( p_CellId,
                                      tsc_RB3,
                                      {activatePDPContextAccept := cs_ActPDP_ContextAcpMT_Common ( p_Ti_S,
                                                                                                   cs_LLC_SAPI_UMTS,
                                                                                                   cs_QoS_InteractiveOrBackgroundMT_HS ( p_QualityOfService.delayClass,
                                                                                                                                         p_QualityOfService.trafficClass,
                                                                                                                                         p_QualityOfService.peakThroughput,
                                                                                                                                         p_QualityOfService.maxSduSize,
                                                                                                                                         p_QualityOfService.maxBitRateUL,
                                                                                                                                         p_QualityOfService.maxBitRateDL,
                                                                                                                                         p_QualityOfService.maxBitRateDL_Ext ),
                                                                                                   cs_RadioPriorityHigh (omit),
                                                                                                   cs_PktDataProtoAddrMT ( p_LenOct, p_Addr, p_IP_TypeNo ),
                                                                                                   omit,
                                                                                                   omit ) } ) );
        }
        else if ( p_RB_ConfigType == cell_DCH_E_HS ) {
          // Send PDP Context Activation Accept, with LLC SAPI set as 0 (not assigned)
          //FFS - Todo
        }
        else {
          FatalError(__FILE__, __LINE__, "Radio Bearar configuration not supported");
        }
      }
      else {// If Static PDP Address Received
        if ( p_RB_ConfigType == cell_DCH_64kPS_RAB_SRB ) {
          // Send PDP Context Activation Accept, with LLC SAPI set as 0 (not assigned)
          U_Dc.send ( cs_PS_DataReq ( p_CellId,
                                      tsc_RB3,
                                      {activatePDPContextAccept := cs_ActPDP_ContextAcpMT_Common ( p_Ti_S,
                                                                                                   cs_LLC_SAPI_UMTS,
                                                                                                   cs_QoS_InteractiveOrBackgroundMT ( p_QualityOfService.delayClass,
                                                                                                                                      p_QualityOfService.trafficClass ),
                                                                                                   cs_RadioPriorityHigh (omit),
                                                                                                   omit,
                                                                                                   omit,
                                                                                                   omit ) } ) );
        }
        else if ( p_RB_ConfigType == cell_DCH_HS_DSCH ) {
          // Send PDP Context Activation Accept, with LLC SAPI set as 0 (not assigned)
          U_Dc.send ( cs_PS_DataReq ( p_CellId,
                                      tsc_RB3,
                                      {activatePDPContextAccept := cs_ActPDP_ContextAcpMT_Common ( p_Ti_S,
                                                                                                   cs_LLC_SAPI_UMTS,
                                                                                                   cs_QoS_InteractiveOrBackgroundMT_HS ( p_QualityOfService.delayClass,
                                                                                                                                         p_QualityOfService.trafficClass,
                                                                                                                                         p_QualityOfService.peakThroughput,
                                                                                                                                         p_QualityOfService.maxSduSize,
                                                                                                                                         p_QualityOfService.maxBitRateUL,
                                                                                                                                         p_QualityOfService.maxBitRateDL,
                                                                                                                                         p_QualityOfService.maxBitRateDL_Ext ),
                                                                                                   cs_RadioPriorityHigh (omit),
                                                                                                   omit,
                                                                                                   omit,
                                                                                                   omit ) } ) );
        }
        else if ( p_RB_ConfigType == cell_DCH_E_HS ) {
          // Send PDP Context Activation Accept, with LLC SAPI set as 0 (not assigned)
          //FFS - Todo
        }
        else {
          FatalError(__FILE__, __LINE__, "Radio Bearar configuration not supported");
        }
      }
    }
  }
  
  //------------------------------------------------------------------------------------
  // Physical Channel Reconfiguration - Configuration of Compressed Mode in UE and SS
  //------------------------------------------------------------------------------------
  
  function f_UTRAN_PhyChReconf_InterRatCompresseModeActivate ( UTRAN_CellId_Type p_CellId ) runs on UTRAN_PTC
  {
    var UTRAN_CFN_Info_Type v_CfnInfo := f_CalculateActTime ( p_CellId );
    var UTRAN_SecurityInfo_Type v_SecurityInfo := f_UTRAN_Security_Get ( );
    var template (value) SS_ActivationTime v_SS_ActivationTime := cas_ActivateCNF ( v_CfnInfo.actTime );
    var RRC_TransactionIdentifier v_RRC_TI := tsc_RRC_TI;
    var RB_ConfigType v_CellConfig := f_UTRAN_CellInfo_GetConfigType ( p_CellId );
    var template (value) DL_CommonInformation_r8 v_DL_CommonInformation;
    var SF512_AndCodeNumber v_SF512_AndCodeNumber;
    var DL_TxPower v_DL_TxPower;
    var UTRAN_FDD_TDD v_FDD_TDD_Mode := f_UTRAN_CellInfo_GetFDD_TDD ( p_CellId );
    
    if ( v_CellConfig == cell_DCH_Speech ) {
      FatalError (__FILE__,__LINE__, "Speech branch not yet supported");
    }
    else if ( v_CellConfig == cell_DCH_64kPS_RAB_SRB ) {
      v_SF512_AndCodeNumber := tsc_DL_DPCH1_ChC_64k_PS;
      v_DL_TxPower := tsc_DL_TxPower_DPCH_64k;
    }
    else if ( v_CellConfig == cell_DCH_HS_DSCH ) {
      v_SF512_AndCodeNumber := tsc_Sfc256_C0;
      v_DL_TxPower := tsc_DL_TxPower_DPCH;
    }
    else if ( v_CellConfig == cell_DCH_E_HS ) {
      FatalError (__FILE__,__LINE__, "HSDPA/HSUPA branch not supported");
    }
    else {
      FatalError (__FILE__,__LINE__, "Invalid Cell configuration");
    }
    
    if ( v_FDD_TDD_Mode == UTRAN_FDD ) {
      if ( (not pc_InterRAT_UL_CompressedModeRequired) and (not pc_InterRAT_DL_CompressedModeRequired) ) {
        // Compressed mode does not need to be configured
        return;
      }
      else if ( (pc_InterRAT_UL_CompressedModeRequired) and (pc_InterRAT_DL_CompressedModeRequired ) ) {
        v_DL_CommonInformation := cs_DL_CommonInformation_FDD ( cs_UL_DL_Mode_ULDL_HLS );
      }
      else if ( pc_InterRAT_DL_CompressedModeRequired ) {
        v_DL_CommonInformation := cs_DL_CommonInformation_FDD ( cs_UL_DL_Mode_DL_HLS );
      }
      else if ( pc_InterRAT_UL_CompressedModeRequired ) {
        v_DL_CommonInformation := cs_DL_CommonInformation_FDD ( cs_UL_DL_Mode_UL_HLS );
      }
      else {
        FatalError (__FILE__,__LINE__, "Invalid PICS settings");
      }
      
      // Transmit Physical Channel Configuration including Compressed Mode parameters for UL and/or DL
      U_AM.send ( cas_RLC_Data_Req_NoCnf ( p_CellId,
                                           tsc_RB2,
                                           cs_PhysicalChannelReconfiguration_FDD ( v_SecurityInfo.dl_IntegrityCheckInfo,
                                                                                   v_RRC_TI,
                                                                                   v_CfnInfo.actTime,
                                                                                   v_DL_CommonInformation ) ) );
      // Configure compressed mode in SS
      f_CPHY_RL_Modify ( cas_CompressedModeDPCH_Info_FDD ( p_CellId,
                                                           tsc_DL_DPCH1,
                                                           cs_DPCHInfo_DL ( cs_DL_DPCH_FDD ( v_DL_CommonInformation,
                                                                                             v_SF512_AndCodeNumber,
                                                                                             v_DL_TxPower ) ),
                                                           v_SS_ActivationTime ) );
      
      // Receive Physical Channel Reconfiguration Complete
      U_AM.receive ( car_RLC_Data_Ind ( p_CellId,
                                        tsc_RB2,
                                        cr_PhysicalChannelReconfigurationComplete( v_RRC_TI ) ) );
    }
    else {
      FatalError (__FILE__,__LINE__, "TDD branch not yet implemented");
    }
  }
  
  //------------------------------------------------------------------------------------
  // Radio Bearer Establishement in UTRAN
  //------------------------------------------------------------------------------------

  /*
   * @desc      Function to establish Speech RAB in UTRA
   * @param     p_CellId
   * @param     p_Security
   * @status
   */
  function f_UTRAN_Setup_RAB_Speech ( UTRAN_CellId_Type p_CellId,
                                      boolean           p_Security := true ) runs on UTRAN_PTC
  {
    var B8_Type v_RAB_ID := tsc_RAB_DefCS;
    var UTRAN_SecurityInfo_Type v_SecurityInfo := f_UTRAN_Security_Get();
    var U_RLC_AM_IND v_UTRAN_RLC_AM_IND;
    var UTRAN_FDD_TDD v_FDD_TDD_Mode := f_UTRAN_CellInfo_GetFDD_TDD ( p_CellId );
    var UTRAN_CFN_Info_Type v_CfnInfo := f_CalculateActTime ( p_CellId );
    var UTRAN_CellInfo_Type_TDD v_CellInfoTDD := f_UTRAN_CellInfo_GetTDDSpecific ( p_CellId );
    
    if ( v_FDD_TDD_Mode == UTRAN_FDD ) {
      U_AM.send ( cas_RLC_Data_Req_Cnf ( p_CellId,
                                         tsc_RB2,
                                         tsc_Mui,
                                         cs_108_RB_SetUpSpeech_FDD ( v_SecurityInfo.dl_IntegrityCheckInfo,
                                                                     tsc_RRC_TI,
                                                                     v_CfnInfo.actTime,
                                                                     v_RAB_ID,
                                                                     f_UTRAN_CellInfo_GetPriScrmCode_FDD ( p_CellId ),
                                                                     f_UTRAN_CellInfo_GetULScrmCode_FDD ( p_CellId ) ) ) );

      //Configure SS with for CS Speech RAB
      f_SS_4DCH_Modify_FDD ( p_CellId,
                             v_CfnInfo.actTime,
                             cs_DL_CommonInformationRB_SetUpSpeech ( tsc_DL_DPCH1_SFP_Speech ),
                             cs_UL_DPCH_Info_FDD ( tsc_UL_DPDCH_SF_Speech,
                                                   pl0_84,
                                                   f_UTRAN_CellInfo_GetULScrmCode_FDD ( p_CellId ) ),
                             omit );

      f_SS_RB10_ToRB12_TM_Cfg ( p_CellId );
    }
    else if ( v_FDD_TDD_Mode == UTRAN_TDD ) {
      U_AM.send ( cas_RLC_Data_Req_Cnf ( p_CellId,
                                         tsc_RB2,
                                         tsc_Mui,
                                         cs_108_RB_SetUpSpeech_TDD ( v_SecurityInfo.dl_IntegrityCheckInfo,
                                                                     tsc_RRC_TI,
                                                                     v_CfnInfo.actTime,
                                                                     v_RAB_ID,
                                                                     v_CellInfoTDD.cellParametersID) ) );

      //Configure SS with for CS Speech RAB
      f_SS_4DCH_Modify_TDD ( p_CellId,
                             v_CfnInfo.actTime,
                             cs_DL_CommonInfoDCH_initialise_TDD,
                             cs_UL_DPCH_Speech_TDD,
                             omit );

      f_SS_RB10_ToRB12_TM_Cfg ( p_CellId );
    }
    else {
      FatalError(__FILE__, __LINE__, "Cell is neither FDD nor TDD");
    }
    
    //Save cell configuration
    f_UTRAN_CellInfo_SetConfigType ( p_CellId, cell_DCH_Speech );

    if ( p_Security ) {//Do security
      f_CMAC_SecurityMode_Config ( v_SecurityInfo.recentSecureDomain,
                                   v_SecurityInfo.start_CS,
                                   v_SecurityInfo.authKeys.AuthCS.CKey,
                                   omit,
                                   omit );

      f_CMAC_UL_DL_CipherCfg ( v_SecurityInfo.dL_CipherMode,
                               v_CfnInfo.actTime,
                               notInc );

      //Receive Radio Bearer Setup Complete message
      U_AM.receive ( car_RLC_Data_Ind ( p_CellId,
                                        tsc_RB2,
                                        cr_108_RB_SetUpCmpl ( tsc_RRC_TI ) ) ) -> value v_UTRAN_RLC_AM_IND;

      v_SecurityInfo.start_CS := v_UTRAN_RLC_AM_IND.data.aM_message.uL_DCCH_Message.message_.radioBearerSetupComplete.start_Value;
    }
    else {
      alt {
        //No start value. No RB UL cipher. USIM is removed -> Count-C not provided by UE
        [] U_AM.receive ( car_RLC_Data_Ind ( p_CellId,
                                             tsc_RB2,
                                             cdr_RRC_RB_SetUpCmplNoStartVal ( tsc_RRC_TI ) ) )
        {}
        //A new start value is provided. USIM is removed -> Count-C not provided by UE
        [] U_AM.receive ( car_RLC_Data_Ind ( p_CellId,
                                             tsc_RB2,
                                             cr_108_RB_SetUpCmpl ( tsc_RRC_TI ) ) ) -> value v_UTRAN_RLC_AM_IND
        {
          v_SecurityInfo.start_CS := v_UTRAN_RLC_AM_IND.data.aM_message.uL_DCCH_Message.message_.radioBearerSetupComplete.start_Value;
        }
      }
    }
    //Store the security information
    f_UTRAN_Security_Set ( v_SecurityInfo );
    //Download security keys to SS
    f_SS_DownloadSecurityKey ( p_CellId, cs_domain );
  }

  /*
   * @desc      Performs UTRA PS RB Establishment according to TS 34.108 subclause 7.4.2 in a UTRAN cell.
   * @param     p_CellId
   * @param     p_RB_Configuration The Radio Bearer type to be configured
   * @status
   */
  function f_UTRAN_UE_PsRB_Est ( UTRAN_CellId_Type p_CellId,
                                 RB_ConfigType     p_RB_Configuration ) runs on UTRAN_PTC
  {
    var template (value) EstablishmentCause v_EstCause := fl_GetMoEstCause();
    var RB_ConfigType v_CellConfiguration := f_UTRAN_CellInfo_GetConfigType ( p_CellId );
    var ACTIVATEPDPCONTEXTREQUESTul v_ActPdpContextReq;
    var PktDataProtoAddr v_ReceivedPDN_Address;
    var template (value) PktDataProtoAddr v_ExpectedPDN_Address;
    var boolean v_NewKeyFlag := true;
    var boolean v_StaticPDP_AddressReceived;
    var B8_Type v_RAB_Id;//v_RAB_Id is set to the value received from UE in the ACTIVATE PDP CONTEXT REQUEST message.
    var TI v_Ti_R, v_Ti_S;// Transaction Identifier. r = value used to receive CC PDU. s = value used to send CC PDU.
    var UTRAN_CFN_Info_Type v_CfnInfo;
    var template (value) QualityOfService v_QualityOfService;
    var integer v_DedicatedId := 1;
    
    // Init QoS and PDN Address parameters only if PS RAB is to be configured
    if ( ( p_RB_Configuration == cell_DCH_64kPS_RAB_SRB ) or
         ( p_RB_Configuration == cell_DCH_HS_DSCH ) or
         ( p_RB_Configuration == cell_DCH_E_HS ) ) {
      
      v_ExpectedPDN_Address := f_UG_GetPktDataProtoAddr ( true );
      v_QualityOfService := f_UTRAN_InitialiseQoS (p_CellId, p_RB_Configuration);
    }
    
    // Initiate an outgoing PS call
    f_UT_ActivatePDPContextUTRAN ( UT,
                                   v_DedicatedId,
                                   v_ExpectedPDN_Address.addrInfo,
                                   v_QualityOfService,
                                   "" );
    
    if ( v_CellConfiguration == cell_DCH_StandAloneSRB_NoConn ) {
      // Steps 1-3 in 34.108 cl. 7.4.2.2.2.3: RRC connection establishment procedure for MO PS calls on DCH
      f_UTRAN_RRC_ConnEst ( p_CellId, est_MO, v_EstCause );
      
      // Step 4 in 34.108 cl. 7.4.2.2.2.3: RRC connection establishment procedure for MO PS calls on DCH
      f_UTRAN_GMM_ServReq ( p_CellId, ps_domain );
      
      // Perform NAS session activation procedure for packet switched sessions (34.108 cl. 7.4.2.4.2)
      // Steps 1-2 in 34.108 cl. 7.4.2.4.2: Generate authentication and run authentication procedure
      f_GMM_Authentication ();
      
      // Step 3-4 in 34.108 cl. 7.4.2.4.2: Transmit Security Mode Comamnd & Receive Security Mode Comlpete
      f_RRC_Security ( p_CellId, v_NewKeyFlag, ps_domain );
      
      // Step 5 in 34.108 cl. 7.4.2.4.2: Receive PDP Context Activation Request
      v_ActPdpContextReq := f_UTRAN_PS_SessionAct_ReceivePDP_Req ( p_CellId, p_RB_Configuration, v_QualityOfService );
      v_ReceivedPDN_Address := v_ActPdpContextReq.pDP_Address;
      
      // Assign v_RAB_Id (BITSTRING[8]) with the NSAPI (BITSTRING[4]) value received in ACTIVATE PDP CONTEXT REQUEST message:
      v_RAB_Id := int2bit ( bit2int ( v_ActPdpContextReq.requestedNSAPI.nSAPI_Value ), 8 );
      v_Ti_R := v_ActPdpContextReq.ti;
      v_Ti_S.tiFlag := '1'B;
      v_Ti_S.tiVal := v_Ti_R.tiVal;
      
      v_StaticPDP_AddressReceived := match ( v_ReceivedPDN_Address,
                                             cr_PktDataProtoAddrMO_Len ( v_ExpectedPDN_Address.iel,
                                                                         v_ExpectedPDN_Address.pDP_TypeNo,
                                                                         v_ExpectedPDN_Address.addrInfo ) );
      
      // Step 1-3 in 34.108 cl. 7.4.2.6.2.3: Radio access bearer establishment procedure for PS mobilie originated calls.
      // Step 1-2 in 34.108 cl. 7.4.2.6.2.3: Send RADIO BEARER SETUP and receive COMPLETE
      v_CfnInfo := f_CalculateActTime ( p_CellId );
      f_UTRAN_SendRB_SetUp ( p_CellId, p_RB_Configuration, v_CfnInfo.actTime );
      
      // Step 3 in 34.108 cl. 7.4.2.6.2.3: Send ACTIVATE PDP CONTEXT ACCEPT
      f_UTRAN_SendActivatePDP_Accept_DCH ( p_CellId,
                                           v_ExpectedPDN_Address.pDP_TypeNo,
                                           v_ExpectedPDN_Address.addrInfo,
                                           v_ExpectedPDN_Address.iel,
                                           v_StaticPDP_AddressReceived,
                                           v_Ti_S,
                                           v_QualityOfService,
                                           p_RB_Configuration );
    }
    else {
      FatalError(__FILE__, __LINE__, "Configuration not supported");
    }
  }
  
  //* @desc Configure a UTRA PS Radio Bearer in UE and SS according to TS 34.108 subclause 6.10.2.4.1.26
  //* Interactive or background / UL:64 DL: 64 kbps / PS RAB + UL:3.4 DL:3.4 kbps SRBs for DCCH
  function f_UTRAN_UE_64kPS_Rb_Est ( UTRAN_CellId_Type p_CellId ) runs on UTRAN_PTC {
    f_UTRAN_UE_PsRB_Est ( p_CellId, cell_DCH_64kPS_RAB_SRB );
  }
  
  //* @desc Configure a UTRA HSDPA Radio Bearer in UE and SS according to TS 34.108 subclause 6.10.2.4.5.1
  //* Interactive or background / UL:64 DL: [max bit rate depending on UE category] / PS RAB + UL:3.4 DL:3.4 kbps SRBs for DCCH
  function f_UTRAN_UE_HSDPA_Rb_Est ( UTRAN_CellId_Type p_CellId ) runs on UTRAN_PTC {
    f_UTRAN_UE_PsRB_Est ( p_CellId, cell_DCH_HS_DSCH );
  }

  //* @desc Configure a UTRA HSUPA/HSDPA Radio Bearer in UE and SS according to TS 34.108 subclause 6.10.2.4.6.3
  //* Interactive or background / UL:64 DL: [max bit rate depending on UE category] / PS RAB + UL:3.4 DL:3.4 kbps SRBs for DCCH
  function f_UTRAN_UE_HSUPA_Rb_Est ( UTRAN_CellId_Type p_CellId ) runs on UTRAN_PTC {
    f_UTRAN_UE_PsRB_Est ( p_CellId, cell_DCH_E_HS );
  }
}
