/******************************************************************************/
// @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-05-09 13:11:08 +0200 (Mon, 09 May 2022) $
// $Rev: 33208 $
/******************************************************************************/

module NG_V2X_TypeDefs {

  import from CommonDefs all;
  import from NAS_CommonTypeDefs all;
  
  //****************************************************************************
  // NAS PROTOCOL DEFINITIONS: Message Types
  //----------------------------------------------------------------------------
  const MessageType tsc_MT_DirectLinkEstablishmentRequest         := '00000001'B;
  const MessageType tsc_MT_DirectLinkEstablishmentAccept          := '00000010'B;
  const MessageType tsc_MT_DirectLinkEstablishmentReject          := '00000011'B;
  const MessageType tsc_MT_DirectLinkModificationRequest          := '00000100'B;
  const MessageType tsc_MT_DirectLinkModificationAccept           := '00000101'B;
  const MessageType tsc_MT_DirectLinkModificationReject           := '00000110'B;
  const MessageType tsc_MT_DirectLinkReleaseRequest               := '00000111'B;
  const MessageType tsc_MT_DirectLinkReleaseAccept                := '00001000'B;
  const MessageType tsc_MT_DirectLinkKeepaliveRequest             := '00001001'B;
  const MessageType tsc_MT_DirectLinkKeepaliveResponse            := '00001010'B;
  const MessageType tsc_MT_DirectLinkAuthenticationRequest        := '00001011'B;
  const MessageType tsc_MT_DirectLinkAuthenticationResponse       := '00001100'B;
  const MessageType tsc_MT_DirectLinkAuthenticationReject         := '00001101'B;
  const MessageType tsc_MT_DirectLinkSecurityModeCommand          := '00001110'B;
  const MessageType tsc_MT_DirectLinkSecurityModeComplete         := '00001111'B;
  const MessageType tsc_MT_DirectLinkSecurityModeReject           := '00010000'B;
  const MessageType tsc_MT_DirectLinkRekeyingRequest              := '00010001'B;
  const MessageType tsc_MT_DirectLinkRekeyingResponse             := '00010010'B;
  const MessageType tsc_MT_DirectLinkIdentifierUpdateRequest      := '00010011'B;
  const MessageType tsc_MT_DirectLinkIdentifierUpdateAccept       := '00010100'B;
  const MessageType tsc_MT_DirectLinkIdentifierUpdateAck          := '00010101'B;
  const MessageType tsc_MT_DirectLinkIdentifierUpdateReject       := '00010110'B;
  const MessageType tsc_MT_DirectLinkAuthenticationFailure        := '00010111'B;

  //****************************************************************************
  // NAS PROTOCOL DEFINITIONS: PDUs
  //----------------------------------------------------------------------------
  // Direct Link messages (24.587 cl. 7.3)
  //----------------------------------------------------------------------------

  type record DIRECT_LINK_ESTABLISHMENT_REQUEST {                          /* 24.587 cl. 7.3.1
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1   M V 1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2   M V 1   */
    V2X_ServiceIds                      v2xServiceId,                            /* cl. 8.4.3   M LV 5-253 */
    ApplicationLayerId                  sourceUserInfo,                          /* cl. 8.4.4   M LV 3-253 */
    PC5_UESecurityCap                   ueSecurityCapability,                    /* cl. 8.4.14  M LV 3-9   */
    UE_PC5UnicastSecurityPolicy         uePC5UnicastSigSecurityPolicy,           /* cl. 8.4.15  M V  1  */
    KeyEstabInfoContainer               keyEstabInfoContainer         optional,  /* cl. 8.4.12  O TLV-E 4-n IEI=74 */
    PC5_Nonce                           nonce_1                       optional,  /* cl. 8.4.13  O TV 17 IEI=53 */
    K_NRPsessId_SigBits                 msb_K_NRPsessId               optional,  /* cl. 8.4.16  O TV 2  IEI=54 */
    ApplicationLayerId                  targetUserInfo                optional,  /* cl. 8.4.4   O TLV  4-254 IEI=28 */
    K_NRPId                             k_NRPId                       optional   /* cl. 8.4.17  O TV 5 IEI=52 */
  };

