/******************************************************************************/
// @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-11 16:42:06 +0200 (Fri, 11 Jun 2010) $
// $Rev: 3352 $
/******************************************************************************/

module UTRAN_Component {
  import from UpperTesterDefs all;    // all messages being defined to communicate with the upper tester; port definitions
  import from CommonIratDefs all;     // all messages being defined to communicate Geran/Utran components; port definitions
  import from CommonDefs all;
  import from UTRAN_TypeDefs all;
  import from UTRAN_CellInfo all;
  import from UTRAN_RRC_ASN1_Definitions language "ASN.1:1997" all;
  import from UTRAN_ASP_Definitions language "ASN.1:1997" all;
  import from UTRAN_ASN1_Templates all;

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

  type enumerated UTRAN_Default_Enum_Type {StandardDefault};            /* refers to common default alt_UTRAN_Standard_Default */

  type record UTRAN_Ctrl_Type {                 /* @status    APPROVED */
    default                     Default,        /* default behaviour being activated on UTRAN */
    boolean                     TestBody        /* true:  => fail may be assigend
                                                   false: => inconc is assigned instead of fail */
  };

  type record UTRAN_Global_Type {               /* @status    APPROVED */
    UTRAN_Ctrl_Type             Ctrl,
    UTRAN_SecurityInfo_Type     Security,
    UTRAN_CellInfoList_Type     CellArray
  };

  type component UTRAN_PTC {                    /* @status    APPROVED */
    var  UTRAN_Global_Type vc_UTRAN_Global;

    port UTRAN_AM_PORT          U_AM;
    port UTRAN_TM_PORT          U_TM;
    port UTRAN_UM_PORT          U_UM;
    port UTRAN_CPHY_PORT        U_CPHY;
    port UTRAN_CMAC_PORT        U_CMAC;
    port UTRAN_CRLC_PORT        U_CRLC;
    port UTRAN_Dc_PORT          U_Dc;
    port UT_PTC_MTC_PORT        UT;
    port IRAT_CO_ORD_PORT       EUTRA;
    port IRAT_CO_ORD_PORT       GERAN;
  };

  //============================================================================
  // standard default behaviour:

  altstep a_UTRAN_StandardDefault() runs on UTRAN_PTC {

  [] U_AM.receive {
    all timer.stop;
    f_UTRAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "unexpected receive event at U_AM port");
  }
  [] U_TM.receive {
    all timer.stop;
    f_UTRAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "unexpected receive event at U_TM port");
  }
  [] U_UM.receive {
    all timer.stop;
    f_UTRAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "unexpected receive event at U_UM port");
  }
  [] U_CPHY.receive {
    all timer.stop;
    f_UTRAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "unexpected receive event at U_CPHY port");
  }
  [] U_CMAC.receive {
    all timer.stop;
    f_UTRAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "unexpected receive event at U_CMAC port");
  }
  [] U_CRLC.receive {
    all timer.stop;
    f_UTRAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "unexpected receive event at U_CRLC port");
  }
  [] U_Dc.receive {
    all timer.stop;
    f_UTRAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "unexpected receive event at U_Dc port");
  }
  [] UT.receive {
    all timer.stop;
    f_UTRAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "unexpected receive event at UT port");
  }
  [] any timer.timeout {
    all timer.stop;
    f_UTRAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "unexpected timeout");
  }
  }

  //============================================================================
  // common functions:

  function f_UTRAN_TestBody_Set(boolean p_TestBodyFlag) runs on UTRAN_PTC {
    vc_UTRAN_Global.Ctrl.TestBody := p_TestBodyFlag;
  }
  function fl_UTRAN_TestBody_Check() runs on UTRAN_PTC return boolean {
    return vc_UTRAN_Global.Ctrl.TestBody;
  }

  function f_UTRAN_SetVerdictFailOrInconc(charstring p_FileName,
                                          LineNo_Type p_LineNo,
                                          charstring p_Msg) runs on UTRAN_PTC {
    if (fl_UTRAN_TestBody_Check()) {
      f_SetVerdict(fail, p_FileName, p_LineNo, p_Msg);
    } else {
      f_SetVerdict(inconc, p_FileName, p_LineNo, p_Msg);
    }
    self.kill;  // => testcase will terminate immediately
  }
  function f_UTRAN_PreliminaryPass(charstring p_FileName,
                                   LineNo_Type p_LineNo,
                                   charstring p_Msg) runs on UTRAN_PTC {
    if (fl_UTRAN_TestBody_Check()) {
      f_SetVerdict(pass, p_FileName, p_LineNo, p_Msg);
    }
  }

  //----------------------------------------------------------------------------
  function f_UTRAN_ActivateDefault(UTRAN_Default_Enum_Type p_Default) runs on UTRAN_PTC {

    deactivate(vc_UTRAN_Global.Ctrl.Default);

    select (p_Default) {
      case (StandardDefault) {
        vc_UTRAN_Global.Ctrl.Default := activate(a_UTRAN_StandardDefault());
      }
      case else {
        FatalError (__FILE__, __LINE__, "unknown default behaviour");
      }
    }
  }

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

  function f_UTRAN_Init(IRAT_ConfiguredPTCs_Type p_ConfiguredPTCs) runs on UTRAN_PTC {
//    var IRAT_CoOrd_SysInfo_Type v_EUTRA_SysInfo;
    var integer v_I;

    vc_UTRAN_Global.Ctrl.Default := null;
    vc_UTRAN_Global.Ctrl.TestBody := false;
    vc_UTRAN_Global.CellArray := f_UTRAN_CellArray_Init();

    // Now update sys info with inter RAT parameters for all cells
    select (p_ConfiguredPTCs)
    {
      case (EUTRA_UTRAN) {
        vc_UTRAN_Global.CellArray := f_UTRAN_IR_SIB19_Init(vc_UTRAN_Global.CellArray, f_IRAT_InitialCoOrd(EUTRA, f_UTRAN_IR_SysInfoInit (vc_UTRAN_Global.CellArray)));
      }
      case (EUTRA_UTRAN_GERAN) {
        vc_UTRAN_Global.CellArray := f_UTRAN_IR_SIB11And19_Init(vc_UTRAN_Global.CellArray, f_IRAT_InitialCoOrd_2Ports(EUTRA, GERAN, f_UTRAN_IR_SysInfoInit (vc_UTRAN_Global.CellArray)));
        for (v_I := 0; v_I < tsc_UTRAN_NumberOfCells; v_I := v_I + 1)
        {
            f_UTRAN_SysInfo_SetMIB ( vc_UTRAN_Global.CellArray[v_I].cellId, cs_MIB_UTRAN_GERAN_Def (vc_UTRAN_Global.CellArray[v_I].plmnId));
            f_UTRAN_SysInfo_SetSB1 ( vc_UTRAN_Global.CellArray[v_I].cellId, cs_SB1_UTRAN_GERAN_Def )
        }
      }
    }
    vc_UTRAN_Global.Security := f_UTRAN_SecurityInfo_Init();

    f_UTRAN_ActivateDefault(StandardDefault);
  }
 //----------------------------------------------------------------------------
