/******************************************************************************/
// @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-07-01 23:13:43 +0200 (Thu, 01 Jul 2010) $
// $Rev: 3489 $
/******************************************************************************/

module EUTRA_Security_Templates {
  import from CommonDefs all;
  import from EUTRA_CommonDefs all;
  import from EUTRA_RRC_ASN1_Definitions language "ASN.1:1997" all;
  import from EUTRA_ASP_TypeDefs all;
  import from EUTRA_ASP_NasCtrl all;
  import from EUTRA_AspCommon_Templates all;
  
  //****************************************************************************
  // Configuration of AS security
  //----------------------------------------------------------------------------
  
  template (value) PdcpSQN_Type cs_PdcpSQN_SRB(integer p_Value) :=
  {
    Format := PdcpCount_Srb,
    Value  := p_Value
  };
  
  template (value) PDCP_ActTime_Type cs_PDCP_ActTime_SQN (template (value) PdcpSQN_Type p_PDCP_SQN) :=
  {
    SQN := p_PDCP_SQN
  };
  
  template (value) AS_CipheringInfo_Type cs_AS_CipheringInfo(CipheringAlgorithm_Type  p_Algo,
                                                             B128_Key_Type p_KeyRRC,
                                                             B128_Key_Type p_KeyUP,
                                                             template (value) SecurityActTimeList_Type p_ActList) :=
  { /* @status    APPROVED */
    Algorithm   := p_Algo,
    KRRCenc     := p_KeyRRC,
    KUPenc      := p_KeyUP,
    ActTimeList := p_ActList
  };
  
  template (value) AS_SecStartRestart_Type cs_AS_IntProtActivate(template (value) AS_IntegrityInfo_Type p_IntInfo) :=
  { /* @status    APPROVED */
    Integrity := p_IntInfo,
    Ciphering := omit
  };
  
  template (value) AS_SecStartRestart_Type cs_AS_CipheringActivate(template (value) AS_CipheringInfo_Type p_CiphInfo) :=
  { /* @status    APPROVED */
    Integrity := omit,
    Ciphering := p_CiphInfo
  };
  
  template (value) SYSTEM_CTRL_REQ cas_AsSecurityStart_REQ(CellId_Type p_CellId,
                                                           template (value) AS_SecStartRestart_Type p_AS_SecStartRestart,
                                                           template (value) TimingInfo_Type p_TimingInfo := cs_TimingInfo_Now,
                                                           boolean p_CnfFlag := tsc_CnfReq) :=
  { /* @status    APPROVED */
    /* Note: when p_TimingInfo is not cs_TimingInfo_Now p_CnfFlag shall be set to tsc_NoCnfReq */
    /* @sic R5s100178 sic@ */
    Common := cs_ReqAspCommonPart_CellCfg(p_CellId, p_TimingInfo, p_CnfFlag),
    Request := {
      AS_Security := {
        StartRestart := p_AS_SecStartRestart
      }
    }
  };
  
  template (value) SYSTEM_CTRL_REQ cas_AsSecurityRelease_REQ(CellId_Type p_CellId,
                                                             template (value) TimingInfo_Type p_TimingInfo := cs_TimingInfo_Now,
                                                             boolean p_CnfFlag := tsc_CnfReq) :=
  { /* @sic R5s100072 sic@ */
    /* @sic R5s100135 sic@ */
    /* @status    APPROVED */
    Common := cs_ReqAspCommonPart_CellCfg(p_CellId, p_TimingInfo, p_CnfFlag),
    Request := {
      AS_Security := {
        Release := true
      }
    }
  };
  
  template SYSTEM_CTRL_CNF car_AsSecurity_CNF(CellId_Type p_CellId) :=
  { /* @status    APPROVED */
    Common := cr_CnfAspCommonPart_CellCfg(p_CellId),
    Confirm := {
      AS_Security := true
    }
  };
  
  //----------------------------------------------------------------------------
  // Enquiry of PDCP COUNT values
  
  template (value) PDCP_CountReq_Type cs_PDCP_CountSet(PdcpCountInfoList_Type p_PdcpCountInfoList) :=
  { /* @status    APPROVED */
    Set := p_PdcpCountInfoList
  };

  template (value) PDCP_CountReq_Type cs_PDCP_CountGet_AllRBs  :=
  { /* @status    APPROVED */
    Get := {
      AllRBs := true
    }
  };

  template (value) SYSTEM_CTRL_REQ cas_PdcpCount_REQ(CellId_Type p_CellId,
                                                     template (value) PDCP_CountReq_Type p_CountReq) :=
  { /* @status    APPROVED */
    Common  := cs_ReqAspCommonPart_CellCfg(p_CellId),
    Request := {
      PdcpCount := p_CountReq
    }
  };