  type record DIRECT_LINK_ESTABLISHMENT_ACCEPT {                          /* 24.587 cl. 7.3.2
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V 1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V 1   */
    ApplicationLayerId                  sourceUserInfo,                          /* cl. 8.4.4  M LV 3-253 */
    PC5QoSFlowDescr                     qosFlowDescr,                            /* cl. 8.4.5  M LV-E 5-65537 */
    UE_PC5UnicastSecurityPolicy         configUEPC5UnicastUPSecurityProtection,  /* cl. 8.4.23 M V  1  */
    IPAddressConfig                     ipAddressConfig               optional,  /* cl. 8.4.6  O TV 2  IEI=57 */
    LinkLocalIPv6Addr                   linkLocalIPv6Addr             optional   /* cl. 8.4.7  O TV 17 IEI=58 */
  };

  type record DIRECT_LINK_MODIFICATION_REQUEST {                          /* 24.587 cl. 7.3.4
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V 1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V 1   */
    O1_Type                             linkModOperationCode,                    /* cl. 8.4.8  M V 1   */
    PC5QoSFlowDescr                     qosFlowDescr                             /* cl. 8.4.5  M LV-E 5-65537 */
  };

  type record DIRECT_LINK_MODIFICATION_ACCEPT {                          /* 24.587 cl. 7.3.5
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V 1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V 1   */
    PC5QoSFlowDescr                     qosFlowDescr                   optional  /* cl. 8.4.5  O TLV-E 6-65538 IEI=79 */
  };

  type record DIRECT_LINK_RELEASE_REQUEST {                          /* 24.587 cl. 7.3.6
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V 1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V 1   */
    O1_Type                             pc5SigProtocolCauseValue,                /* cl. 8.4.9  M V 1   */
    K_NRP_Id_SigBits                    msb_K_NRPId                              /* cl. 8.4.20 M V 2   */
  };

  type record DIRECT_LINK_RELEASE_ACCEPT {                          /* 24.587 cl. 7.3.7
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V 1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V 1   */
    K_NRP_Id_SigBits                    lsb_K_NRPId                              /* cl. 8.4.21 M V 2   */
  };

  type record DIRECT_LINK_KEEPALIVE_REQUEST {                          /* 24.587 cl. 7.3.8
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V  1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V  1   */
    O4_Type                             keepAliveCounter,                        /* cl. 8.4.10 M V  4   */
    MaxInactivityPeriod                 maxInactivityPeriod            optional  /* cl. 8.4.11 O TV 5 IEI=55 */
  };

  type record DIRECT_LINK_KEEPALIVE_RESPONSE {                          /* 24.587 cl. 7.3.9
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V  1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V  1   */
    O4_Type                             keepAliveCounter                         /* cl. 8.4.10 M V  4   */
  };

  type record DIRECT_LINK_AUTHENTICATION_REQUEST {                          /* 24.587 cl. 7.3.10
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V  1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V  1   */
    KeyEstabInfoContainer               keyEstabInfoContainer                    /* cl. 8.4.12 M LV-E 3-n */
  };

  type record DIRECT_LINK_AUTHENTICATION_RESPONSE {                          /* 24.587 cl. 7.3.11
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V  1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V  1   */
    KeyEstabInfoContainer               keyEstabInfoContainer                    /* cl. 8.4.12 M LV-E 3-n */
  };

  type record DIRECT_LINK_AUTHENTICATION_REJECT {                          /* 24.587 cl. 7.3.12
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V  1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V  1   */
    O1_Type                             pc5SigProtocolCauseValue                 /* cl. 8.4.9  M V  1   */
  };

