///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2023 Ericsson Telecom AB
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v2.0
// which accompanies this distribution, and is available at
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
///////////////////////////////////////////////////////////////////////////////
//
//  File:               MobileL3_Types.ttcn
//  Rev:                R2A
//  Prodnr:             CNL 113 832
//  Contact:            http://ttcn.ericsson.se
//  Reference:          3GPP TS 24.008 v13.4.0

module MobileL3_Types
{

import from General_Types           all;
import from MobileL3_CommonIE_Types all;
import from MobileL3_GMM_SM_Types   all;
import from MobileL3_MM_Types       all;
import from MobileL3_CC_Types       all;
import from MobileL3_RRM_Types      all;
import from MobileL3_SMS_Types      all;
import from MobileL3_SS_Types       all;

external function enc_PDU_L3_MS_SGSN(in PDU_L3_MS_SGSN pdu) return octetstring
with { extension "prototype(convert)" extension "encode(RAW)" }
external function enc_PDU_L3_MS_SGSN_fast(in PDU_L3_MS_SGSN pdu, out octetstring stream)
with { extension "prototype(fast)" extension "encode(RAW)" }

// new external function for decoding MS -> SGSN
external function dec_PDU_L3_MS_SGSN(in octetstring stream) return PDU_L3_MS_SGSN
with { extension "prototype(convert)" extension "decode(RAW)" }
external function dec_PDU_L3_MS_SGSN_backtrack(in octetstring stream, out PDU_L3_MS_SGSN pdu) return integer
with { extension "prototype(backtrack)" extension "decode(RAW)" }

// new external function for encoding SGSN -> MS
external function enc_PDU_L3_SGSN_MS(in PDU_L3_SGSN_MS pdu) return octetstring
with { extension "prototype(convert)" extension "encode(RAW)" }
external function enc_PDU_L3_SGSN_MS_fast(in PDU_L3_SGSN_MS pdu, out octetstring stream)
with { extension "prototype(fast)" extension "encode(RAW)" }

external function dec_PDU_L3_SGSN_MS(in octetstring stream) return PDU_L3_SGSN_MS
with { extension "prototype(convert)" extension "decode(RAW)" }
external function dec_PDU_L3_SGSN_MS_backtrack(in octetstring stream, out PDU_L3_SGSN_MS pdu) return integer
with { extension "prototype(backtrack)" extension "decode(RAW)" }

external function enc_PDU_ML3_NW_MS(in PDU_ML3_NW_MS pdu) return octetstring
with { extension "prototype(convert)" extension " encode(RAW)" }
external function enc_PDU_ML3_NW_MS_fast(in PDU_ML3_NW_MS pdu, out octetstring stream)
with { extension "prototype(fast)" extension " encode(RAW)" }

external function dec_PDU_ML3_NW_MS(in octetstring stream) return PDU_ML3_NW_MS
with { extension "prototype(convert)" extension " decode(RAW)" }
external function dec_PDU_ML3_NW_MS_backtrack(in octetstring stream, out PDU_ML3_NW_MS pdu) return integer
with { extension "prototype(backtrack)" extension " decode(RAW)" }

external function enc_PDU_ML3_MS_NW(in PDU_ML3_MS_NW pdu) return octetstring
with { extension "prototype(convert)" extension " encode(RAW)" }
external function enc_PDU_ML3_MS_NW_fast(in PDU_ML3_MS_NW pdu, out octetstring stream)
with { extension "prototype(fast)" extension " encode(RAW)" }

external function dec_PDU_ML3_MS_NW(in octetstring stream) return PDU_ML3_MS_NW
with { extension "prototype(convert)" extension " decode(RAW)" }
external function dec_PDU_ML3_MS_NW_backtrack(in octetstring stream, out PDU_ML3_MS_NW pdu) return integer
with { extension "prototype(backtrack)" extension " decode(RAW)" }

// ***************************************************************************
// *     The container types of all L3_PDU
// ***************************************************************************
type record L3_TransactionId
{
  BIT3               tio,
  BIT1               tiFlag ,
  TI_Extension       tIExtension  optional
  // an extension octet (TI) can be used for session management messages
  // not yet implemented (see 24.008 clause 10.3.2 for more detail
} with { variant (tIExtension) "PRESENCE(tio = '111'B)" };

type record L3_TransactionId_not_extended
{
  BIT3               tio,
  BIT1               tiFlag
};

type union TiOrSkip_not_extended
{
  BIT4                                   skipIndicator,
  L3_TransactionId_not_extended          transactionId
};


type union TiOrSkip
{
  BIT4               skipIndicator,
  L3_TransactionId   transactionId
};

type union L3_Discr_SGSN_MS
{
  octetstring        gcc,       //group call control
  octetstring        bcc,      // broadcast call control
  octetstring        cc,       // call control; call related SS messages PDU_ypes_CC_MSC_MS
  octetstring        gttp,     // GPRS Transparent Transport Protocol
  octetstring        mm,       // mobility management messages  PDU_DTAP_MM
  octetstring        rrm,      // radio resource management messages PDU_DTAP_RRM
  L3_GMM_SGSN_MS     gprs_mm,  // GPRS mobility management messages
  octetstring        sms,      // SMS messages
  L3_GSM_SGSN_MS     gprs_sm,  // GPRS session management messages
  octetstring        ss,       // non call related SS messages
  octetstring        loc,      // Location services
  octetstring        reserved
};


type record PDU_L3_SGSN_MS_unextended_ti
{
  BIT4                         discriminator,
  TiOrSkip_not_extended        tiOrSkip,
  L3_Discr_SGSN_MS             msgs
} with { variant (msgs)"CROSSTAG(
  gcc,        discriminator='0000'B;
  bcc,        discriminator='0001'B;
  cc,         discriminator='0011'B;
  gttp,       discriminator='0100'B;
  mm,         discriminator='0101'B;
  rrm,        discriminator='0110'B;
  gprs_mm,    discriminator='1000'B;
  sms,        discriminator='1001'B;
  gprs_sm,    discriminator='1010'B;
  ss,         discriminator='1011'B;
  loc,        discriminator='1100'B;
  reserved, { discriminator='0010'B,
  discriminator='0111'B,
  discriminator='1101'B,
  discriminator='1110'B,
  discriminator='1111'B }
  )";
  variant (tiOrSkip)"CROSSTAG(
  skipIndicator,    { discriminator='0010'B,
  discriminator='0100'B,
  discriminator='0101'B,
  discriminator='0110'B,
  discriminator='0111'B,
  discriminator='1000'B,
  discriminator='1100'B,
  discriminator='1101'B,
  discriminator='1110'B,
  discriminator='1111'B };
  transactionId,    { discriminator='0000'B,
  discriminator='0001'B,
  discriminator='0011'B,
  discriminator='1001'B,
  discriminator='1011'B,
  discriminator='1010'B }
  )";
};


