/******************************************************************************/
// @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-16 23:11:35 +0200 (Thu, 16 Sep 2010) $
// $Rev: 3943 $
/******************************************************************************/

module EPS_NAS_MsgContainers
{
  import from EUTRA_RRC_ASN1_Definitions language "ASN.1:1997" all;             // needed to get definition of maxDRB */
  import from EPS_NAS_TypeDefs all;
  import from EUTRA_LoopBack_TypeDefs all;

  type union NAS_UL_Message_Type {                                              /* NAS message with direction 'UE to network ' or 'both' */
    ATTACH_COMPLETE                                     aTTACH_COMPLETE,
    ATTACH_REQUEST                                      aTTACH_REQUEST,

    AUTHENTICATION_FAILURE                              aUTHENTICATION_FAILURE,
    AUTHENTICATION_RESPONSE                             aUTHENTICATION_RESPONSE,

    DETACH_ACCEPT                                       dETACH_ACCEPT, /* direction: both */
    DETACH_REQUEST_MO                                   dETACH_REQUEST_MO,

    EMM_STATUS                                          eMM_STATUS, /* direction: both */

    EXT_SERVICE_REQUEST                                 eXT_SERVICE_REQUEST,

    GUTI_REALLOCATION_COMPLETE                          gUTI_REALLOCATION_COMPLETE,

    IDENTITY_RESPONSE                                   iDENTITY_RESPONSE,

    SECURITY_MODE_COMPLETE                              sECURITY_MODE_COMPLETE,
    SECURITY_MODE_REJECT                                sECURITY_MODE_REJECT,

    SECURITY_PROTECTED_NAS_MESSAGE                      sECURITY_PROTECTED_NAS_MESSAGE,

    SERVICE_REQUEST                                     sERVICE_REQUEST,

    TRACKING_AREA_UPDATE_COMPLETE                       tRACKING_AREA_UPDATE_COMPLETE,
    TRACKING_AREA_UPDATE_REQUEST                        tRACKING_AREA_UPDATE_REQUEST,

    UL_NAS_TRANSPORT                                    ul_NAS_TRANSPORT,

    ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_ACCEPT        aCTIVATE_DEDICATED_EPS_BEARER_CONTEXT_ACCEPT,
    ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REJECT        aCTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REJECT,

    ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_ACCEPT          aCTIVATE_DEFAULT_EPS_BEARER_CONTEXT_ACCEPT,
    ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REJECT          aCTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REJECT,

    BEARER_RESOURCE_ALLOCATION_REQUEST                  bEARER_RESOURCE_ALLOCATION_REQUEST,
    BEARER_RESOURCE_MODIFICATION_REQUEST                bEARER_RESOURCE_MODIFICATION_REQUEST,

    DEACTIVATE_EPS_BEARER_CONTEXT_ACCEPT                dEACTIVATE_EPS_BEARER_CONTEXT_ACCEPT,

    ESM_INFORMATION_RESPONSE                            eSM_INFORMATION_RESPONSE,

    ESM_STATUS                                          eSM_STATUS, /* direction: both */

    MODIFY_EPS_BEARER_CONTEXT_ACCEPT                    mODIFY_EPS_BEARER_CONTEXT_ACCEPT,
    MODIFY_EPS_BEARER_CONTEXT_REJECT                    mODIFY_EPS_BEARER_CONTEXT_REJECT,

    PDN_CONNECTIVITY_REQUEST                            pDN_CONNECTIVITY_REQUEST,

    PDN_DISCONNECT_REQUEST                              pDN_DISCONNECT_REQUEST,

    ACTIVATE_TEST_MODE_COMPLETE                      aCTIVATE_TEST_MODE_COMPLETE,
    DEACTIVATE_TEST_MODE_COMPLETE                    dEACTIVATE_TEST_MODE_COMPLETE,

    CLOSE_UE_TEST_LOOP_COMPLETE                         cLOSE_UE_TEST_LOOP_COMPLETE,
    OPEN_UE_TEST_LOOP_COMPLETE                          oPEN_UE_TEST_LOOP_COMPLETE
  };