  type record DIRECT_LINK_SECURITY_MODE_COMMAND {                          /* 24.587 cl. 7.3.13
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V 1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V 1   */
    SelectedSecurityAlgs                selectedSecurityAlgs,                    /* cl. 8.4.18 M V  1  */
    PC5_UESecurityCap                   ueSecurityCapability,                    /* cl. 8.4.14 M LV 3-9   */
    UE_PC5UnicastSecurityPolicy         uePC5UnicastSigSecurityPolicy,           /* cl. 8.4.15 O TV  2 IEI=59  */
    PC5_Nonce                           nonce_2                       optional,  /* cl. 8.4.13 O TV 17 IEI=55 */
    K_NRPsessId_SigBits                 lsb_K_NRPsessId               optional,  /* cl. 8.4.16 O TV 2  IEI=52 */
    KeyEstabInfoContainer               keyEstabInfoContainer         optional,  /* cl. 8.4.12 O TLV-E 4-n IEI=74 */
    K_NRP_Id_SigBits                    msb_K_NRPId                   optional   /* cl. 8.4.20 O TV 3  IEI=62   */
  };

  type record DIRECT_LINK_SECURITY_MODE_COMPLETE {                          /* 24.587 cl. 7.3.14
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V 1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V 1   */
    PC5QoSFlowDescr                     qosFlowDescr,                            /* cl. 8.4.5  M LV-E 6-n */
    UE_PC5UnicastSecurityPolicy         uePC5UnicastUPSecurityPolicy,            /* cl. 8.4.22 M V 1   */
    IPAddressConfig                     ipAddressConfig               optional,  /* cl. 8.4.6  O TV 2  IEI=57 */
    LinkLocalIPv6Addr                   linkLocalIPv6Addr             optional,  /* cl. 8.4.7  O TV 17 IEI=58 */
    K_NRP_Id_SigBits                    lsb_K_NRPId                   optional   /* cl. 8.4.20 O TV 3  IEI=52   */
  };

  type record DIRECT_LINK_SECURITY_MODE_REJECT {                          /* 24.587 cl. 7.3.15
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V  1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V  1   */
    O1_Type                             pc5SigProtocolCauseValue                 /* cl. 8.4.9  M V  1   */
  };

  type record DIRECT_LINK_REKEYING_REQUEST {                          /* 24.587 cl. 7.3.16
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V 1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V 1   */
    PC5_UESecurityCap                   ueSecurityCapability,                    /* cl. 8.4.14 M LV 3-9   */
    KeyEstabInfoContainer               keyEstabInfoContainer         optional,  /* cl. 8.4.12 O TLV-E 4-n IEI=74 */
    PC5_Nonce                           nonce_1                       optional,  /* cl. 8.4.13 O TV 17 IEI=53 */
    K_NRPsessId_SigBits                 msb_K_NRPsessId               optional,  /* cl. 8.4.16 O TV 2  IEI=54 */
    ReAuthInd                           reauthenticationInd           optional   /* cl. 8.4.24 O TV 2  IEI=56   */
  };

  type record DIRECT_LINK_REKEYING_RESPONSE {                          /* 24.587 cl. 7.3.17
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V  1   */
    SequenceNumber                      sequenceNumber                           /* cl. 8.4.2  M V  1   */
  };

  type record DIRECT_LINK_IDENTIFIER_UPDATE_REQUEST {                          /* 24.587 cl. 7.3.18
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V 1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V 1   */
    K_NRPsessId_SigBits                 msb_K_NRPsessId,                         /* cl. 8.4.16 M V 1   */
    Layer2Id                            layer2Id,                                /* cl. 8.4.25 M V 3   */
    ApplicationLayerId                  sourceUserInfo                optional,  /* cl. 8.4.4  O TLV  4-254 IEI=57 */
    LinkLocalIPv6Addr                   sourceLinkLocalIPv6Addr       optional   /* cl. 8.4.7  O TV 17 IEI=58 */
  };