type record PDU_L3_SGSN_MS
{
  BIT4               discriminator,
  TiOrSkip           tiOrSkip,
  L3_Discr_SGSN_MS   msgs
}  with { variant (msgs)"CROSSTAG(
  gcc,        discriminator='0000'B;
  bcc,        discriminator='0001'B;
  cc,         discriminator='0011'B;
  gttp,       discriminator='0100'B;
  mm,         discriminator='0101'B;
  rrm,        discriminator='0110'B;
  gprs_mm,    discriminator='1000'B;
  sms,        discriminator='1001'B;
  gprs_sm,    discriminator='1010'B;
  ss,         discriminator='1011'B;
  loc,        discriminator='1100'B;
  reserved, { discriminator='0010'B,
  discriminator='0111'B,
  discriminator='1101'B,
  discriminator='1110'B,
  discriminator='1111'B }
  )";
  variant (tiOrSkip)"CROSSTAG(
  skipIndicator,    { discriminator='0010'B,
  discriminator='0100'B,
  discriminator='0101'B,
  discriminator='0110'B,
  discriminator='0111'B,
  discriminator='1000'B,
  discriminator='1100'B,
  discriminator='1101'B,
  discriminator='1110'B,
  discriminator='1111'B };
  transactionId,    { discriminator='0000'B,
  discriminator='0001'B,
  discriminator='0011'B,
  discriminator='1011'B,
  discriminator='1001'B,
  discriminator='1010'B }
  )";
};