  type union NAS_DL_Message_Type {                                              /* NAS message with direction 'network to UE' or 'both' */
    ATTACH_ACCEPT                                       aTTACH_ACCEPT,
    ATTACH_REJECT                                       aTTACH_REJECT,

    AUTHENTICATION_REJECT                               aUTHENTICATION_REJECT,
    AUTHENTICATION_REQUEST                              aUTHENTICATION_REQUEST,
    
    CS_SERVICE_NOTIFICATION                             cS_SERVICE_NOTIFICATION,

    DETACH_ACCEPT                                       dETACH_ACCEPT, /* direction: both */
    DETACH_REQUEST_MT                                   dETACH_REQUEST_MT,

    DL_NAS_TRANSPORT                                    dl_NAS_TRANSPORT,

    EMM_INFORMATION                                     eMM_INFORMATION,
    EMM_STATUS                                          eMM_STATUS, /* direction: both */

    GUTI_REALLOCATION_COMMAND                           gUTI_REALLOCATION_COMMAND,

    IDENTITY_REQUEST                                    iDENTITY_REQUEST,

    SECURITY_MODE_COMMAND                               sECURITY_MODE_COMMAND,

    SECURITY_PROTECTED_NAS_MESSAGE                      sECURITY_PROTECTED_NAS_MESSAGE,

    SERVICE_REJECT                                      sERVICE_REJECT,

    TRACKING_AREA_UPDATE_ACCEPT                         tRACKING_AREA_UPDATE_ACCEPT,
    TRACKING_AREA_UPDATE_REJECT                         tRACKING_AREA_UPDATE_REJECT,

    ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST       aCTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST,

    ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST         aCTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST,

    BEARER_RESOURCE_ALLOCATION_REJECT                   bEARER_RESOURCE_ALLOCATION_REJECT,
    BEARER_RESOURCE_MODIFICATION_REJECT                 bEARER_RESOURCE_MODIFICATION_REJECT,

    DEACTIVATE_EPS_BEARER_CONTEXT_REQUEST               dEACTIVATE_EPS_BEARER_CONTEXT_REQUEST,

    ESM_INFORMATION_REQUEST                             eSM_INFORMATION_REQUEST,

    ESM_STATUS                                          eSM_STATUS, /* direction: both */

    MODIFY_EPS_BEARER_CONTEXT_REQUEST                   mODIFY_EPS_BEARER_CONTEXT_REQUEST,

    PDN_CONNECTIVITY_REJECT                             pDN_CONNECTIVITY_REJECT,

    PDN_DISCONNECT_REJECT                               pDN_DISCONNECT_REJECT,

    ACTIVATE_TEST_MODE                                  aCTIVATE_TEST_MODE,
    DEACTIVATE_TEST_MODE                                dEACTIVATE_TEST_MODE,

    CLOSE_UE_TEST_LOOP                                  cLOSE_UE_TEST_LOOP,
    OPEN_UE_TEST_LOOP                                   oPEN_UE_TEST_LOOP
  };

  //****************************************************************************
  // NAS SECURITY PROTECTION
  //****************************************************************************
  // acc. to 24.301 cl. 9.1 there are different kinds of NAS messages:
  // - NAS messages being security protected:
  //   in this case the NAS message is contained in SECURITY PROTECTED NAS MESSAGE (i.e. SECURITY PROTECTED NAS MESSAGE is the NAS PDU)
  // - NAS messages not being security protected:
  //   in this case the NAS message is not contained in SECURITY PROTECTED NAS MESSAGE (i.e. the NAS message is the NAS PDU)
  // - SERVICE REQUEST (UE -> network):
  //   SERVICE REQUEST is always already a NAS PDU i.e. never contained in a SECURITY PROTECTED NAS MESSAGE
  //   (assumptions: SERVICE REQUEST is not ciphered; (short) MAC needs not to be evaluated)
  // in oder to allow easy handling of NAS messages in the testcases and to allow straight forward codec implementation
  // TTCN (normally) shall deal with the pure NAS messages rather than with the SECURITY PROTECTED NAS MESSAGE (which is more or less a container only)
  // => SecurityHeaderType, ProtocolDiscriminator, MessageAuthenticationCode and NAS_SequenceNumber are treated as separated information and the
  //    NAS emulation is responsible to
  //    - encode/decode the SECURITY PROTECTED NAS MESSAGE (if necessary)
  //    - apply NAS security (if necessary)
  //    - manage NAS sequence numbers