  template PdcpCount_Type cr_PDCPCount_SRB :=
  {
    Format := PdcpCount_Srb,
    Value  := ?
  };
  
  template PdcpCount_Type cr_PDCPCount_DRB_LongSQN :=
  {
    Format := PdcpCount_DrbLongSQN,
    Value  := ?
  };
  
  template PdcpCountInfo_Type cr_PDCPCountInfo_DRB_LongSQN(DRB_Identity p_DRB_Id) :=
  {
    RadioBearerId := {
      Drb := p_DRB_Id
    },
    UL := cr_PDCPCount_DRB_LongSQN,
    DL := cr_PDCPCount_DRB_LongSQN
  };
  
  template PdcpCountInfo_Type cr_PDCPCountInfo_SRB(SRB_Identity_Type p_SRB_Id) :=
  {
    RadioBearerId := {
      Srb := p_SRB_Id
    },
    UL := cr_PDCPCount_SRB,
    DL := cr_PDCPCount_SRB
  };
  
  template PdcpCountInfoList_Type cr_PdcpCountInfoList_SRB := {
    cr_PDCPCountInfo_SRB(tsc_SRB1),
    cr_PDCPCountInfo_SRB(tsc_SRB2)
  };
  
  template PdcpCountInfoList_Type cr_PdcpCountInfoList_SRB_1DRB_LongSQN := {
    cr_PDCPCountInfo_SRB(tsc_SRB1),
    cr_PDCPCountInfo_SRB(tsc_SRB2),
    cr_PDCPCountInfo_DRB_LongSQN(tsc_DRB1)
  };
  
  template SYSTEM_CTRL_CNF car_PdcpCount_CNF(CellId_Type p_CellId,
                                             template (present) PDCP_CountCnf_Type p_PDCP_CountCnf) :=
  { /* @status    APPROVED */
    Common := cr_CnfAspCommonPart_CellCfg(p_CellId),
    Confirm := {
      PdcpCount := p_PDCP_CountCnf
    }
  };
  
  template PdcpCountInfo_Type cr_PdcpCountInfo_DRB(template (present) DRB_Identity p_Drb) :=
  { /* @status    APPROVED */
    RadioBearerId := {Drb := p_Drb},
    UL := *,
    DL := *
  };

  //****************************************************************************
  // Configuration of NAS security
  //----------------------------------------------------------------------------
  
  template (value) NAS_SecurityStartRestart_Type cs_NAS_SecurityInit(B3_Type       p_IntegrityAlgorithm,
                                                                     B128_Key_Type p_K_NASint,
                                                                     B3_Type       p_CipheringAlgorithm,
                                                                     B128_Key_Type p_K_NASenc) :=
  { /* @status    APPROVED */
    Integrity := {
      Algorithm := p_IntegrityAlgorithm,
      K_NAS := p_K_NASint
    },
    Ciphering := {
      Algorithm := p_CipheringAlgorithm,
      K_NAS := p_K_NASenc
    },
    NasCountReset := true
  };
  
  template (value) NAS_CTRL_REQ cas_NasSecurityStart_REQ(template (value) NAS_SecurityStartRestart_Type p_SecurityStartRestart) :=
  { /* Note: NAS security seems to be cell independent
       @status    APPROVED */
    Common := cs_ReqAspCommonPart_CellCfg(eutra_Cell_NonSpecific),
    Request := {
      Security := {
        StartRestart := p_SecurityStartRestart
      }
    }
  };
  
  template (value) NAS_CTRL_REQ cas_NasSecurityRelease_REQ :=
  { /* Note: NAS security seems to be cell independent */
    Common := cs_ReqAspCommonPart_CellCfg(eutra_Cell_NonSpecific),
    Request := {
      Security := {
        Release := true
      }
    }
  };
  
  template NAS_CTRL_CNF car_NasSecurity_CNF :=
  { /* Note: NAS security seems to be cell independent
       @status    APPROVED */
    Common := cr_CnfAspCommonPart_CellCfg(eutra_Cell_NonSpecific),
    Confirm := {
      Security := true
    }
  };
  
  //****************************************************************************
  // Dealing with DL NAS COUNT
  //----------------------------------------------------------------------------
  
  template (value) NAS_CTRL_REQ cas_NasCountGet_REQ :=
  {
    Common := cs_ReqAspCommonPart_CellCfg(eutra_Cell_NonSpecific),
    Request := {
      NasCount := {
        Get := true
      }
    }
  };

  template NAS_CTRL_CNF car_NasCountGet_CNF :=
  {
    Common := cr_CnfAspCommonPart_CellCfg(eutra_Cell_NonSpecific),
    Confirm := {
      NasCount := {
        Get := {
          UL := ?,
          DL := ?
        }
      }
    }
  };

}
