/******************************************************************************/
// @copyright   Copyright Notification
//   No part may be reproduced except as authorized by written permission.
//   The copyright and the foregoing restriction extend to reproduction in all media.
//   Trademark 2010, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC).
//   All rights reserved.
// @version: IWD_10wk37
// $Date: 2010-09-12 18:22:36 +0200 (Sun, 12 Sep 2010) $
// $Rev: 3849 $
/******************************************************************************/

module CDMA2000_CellInfo {
  import from CommonDefs all;
  import from CommonIratDefs all;
  import from CDMA2000_CommonDefs all;
  import from CDMA2000_ASP_TypeDefs all;
  import from CDMA2000_Constants all;
  import from CDMA2000_Parameters all;
  
  //----------------------------------------------------------------------------

  type record CDMA2000_CommonCellInfo_Type {            /* @status    APPROVED */
    CDMA2000_CellParameters_Type     CommonCellParams,
    SearchWindowSize_Type            SearchWindowSize
  };

  type record CDMA2000_ReferenceCellPower_Type {        /* @status    APPROVED */
    CDMA2000_AbsoluteCellPower_Type  CellPower,
    CDMA2000_Attenuation_Type        CellAttenuation
  };

  type record CDMA2000_CellInfo_Type {                  /* @status    APPROVED */
    CDMA2000_CommonCellInfo_Type     CommonCellInfo,
    CDMA2000_ReferenceCellPower_Type ReferenceCellPower,
    ModeSpecificCellParams_Type      ModeSpecificParams
  };

  type record length (tsc_CDMA2000_MaxNumberOfCells) of CDMA2000_CellInfo_Type CDMA2000_CellArray_Type;    /* @status    APPROVED */
  
  template (value) CDMA2000_Attenuation_Type  cs_CDMA2000_Attenuation_Def ( Attenuation_Type p_Attenuation := tsc_AttenuationDef) :=
  {
    Value := p_Attenuation
  };
  
  template (value) CDMA2000_ReferenceCellPower_Type cs_CDMA2000_ReferenceCellPower_Def( template (value) CDMA2000_AbsoluteCellPower_Type p_CellPower,
                                                                                        template (value) CDMA2000_Attenuation_Type       p_Attenuation) :=
  {
    CellPower := p_CellPower,
    CellAttenuation := p_Attenuation
  };
  
  template (value) CarrierFreqCDMA2000_Type  cs_CarrierFreqCDMA2000_Def(BandclassCDMA2000_Type p_Bandclass := px_HRPD_BandClass,
                                                                        ARFCN_ValueCDMA2000_Type p_ChannelNum := px_HRPD_ChannelNum_F14 ):=
  {
    BandClass := p_Bandclass,
    ARFCN := p_ChannelNum
  };
  
  template (value) CDMA2000_AbsoluteCellPower_Type cs_CDMA2000_AbsoluteCellPowerDef (PowerIoc_Type p_PowerIoc := tsc_PowerIocDef,
                                                                                     PowerIor_Type p_PowerIor := tsc_PowerIorDef,
                                                                                     PilotOffset_Type p_PilotOffset := tsc_PilotOffsetHRPDDef) := //@sic R5-104718 sic@
  {
    PowerIoc := p_PowerIoc,
    PowerIor := p_PowerIor,
    PilotOffset := p_PilotOffset
  };
  
  template (value) CDMA2000_InitialCellPower_Type cs_CDMA2000_InitialCellPowerDef (PowerIoc_Type    p_PowerIoc := tsc_PowerIocDef,
                                                                                   PowerIor_Type    p_PowerIor := tsc_PowerIorDef,
                                                                                   PilotOffset_Type p_PilotOffset := tsc_PilotOffsetHRPDDef ) := { //@sic R5-104718 sic@
    MaxReferencePower := cs_CDMA2000_AbsoluteCellPowerDef (p_PowerIoc, p_PowerIor, p_PilotOffset),
    Attenuation := tsc_CDMA2000_Attenuation_Off
  };
  
  template (value) CDMA2000_CellParameters_Type cs_CDMA2000_CellParameters_HRPD_Def (PhysCellIdCDMA2000_Type  p_PNOffset := tsc_PNOffsetDef,
                                                                                     SectorID_HRPD_Type       p_SectorID := px_HRPD_SectorID_Cell15,
                                                                                     ARFCN_ValueCDMA2000_Type p_ChannelNum := px_HRPD_ChannelNum_F14,
                                                                                     BandclassCDMA2000_Type   p_Bandclass := px_HRPD_BandClass) :=
  {
    Type         := typeHRPD,
    CarrierFreq  := cs_CarrierFreqCDMA2000_Def(p_Bandclass, p_ChannelNum), // Contains bandclass and arfcn i.e. 11 bit channel number
    PhysCellId   := p_PNOffset, // PN offset of pilot 0..511
    CellGlobalId := {
      HRPD := p_SectorID        // Contains the 128 bit cell ID for HRPD and 47 bit cell ID for 1XRTT
    }
  };
  