group Get_SetFunctions {
  function fl_UTRAN_CellInfo_Get(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return UTRAN_CellInfo_Type {
    var integer v_Index := f_UTRAN_CellInfo_GetIndex(p_CellId);
    return vc_UTRAN_Global.CellArray[v_Index];
  }
  function f_UTRAN_CellInfo_Set(UTRAN_CellId_Type p_CellId,
                                UTRAN_CellInfo_Type p_CellInfo) runs on UTRAN_PTC {
    var integer v_Index := f_UTRAN_CellInfo_GetIndex(p_CellId);
    vc_UTRAN_Global.CellArray[v_Index] := p_CellInfo;
  }
  function f_UTRAN_CellInfo_GetNMO(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return octetstring {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.nmo;
  }
  function f_UTRAN_CellInfo_SetNMO(UTRAN_CellId_Type p_CellId, octetstring p_NMO) runs on UTRAN_PTC {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    v_CellInfo.nmo := p_NMO;
    f_UTRAN_CellInfo_Set(p_CellId, v_CellInfo);
  }
  function f_UTRAN_CellInfo_GetLAC(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return octetstring {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.lac;
  }
  function f_UTRAN_CellInfo_GetRAC(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return octetstring {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.rac;
  }
  function f_UTRAN_CellInfo_GetPLMNIdentity(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return PLMN_Identity {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.plmnId;
  }
  function f_UTRAN_CellInfo_SetPLMNIdentity(UTRAN_CellId_Type p_CellId, PLMN_Identity p_PLMN) runs on UTRAN_PTC {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    v_CellInfo.plmnId := p_PLMN;
    f_UTRAN_CellInfo_Set(p_CellId, v_CellInfo);
  }
    function f_UTRAN_CellInfo_GetNodeB_Id(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return integer {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.nodeB_Id;
  }
    function f_UTRAN_CellInfo_GetC_RNTI(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return C_RNTI {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.cRNTI;
  }
    function f_UTRAN_CellInfo_GetU_RNTI(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return U_RNTI {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.uRNTI;
  }
    function f_UTRAN_CellInfo_GetPICH_PowerOffset(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return PICH_PowerOffset {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.powerPICH;
  }
    function f_UTRAN_CellInfo_GetpCCPCH_Power_FDD(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return DL_TxPower {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.cellInfo_Specific_FDD.powerpCCPCH;
  }
    function f_UTRAN_CellInfo_GetpCCPCH_Power_TDD(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return DL_TxPower {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.cellInfo_Specific_TDD.powerpCCPCH;
  }
  function f_UTRAN_CellInfo_GetsCCPCH1_Power(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return DL_TxPower {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.powersCCPCH1;
  }
    function f_UTRAN_CellInfo_GetCellTxPower(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return CellTxPowerLevel {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.cellTxPowerLevel;
  }
    function f_UTRAN_CellInfo_GetSFNOffset(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return integer {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.sfnOffset;
  }
    function f_UTRAN_CellInfo_Attenuation(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return integer {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.attenuationLevel;
  }
    function f_UTRAN_CellInfo_PuncturingLimit(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return PuncturingLimit {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.puncLimit;
  }
    function f_UTRAN_CellInfo_SF_PRACH(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return SF_PRACH {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.sf_PRACH;
  }
    function f_UTRAN_CellInfo_GetFrequencyInfo(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return FrequencyInfo {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.frequencyInfo;
  }
    function f_UTRAN_CellInfo_GetFDD_TDD(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return UTRAN_FDD_TDD {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.fdd_tdd;
  }
    function f_UTRAN_CellInfo_GetULScrmCode_FDD ( UTRAN_CellId_Type p_CellId ) runs on UTRAN_PTC return UL_ScramblingCode {
      var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get ( p_CellId );
      return v_CellInfo.cellInfo_Specific_FDD.uL_ScramblingCode;
    }
    function f_UTRAN_CellInfo_GetFDDSpecific(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return UTRAN_CellInfo_Type_FDD {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.cellInfo_Specific_FDD;
  }
    function f_UTRAN_CellInfo_GetTDDSpecific(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return UTRAN_CellInfo_Type_TDD {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.cellInfo_Specific_TDD;
  }
    function f_UTRAN_CellInfo_GetRLCParams(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return RlcCtrl_Type {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.rlcParams;
  }
    function f_UTRAN_CellInfo_GetDRX_CycleLength(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return DRX_CycleLengthStructure {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.dRX_CycleLength;
  }
  function f_UTRAN_CellInfo_GetAttFlag ( UTRAN_CellId_Type p_CellId ) runs on UTRAN_PTC return integer {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.attFlag;
  }

  function f_UTRAN_CellInfo_GetCellParametersID_TDD ( UTRAN_CellId_Type p_CellId ) runs on UTRAN_PTC return CellParametersID {

    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get ( p_CellId );
    return v_CellInfo.cellInfo_Specific_TDD.cellParametersID;
  }

  function f_UTRAN_CellInfo_GetPriScrmCode_FDD ( UTRAN_CellId_Type p_CellId ) runs on UTRAN_PTC return PrimaryScramblingCode {

    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get ( p_CellId );
    return v_CellInfo.cellInfo_Specific_FDD.priScrmCode;
  }
  function f_UTRAN_CellInfo_GetConfigType(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return RB_ConfigType {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.cellConfig;
  }
  
  /*
   * @desc      Function that returns the UARFCN of the specified UTRAN cell
   * @param     p_CellId
   * @status
   */
  function f_UTRAN_CellInfo_GetUARFCN ( UTRAN_CellId_Type p_CellId ) runs on UTRAN_PTC return UARFCN {
    var UARFCN v_UARFCN;
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get( p_CellId );
    var UTRAN_FDD_TDD v_UTRAN_FDD_TDD := f_UTRAN_CellInfo_GetFDD_TDD( p_CellId );
    
    if ( v_UTRAN_FDD_TDD == UTRAN_FDD )
    { v_UARFCN := v_CellInfo.frequencyInfo.modeSpecificInfo.fdd.uarfcn_DL; }
    else
    { v_UARFCN := v_CellInfo.frequencyInfo.modeSpecificInfo.tdd.uarfcn_Nt; }
    return v_UARFCN;
  }
  function f_UTRAN_CellInfo_SetConfigType(UTRAN_CellId_Type p_CellId, RB_ConfigType p_CellConfig) runs on UTRAN_PTC {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    v_CellInfo.cellConfig := p_CellConfig;
    f_UTRAN_CellInfo_Set(p_CellId, v_CellInfo);
  }
  //----------------------------------------------------------------------------
  // Access to Security Parameters:

  function f_UTRAN_Security_Get() runs on UTRAN_PTC return UTRAN_SecurityInfo_Type {
    return vc_UTRAN_Global.Security;
  }
  function f_UTRAN_Security_Set(UTRAN_SecurityInfo_Type p_Auth_Params) runs on UTRAN_PTC {
    vc_UTRAN_Global.Security := p_Auth_Params;
  }
  //----------------------------------------------------------------------------

  function f_UTRAN_SysInfo_Get(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return UTRAN_CellSysInfo_Type {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.sysInfo;
  }
  function f_UTRAN_SysInfo_Set(UTRAN_CellId_Type p_CellId, UTRAN_CellSysInfo_Type p_SysInfo) runs on UTRAN_PTC {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    v_CellInfo.sysInfo := p_SysInfo;
    f_UTRAN_CellInfo_Set(p_CellId, v_CellInfo);
  }
  function f_UTRAN_SysInfo_GetSIB19(UTRAN_CellId_Type p_CellId) runs on UTRAN_PTC return SysInfoType19 {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    return v_CellInfo.sysInfo.SIB19;
  }
  function f_UTRAN_SysInfo_SetSIB19(UTRAN_CellId_Type p_CellId, template (value) SysInfoType19 p_SIB19) runs on UTRAN_PTC {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    v_CellInfo.sysInfo.SIB19 := valueof(p_SIB19);
    f_UTRAN_CellInfo_Set(p_CellId, v_CellInfo);
  }
  function f_UTRAN_SysInfo_SetMIB(UTRAN_CellId_Type p_CellId, template (value) MasterInformationBlock p_MIB) runs on UTRAN_PTC {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    v_CellInfo.sysInfo.MIB := valueof(p_MIB);
    f_UTRAN_CellInfo_Set(p_CellId, v_CellInfo);
  }

  function f_UTRAN_SysInfo_SetSB1(UTRAN_CellId_Type p_CellId, template (value) SysInfoTypeSB1 p_SB1) runs on UTRAN_PTC {
    var UTRAN_CellInfo_Type v_CellInfo := fl_UTRAN_CellInfo_Get(p_CellId);
    v_CellInfo.sysInfo.SB1 := valueof(p_SB1);
    f_UTRAN_CellInfo_Set(p_CellId, v_CellInfo);
  }

  } // end of group Get_SetFunctions
}
