/******************************************************************************/
// @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-06-04 14:58:42 +0200 (Fri, 04 Jun 2010) $
// $Rev: 3274 $
/******************************************************************************/

module EUTRA_CapabilityFunctions {
  
  import from EUTRA_RRC_ASN1_Definitions language "ASN.1:1997" all;
  import from EUTRA_CommonDefs all;
  import from EUTRA_RRC_Templates all;
  import from EUTRA_DRB_Templates all;
  import from CommonDefs all;
  import from Parameters all;

  //----------------------------------------------------------------------
  // Templates
  //----------------------------------------------------------------------
  template (value) DL_DCCH_Message cs_RRCConnectionReconfiguration_SRB1_SRB2_1AM_DRB_Est ( RRC_TransactionIdentifier p_RRC_TI,
                                                                                           template (omit) CQI_ReportPeriodic p_CQI_ReportingPeriodic,
                                                                                           template (omit) SoundingRS_UL_ConfigDedicated p_SoundingRsUl_ConfigDedicated,
                                                                                           template (value) PhysicalConfigDedicated_AntennaInfo_Type p_AntennaInfo  // @sic R5-100786 sic@
                                                                                           ) :=
  /* Values according to 36.508 cl. 4.6.1 Table 4.6.1-8 (using condition SRB1-SRB2-DRB(n, m), where n=1 & m=0) */
    cs_RRCConnectionReconfiguration_Common ( p_RRC_TI,
                                             omit,
                                             omit,
                                             cs_SRB1_SRB2_1AM_DRB_Config_Def ( p_CQI_ReportingPeriodic, p_SoundingRsUl_ConfigDedicated, p_AntennaInfo ),
                                             omit);
  
  
  
  template (value) RadioResourceConfigDedicated cs_SRB1_SRB2_1AM_DRB_Config_Def ( template (omit) CQI_ReportPeriodic p_CQI_ReportingPeriodic,
                                                                                  template (omit) SoundingRS_UL_ConfigDedicated p_SoundingRsUl_ConfigDedicated,
                                                                                  template (value) PhysicalConfigDedicated_AntennaInfo_Type p_AntennaInfo  // @sic R5-100786 sic@
                                                                                  ) :=
  /* Values according to 36.508 cl. 4.6.3 Table 4.6.3-18 (using condition n=1 & m=0) */
    cs_508_RadioResourceConfigDedicated_Srb1_Srb2( { cs_508_DRB_ToAddMod_DEFAULT_AM(tsc_DRB1) },
                                                   cs_508_MAC_MainConfig_Explicit_RBC_DrxL,
                                                   cs_508_PhysicalConfigDedicated_Default_RBC ( p_CQI_ReportingPeriodic, p_SoundingRsUl_ConfigDedicated, p_AntennaInfo ) );
  
  
  template (value) RadioResourceConfigDedicated cs_508_RadioResourceConfigDedicated_Srb1_Srb2(template (value) DRB_ToAddModList        p_DRB_ToAddModList,
                                                                                              template (value) MAC_MainConfig_Type     p_MAC_MainConfig,
                                                                                               template (value) PhysicalConfigDedicated p_PhysicalConfigDedicated) :=
  { /* Default value according to 36.508 cl. 4.6.3 Table 4.6.3-18 */
    srb_ToAddModList := { cs_508_SRB1_ToAddMod_DEFAULT, cs_508_SRB2_ToAddMod_DEFAULT },
    drb_ToAddModList := p_DRB_ToAddModList,
    drb_ToReleaseList := omit,
    mac_MainConfig := p_MAC_MainConfig,
    sps_Config := omit,
    physicalConfigDedicated := p_PhysicalConfigDedicated
  };
  