type union L3_Discr_MS_SGSN
{
  octetstring        gcc,      //group call control
  octetstring        bcc,      // broadcast call control
  octetstring        cc,       // call control; call related SS messages PDU_DTAP_CC_MS_MSC
  octetstring        gttp,     // GPRS Transparent Transport Protocol
  octetstring        mm,       // mobility management messages PDU_DTAP_MM
  octetstring        rrm,      // radio resource management messages PDU_DTAP_RRM
  L3_GMM_MS_SGSN     gprs_mm,  // GPRS mobility management messages
  octetstring        sms,      // SMS messages
  L3_GSM_MS_SGSN     gprs_sm,  // GPRS session management messages
  octetstring        ss,  // non call related SS messages
  octetstring        loc, // Location services
  octetstring        reserved
};


type record PDU_L3_MS_SGSN
{
  BIT4               discriminator,
  TiOrSkip           tiOrSkip,
  L3_Discr_MS_SGSN   msgs
} with { variant (msgs)"CROSSTAG(
  gcc,        discriminator='0000'B;
  bcc,        discriminator='0001'B;
  cc,         discriminator='0011'B;
  gttp,       discriminator='0100'B;
  mm,         discriminator='0101'B;
  rrm,        discriminator='0110'B;
  gprs_mm,    discriminator='1000'B;
  sms,        discriminator='1001'B;
  gprs_sm,    discriminator='1010'B;
  ss,         discriminator='1011'B;
  loc,        discriminator='1100'B;
  reserved, { discriminator='0010'B,
  discriminator='0111'B,
  discriminator='1101'B,
  discriminator='1110'B,
  discriminator='1111'B }
  )";
  variant (tiOrSkip)"CROSSTAG(
  skipIndicator,    { discriminator='0010'B,
  discriminator='0100'B,
  discriminator='0101'B,
  discriminator='0110'B,
  discriminator='0111'B,
  discriminator='1000'B,
  discriminator='1100'B,
  discriminator='1101'B,
  discriminator='1110'B,
  discriminator='1111'B };
  transactionId,    { discriminator='0000'B,
  discriminator='0001'B,
  discriminator='0011'B,
  discriminator='1001'B,
  discriminator='1011'B,
  discriminator='1010'B }
  )";
};


//***************************************************************************
//  24.007/11.2.3.1.1 and 24.008/10.2 Protocol Discriminator    NW->MS
//***************************************************************************
type union ML3_Discr_NW_MS
{
  octetstring        gcc,      // group call control                      <- 24.068  WITHDRAWN
  octetstring        bcc,      // broadcast call control                  <- 24.069 WITHDRAWN
  PDU_ML3_CC_NW_MS   cc,       // call control; call related SS messages  <-24.008, implemented
  octetstring        gttp,     // GPRS Transparent Transport Protocol <- not required in MSC
  PDU_ML3_MM         mm,       // mobility management messages        <- 24.008,
  PDU_RRM_NW_MS      rrm,      // radio resource management messages  <- 24.008, 24.018
  octetstring        gprs_mm,  // GPRS mobility management messages   <- Not required in MSC
  // but implemented as L3_GMM_SGSN_MS in L3_Types (SGSN)
  L3_SMS_SGSN_MS     sms,      // SMS messages
  //<-24.011, imported from L3_SMS_Types
  octetstring        gprs_sm,  // GPRS session management messages    <- not required in MSC
  // but impl. as L3_GMM_MS_SGSN in L3_GSM_SGSN_MS_Types
  PDU_ML3_SS_NW_MS   ss,       // non call related SS messages
  //<- 24.080 ASN1 or implemented by ethgbh
  octetstring        loc,      // Location services(LCS)              <- 24.030
  octetstring        reserved
};