  template (value) CDMA2000_CommonCellInfo_Type cs_CDMA2000_CommonCellInfo_Def (template (value) CDMA2000_CellParameters_Type p_CDMA2000_CellParameters,
                                                                                SearchWindowSize_Type p_SearchWindowSize := tsc_SearchWindowDef) :=
  {
    CommonCellParams := p_CDMA2000_CellParameters,
    SearchWindowSize := p_SearchWindowSize
  };
  
  template (value) HRPD_CellParameters_Type cs_HRPD_CellParametersDef (SystemType_Type  p_SystemType := tsc_SystemTypeDef,
                                                                       B8_Type          p_SubNetMask  := tsc_SubNetMaskDef,
                                                                       ColorCode_Type   p_ColorCode := px_ColorCode,
                                                                       MCC_Type              p_CountryCode := tsc_CountryCodeDef,
                                                                       OpenLoopAdjust_Type   p_OpenLoopAdjust := px_OpenLoopAdjust,
                                                                       ReverseRateLimit_Type      p_ReverseRateLimit := tsc_ReverseRateLimitDef,
                                                                       ReverseLinkMACIndex_Type   p_MACIndex := tsc_MACIndexDef,
                                                                       PacketApplication_Type     p_PacketApp := tsc_PacketAppDef,
                                                                       ControlChannelRate_Type    p_ControlChannelRate := tsc_ControlChannelRateDef) :=
  {
    SystemType       := p_SystemType,
    SubNetMask       := p_SubNetMask,
    ColorCode        := p_ColorCode,
    CountryCode      := p_CountryCode, // 7.11.6.2.2 of C.S0024
    OpenLoopAdjust   := p_OpenLoopAdjust,
    ReverseRateLimit := p_ReverseRateLimit,//
    MACIndex         := p_MACIndex ,
    PacketApp        := p_PacketApp,
    ControlChannelRate  := p_ControlChannelRate
  };
  
  template (value) ModeSpecificCellParams_Type cs_ModeSpecificCellParams_HRPD_Def (template (value) HRPD_CellParameters_Type p_HRPD_CellParameters) :=
  {
    HRPD := p_HRPD_CellParameters
  };
  
  template (value) CDMA2000_AbsoluteCellPower_Type cs_CDMA2000_AbsoluteCellPower_Def (PowerIor_Type    p_PowerIor := tsc_PowerIorDef,
                                                                                      PowerIoc_Type   p_PowerIoc := tsc_PowerIocDef,
                                                                                      PilotOffset_Type  p_PilotOffset := tsc_PilotOffsetHRPDDef) := //@sic R5-104718 sic@
  {
    PowerIoc    := p_PowerIoc,
    PowerIor    := p_PowerIor,
    PilotOffset := p_PilotOffset
  };
  
  template (value) CDMA2000_CellInfo_Type cs_CDMA2000_CellInfo_HRPD_Def (template (value) CDMA2000_CellParameters_Type p_CDMA2000_CellParameters,
                                                                         template (value) ModeSpecificCellParams_Type p_ModeSpecificCellParams,
                                                                         SearchWindowSize_Type p_SearchWindowSize := tsc_SearchWindowDef,
                                                                         PowerIor_Type    p_PowerIor := tsc_PowerIorDef,
                                                                         PowerIoc_Type    p_PowerIoc := tsc_PowerIocDef,
                                                                         PilotOffset_Type p_PilotOffset:= tsc_PilotOffsetHRPDDef) := //@sic R5-104718 sic@
  {
    CommonCellInfo     := cs_CDMA2000_CommonCellInfo_Def (p_CDMA2000_CellParameters,p_SearchWindowSize),
    ReferenceCellPower := cs_CDMA2000_ReferenceCellPower_Def(cs_CDMA2000_AbsoluteCellPower_Def (p_PowerIor, p_PowerIoc, p_PilotOffset),
                                                             cs_CDMA2000_Attenuation_Def),
    ModeSpecificParams := p_ModeSpecificCellParams
  };
  
  //----------------------------------------------------------------------------
  // Access to Cell Array
  
  function f_CDMA2000_CellInfo_GetIndex (CDMA2000_CellId_Type p_CellId) return integer
  {
    select (p_CellId)
    {
      case (cdma2000_Cell15) {
        return 0;
      } case (cdma2000_Cell16) {
        return 1;
      } case (cdma2000_Cell17) {
        return 2;
      } case (cdma2000_Cell18) {
        return 3;
      } case (cdma2000_Cell18) {
        return 3;
      } case (cdma2000_Cell19) {
        return 4;
      } case (cdma2000_Cell20) {
        return 5;
      } case (cdma2000_Cell21) {
        return 6;
      } case (cdma2000_Cell22) {
        return 7;
      } case else {
        FatalError (__FILE__, __LINE__, "Invalid CellId");
        return 0;
      }
    }
  }
  