  //----------------------------------------------------------------------
  // Functions
  //----------------------------------------------------------------------
  /*
   * @desc      Returns the corresponding integer to the UL bandwidth being used
   * @param     p_UL_BandWidth
   * @return    integer
   * @status    APPROVED
   */
  function f_ConvertUL_BandwidthToInteger(Ul_Bandwidth_Type p_UL_BandWidth) return integer
  {
    select (p_UL_BandWidth)
    {
      case (n6) {
        return 6;
      }
      case (n15) {
        return 15;
      }
      case(n25) {
        return 25;
      }
      case(n50) {
        return 50;
      }
      case(n75) {
        return 75;
      }
      case(n100) {
        return 100;
      }
      case else {
        FatalError (__FILE__, __LINE__, "invalid BandWidth");
        return 0;// dummy statement to satisfy compiler
      }
    }
  }

  //----------------------------------------------------------------------------
  /*
   * @desc      Returns the corresponding integer to the DL bandwidth being used
   * @param     p_DL_BandWidth
   * @return    integer
   * @status    APPROVED
   */
  function f_ConvertDL_BandwidthToInteger( Dl_Bandwidth_Type p_DL_BandWidth) return integer
  {
    select (p_DL_BandWidth)
    {
      case (n6)
        {
          return 6;
        }
      case (n15)
        {
          return 15;
        }
      case(n25)
        {
          return 25;
        }
      case(n50)
        {
          return 50;
        }
      case(n75)
        {
          return 75;
        }
      case(n100)
        {
          return 100;
        }
      case else{
        FatalError (__FILE__, __LINE__, "invalid BandWidth");
        return 0;// dummy statement to satisfy compiler
      }
    }
  }
  
  function f_U_Encode_RRCConnectionReconfigurationEUTRAMessage_FDD ( ) return octetstring
  {
    // @desc To be called from the EUTRA PTC to encode the Handover from Utran command.
    // @return The encoded octetstring
    var bitstring v_Bitstring := encvalue ( ( cs_RRCConnectionReconfiguration_SRB1_SRB2_1AM_DRB_Est ( tsc_RRC_TI_Def,
                                                                                                      cs_CQI_ReportingPeriodic_FDD,
                                                                                                      cs_508_SoundingRsUl_ConfigDedicated_Default_FDD,
                                                                                                      cs_PhysicalConfigDedicated_AntennaInfo_Def ) ) );
    //* Make bitstring aligned with octetstring.
    // This is because bit2oct will add additional bits at the beginning (MSB) whereas in
    // this case it should be added at the end (LSB).
    // Take care of padding the bitstring to make it a multiple of 8.
    var octetstring v_Octetstring := bit2oct ( f_OctetAlignedBitString ( v_Bitstring ) );
    
    return ( v_Octetstring );
  }

  function f_U_Encode_RRCConnectionReconfigurationEUTRAMessage_TDD ( ) return octetstring
  {
    // @desc To be called from the EUTRA PTC to encode the Handover from Utran command.
    // @return The encoded octetstring
    var bitstring v_Bitstring := encvalue ( ( cs_RRCConnectionReconfiguration_SRB1_SRB2_1AM_DRB_Est ( tsc_RRC_TI_Def,
                                                                                                      cds_CQI_ReportingPeriodic_TDD,
                                                                                                      cds_508_SoundingRsUl_ConfigDedicated_Default_TDD,
                                                                                                      cs_PhysicalConfigDedicated_AntennaInfo_Def ) ) );
    //* Make bitstring aligned with octetstring.
    // This is because bit2oct will add additional bits at the beginning (MSB) whereas in
    // this case it should be added at the end (LSB).
    // Take care of padding the bitstring to make it a multiple of 8.
    var octetstring v_Octetstring := bit2oct ( f_OctetAlignedBitString ( v_Bitstring ) );
    
    return ( v_Octetstring );
  }

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

  function f_ConvertDL_BandwidthPIXITToInteger() return integer
  {
    return (f_ConvertDL_BandwidthToInteger(px_ePrimaryBandChannelBandwidth));
  }

}