// ref: 24.007/11.2.3.1.1 "Protocol discriminator" and
// Table 11.2 "Protocol dicriminator values"
type record PDU_ML3_NW_MS
{
  BIT4             discriminator, //24.008/10.2
  TiOrSkip         tiOrSkip,      //24.008/10.3
  ML3_Discr_NW_MS  msgs
} with { variant (msgs)"CROSSTAG(
  gcc,        discriminator='0000'B;
  bcc,        discriminator='0001'B;
  cc,         discriminator='0011'B;
  gttp,       discriminator='0100'B;
  mm,         discriminator='0101'B;
  rrm,        discriminator='0110'B;
  gprs_mm,    discriminator='1000'B;
  sms,        discriminator='1001'B;
  gprs_sm,    discriminator='1010'B;
  ss,         discriminator='1011'B;
  loc,        discriminator='1100'B;
  reserved, { discriminator='0010'B,
              discriminator='0111'B,
              discriminator='1101'B,
              discriminator='1110'B,
              discriminator='1111'B }
  )";
  variant (tiOrSkip)"CROSSTAG(
  skipIndicator,    { discriminator='0010'B,
                      discriminator='0100'B,
                      discriminator='0101'B,
                      discriminator='0110'B,
                      discriminator='0111'B,
                      discriminator='1000'B,
                      discriminator='1100'B,
                      discriminator='1101'B,
                      discriminator='1110'B,
                      discriminator='1111'B };
  transactionId,    { discriminator='0000'B,
                      discriminator='0001'B,
                      discriminator='0011'B,
                      discriminator='1001'B,
                      discriminator='1011'B,
                      discriminator='1010'B }
  )";
};


type union ML3_Discr_MS_NW
{
  octetstring        gcc,      //group call control
  octetstring        bcc,      // broadcast call control
  PDU_ML3_CC_MS_NW   cc,       // call control; call related SS messages
  octetstring        gttp,     // GPRS Transparent Transport Protocol
  PDU_ML3_MM         mm,       // mobility management messages
  PDU_RRM_MS_NW      rrm,      // radio resource management messages
  octetstring        gprs_mm,  // GPRS mobility management messages
  L3_SMS_MS_SGSN     sms,      // SMS messages
  octetstring        gprs_sm,  // GPRS session management messages
  PDU_ML3_SS_MS_NW   ss,  // non call related SS messages
  octetstring        loc, // Location services
  octetstring        reserved
};

type record PDU_ML3_MS_NW
{
  BIT4                discriminator,
  TiOrSkip            tiOrSkip,
  ML3_Discr_MS_NW     msgs
} with { variant (msgs)"CROSSTAG(
  gcc,        discriminator='0000'B;
  bcc,        discriminator='0001'B;
  cc,         discriminator='0011'B;
  gttp,       discriminator='0100'B;
  mm,         discriminator='0101'B;
  rrm,        discriminator='0110'B;
  gprs_mm,    discriminator='1000'B;
  sms,        discriminator='1001'B;
  gprs_sm,    discriminator='1010'B;
  ss,         discriminator='1011'B;
  loc,        discriminator='1100'B;
  reserved, { discriminator='0010'B,
              discriminator='0111'B,
              discriminator='1101'B,
              discriminator='1110'B,
              discriminator='1111'B }
  )";
  variant (tiOrSkip)"CROSSTAG(
  skipIndicator,    { discriminator='0010'B,
                      discriminator='0100'B,
                      discriminator='0101'B,
                      discriminator='0110'B,
                      discriminator='0111'B,
                      discriminator='1000'B,
                      discriminator='1100'B,
                      discriminator='1101'B,
                      discriminator='1110'B,
                      discriminator='1111'B };
  transactionId,    { discriminator='0000'B,    //24.008/10.3.2
                      discriminator='0001'B,
                      discriminator='0011'B,
                      discriminator='1001'B,
                      discriminator='1011'B,
                      discriminator='1010'B }   //24.008/10.3.2
  )";
};

}//end of module
with {
extension "version R2A"
encode "RAW"
}

