/******************************************************************************/
// @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.
//   (c) 2023, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC).
//   All rights reserved.
// @version: IWD_23wk37
// $Date: 2022-09-13 13:03:05 +0200 (Tue, 13 Sep 2022) $
// $Rev: 34148 $
/******************************************************************************/

module NG_NAS_MsgContainers
{
 // import from NR_RRC_ASN1_Definitions language "ASN.1:2002" all with {encode "UNALIGNED_PER_OctetAligned"};             // needed to get definition of maxDRB */
  import from NG_NAS_TypeDefs all;
  import from CommonDefs all;
  import from NAS_CommonTypeDefs all;
  import from EPS_NAS_LoopBack_TypeDefs all;
  import from Common4G5G_LoopBack all;
  import from EPS_NAS_TypeDefs all;

  type union NG_NAS_UL_Message_Type {                                              /* NAS message with direction 'UE to network ' or 'both' */
    NG_SECURITY_PROTECTED_NAS_MESSAGE                      security_Protected_Nas_Message,
    NG_AUTHENTICATION_FAILURE                              authentication_Failure,
    NG_AUTHENTICATION_RESPONSE                             authentication_Response,
    NG_CONFIGURATION_UPDATE_COMPLETE                       configuration_Update_Complete,
    NG_CP_SERVICE_REQUEST                                  cp_Service_Request,              // @sic R5s201387 Baseline Moving sic@
    NG_DEREGISTRATION_ACCEPT                               deregistration_Accept,
    NG_DEREGISTRATION_REQUEST_MO                           deregistration_RequestMO,
    NG_GMM_STATUS                                          gmm_Status,
    NG_GSM_STATUS                                          gsm_Status,
    NG_NETWORK_SLICE_SPECIFIC_AUTHENTICATION_COMPLETE      network_Slice_Specific_Authentication_Complete,  // @sic R5s201387 Baseline Moving sic@
    NG_IDENTITY_RESPONSE                                   identity_Response,
    NG_NOTIFICATION_RESPONSE                               notification_Response,
    NG_PDU_SESSION_AUTHENTICATION_COMPLETE                 pdu_Session_Authentication_Complete,
    NG_PDU_SESSION_ESTABLISHMENT_REQUEST                   pdu_Session_Establishment_Request,
    NG_PDU_SESSION_MODIFICATION_COMMAND_REJECT             pdu_Session_Modification_Command_Reject,
    NG_PDU_SESSION_MODIFICATION_COMPLETE                   pdu_Session_Modification_Complete,
    NG_PDU_SESSION_MODIFICATION_REQUEST                    pdu_Session_Modification_Request,
    NG_PDU_SESSION_RELEASE_COMPLETE                        pdu_Session_Release_Complete,
    NG_PDU_SESSION_RELEASE_REQUEST                         pdu_Session_Release_Request,
    NG_REGISTRATION_COMPLETE                               registration_Complete,
    NG_REGISTRATION_REQUEST                                registration_Request,
    NG_SECURITY_MODE_COMPLETE                              security_Mode_Complete,
    NG_SECURITY_MODE_REJECT                                security_Mode_Reject,
    NG_SERVICE_REQUEST                                     service_Request,
    NG_UL_NAS_TRANSPORT                                    ul_Nas_Transport,

    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,

    NSSAI_DELETE_RESPONSE                                  nssai_Delete_Response,
    SET_UAI_RESPONSE                                       set_UAI_Response,
    SET_UL_MESSAGE_RESPONSE                                set_UL_Message_Response,
    UE_TEST_LOOP_NR_SIDELINK_COUNTER_RESPONSE              test_Loop_Sidelink_Counter_Response // @sic R5-225291 sic@
  } with { // FIXME FSCOM Check messageType for deregistration_RequestMO
    variant "TAG(
      security_Protected_Nas_Message,                 securityHeaderType = '0001'B;
      security_Protected_Nas_Message,                 securityHeaderType = '0010'B;
      security_Protected_Nas_Message,                 securityHeaderType = '0011'B;
      security_Protected_Nas_Message,                 securityHeaderType = '0100'B;
      authentication_Failure,                         messageType = '01011001'B;
      authentication_Response,                        messageType = '01010111'B;
      configuration_Update_Complete,                  messageType = '01010101'B;
      cp_Service_Request,                             messageType = '01001111'B;
      deregistration_Accept,                          messageType = '01000110'B;
      deregistration_RequestMO,                       messageType = '01000101'B;
      gmm_Status,                                     messageType = '01100100'B;
      gsm_Status,                                     messageType = '11010110'B;
      network_Slice_Specific_Authentication_Complete, messageType = '01010001'B;
      identity_Response,                              messageType = '01011100'B;
      notification_Response,                          messageType = '01100110'B;
      pdu_Session_Authentication_Complete,            messageType = '11000110'B;
      pdu_Session_Establishment_Request,              messageType = '11000001'B;
      pdu_Session_Modification_Command_Reject,        messageType = '11001101'B;
      pdu_Session_Modification_Complete,              messageType = '11001100'B;
      pdu_Session_Modification_Request,               messageType = '11001001'B;
      pdu_Session_Release_Complete,                   messageType = '11010100'B;
      pdu_Session_Release_Request,                    messageType = '11010001'B;
      registration_Request,                           messageType = '01000001'B;
      registration_Complete,                          messageType = '01000011'B;
      security_Mode_Complete,                         messageType = '01011110'B;
      security_Mode_Reject,                           messageType = '01011111'B;
      service_Request,                                messageType = '01001100'B;
      ul_Nas_Transport,                               messageType = '01100111'B;
      )"

  }

  type union NG_NAS_DL_Message_Type {                                              /* NAS message with direction 'network to UE' or 'both' */
    NG_SECURITY_PROTECTED_NAS_MESSAGE                      security_Protected_Nas_Message,
    NG_AUTHENTICATION_REJECT                               authentication_Reject,
    NG_AUTHENTICATION_REQUEST                              authentication_Request,
    NG_AUTHENTICATION_RESULT                               authentication_Result,
    NG_CONFIGURATION_UPDATE_COMMAND                        configuration_Update_Command,
    NG_DEREGISTRATION_ACCEPT                               deregistration_Accept,
    NG_DEREGISTRATION_REQUEST_MT                           deregistration_RequestMT,
    NG_DL_NAS_TRANSPORT                                    dl_Nas_Transport,
    NG_GMM_STATUS                                          gmm_Status,
    NG_GSM_STATUS                                          gsm_Status,
    NG_IDENTITY_REQUEST                                    identity_Request,
    NG_NETWORK_SLICE_SPECIFIC_AUTHENTICATION_COMMAND       network_Slice_Specific_Authentication_Command,  // @sic R5s201387 Baseline Moving sic@
    NG_NETWORK_SLICE_SPECIFIC_AUTHENTICATION_RESULT        network_Slice_Specific_Authentication_Result,   // @sic R5s201387 Baseline Moving sic@
    NG_NOTIFICATION                                        notification,
    NG_PDU_SESSION_AUTHENTICATION_COMMAND                  pdu_Session_Authentication_Command,
    NG_PDU_SESSION_AUTHENTICATION_RESULT                   pdu_Session_Authentication_Result,
    NG_PDU_SESSION_ESTABLISHMENT_ACCEPT                    pdu_Session_Establishment_Accept,
    NG_PDU_SESSION_ESTABLISHMENT_REJECT                    pdu_Session_Establishment_Reject,
    NG_PDU_SESSION_MODIFICATION_COMMAND                    pdu_Session_Modification_Command,
    NG_PDU_SESSION_MODIFICATION_REJECT                     pdu_Session_Modification_Reject,
    NG_PDU_SESSION_RELEASE_COMMAND                         pdu_Session_Release_Command,
    NG_PDU_SESSION_RELEASE_REJECT                          pdu_Session_Release_Reject,
    NG_REGISTRATION_ACCEPT                                 registration_Accept,
    NG_REGISTRATION_REJECT                                 registration_Reject,
    NG_SECURITY_MODE_COMMAND                               security_Mode_Command,
    NG_SERVICE_ACCEPT                                      service_Accept,
    NG_SERVICE_REJECT                                      service_Reject,

    RESETUEPOSITIONINGSTOREDINFORMATION                    reset_UE_Positioning_Stored_Information, // For AGNSS

    ACTIVATE_TEST_MODE                                     activate_Test_Mode,
    DEACTIVATE_TEST_MODE                                   deactivate_Test_Mode,

    NR_CLOSE_UE_TEST_LOOP                                  close_Ue_Test_Loop,
    OPEN_UE_TEST_LOOP                                      open_Ue_Test_Loop,

    NSSAI_DELETE_REQUEST                                   nssai_Delete_Request,
    SET_UAI_REQUEST                                        set_UAI_Request,
    SET_UL_MESSAGE_REQUEST                                 set_UL_Message_Request,          // @sic R5-216275 sic@
    UE_TEST_LOOP_NR_SIDELINK_COUNTER_REQUEST               test_Loop_Sidelink_Counter_Request, // @sic R5-225291 sic@

    UPDATE_UE_LOCATION_INFORMATION                         update_Ue_Location_Information   //@sic R5-213421 sic@

  } with { // FIXME FSCOM Check messageType for deregistration_RequestMT
    variant "TAG(
      security_Protected_Nas_Message,                securityHeaderType = '0001'B;
      security_Protected_Nas_Message,                securityHeaderType = '0010'B;
      security_Protected_Nas_Message,                securityHeaderType = '0011'B;
      security_Protected_Nas_Message,                securityHeaderType = '0100'B;
      authentication_Reject,                         messageType = '01011000'B;
      authentication_Request,                        messageType = '01010110'B;
      authentication_Result,                         messageType = '01011010'B;
      configuration_Update_Command,                  messageType = '01010100'B;
      deregistration_Accept,                         messageType = '01000110'B;
      deregistration_RequestMT,                      messageType = '01001000'B;
      dl_Nas_Transport,                              messageType = '01101000'B;
      gmm_Status,                                    messageType = '01100100'B;
      gsm_Status,                                    messageType = '11010110'B;
      identity_Request,                              messageType = '01011011'B;
      network_Slice_Specific_Authentication_Command, messageType = '01010000'B;
      network_Slice_Specific_Authentication_Result,  messageType = '01010010'B;
      notification,                                  messageType = '01100101'B;
      pdu_Session_Authentication_Command,            messageType = '11000101'B;
      pdu_Session_Authentication_Result,             messageType = '11000111'B;
      pdu_Session_Establishment_Accept,              messageType = '11000010'B;
      pdu_Session_Establishment_Reject,              messageType = '11000011'B;
      pdu_Session_Modification_Command,              messageType = '11001011'B;
      pdu_Session_Modification_Reject,               messageType = '11001010'B;
      pdu_Session_Release_Command,                   messageType = '11010011'B;
      pdu_Session_Release_Reject,                    messageType = '11010010'B;
      registration_Accept,                           messageType = '01000010'B;
      registration_Reject,                           messageType = '01000100'B;
      security_Mode_Command,                         messageType = '01011101'B;
      service_Accept,                                messageType = '01001110'B;
      service_Reject,                                messageType = '01001101'B;
      )"
    }

  //****************************************************************************
  // NAS SECURITY PROTECTION
  //****************************************************************************

  type record NG_NAS_SecurityProtectionInfoUL_Type {
     SecurityHeaderType             Status,
     NasCount_Type                  NasCount
  };

  type record NG_NAS_SecurityProtectionInfoDL_Type {
     SecurityHeaderType             Status,
     boolean                        ForceMacError        /* Force the NAS emulator to send NAS PDU with erroneous MAC */
  };

  //****************************************************************************
  // 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 NG_NAS_UL_Pdu_Type {
    NG_NAS_UL_Message_Type              Msg,
    NG_NAS_UL_PduList_Type              PiggybackedPduList optional
  };

  type record of NG_NAS_UL_Pdu_Type NG_NAS_UL_PduList_Type;

  // recursive type definition:
  type record NG_NAS_DL_Pdu_Type {
    NG_NAS_DL_Message_Type              Msg,
    NG_NAS_DL_PduList_Type              PiggybackedPduList optional
  };

  type record of NG_NAS_DL_Pdu_Type NG_NAS_DL_PduList_Type;

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

  type record length(1) of NG_NAS_MSG_Indication_Type NG_NAS_MSG_IndicationList_Type;

  type record NG_NAS_MSG_Request_Type {
    NG_NAS_SecurityProtectionInfoDL_Type        SecurityProtection,     /* contains security status */
    NG_NAS_DL_Pdu_Type                          Pdu                     /* => only one NAS PDU on top level */
  };

  type record of NG_NAS_MSG_Request_Type NG_NAS_MSG_RequestList_Type;

// The encoding rule is needed because the types in this file are part of the overall message sent over the air
}  with { encode "RAW"/*"NAS Types"*/extension "errorbehavior(ALL:WARNING)"}
