/******************************************************************************/
// @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-01-28 18:31:55 +0100 (Thu, 28 Jan 2010) $
// $Rev: 2408 $
/******************************************************************************/

module GERAN_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 GERAN_TypeDefs all;
  import from NAS_24008TypeDefs all;
  import from NAS_CommonTypeDefs all;
  import from GERAN_CellInfo all;

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

  type enumerated GERAN_Default_Enum_Type {StandardDefault};            /* refers to common default alt_GERAN_Standard_Default */

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

  type record GERAN_Global_Type {               /* @status    APPROVED */
    GERAN_Ctrl_Type             Ctrl,
    GERAN_SecurityInfo_Type     Security,
    GERAN_CellArray_Type        CellArray
  };

  type component GERAN_PTC {                    /* @status    APPROVED */
    var  GERAN_Global_Type vc_GERAN_Global;

    port UT_PTC_MTC_PORT        UT;
    port IRAT_CO_ORD_PORT       EUTRA;
    port IRAT_CO_ORD_PORT       UTRAN;
    port GERAN_CL1_PORT         G_CL1;
    port GERAN_CLLC_PORT        G_CLLC;
    port GERAN_CRLC_PORT        G_CRLC;
    port GERAN_L2_PORT          G_L2;
    port GERAN_LLC_PORT         G_LLC;
    port GERAN_RLC_PORT         G_RLC;
  };

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

  altstep a_GERAN_StandardDefault() runs on GERAN_PTC {

    [] G_CL1.receive {
      all timer.stop;
      f_GERAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "unexpected receive event at the G_CL1 port");
    }
    [] G_CLLC.receive {
      all timer.stop;
      f_GERAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "unexpected receive event at the G_CLLC port");
    }
    [] G_CRLC.receive {
      all timer.stop;
      f_GERAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "unexpected receive event at the G_CRLC port");
    }
    [] G_L2.receive {
      all timer.stop;
      f_GERAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "unexpected receive event at the G_L2 port");
    }
    [] G_LLC.receive {
      all timer.stop;
      f_GERAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "unexpected receive event at the G_LLC port");
    }
    [] G_RLC.receive {
      all timer.stop;
      f_GERAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "unexpected receive event at the G_RLC port");
    }
    [] UT.receive {
      all timer.stop;
      f_GERAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "unexpected receive event at the UT port");
    }
    [] any timer.timeout {
      all timer.stop;
      f_GERAN_SetVerdictFailOrInconc(__FILE__, __LINE__, "unexpected timeout");
    }
  }

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

  function f_GERAN_TestBody_Set(boolean p_TestBodyFlag) runs on GERAN_PTC {
    vc_GERAN_Global.Ctrl.TestBody := p_TestBodyFlag;
  }
  function fl_GERAN_TestBody_Check() runs on GERAN_PTC return boolean {
    return vc_GERAN_Global.Ctrl.TestBody;
  }

  function f_GERAN_SetVerdictFailOrInconc(charstring p_FileName,
                                          LineNo_Type p_LineNo,
                                          charstring p_Msg) runs on GERAN_PTC {
    if (fl_GERAN_TestBody_Check()) {
      f_SetVerdict(fail, p_FileName, p_LineNo, p_Msg);
    } else {
      f_SetVerdict(inconc, p_FileName, p_LineNo, p_Msg);
    }
    self.kill; // => test case will terminate immediately
  }
  function f_GERAN_PreliminaryPass(charstring p_FileName,
                                   LineNo_Type p_LineNo,
                                   charstring p_Msg) runs on GERAN_PTC {
    if (fl_GERAN_TestBody_Check()) {
      f_SetVerdict(pass,p_FileName, p_LineNo, p_Msg);
    }
  }

  //----------------------------------------------------------------------------
  function f_GERAN_ActivateDefault(GERAN_Default_Enum_Type p_Default) runs on GERAN_PTC {

    deactivate(vc_GERAN_Global.Ctrl.Default);

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

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

  function f_GERAN_Init(IRAT_ConfiguredPTCs_Type p_ConfiguredPTCs) runs on GERAN_PTC {

    var IRAT_CoOrd_SysInfo_List_Type v_IR_SysInfoList;
    vc_GERAN_Global.Ctrl.Default := null;
    vc_GERAN_Global.Ctrl.TestBody := false;
    vc_GERAN_Global.Security := f_GERAN_Security_Init();
    vc_GERAN_Global.CellArray := f_GERAN_CellArray_Init();

    // Now initialize sys info, together with EUTRA inter RAT parameters, for all cells
    select (p_ConfiguredPTCs)
    {
     case (EUTRA_UTRAN_GERAN) {
      // update sys info with UTRAN inter RAT parameters for all cells
      vc_GERAN_Global.CellArray := f_GERAN_SystemInformation_Init(vc_GERAN_Global.CellArray, f_IRAT_InitialCoOrd_2Ports(EUTRA, UTRAN, f_GERAN_IR_SysInfoInit (vc_GERAN_Global.CellArray)));
     }
     case (EUTRA_GERAN) {
    v_IR_SysInfoList[0] := f_IRAT_InitialCoOrd(EUTRA, f_GERAN_IR_SysInfoInit (vc_GERAN_Global.CellArray));
    vc_GERAN_Global.CellArray := f_GERAN_SystemInformation_Init(vc_GERAN_Global.CellArray, v_IR_SysInfoList);
     }
     case else {
        FatalError (__FILE__, __LINE__, "wrong PTC configuration specified in test case");
    }}


    f_GERAN_ActivateDefault(StandardDefault);
  }

  //--------------------------------------------------------
  function f_GERAN_CellInfo_Get(GERAN_CellId_Type p_CellId) runs on GERAN_PTC return GERAN_CellInfo_Type {
    var integer v_Index := f_GERAN_CellInfo_GetIndex(p_CellId);
    return vc_GERAN_Global.CellArray[v_Index];
  }
  function f_GERAN_CellInfo_Set(GERAN_CellId_Type p_CellId, GERAN_CellInfo_Type p_CellCfg) runs on GERAN_PTC {
    var integer v_Index := f_GERAN_CellInfo_GetIndex(p_CellId);
    vc_GERAN_Global.CellArray[v_Index] := p_CellCfg;
 }

  function f_GERAN_SysInfo_Get(GERAN_CellId_Type p_CellId) runs on GERAN_PTC return GERAN_SystemInformation_Type {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    return v_CellInfo.sysInfo;
  }

  function f_GERAN_SysInfo_Set(GERAN_CellId_Type p_CellId, GERAN_SystemInformation_Type p_SysInfo) runs on GERAN_PTC {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    v_CellInfo.sysInfo := p_SysInfo;
    f_GERAN_CellInfo_Set (p_CellId, v_CellInfo);
  }

  function f_GERAN_SysInfo_GetSI2q_1(GERAN_CellId_Type p_CellId) runs on GERAN_PTC return SYSTEMINFORMATIONTYPE2quater {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    return v_CellInfo.sysInfo.si2quater_1;
  }

  function f_GERAN_SysInfo_GetSI2q_2(GERAN_CellId_Type p_CellId) runs on GERAN_PTC return SYSTEMINFORMATIONTYPE2quater {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    return v_CellInfo.sysInfo.si2quater_2;
  }

  function f_GERAN_SysInfo_SetSI2q_1(GERAN_CellId_Type p_CellId, SYSTEMINFORMATIONTYPE2quater p_SI2q) runs on GERAN_PTC {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    v_CellInfo.sysInfo.si2quater_1 := p_SI2q;
    f_GERAN_CellInfo_Set (p_CellId, v_CellInfo);
  }

  function f_GERAN_SysInfo_SetSI2q_2(GERAN_CellId_Type p_CellId, SYSTEMINFORMATIONTYPE2quater p_SI2q) runs on GERAN_PTC {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    v_CellInfo.sysInfo.si2quater_2 := p_SI2q;
    f_GERAN_CellInfo_Set (p_CellId, v_CellInfo);
  }

  function f_GERAN_SecurityInfo_Get() runs on GERAN_PTC return GERAN_SecurityInfo_Type {
    return vc_GERAN_Global.Security;
  }
  function f_GERAN_SecurityInfo_Set(GERAN_SecurityInfo_Type p_Info) runs on GERAN_PTC {
    vc_GERAN_Global.Security := p_Info;
  }

  function f_GERAN_BCCHFreq_Get (GERAN_CellId_Type p_CellId) runs on GERAN_PTC return B10_Type {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    return v_CellInfo.freq.bCCH_Freq;
  }
  function f_GERAN_GPRSFreq_Get (GERAN_CellId_Type p_CellId) runs on GERAN_PTC return B10_Type {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    return v_CellInfo.freq.gPRSCh_Freq;
  }
  function f_GERAN_BandInd_Get (GERAN_CellId_Type p_CellId) runs on GERAN_PTC return B1_Type {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    return v_CellInfo.freq.bandIndicator;
  }
  function f_GERAN_DLPwrLevel_Get (GERAN_CellId_Type p_CellId) runs on GERAN_PTC return integer {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    return v_CellInfo.info.downlinkPowerLevel;
  }
  function f_GERAN_NCC_Get (GERAN_CellId_Type p_CellId) runs on GERAN_PTC return B3_Type {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    return v_CellInfo.info.ncc;
  }
  function f_GERAN_BCC_Get (GERAN_CellId_Type p_CellId) runs on GERAN_PTC return B3_Type {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    return v_CellInfo.info.bcc;
  }
  function f_GERAN_TSC_Get (GERAN_CellId_Type p_CellId) runs on GERAN_PTC return B3_Type {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    return v_CellInfo.info.tSC;
  }
  function f_GERAN_NMO_Get (GERAN_CellId_Type p_CellId) runs on GERAN_PTC return B2_Type {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    return v_CellInfo.info.nmo;
  }
  function f_GERAN_NMO_Set (GERAN_CellId_Type p_CellId, B2_Type p_NMO) runs on GERAN_PTC {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    v_CellInfo.info.nmo := p_NMO;
    f_GERAN_CellInfo_Set (p_CellId, v_CellInfo);
  }
  function f_GERAN_TA_Get (GERAN_CellId_Type p_CellId) runs on GERAN_PTC return O1_Type {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    return v_CellInfo.info.timingAdvance;
  }
  function f_GERAN_GAMMA_Get (GERAN_CellId_Type p_CellId) runs on GERAN_PTC return B5_Type {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    return v_CellInfo.info.gamma;
  }
  function f_GERAN_PLMN_Get (GERAN_CellId_Type p_CellId) runs on GERAN_PTC return O3_Type {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    return v_CellInfo.info.plmn;
  }
  function f_GERAN_PLMN_Set (GERAN_CellId_Type p_CellId, O3_Type p_PLMN) runs on GERAN_PTC {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    v_CellInfo.info.plmn := p_PLMN;
    f_GERAN_CellInfo_Set (p_CellId, v_CellInfo);
  }
  function f_GERAN_LAC_Get (GERAN_CellId_Type p_CellId) runs on GERAN_PTC return O2_Type {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    return v_CellInfo.info.lac;
  }
  function f_GERAN_RAC_Get (GERAN_CellId_Type p_CellId) runs on GERAN_PTC return O1_Type {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    return v_CellInfo.info.rac;
  }
 function f_GERAN_TLLI_Get(GERAN_CellId_Type p_CellId) runs on GERAN_PTC return TLLI {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
   return v_CellInfo.info.tlli;
 }
 function f_GERAN_TLLI_Set(GERAN_CellId_Type p_CellId, TLLI p_TLLI) runs on GERAN_PTC {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    v_CellInfo.info.tlli := p_TLLI;
    f_GERAN_CellInfo_Set (p_CellId, v_CellInfo);
 }
 function f_GERAN_OldTLLI_Get(GERAN_CellId_Type p_CellId) runs on GERAN_PTC return TLLI {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
   return v_CellInfo.info.oldTlli;
 }
 function f_GERAN_OldTLLI_Set(GERAN_CellId_Type p_CellId, TLLI p_TLLI) runs on GERAN_PTC {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    v_CellInfo.info.oldTlli := p_TLLI;
    f_GERAN_CellInfo_Set (p_CellId, v_CellInfo);
 }
  function f_GERAN_ControlChDesc_Get (GERAN_CellId_Type p_CellId) runs on GERAN_PTC return ControlChDescr {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    return v_CellInfo.info.controlChDesr;
  }
 function f_GERAN_SplitPGCycle_Get(GERAN_CellId_Type p_CellId) runs on GERAN_PTC return DRXparameter {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
   return v_CellInfo.info.splitPGcycle;
 }
 function f_GERAN_SplitPGCycle_Set(GERAN_CellId_Type p_CellId, DRXparameter p_SplitPGCycle) runs on GERAN_PTC {
    var GERAN_CellInfo_Type v_CellInfo := f_GERAN_CellInfo_Get(p_CellId);
    v_CellInfo.info.splitPGcycle := p_SplitPGCycle;
    f_GERAN_CellInfo_Set (p_CellId, v_CellInfo);
 }

}