  type record NAS_SecurityProtectionInfoUL_Type {
    SecurityHeaderType             Status,
    NasCount_Type                  NasCount
  };

  type record NAS_SecurityProtectionInfoDL_Type {
    SecurityHeaderType             Status,
    boolean                        ForceMacError        /* Force the NAS emulator to send NAS PDU with erroneous MAC
                                                           @sic R5s100358 additional changes sic@ */
  };

  //****************************************************************************
  // Generic definition of NAS PDUs containing other piggy-backed PDUs
  //****************************************************************************
  // Note: the type definition allows much more combinitions than being valid acc. to the NAS standard
  //       appropriate templates shall restrict the generic type definitions
  // Working Assumptions:
  // - acc. to DEC 08 ASN.1 in RRCConnectionReconfiguration there can be up to maxDRB times DedicatedInfoNAS
  //   => several EMM messages can be contained each having its own security protection
  // - within any DedicatedInfoNAS there is one security protected NAS PDU
  //   (i.e. the assumption is that the security container contains just one PDU)
  // - the EMM PDU being contained in the DedicatedInfoNAS may contain further piggy-backing:
  //   even though in 24.301 V8.0.0 it is stated that
  //   "The purpose of the ESM message container information element is to enable piggybacked transfer of
  //    a single ESM message within an EMM message" (cl. 9.9.3.15)
  //   the type definition allows even more than one piggy-backed PDU and as well further levels of piggybacking
  // => type definitions can be applied even when the standard will be enhanced in the future

  // recursive type definition:
  type record NAS_UL_Pdu_Type {
    NAS_UL_Message_Type                 Msg,
    NAS_UL_PduList_Type                 PiggybackedPduList optional
  };

  type record of NAS_UL_Pdu_Type NAS_UL_PduList_Type;

  // recursive type definition:
  type record NAS_DL_Pdu_Type {
    NAS_DL_Message_Type                 Msg,
    NAS_DL_PduList_Type                 PiggybackedPduList optional
  };

  type record of NAS_DL_Pdu_Type NAS_DL_PduList_Type;

  type record NAS_MSG_Indication_Type {
    NAS_SecurityProtectionInfoUL_Type   SecurityProtection,     /* contains security status and NAS COUNT */
    NAS_UL_Pdu_Type                     Pdu                     /* => only one NAS PDU on top level */
  };

  type record length(1) of NAS_MSG_Indication_Type NAS_MSG_IndicationList_Type;         /* acc. to DEC 08 ASN.1 max. one DedicatedInfoNAS
                                                                                           may be contained in any UL RRC message */

  type record NAS_MSG_Request_Type {
    NAS_SecurityProtectionInfoDL_Type   SecurityProtection,     /* contains security status */
    NAS_DL_Pdu_Type                     Pdu                     /* => only one NAS PDU on top level */
  };

  type record length(1..maxDRB) of NAS_MSG_Request_Type NAS_MSG_RequestList_Type;       /* acc. to DEC 08 ASN.1 in RRCConnectionReconfiguration
                                                                                           there can be up to maxDRB times DedicatedInfoNAS */

// The encoding rule is needed because the types in this file are part of the overall message sent over the air
}  with { encode "NAS Types"}