  type record DIRECT_LINK_IDENTIFIER_UPDATE_ACCEPT {                          /* 24.587 cl. 7.3.19
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V 1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V 1   */
    K_NRPsessId_SigBits                 lsb_K_NRPsessId,                         /* cl. 8.4.17 M V 1   */
    K_NRPsessId_SigBits                 msb_K_NRPsessId,                         /* cl. 8.4.16 M V 1   */
    Layer2Id                            sourceLayer2Id,                          /* cl. 8.4.25 M V 3   */
    Layer2Id                            targetLayer2Id,                          /* cl. 8.4.25 M V 3   */
    ApplicationLayerId                  targetUserInfo                optional,  /* cl. 8.4.4  O TLV  4-254 IEI=28 */
    LinkLocalIPv6Addr                   targetLinkLocalIPv6Addr       optional,  /* cl. 8.4.7  O TV 17 IEI=59 */
    ApplicationLayerId                  sourceUserInfo                optional,  /* cl. 8.4.4  O TLV  4-254 IEI=57 */
    LinkLocalIPv6Addr                   sourceLinkLocalIPv6Addr       optional   /* cl. 8.4.7  O TV 17 IEI=58 */
  };

  type record DIRECT_LINK_IDENTIFIER_UPDATE_ACK {                          /* 24.587 cl. 7.3.20
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V 1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V 1   */
    K_NRPsessId_SigBits                 lsb_K_NRPsessId,                         /* cl. 8.4.17 M V 1   */
    Layer2Id                            targetLayer2Id,                          /* cl. 8.4.25 M V 3   */
    ApplicationLayerId                  targetUserInfo                optional,  /* cl. 8.4.4  O TLV  4-254 IEI=28 */
    LinkLocalIPv6Addr                   targetLinkLocalIPv6Addr       optional   /* cl. 8.4.7  O TV 17 IEI=59 */
  };

  type record DIRECT_LINK_IDENTIFIER_UPDATE_REJECT {                          /* 24.587 cl. 7.3.21
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V  1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V  1   */
    O1_Type                             pc5SigProtocolCauseValue                 /* cl. 8.4.9  M V  1   */
  };

  type record DIRECT_LINK_MODIFICATION_REJECT {                          /* 24.587 cl. 7.3.22
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V  1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V  1   */
    O1_Type                             pc5SigProtocolCauseValue                 /* cl. 8.4.9  M V  1   */
  };

  type record DIRECT_LINK_ESTABLISHMENT_REJECT {                          /* 24.587 cl. 7.3.23
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V  1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V  1   */
    O1_Type                             pc5SigProtocolCauseValue                 /* cl. 8.4.9  M V  1   */
  };

  type record DIRECT_LINK_AUTHENTICATION_FAILURE {                          /* 24.587 cl. 7.3.24
      // FFS: Errors in core spec definition!
                                                                   Significance:  dual
                                                                   Direction:     UE to peer UE */
    MessageType                         messageType,                             /* cl. 8.4.1  M V  1   */
    SequenceNumber                      sequenceNumber,                          /* cl. 8.4.2  M V  1   */
    KeyEstabInfoContainer               keyEstabInfoContainer         optional   /* cl. 8.4.12 O TLV-E 4-n IEI=74 */
  };

  //****************************************************************************
  // NAS PROTOCOL DEFINITIONS: information elements (24.587 cl. 8.4)
  //----------------------------------------------------------------------------
  type O1_Type SequenceNumber;                                         /* 24.587 cl. 8.4.2 */
  
  type record V2X_ServiceIds {                                         /* 24.587 cl. 8.4.3 */
    // IEI is not used for this type
    Type4Length_Type           lenOfContent,
    record of O4_Type          serviceId
  };

  type record ApplicationLayerId {                                     /* 24.587 cl. 8.4.4 */
    IEI8_Type                   iei                   optional,        /* present in case of TV; omit in case of V */
    Type4Length_Type            iel,
    octetstring                 appLayerContents
  };

  type record PC5QoS_Flow {                                            /* 24.587 cl. 8.4.5 */
    B2_Type                     spare2,
    B6_Type                     pqfi,
    B3_Type                     operationCode,
    B6_Type                     spare6,
    B1_Type                     eBit,
    B6_Type                     numOfParameters,
    V2X_ServiceIds              associatedV2XServiceIds optional,
    QoSParametersList           parameterList           optional
  };
  