  /* function f_CDMA2000_CellInfo_GetCellIdentity(CDMA2000_CellId_Type p_CellId) return O2_Type
     {
    select (p_CellId)
    {
      case (cdma2000_Cell15) {
        return '0001'O;
      } case (cdma2000_Cell16) {
      return '0002'O;
      } case (cdma2000_Cell17) {
        return '0003'O;
      } case (cdma2000_Cell18) {
        return '0004'O;
      } case else {
        FatalError (__FILE__, __LINE__, "Invalid CellId");
        return '0000'O;
      }
    }
  } */

  function f_CDMA2000_CellInfo_Init (CDMA2000_CellId_Type p_CellId) return CDMA2000_CellInfo_Type
  {
    var template (value) CDMA2000_CellInfo_Type v_CellInfo;
    var PhysCellIdCDMA2000_Type v_PNOffset := tsc_PNOffsetDef;
    var SectorID_HRPD_Type v_SectorID := px_HRPD_SectorID_Cell15;
    var ARFCN_ValueCDMA2000_Type v_ChannelNum := px_HRPD_ChannelNum_F14;
    var template (value)ModeSpecificCellParams_Type v_ModeSpecificCellParams;
    
    select (p_CellId) {
      case(cdma2000_Cell15,
           cdma2000_Cell16,
           cdma2000_Cell17,
           cdma2000_Cell18) // HRPD Cells
        {
          v_ModeSpecificCellParams := cs_ModeSpecificCellParams_HRPD_Def(cs_HRPD_CellParametersDef);
        }
      case(cdma2000_Cell19,
           cdma2000_Cell20,
           cdma2000_Cell21,
           cdma2000_Cell22) // RTT1X Cells
        {
          //TBD
        }
      case else {
        FatalError (__FILE__, __LINE__, "invalid C2k cell Identity");
      }
    }
    
    select  (p_CellId ) {
      case ( cdma2000_Cell15 )
        {
          // Default values
        }
      case ( cdma2000_Cell16 )
        {
          v_PNOffset := tsc_PNOffset2;
          v_SectorID := px_HRPD_SectorID_Cell16;
          v_ChannelNum := px_HRPD_ChannelNum_F14;
        }
      case ( cdma2000_Cell17 )
        {
          v_PNOffset := tsc_PNOffset3;
          v_SectorID := px_HRPD_SectorID_Cell17;
          v_ChannelNum := px_HRPD_ChannelNum_F15;
        }
      case ( cdma2000_Cell18 )
        {
          v_PNOffset := tsc_PNOffset4;
          v_SectorID := px_HRPD_SectorID_Cell18;
          v_ChannelNum := px_HRPD_ChannelNum_F16;
        }
      case (cdma2000_Cell19,
            cdma2000_Cell20,
            cdma2000_Cell21,
            cdma2000_Cell22)
        {
          //TBD
        }
      case else {
        FatalError (__FILE__, __LINE__, "invalid C2k cell Identity");
      }
    }
    
    v_CellInfo := cs_CDMA2000_CellInfo_HRPD_Def (cs_CDMA2000_CellParameters_HRPD_Def(v_PNOffset,
                                                                                     v_SectorID,
                                                                                     v_ChannelNum),
                                                 v_ModeSpecificCellParams);
    
    return valueof(v_CellInfo);
  }
  
  
  function f_CDMA2000_CellArray_Init () return CDMA2000_CellArray_Type
  {
    var template (value) CDMA2000_CellArray_Type v_CDMA2000_Cells;
    //var O2_Type v_CellId;
    var integer v_Index;
    
    v_Index := f_CDMA2000_CellInfo_GetIndex (cdma2000_Cell15);
    v_CDMA2000_Cells[v_Index] := f_CDMA2000_CellInfo_Init(cdma2000_Cell15);
    
    v_Index := f_CDMA2000_CellInfo_GetIndex (cdma2000_Cell16);
    v_CDMA2000_Cells[v_Index] := f_CDMA2000_CellInfo_Init (cdma2000_Cell16);
    
    v_Index := f_CDMA2000_CellInfo_GetIndex (cdma2000_Cell17);
    v_CDMA2000_Cells[v_Index] := f_CDMA2000_CellInfo_Init(cdma2000_Cell17);
    
    v_Index := f_CDMA2000_CellInfo_GetIndex (cdma2000_Cell18);
    v_CDMA2000_Cells[v_Index] := f_CDMA2000_CellInfo_Init (cdma2000_Cell18);
    
    v_Index := f_CDMA2000_CellInfo_GetIndex (cdma2000_Cell19);
    v_CDMA2000_Cells[v_Index] := f_CDMA2000_CellInfo_Init(cdma2000_Cell19);
    
    v_Index := f_CDMA2000_CellInfo_GetIndex (cdma2000_Cell20);
    v_CDMA2000_Cells[v_Index] := f_CDMA2000_CellInfo_Init (cdma2000_Cell20);
    
    v_Index := f_CDMA2000_CellInfo_GetIndex  (cdma2000_Cell21);
    v_CDMA2000_Cells[v_Index] := f_CDMA2000_CellInfo_Init(cdma2000_Cell21);
    
    v_Index := f_CDMA2000_CellInfo_GetIndex (cdma2000_Cell22);
    v_CDMA2000_Cells[v_Index] := f_CDMA2000_CellInfo_Init (cdma2000_Cell22);
    
    return valueof(v_CDMA2000_Cells);
  }

