/******************************************************************************/
// @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_Templates {
  import from CDMA2000_CommonDefs all;
  import from CDMA2000_ASP_TypeDefs all;
  import from CDMA2000_Constants all;
  import from CommonDefs all;
  import from Parameters all;
  import from CommonIP all;
  
  //============================================================================
  template (value) PDN_Address_Type cs_PDN_Address_IPv4 (IPv4_Address_Type  p_Address ):=
  {
    IPv4  := p_Address
  };

  template (value) PDN_Address_Type cs_PDN_Address_IPv6 (IPv6_Address_Type  p_Address ):=
  {
    IPv6  := p_Address
  };

  template (value) PDN_Address_Type cs_PDN_Address_IPv4v6 (IPv4_Address_Type  p_AddressV4,
                                                           IPv6_Address_Type  p_AddressV6):=
  {
    IPv4v6  := {
      IPv4  := p_AddressV4,
      IPv6  := p_AddressV6
    }
  };

  function fl_GeneratePDN_Address () return template (value) PDN_Address_Type
  {
    var template (value) PDN_Address_Type v_PDN_Address ;
    if ( pc_IPv4 and (not pc_IPv6)) {
      v_PDN_Address:=  cs_PDN_Address_IPv4(f_Convert_IPv4Addr2OctString(px_IPv4_Address));
    }// IPv4
    if ( pc_IPv6 and (not pc_IPv4)) {
      
      v_PDN_Address:= cs_PDN_Address_IPv6 (substr( f_Convert_IPv6Addr2OctString(px_IPv6_Address), 8, 8 ));
    }// IPv6
    if ( pc_IPv6 and pc_IPv4) {
      // Address info consists of 8 octets IPv6 interface identifier followed with the 4 octets IPv4 address
      // See TS 24.301 clause 9.9.4.9
      v_PDN_Address:= cs_PDN_Address_IPv4v6 (f_Convert_IPv4Addr2OctString(px_IPv4_Address),
                                             substr( f_Convert_IPv6Addr2OctString(px_IPv6_Address), 8, 8 ));
    }//IPv4v6
    return v_PDN_Address;
  };

  template (value) PDN_Address_Type  cs_PDN_Address_Def := fl_GeneratePDN_Address ();
 
  //============================================================================
  
  template (value) CDMA2000_RoutingInfo_Type crs_RoutingInfoNone :=
  {
    None := true
  };
  
  template (value) CDMA2000_TimingInfo_Type cs_CDMA2000_TimingInfoNow :=
  {
    Now := true
  };

  template CDMA2000_TimingInfo_Type cr_CDMA2000_TimingInfo_Any :=
  {
    SubFrame :=
    {
      SystemTimeStamp := { TimeStampLong := ?},
      Subframe        := { Number := ?}
    }
  };
  
  template  CDMA2000_TimingInfo_Type cr_CDMA2000_TimingInfoNone :=
  {
    None := true
  };
  
  template CDMA2000_CnfAspCommonPart_Type cr_CDMA2000_CnfAspCommonPart_CellCfg (CDMA2000_CellId_Type p_CellId) :=
  {
    CellId := p_CellId,
    RoutingInfo := { None := true },
    TimingInfo := ?,
    Result := { Success := true }
  };
  
  template (value) CDMA2000_ReqAspCommonPart_Type cs_CDMA2000_ReqAspCommonPart_CellCfg (CDMA2000_CellId_Type p_CellId,
                                                                                        template (value) CDMA2000_TimingInfo_Type p_TimingInfo := cs_CDMA2000_TimingInfoNow,
                                                                                        boolean p_CnfFlag := true) :=
  {
    CellId := p_CellId,
    RoutingInfo := { None := true },
    TimingInfo := p_TimingInfo,
    ControlInfo := {
      CnfFlag      := p_CnfFlag,
      FollowOnFlag := false
    }
  };
  
  template (value) CDMA2000_ReqAspCommonPart_Type cs_CDMA2000_ReqAspCommonPart_SysCmd (CDMA2000_CellId_Type p_CellId,
                                                                                       template (value) CDMA2000_TimingInfo_Type p_TimingInfo := cs_CDMA2000_TimingInfoNow) :=
  {
    CellId := p_CellId,
    RoutingInfo := { None := true },
    TimingInfo := p_TimingInfo,
    ControlInfo := {
      CnfFlag      := false,
      FollowOnFlag := false
    }
  };
  
  template (value) CDMA2000_InitialCellPower_Type cs_CDMA2000_InitialCellPower (template (value) CDMA2000_AbsoluteCellPower_Type p_MaxReferencePower) :=
  {
    MaxReferencePower := p_MaxReferencePower,
    Attenuation       := tsc_CDMA2000_Attenuation_Off
  };
  
  template (value) CDMA2000_SYSTEM_CTRL_REQ cas_HRPD_CellConfig_REQ (CDMA2000_CellId_Type p_CellId,
                                                                     template (value) CDMA2000_CellParameters_Type    p_CellParameters,
                                                                     template (value) HRPD_CellParameters_Type        p_HRPD_CellParameters,
                                                                     template (value) CDMA2000_AbsoluteCellPower_Type p_ReferencePower,
                                                                     template (value) CDMA2000_TimingInfo_Type        p_TimingInfo := cs_CDMA2000_TimingInfoNow):=
  {
    Common  := cs_CDMA2000_ReqAspCommonPart_CellCfg (p_CellId, p_TimingInfo),
    Request := {
      Cell := {
        AddOrReconfigure := {
          CellParameters  := p_CellParameters,
          InitialCellPower := cs_CDMA2000_InitialCellPower(p_ReferencePower),
          ModeSpecificCellParams := {
            HRPD := p_HRPD_CellParameters
          }
        }
      }
    }
  };
  
  template (value) CDMA2000_SYSTEM_CTRL_REQ cas_CDMA2000_CellRel_REQ (CDMA2000_CellId_Type p_CellId := cdma2000_Cell_NonSpecific, // Release all cells
                                                                      template (value) CDMA2000_TimingInfo_Type p_TimingInfo := cs_CDMA2000_TimingInfoNow) :=
  {
    Common  :=  cs_CDMA2000_ReqAspCommonPart_CellCfg (p_CellId, p_TimingInfo),
    Request := {
      Cell := {
        Release := true
      }
    }
  };
  
  template (value) CDMA2000_SYSTEM_CTRL_REQ cas_CDMA2000_CellConfig_Power_REQ (template (value) CDMA2000_CellAttenuationList_Type p_CellAttenuationList,
                                                                               template (value) CDMA2000_TimingInfo_Type p_TimingInfo) :=
  { /* ASPs to modify cell power */
    Common := cs_CDMA2000_ReqAspCommonPart_CellCfg (cdma2000_Cell_NonSpecific,p_TimingInfo) ,
    Request := {
      CellAttenuationList := p_CellAttenuationList
    }
  };
  
  template CDMA2000_SYSTEM_CTRL_CNF car_CDMA2000_CellConfig_CNF (CDMA2000_CellId_Type p_CellId) :=
  {
    Common := cr_CDMA2000_CnfAspCommonPart_CellCfg(p_CellId),
    Confirm :=  {
      Cell := true
    }
  };
  template CDMA2000_SYSTEM_CTRL_CNF car_CDMA2000_CellConfig_Power_CNF :=
  {
    Common := cr_CDMA2000_CnfAspCommonPart_CellCfg(cdma2000_Cell_NonSpecific),
    Confirm := {
      CellAttenuationList := true
    }
  };
  
  group HRPD_SysIndicationAndCommands {
  
  template (value) UATI104_Type cs_UATI104_None :=
  {
    None := true
  };
  
  template (value) UATI_Type cs_UATI_Def (O3_Type p_UATI24 := tsc_UATI24,
                                          template (value) UATI104_Type p_UATI104 := cs_UATI104_None) :=
  {
    UATI24 := p_UATI24,
    UATI104 := p_UATI104
  };
  
  template (value) HRPD_SystemCommand_Type cs_HRPD_SysCmd_RegAndDefBearerEst_Def (PDN_Id_Type p_PDN_Id := tsc_PDN_Id,
                                                                                  template (value) PDN_Address_Type p_PDN_Address := cs_PDN_Address_Def,
                                                                                  RLP_FlowId_Type p_RLP_FlowId := tsc_RLP_FlowId1,
                                                                                  template (value) UATI_Type p_UATI := cs_UATI_Def,
                                                                                  HRPD_UE_InitStateType p_HRPD_UE_InitState := idle_Null,
                                                                                  CDMA2000_AttachType p_CDMA2000_AttachType := tsc_HandoverAttach) :=
  {
    RegAndDefBearerEst := {
      InitState   := p_HRPD_UE_InitState,
      PDN_Id      := p_PDN_Id,                 /* PDN_ID of the bearer */
      PDN_Address := p_PDN_Address,            /* the PDN Address to be provided to the UE in VSNCP ConfigAck */
      RLP_FlowId  := p_RLP_FlowId,             /* Associated RLP Flow ID */
      UATI        := p_UATI,                   /* UATI to be Assigned to the UE */
      AttachType  := p_CDMA2000_AttachType          /* The Attach Type to be expected in VSNCP procedure */
    }
  };
  
  template (value) CDMA2000_SystemCommand_Type cs_CDMA2000_SystemCommand_HRPD (template (value) HRPD_SystemCommand_Type  p_HRPD_SystemCommand) :=
  {
    HRPD := p_HRPD_SystemCommand
  };

  template (value) CDMA2000_SYSTEM_CMD cas_CDMA2000_SYSTEM_CMD_HRPD (CDMA2000_CellId_Type p_CellId,
                                                                     template (value) CDMA2000_TimingInfo_Type p_TimingInfo := cs_CDMA2000_TimingInfoNow,
                                                                     template (value) HRPD_SystemCommand_Type  p_HRPD_SystemCommand):=
  {
    Common :=cs_CDMA2000_ReqAspCommonPart_SysCmd ( p_CellId, p_TimingInfo ),
    Command :=cs_CDMA2000_SystemCommand_HRPD (  p_HRPD_SystemCommand)
  };
  
  template HRPD_SystemIndication_Type cr_SysInd_RegAndDef (template (present) RegAndDefBearerEstInd_Type p_RegAndDefBearerEstInd := cr_RegAndDefBearerEstInd_Def) :=
  {
    RegAndDefBearerEstInd := p_RegAndDefBearerEstInd
  };

  template HRPD_SystemIndication_Type cr_SysInd_InitialAccesProbRcvd :=
  {
    InitialAccessProbeRcvd := true
  };
  
  template CDMA2000_IndicationStatus_Type cr_CDMA2000_IndicationStatus_Ok :=
  {
    Ok := true
  };
  
  template CDMA2000_IndAspCommonPart_Type cr_CDMA2000_IndAspCommonPart_Common (CDMA2000_CellId_Type        p_CellId,
                                                                               template (present) CDMA2000_RoutingInfo_Type p_RoutingInfo :=crs_RoutingInfoNone,
                                                                               template (present) CDMA2000_TimingInfo_Type  p_TimingInfo :=cr_CDMA2000_TimingInfo_Any) :=
  {
    CellId      := p_CellId,
    RoutingInfo := p_RoutingInfo,
    TimingInfo  := p_TimingInfo,
    Status      := cr_CDMA2000_IndicationStatus_Ok
  };
  
  template RegAndDefBearerEstInd_Type cr_RegAndDefBearerEstInd_Def :=
  {
    UATI_AssignmentCmpl     := true,  // UATI Assignment procedure is completed
    ChAssignCmpl            := true,  // Channel Assignment procedure is completed
    SCP_ConfigCmpl          := true,  // Session configuration procedure is completed
    Stream_ConfigCmpl       := true,  // Stream configuration procedure is completed
    EMPA_ConfigCmpl         := true,  // Eanhanced multi flow packet application procedure is completed
    SessionNegotiationCmpl  := *,     // Session negotiation  procedure is optionally completed
    DeviceAuthCmpl          := *,     // Device authectication procedure is optionally completed
    LocationUpdateCmpl      := *,     // Location update procedure is optionally completed
    EAP_AKA_Cmpl            := true,  // AKA procedure is completed
    VSNCP_ConfigCmpl        := true,  // VSNCP  procedure is completed
    DHCP_ConfigCmpl         := *      // DHCP IPv4 address allocatione is optionally completed
  };
  
  template HRPD_SystemIndication_Type cr_DetachOnSwitchOffInd :=
  {
    DefaultBearerRelDetachInd := {
      VSNCP_TerminateCmpl  := omit,       /* Default bearer is not released before Detach as switch off*/
      LCP_TerminateCmpl    := true         /* To detach the UE x.s0057 clause 11.2 Detach completed */
    }
  };
  
  template CDMA2000_SYSTEM_IND car_CDMA2000_SYSTEM_IND_HRPD (CDMA2000_CellId_Type        p_CellId,
                                                             template (present) CDMA2000_RoutingInfo_Type  p_RoutingInfo :=crs_RoutingInfoNone,
                                                             template (present) CDMA2000_TimingInfo_Type   p_TimingInfo :=cr_CDMA2000_TimingInfo_Any,
                                                             template (present) HRPD_SystemIndication_Type p_HRPD_SystemIndication  ) :=
  {
    Common := cr_CDMA2000_IndAspCommonPart_Common(p_CellId, p_RoutingInfo, p_TimingInfo ),
    Indication := { HRPD :=  p_HRPD_SystemIndication}
  };

  template (value) HRPD_SystemCommand_Type cs_DetachOnSwitchOff(HRPD_UE_InitStateType   p_InitState := tsc_HRPD_UE_InitState_Active,
                                                                PDN_Id_Type             p_PDN_Id := tsc_PDN_Id,
                                                                RLP_FlowId_Type         p_RLP_FlowId := tsc_RLP_FlowId1) :=
  {
    DefaultBearerRelDetach := {
      InitState         :=   p_InitState,
      PDN_Id            := p_PDN_Id,
      RLP_FlowId        := p_RLP_FlowId,
      UE_NW_Initiated  := tsc_UEInitDetach
    }
  };
  
  template (value) HRPD_SystemCommand_Type cs_ConfigReportInitAccesProbe :=
  {
    ReportInitialAccesProbe := true
  };
  
  } //end of group HRPD_SysIndicationAndCommands
  
} // end of module