  type record of PC5QoS_Flow PC5QoS_FlowList;
  
  type record PC5QoSFlowDescr {                                        /* 24.587 cl. 8.4.5 */
    IEI8_Type                   iei                 optional,
    Type6Length_Type            iel,
    PC5QoS_FlowList             listofFlows
  };

  type record IPAddressConfig {                                       /* 24.587 cl. 8.4.6 */
    IEI8_Type                   iei                   optional,       /* present in case of TV; omit in case of V */
    B4_Type                     spare,
    B4_Type                     ipAddrContents
  };

  type record LinkLocalIPv6Addr {                                      /* 24.587 cl. 8.4.7 */
    IEI8_Type                   iei                   optional,        /* present in case of TV; omit in case of V */
    O16_Type                    ipv6Addr
  };

  type record MaxInactivityPeriod {                                    /* 24.587 cl. 8.4.11 */
    IEI8_Type                   iei                   optional,        /* present in case of TV; omit in case of V */
    O4_Type                     maxInactivePeriod
  };

  type record KeyEstabInfoContainer {                                  /* 24.587 cl. 8.4.12 */
    IEI8_Type                   iei                   optional,        /* present in case of TV; omit in case of V */
    Type6Length_Type            iel,
    octetstring                 keyEstablishmentInfo
  };

  type record PC5_Nonce {                                             /* 24.587 cl. 8.4.13 */
    IEI8_Type                   iei                   optional,       /* present in case of TV; omit in case of V */
    O16_Type                    nonceValue
  };

  type record PC5_UESecurityCap {                                     /* 24.587 cl. 98.4.14 */
    IEI8_Type                   iei                   optional,       /* present in case of TLV; omit in case of LV */
    Type4Length_Type            iel,
    O1_Type                     ngeaCap,
    O1_Type                     ngiaCap,
    octetstring                 spare  length(1..6)   optional
  };

  type record UE_PC5UnicastSecurityPolicy {                           /* 24.587 cl. 8.4.15/22/23 */
                                                                      /* Definition is exactly the same for:
                                                                          UE PC5 Unicast Signalling Security Policy,
                                                                          UE PC5 Unicast User Plane Security Policy,
                                                                          Configuration of UE PC5 Unicast User Plane Security Protextion */
    IEI8_Type                   iei                   optional,       /* present in case of TV; omit in case of V */
    B1_Type                     spareBit1,
    B3_Type                     cipheringPolcy,
    B1_Type                     spareBit2,
    B4_Type                     integrityPolicy
  };

  type record K_NRPsessId_SigBits {                                    /* 24.587 cl. 8.4.16/19 */
    IEI8_Type                   iei                   optional,        /* present in case of TV; omit in case of V */
    O1_Type                     significantBits
  };

  type record K_NRPId {                                                /* 24.587 cl. 8.4.17 */
    IEI8_Type                   iei                   optional,        /* present in case of TV; omit in case of V */
    O4_Type                     id
  };

  type record SelectedSecurityAlgs {                                  /* 24.587 cl. 8.4.18 */
    IEI8_Type                   iei                   optional,       /* present in case of TV; omit in case of V */
    B1_Type                     spareBit1,
    B3_Type                     cipheringPolcy,
    B1_Type                     spareBit2,
    B4_Type                     integrityPolicy
  };

  type record K_NRP_Id_SigBits {                                       /* 24.587 cl. 8.4.20/21 */
    IEI8_Type                   iei                   optional,        /* present in case of TV; omit in case of V */
    O2_Type                     significantBits
  };

  type record ReAuthInd {                                              /* 24.587 cl. 8.4.24 */
    IEI8_Type                   iei                   optional,        /* present in case of TV; omit in case of V */
    B7_Type                     spare,
    B1_Type                     reAuthenticationInd
  };

  type record Layer2Id {                                               /* 24.587 cl. 8.4.25 */
    IEI8_Type                   iei                   optional,        /* present in case of TV; omit in case of V */
    O3_Type                     id
  };

} with { encode "NAS Types"}