  //----------------------------------------------------------------------------
  /*function fl_ConvertBandClassToInteger (BandclassCDMA2000_Type p_Enum) return integer
{
  var integer v_Value := -1;
  select (p_Enum) {
    case (bc0) {
      v_Value := 0;
    } case (bc1) {
      v_Value := 1;
    } case (bc2) {
      v_Value := 2;
    } case (bc3) {
      v_Value := 3;
    } case (bc4) {
      v_Value := 4;
    } case (bc5) {
      v_Value := 5;
    } case (bc6) {
      v_Value := 6;
    } case (bc7) {
      v_Value := 7;
    } case (bc8) {
      v_Value := 8;
    } case (bc9) {
      v_Value := 9;
    } case (bc10) {
      v_Value := 10;
    } case (bc11) {
      v_Value := 11;
    } case (bc12) {
      v_Value := 12;
    } case (bc13) {
      v_Value := 13;
    } case (bc14) {
      v_Value := 14;
    } case (bc15) {
      v_Value := 15;
    } case (bc16) {
      v_Value := 16;
    } case (bc17){
      v_Value := 17;
    }
   }
   return v_Value;
   } */

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

  function f_CDMA2000_IR_InitSingleSysInfo (CDMA2000_CommonCellInfo_Type p_CellInfo) return template (value) CoOrd_CDMA2000SysInfo_Type
  {
    var boolean v_HPRD_Cell;
    
    if (p_CellInfo.CommonCellParams.Type == typeHRPD) {
      v_HPRD_Cell := true;
    } else {
      v_HPRD_Cell := false;
    }
    
    return cs_CoOrdCDMA2000_SysInfoSingleCell (v_HPRD_Cell,
                                               p_CellInfo.CommonCellParams.CarrierFreq.ARFCN,
                                               p_CellInfo.CommonCellParams.CarrierFreq.BandClass,
                                               p_CellInfo.CommonCellParams.PhysCellId,
                                               p_CellInfo.SearchWindowSize,
                                               p_CellInfo.CommonCellParams.CellGlobalId.HRPD,
                                               p_CellInfo.CommonCellParams.CellGlobalId.RTT1X.BaseId,
                                               p_CellInfo.CommonCellParams.CellGlobalId.RTT1X.NID,
                                               p_CellInfo.CommonCellParams.CellGlobalId.RTT1X.SID);
  }
  
  //----------------------------------------------------------------------------
  
  function f_CDMA2000_IR_SysInfoInit (CDMA2000_CellArray_Type p_CellInfo)
    return template (value) IRAT_CoOrd_SysInfo_Type
  {
    
    var integer v_Index_Cell15 := f_CDMA2000_CellInfo_GetIndex(cdma2000_Cell15);
    var integer v_Index_Cell16 := f_CDMA2000_CellInfo_GetIndex(cdma2000_Cell16);
    var integer v_Index_Cell17 := f_CDMA2000_CellInfo_GetIndex(cdma2000_Cell17);
    var integer v_Index_Cell18 := f_CDMA2000_CellInfo_GetIndex(cdma2000_Cell18);
    
    return cs_CoOrdCDMA2000_SysInfo(f_CDMA2000_IR_InitSingleSysInfo (p_CellInfo[v_Index_Cell15].CommonCellInfo),
                                    f_CDMA2000_IR_InitSingleSysInfo (p_CellInfo[v_Index_Cell16].CommonCellInfo),
                                    f_CDMA2000_IR_InitSingleSysInfo (p_CellInfo[v_Index_Cell17].CommonCellInfo),
                                    f_CDMA2000_IR_InitSingleSysInfo (p_CellInfo[v_Index_Cell18].CommonCellInfo));
  }
  
  //----------------------------------------------------------------------------
  
} // End of module
