///////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2000-2019 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:               NAS_EPS_Types.ttcn
//  Rev:                <RnXnn>
//  Prodnr:             1/CNL 113 862
//  Contact:            http://ttcn.ericsson.se
//  Reference:          3GPP 24.301 v15.2.0 (24.008 v15.3.0, 24.011 v15.1.0, 24.161 v15.0.0 

module NAS_EPS_Types
{

import from General_Types all;


external function enc_PDU_NAS_EPS(in PDU_NAS_EPS pdu) return octetstring
with { extension "prototype(convert)" extension "encode(RAW)" }

external function dec_PDU_NAS_EPS(in octetstring stream) return PDU_NAS_EPS
with { extension "prototype(convert)" extension "decode(RAW)" }

external function dec_PDU_NAS_EPS_backtrack(in octetstring stream, out PDU_NAS_EPS pdu) return integer
with { extension "prototype(backtrack) decode(RAW)" }

external function enc_EPS_MobileIdentityV_NAS_EPS(in EPS_MobileIdentityV ePS_mobileIdentityV) return octetstring
with { extension "prototype(convert)" extension "encode(RAW)" }

external function dec_EPS_MobileIdentityV_NAS_EPS(in octetstring ePS_mobileIdentityV_oct) return EPS_MobileIdentityV
with { extension "prototype(convert)" extension "decode(RAW)" }

external function dec_EPS_MobileIdentityV_NAS_EPS_backtrack(in octetstring ePS_mobileIdentityV_oct, out EPS_MobileIdentityV ePS_mobileIdentityV) return integer
with { extension "prototype(backtrack) decode(RAW)" }

external function enc_IMSI_NAS_EPS(in IMSI imsi) return octetstring
with { extension "prototype(convert)" extension "encode(RAW)" }

external function dec_IMSI_NAS_EPS(in octetstring imsi_oct) return IMSI
with { extension "prototype(convert)" extension "decode(RAW)" }

external function dec_IMSI_NAS_EPS_backtrack(in octetstring imsi_oct, out IMSI imsi) return integer
with { extension "prototype(backtrack) decode(RAW)" }

external function enc_GUTI_NAS_EPS(in GUTI guti) return octetstring
with { extension "prototype(convert)" extension "encode(RAW)" }

external function dec_GUTI_NAS_EPS(in octetstring guti_oct) return GUTI
with { extension "prototype(convert)" extension "decode(RAW)" }

external function dec_GUTI_NAS_EPS_backtrack(in octetstring guti_oct, out GUTI guti) return integer
with { extension "prototype(backtrack) decode(RAW)" }

external function enc_IMEI_NAS_EPS(in IMEI imei) return octetstring
with { extension "prototype(convert)" extension "encode(RAW)" }

external function dec_IMEI_NAS_EPS(in octetstring imei_oct) return IMEI
with { extension "prototype(convert)" extension "decode(RAW)" }

external function dec_IMEI_NAS_EPS_backtrack(in octetstring imei_oct, out IMEI imei) return integer
with { extension "prototype(backtrack) decode(RAW)" }

//==================================
// Common Information Elements
//==================================

// 9.9.2.0
type record AdditionalInformationTLV
{
  OCT1              elementIdentifier,
  LIN1              lengthIndicator,
  octetstring       additionalInformation_Value
} with {
  variant "PRESENCE (elementIdentifier = '65'O)"
  variant (lengthIndicator) "LENGTHTO (additionalInformation_Value)" 
}

// 9.9.2.0A  10.5.7.8/24.008
type record DevicePropertiesTV
{
  BIT1             lowPriority,
  BIT3             spare,
  BIT4             elementIdentifier
}

// 9.9.2.1
type record EPS_BearerContextStatusTLV
{
  OCT1              elementIdentifier,
  LIN1              lengthIndicator,
  BIT1              ebi0,
  BIT1              ebi1,
  BIT1              ebi2,
  BIT1              ebi3,
  BIT1              ebi4,
  BIT1              ebi5,
  BIT1              ebi6,
  BIT1              ebi7,
  BIT1              ebi8,
  BIT1              ebi9,
  BIT1              ebi10,
  BIT1              ebi11,
  BIT1              ebi12,
  BIT1              ebi13,
  BIT1              ebi14,
  BIT1              ebi15
} with { 
  variant (lengthIndicator) "LENGTHTO (ebi0,ebi1,ebi2,ebi3,ebi4,ebi5,ebi6,ebi7,ebi8,ebi9,ebi10,ebi11,ebi12,ebi13,ebi14,ebi15)"  
  variant "PRESENCE (elementIdentifier = '57'O )" 
}

// 9.9.2.2 - 10.5.1.3/24.008  

type record LocationAreaIdentificationV {
  OCT3  mcc_mnc,
  OCT2  lac
} 

type record LocationAreaIdentificationTV {
  OCT1  elementIdentifier,
  OCT3  mcc_mnc, 
  OCT2  lac
} with {
  variant "PRESENCE (elementIdentifier = '13'O)"
}

// 9.9.2.3 - 10.5.1.4/24.008

type record MobileIdentityTLV
{
  BIT7              elementIdentifier,
  BIT1              spare1,
  MobileIdentityLV  mobileIdentityLV
} with {
  variant "PRESENCE (elementIdentifier = '0100011'B)"
}

type record MobileIdentityLV
{
  LIN1             lengthIndicator,
  MobileIdentityV  mobileIdentityV
} with { 
  variant (lengthIndicator) "LENGTHTO (mobileIdentityV)"  
}

type record MobileIdentityV
{
  BIT3                         typeOfIdentity,
  OddEvenInd_Identity          oddEvenInd_identity
} with {
  variant (oddEvenInd_identity) "CROSSTAG(
  imsi,                     typeOfIdentity ='001'B;
  imei,                     typeOfIdentity ='010'B;
  imei_sv,                  typeOfIdentity ='011'B;
  tmsi_ptmsi_mtmsi,         typeOfIdentity ='100'B;
  tmgi_and_mbms_sessionID,  typeOfIdentity ='101'B;
  no_identity,              typeOfIdentity ='000'B;
 )"
}

type union OddEvenInd_Identity
{
  IMSI                     imsi,  
  IMEI                     imei,    
  IMEI_SV                  imei_sv,
  TMSI_PTMSI_MTMSI         tmsi_ptmsi_mtmsi,
  TMGI_and_MBMS_SessionID  tmgi_and_mbms_sessionID,
  No_Identity              no_identity
}

type record IMSI
{
  BIT1               oddevenIndicator,       
  hexstring          digits,
  BIT4               fillerDigit  optional   // filler '1111'B 
} with {
  variant (fillerDigit) "PRESENCE (oddevenIndicator   = '0'B) "
}

type record IMEI
{
  BIT1               oddevenIndicator,   
  hexstring          digits,   
  BIT4               fillerDigit  optional   // filler '1111'B  
} with {
  variant (fillerDigit) "PRESENCE (oddevenIndicator   = '0'B) "
}

type record IMEI_SV
{
  BIT1               oddevenIndicator,  
  hexstring          digits,
  BIT4               fillerDigit  optional   // filler '1111'B
} with {
  variant (fillerDigit) "PRESENCE (oddevenIndicator   = '0'B) "
}

type record TMSI_PTMSI_MTMSI
{
  BIT1               oddevenIndicator,  
  BIT4               fillerDigit,   // filler '1111'B
  hexstring          digits
} with {
  variant (fillerDigit) "PRESENCE (oddevenIndicator   = '0'B) ";
  variant (digits) "HEXORDER(high)"  
}

type record TMGI_and_MBMS_SessionID
{
  BIT1               oddevenIndicator,
  BIT1               mccMncIndicator,
  BIT1               sessIdIndicator,
  BIT2               spare,  // '00'B
  OCT3               mBMSServiceID,
  HEX1               mccDigit1 optional,
  HEX1               mccDigit2 optional,  
  HEX1               mccDigit3 optional,  
  HEX1               mncDigit3 optional,   
  HEX1               mncDigit1 optional,
  HEX1               mncDigit2 optional,   
  OCT1               mBMSSessionIdentity optional
} with {
  variant (mccDigit1) "PRESENCE (mccMncIndicator   = '1'B)";
  variant (mccDigit2) "PRESENCE (mccMncIndicator   = '1'B)";
  variant (mccDigit3) "PRESENCE (mccMncIndicator   = '1'B)";
  variant (mncDigit3) "PRESENCE (mccMncIndicator   = '1'B)";
  variant (mncDigit2) "PRESENCE (mccMncIndicator   = '1'B)";
  variant (mncDigit1) "PRESENCE (mccMncIndicator   = '1'B)";
  variant (mBMSSessionIdentity) "PRESENCE (sessIdIndicator   = '1'B)";
}

type record No_Identity
{
  BIT1               oddevenIndicator,
  hexstring          fillerDigits
};

// 9.9.2.4 - 10.5.1.6/24.008
//24.008/ 10.5.1.6 , 4th octet:
type record MobileStationClassmark2_oct4 {
  BIT1  fc, // '0'B no MS support of E/R_GSM
  // '1'B      MS support of E/R_GSM
////BIT2  spare1_2, // '00'B
  BIT1  vgcs,//'0'B no VGCS capability
  //'1'B  VGCS capability and notifications wanted
  BIT1  vbs, //'0'B no VBS capability, 
  //  '1'B VBS capability and notifications wanted
  BIT1  sm_Capability, // '0'B SM capbility present  not
  // '1'B SM capbility        present
  BIT2 ss_ScreenIndicator,
  // '00'B default value of phase1 (GSM+DCS) reserved or (PCS)
  // '01'B capability of notation  ellipsis
  // '10'B for future use
  // '11'B for use  future
  BIT1  ps_Capability, // 'x'B  ignored, received  if
  BIT1  spare2_1   // '0'B
} with { variant "" };


//24.008/ 10.5.1.6 5th octet ( Table 10.5.6a ):
type record MobileStationClassmark2_oct5 {
  BIT1  a5_2,     // '0'B encryption algorithm A5/2 available not(0)
                  // '1'B encryption algorithm A5/available  2   (1)
  BIT1  a5_3,     // '0'B encryption algorithm A5/3 available not(0)
                  // '1'B encryption algorithm A5/available  3   (1)
  //BIT5  spare3_5, //   '00000'B 
  BIT1  cmsp,
  BIT1  solsa,
  BIT1  ucs2,
  BIT1  lcsva_cap,
  BIT1  spare5_7,
  BIT1  cm3       // '0'B  no additional capability info
  // '1'B The MS supports options that are indicated in classmark 3 IE
  //      (additional info  capability)
} with { variant "" };


//24.008/ 10.5.1.6
type record MobileStationClassmark2_TLV {
  OCT1  elementIdentifier,
  LIN1  lengthIndicator, // '01'O..'03'O
  BIT3  rf_PowerCapability, //        '000'B class1 (for GSM+DCS+PCS)
  //        '001'B class2 (for GSM+DCS+PCS)
  //        '010'B class3 (for GSM+DCS+PCS)
  //        '011'class4  B  (only for GSM)
  //        '100'class5  B  (only for GSM)
  BIT1  a5_1, // '0'B encryption algorithm A5/1 available (0)
  // '1'B encryption algorithm A5/1 not available  1  (1)
  BIT1  esind,
  // '0'B controlled early classmark sending option implemented not (0)
  // '1'B controlled early classmark sending implemented option (1)
  BIT2  revisionLevel, //   '00'B reserved for phase1 (GSM+DCS)
  //   '00'B reserved for GSM phase 1 (PCS)
  //   '01'B used by phase2 MSs  (GSM+DCS)
  //   '01'B used by PCS1900 MSs  phase1  (PCS)
  //   '10'B used by  MSs  R99  supporting
  //   '11'B reserved for future use
  BIT1  spare1_1, // '0'B
  MobileStationClassmark2_oct4  mobileStationClassmark2_oct4    optional,
  MobileStationClassmark2_oct5  mobileStationClassmark2_oct5    optional
} with { 
  variant "PRESENCE (elementIdentifier = '11'O)"
  variant (lengthIndicator) "LENGTHTO (rf_PowerCapability, a5_1, esind,
                                             revisionLevel, spare1_1,
                                             mobileStationClassmark2_oct4,
                                             mobileStationClassmark2_oct5)"};


// 9.9.2.5 - 10.5.1.7/24.008
type record MobileStationClassmark3_TLV {
  OCT1  elementIdentifier,
  LIN1  lengthIndicator,
  OCTN  valuePart
} with { 
  variant "PRESENCE (elementIdentifier = '20'O)"
  variant (lengthIndicator) "LENGTHTO (valuePart)"};


// 9.9.2.6
type record NASSecurityParFromEUTRAN_TV{
  OCT1  elementIdentifier,
  BIT4  DL_NAS_count_value,
  BIT4  spare
} //with { 
//  variant "PRESENCE (elementIdentifier = '20'O)"
//};


// 9.9.2.7
type record NASSecurityParToEUTRAN_TV{
  OCT1  elementIdentifier,
  OCT4  nonceMME_value,
  BIT3  typeof_IP_algorithm,
  BIT1  spare,
  BIT3  typeof_ciphering_algorithm,
  BIT1  spare2,
  BIT3  NAS_key_ID,
  BIT1  tSC,
  BIT4  spare3
} // with { 
//  variant "PRESENCE (elementIdentifier = '20'O)"
//};

// 9.9.2.8 - 10.5.1.13/24.008
type record PLMN_ListTLV
{
  OCT1         elementIdentifier,
  LIN1         lengthIndicator,
  MCC_MNC_List mcc_mnc length(1..15)
} with {
  variant (lengthIndicator) "LENGTHTO (mcc_mnc)"
  variant "PRESENCE (elementIdentifier = '4A'O)"
}

type record of OCT3 MCC_MNC_List;

// 9.9.2.9
// implemented as BIT4

// 9.9.2.10 - 10.5.4.32/24.008
type record codec{
  OCT1  systemIdentification1,
  INT1  lengthOfBitmap1,
  OCT1  codecBitmap1_bits1to8,
  OCT1  codecBitmap1_bits9to16 optional,
  octetstring additional_codecs optional
} with { variant (lengthOfBitmap1) "LENGTHTO(codecBitmap1_bits1to8, codecBitmap1_bits9to16, additional_codecs)"; 
};

type record of codec CodecList_ML3 with { variant "" }; 

type record SupportedCodecListTLV {
  OCT1            elementIdentifier,
  LIN1            lengthIndicator, //  
  CodecList_ML3   codecList 
} with { 
  variant "PRESENCE (elementIdentifier = '40'O)"
  variant (lengthIndicator) "LENGTHTO( codecList )"};

//==================================================================
// EPS Mobility Management (EMM) information elements - 9.9.3/24.301
//==================================================================

// 9.9.3.0A
type record AdditionalUpdateResultTV
{
  BIT2      additionalUpdateResultValue,  // "CS Fallback not preferred" is never given as CS Fallback is not supported
  BIT2      spare,
  BIT4      elementIdentifier 
} with{
  variant "PRESENCE (elementIdentifier = '1111'B)"
}

// 9.9.3.0B
type record AdditionalUpdateTypeTV
{
  BIT1      aUTV,
  BIT1      SAF,
  BIT2      pNB_CIoT,
  BIT4      elementIdentifier  
} with{
  variant "PRESENCE (elementIdentifier = '1111'B)"
}

// 9.9.3.1 - 10.5.3.2.2/24.008
type record AuthenticationFailureParameterTLV
{
  OCT1     elementIdentifier,
  LIN1     lengthIndicator,
  OCT14    authenticationFailureParameter
} with{
  variant "PRESENCE (elementIdentifier = '30'O)"
  variant (lengthIndicator) "LENGTHTO (authenticationFailureParameter)"  
}

// 9.9.3.2 - 10.5.3.1.1/24.008
type record AuthenticationParameterAUTNLV
{
  LIN1        lengthIndicator,
  OCT16       aUTN
} with {
  variant (lengthIndicator) "LENGTHTO (aUTN)"  
}

// 9.9.3.3 - 10.5.3.1/24.008
type record AuthenticationParameterRANDV
{
  OCT16       rAND
}

// 9.9.3.4
type record AuthenticationResponseParameterLV
{
  LIN1              lengthIndicator,
  AuthenticationResponseParameterV authenticationResponseParameter
} with {
  variant (lengthIndicator) "LENGTHTO (authenticationResponseParameter)"  
}

type record AuthenticationResponseParameterV
{
  octetstring       rES length (4..16)
}

// 9.9.3.4A - 10.5.1.2/24.008
type record CipheringKeySequenceNumberTV
{
  CipheringKeySequenceNumberV  keySequence,
  BIT4                         elementIdentifier
} with { variant "PRESENCE (elementIdentifier = '1000'B)"; };


type record CipheringKeySequenceNumberV
{
  BIT3               keySequence,
  BIT1               spare
};

// 9.9.3.4B
type record SMS_ServiceStatusTV
{
  BIT3             sMS_ServiceStatusValue,
  BIT1             spare,
  BIT4             elementIdentifier
} with { variant "PRESENCE (elementIdentifier = '1110'B)"; };


// 9.9.3.5
type record CSFB_ResponseTV
{
 BIT3             cSFB_ResponseValue,
 BIT1             spare,
 BIT4             elementIdentifier
} with { variant "PRESENCE (elementIdentifier = '1011'B)"; };

// 9.9.3.6 - 10.5.3.12/24.008
type record DaylightSavingTimeTLV
{
  OCT1                        elementIdentifier,
  DaylightSavingTimeLV        daylightSavingTimeLV

} with { variant "PRESENCE (elementIdentifier = '49'O)"; };

type record DaylightSavingTimeLV
{
  LIN1                         lengthIndicator,
  DaylightSavingTimeV          daylightSavingTimeV
} with {
  variant (lengthIndicator) "LENGTHTO (daylightSavingTimeV)" 
}

type record DaylightSavingTimeV 
{
  BIT2               valueField,
  BIT6               spare     // Shall be set to 000000
}

// 9.9.3.7
// type record DetachTypeTV 
// {
//   DetachTypeV detachType,
//   BIT4 elementIdentifier
// } with {
//   variant "PRESENCE (elementIdentifier = '?? 'O)"
// }

type record DetachTypeV
{
  BIT3     typeofDetach,
  BIT1     switchOff
}

// 9.9.3.8 - 10.5.5.6/24.008
type record DRXParameterTV
{
  OCT1               elementIdentifier,
  DRXParameterV      drxParameter
} with { variant "PRESENCE (elementIdentifier = '5C'O)"; };

type record DRXParameterV
{
  OCT1               splitPGCycleCode,
  BIT3               nonDRXTimer,
  BIT1               splitOnCCCH,
  BIT4               cnSpecificDRXCycleLength
}

// 9.9.3.9
type record EMM_CauseTV
{
  OCT1        elementIdentifier,
  EMM_CauseV  causeValue
} with {
  variant "PRESENCE (elementIdentifier = '53'O)"
}

type record EMM_CauseV
{
  OCT1        causeValue
}

// 9.9.3.10
type record EPS_AttachResultV
{
  BIT3     valueOfAttachResult,
  BIT1     spare
}

// EPS_AttachResultTV -- not used

// 9.9.3.11
type record EPS_AttachTypeV
{
  BIT3     typeOfAttach,
  BIT1     spare
} 

// EPS_AttachTypeTV -- not used

// 9.9.3.12
type record EPS_MobileIdentityTLV
{
  OCT1                         elementIdentifier,
  EPS_MobileIdentityLV         ePS_MobileIdentity
} with {
  variant "PRESENCE (elementIdentifier = '50'O; )" 
}

type record EPS_MobileIdentityLV
{
  LIN1                         lengthIndicator,
  EPS_MobileIdentityV          ePS_MobileIdentity
} with {
  variant (lengthIndicator) "LENGTHTO (ePS_MobileIdentity)"
}

type record EPS_MobileIdentityV 
{
  BIT3                         typeOfIdentity,
  OddEvenInd_Identity_EPS      oddEvenInd_identity
} with {
  variant (oddEvenInd_identity) "CROSSTAG(
  imsi,                     typeOfIdentity ='001'B;
  guti,                     typeOfIdentity ='110'B;
  imei,                     typeOfIdentity ='011'B;
  )"
}

type union OddEvenInd_Identity_EPS
{
  IMSI  imsi,
  GUTI  guti,
  IMEI  imei       
}

type record GUTI
{
  BIT1               oddevenIndicator, 
  BIT4               spare,  // '1111'B
  HEX1               mccDigit1,
  HEX1               mccDigit2,
  HEX1               mccDigit3,
  HEX1               mncDigit3,
  HEX1               mncDigit1,
  HEX1               mncDigit2,
  OCT2               mMEGI,
  OCT1               mMEC,
  OCT4               mTMSI
}

// 9.9.3.12A
type record EPS_NetworkFeatureSupportTLV 
{
  OCT1     elementIdentifier,
  LIN1     lengthIndicator,
  BIT1     iMS_VoPS,
  BIT1     eMCBS,
  BIT1     ePC_LCS,
  BIT2     cS_LCS,
  BIT1     eSR_PS, 
  BIT1     eRwoPDN,
  BIT1     cP_CIoT,
  BIT1     uP_CIoT optional, 
  BIT1     s1_UData optional,
  BIT1     hC_CP_CIoT optional,
  BIT1     ePCO optional,
  BIT1     restrictEC optional,
  BIT1     restrictDCNR optional,
  BIT1     n26OInd optional,
  BIT1     spare optional
} with{
  variant "PRESENCE (elementIdentifier = '64'O)"
  variant (lengthIndicator) "LENGTHTO (iMS_VoPS, eMCBS, ePC_LCS, cS_LCS, eSR_PS, eRwoPDN, cP_CIoT,uP_CIoT,
                                       s1_UData, hC_CP_CIoT, ePCO, restrictEC, restrictDCNR, n26OInd, spare)"  
}

// 9.9.3.13
type record EPS_UpdateResultV
{
  BIT3         valueOfUpdateResult, // set to "TA updated" or "combined TA/LA updated"
  BIT1         spare
}

// 9.9.3.14
type record EPS_UpdateTypeV 
{
  BIT3         typeOfUpdate,
  BIT1         activeFlag  
}

// 9.9.3.15
type record ESM_MessageContainerTLVE
{
  OCT1                      elementIdentifier,
  ESM_MessageContainerLVE   eSM_MessageContainer
} with {
  variant "PRESENCE (elementIdentifier = '78'O)"
}

type record ESM_MessageContainerLVE
{
  LIN2_BO_LAST      lengthIndicator,
  octetstring       content length (1..65535)
} with { 
  variant (lengthIndicator) "LENGTHTO (content)"
}

// 9.9.3.16 - 10.5.7.3/24.008
type record GPRSTimerTV
{
  OCT1        elementIdentifier,   // different values in different PDUs
  GPRSTimerV  gprsTimer
} 

type record GPRSTimerV
{
  BIT5     timerValue,
  BIT3     unit
}

// 9.9.3.16a  10.5.7.4/24.008
type record GPRSTimer2TLV 
{
 OCT1          elementIdentifier,
 LIN1          lengthIndicator,
 GPRSTimer2V   gprsTimer2
} with { 
  variant (lengthIndicator) "LENGTHTO (gprsTimer2)"
}

type record GPRSTimer2V
{
  BIT5     timerValue,
  BIT3     unit
}

// 9.9.3.16b 10.5.7.4a/24.008
type record GPRSTimer3TLV
{
 OCT1          elementIdentifier,
 LIN1          lengthIndicator, 
 GPRSTimer3V   gprsTimer3
} with { 
  variant (lengthIndicator) "LENGTHTO (gprsTimer3)"
}

type record GPRSTimer3V
{
  BIT5     timerValue,
  BIT3     unit
}

// 9.9.3.17 - 10.5.5.9/24.008
type record IdentityType2V
{
  BIT3         typeOfIdentity,
  BIT1         spare  //'0'B
}

// 9.9.3.18 - 10.5.5.10/24.008
type record IMEISV_RequestTV
{ 
  IMEISV_RequestV   iMEISV_Request,
  BIT4              elementIdentifier
} with {
  variant "PRESENCE (elementIdentifier = '1100'B)"
} 

type record IMEISV_RequestV
{
  BIT3         valueOfRequest,
  BIT1         spare  //'0'B
}

//9.9.3.19
type record KSIandSequenceNumberV
{
  BIT5              sequenceNumber,
  BIT3              kSI
}

// 9.9.3.20 - 10.5.5.12/24.008
type record  MSNetworkCapabilityTLV
{
  OCT1                         elementIdentifier,
  MSNetworkCapabilityLV        mSNetworkCapabilityLV
} with { 
  variant "PRESENCE (elementIdentifier = '31'O)" 
};


type record MSNetworkCapabilityLV
{
  LIN1                         lengthIndicator,
  MSNetworkCapabilityV         msNetworkCapabilityV
} with { variant (lengthIndicator) "LENGTHTO (msNetworkCapabilityV)";
  variant (msNetworkCapabilityV)    "PADDING(yes)"
};


type record MSNetworkCapabilityV    //length 3-10 octets
{
  BIT1               gea1bit,
  BIT1               smCapabilitiesviaDedicatedChannels,
  BIT1               smCapabilitiesviaGPRSChannels,
  BIT1               ucs2Support,
  BIT2               ssScreeningIndicator,
  BIT1               solSACapability            optional, //spare in V97
  BIT1               revisionLevelIndicatior    optional, //spare in V97
  BIT1               pFCFeatureMode             optional, //spare in V97(opt)
  BIT6               extendedGEAbits            optional, //spare in V97(opt)
  BIT1               lcsVAcapability            optional, //spare in V97(opt)
  BIT1               pSInterRATHOtoUTRANIuModeCapability optional,
  BIT1               pSInterRATHOtoEUTRANS1ModeCapability optional,//18
  BIT1               eMMCombinedProceduresCapability optional,
  BIT1               iSRSupport                  optional,
  BIT1               sRVCCtoGERANUTRANCapability optional,
  BIT1               epcCapability               optional, //22
  BIT1               nFCapability                optional,
  BIT1               gERANNwSharingCapability    optional,
  BIT1               userPlaneIntegrityProtectionSupport  optional,
  BIT1               gIA4                        optional,
  BIT1               gIA5                        optional,
  BIT1               gIA6                        optional,
  BIT1               gIA7                        optional, //29
  BIT1               ePCOIEIndicator             optional,
  BIT1               restrictionOnUseOfEnhancedCoverageCapability optional,
  BIT1               dualConnectivityOfEUTRANwithNRCapability optional,
  octetstring        spare_octets length(0..6)   optional
} with { variant "FIELDORDER(msb)" };

//9.9.3.20a  10.5.1.15/24.008
type record MS_NetworkFeatureSupportTV
{
  BIT1          extendedPeriodicTimers,
  BIT3          spare,
  BIT4          elementIdentifier
}

// 9.9.3.21
type record NAS_KeySetIdentifierTV
{
  NAS_KeySetIdentifierV     nAS_KeySetIdentifiervalue,
  BIT4                      elementIdentifier
} with { variant "PRESENCE (elementIdentifier = '1011'B)"; }

type record NAS_KeySetIdentifierV
{
  BIT3         identifier,
  BIT1         tSC  // set to "native security context (for KSIASME)" is supported
                    // set to "mapped security context (for KSISGSN)" is ignored if received
}

// 9.9.3.22
type record NAS_MessageContainerTLV
{
  OCT1                   elementIdentifier,
  NAS_MessageContainerLV nAS_MessageContainerLV
}

type record NAS_MessageContainerLV
{
  LIN1                      lengthIndicator,
  NAS_MessageList           nAS_MessageContainerV
} with {
  variant (lengthIndicator) "LENGTHTO (nAS_MessageContainerV)"  
}
//     7.2/24.011
type union NAS_MessageList
{
  CP_DATA   cP_DATA,
  CP_ACK    cP_ACK,
  CP_ERROR  cP_ERROR
} with {
  variant  "TAG
  (
   cP_DATA,   messageType = '01'O;
   cP_ACK,    messageType = '04'O;
   cP_ERROR,  messageType = '10'O;
  )"
}

type record CP_DATA
{
  BIT4  protocolDiscriminator,
  BIT4  transactionID,
  OCT1  messageType,
  CP_UserDataLV cp_UserDataLV
}

type record CP_UserDataLV
{
  LIN1          lengthIndicator,
  octetstring   rPDU length (0..248)
} with {
  variant (lengthIndicator) "LENGTHTO (rPDU)"  
}

type record CP_ACK
{
  BIT4  protocolDiscriminator,
  BIT4  transactionID,
  OCT1  messageType
}

type record CP_ERROR
{
  BIT4  protocolDiscriminator,
  BIT4  transactionID,
  OCT1  messageType,
  OCT1  cP_Cause
}

// 9.9.3.23
type record NAS_SecurityAlgorithmsV
{
  BIT3         typeOfIntegrityProtection, //EIA1 is supported
  BIT1         spare1,
  BIT3         typeOfCiphering, //EEA1 and EEA0 are supported
  BIT1         spare2
} with { variant "" }

// 9.9.3.24 - 10.5.3.5a/24.008
type record NetworkNameTLV
{
  OCT1                      elementIdentifier,
  NetworkNameLV             networkNameLV
} 

type record NetworkNameLV
{
  LIN1            lengthIndicator,
  NetworkNameV    networkNameV
} with {
  variant (lengthIndicator) "LENGTHTO (networkNameV)"
}

type record NetworkNameV
{
  BIT3               nSpareBits,
  BIT1               addCI,
  BIT3               codingScheme,
  BIT1               ext1, //'1'B
  octetstring        textString
  // actually the upper limit depends on the max size of the PDU, see 44.006
};

// 9.9.3.24A - 10.5.5.31/24.008
type record NetworkResourceIdentifierContainerTLV
{
  OCT1            elementIdentifier,
  NetworkResourceIdentifierContainerLV networkResourceIdentifierContainerLV
} with { variant "PRESENCE (elementIdentifier = '10'O)"; }

type record NetworkResourceIdentifierContainerLV
{
  LIN1            lengthIndicator,
  NetworkResourceIdentifierContainerV networkResourceIdentifierContainerV
} with {
  variant (lengthIndicator) "LENGTHTO (networkResourceIdentifierContainerV)"
}

type record NetworkResourceIdentifierContainerV
{
  BIT10       nRIContainerValue,
  BIT6        spare
} with {
  variant (nRIContainerValue) "BITORDER(msb)";
  variant (nRIContainerValue,spare) "FIELDORDER(msb)"
}

// 9.9.3.25
type record NonceTV
{
  OCT1            elementIdentifier,
  OCT4            noncevalue 
} // with { variant "PRESENCE (elementIdentifier = '55'O)"; }  

// 9.9.3.25A
type record PagingIdentityTV {
  OCT1            elementIdentifier,
  PagingIdentityV pagingIdentityValue
} 

type record PagingIdentityV {
  BIT1           pagingIdentityValue,
  BIT7           spare
}

// 9.9.3.26 - 10.5.5.8/24.008
type record P_TMSISignatureTV
{
  OCT1               elementIdentifier,
  OCT3               valueField
} with { variant "PRESENCE (elementIdentifier = '19'O)"; }

// 9.9.3.26A
type record ExtendedEMM_CauseTV
{
  BIT1               eUTRANallowedValue,
  BIT1               ePSoptimizationInfo,
  BIT2               spare,
  BIT4               elementIdentifier
} with { variant "PRESENCE (elementIdentifier = '1010'B)"; }

// 9.9.3.27
// represented as BIT4 in message

// 9.9.3.28 
type record ShortMACTV //not used
{
  OCT1              elementIdentifier,
  ShortMACV         shortMAC
} with {
  variant "PRESENCE (elementIdentifier = '00'O)" //??
}

type record ShortMACV //used
{
  OCT2               valueOfShortMAC
} 

// 9.9.3.29 - 10.5.3.8/24.008 
type record TimeZoneTV
{
  OCT1 elementIdentifier,
  OCT1 valueOfTimeZone
} with {
  variant "PRESENCE (elementIdentifier = '46'O)" //??
}


// 9.9.3.30 - 10.5.3.9/24.008 
type record TimeZoneAndTimeTV
{
  OCT1                  elementIdentifier,
  TimeZoneAndTimeV      timeZoneAndTimeV
} with {
  variant "PRESENCE (elementIdentifier = '47'O)" 
}

type record TimeZoneAndTimeV
{
  OCT1               year,
  OCT1               month,
  OCT1               day,
  OCT1               hour,
  OCT1               minute,
  OCT1               second,
  OCT1               timeZone
};

// 9.9.3.31 - 10.5.5.4/24.008 
type record TMSIStatusTV
{
  TMSIStatusV        tmsiStatusV,
  BIT4               elementIdentifier
} with { variant "PRESENCE (elementIdentifier = '1001'B)" };

type record TMSIStatusV
{
  BIT1               tmsiFlag,
  BIT3               spare // '000'B
};

// 9.9.3.32
type record TrackingAreaIdentityTV
{
  OCT1               elementIdentifier,
  HEX1               mccDigit1,
  HEX1               mccDigit2,
  HEX1               mccDigit3,
  HEX1               mncDigit3,
  HEX1               mncDigit1,
  HEX1               mncDigit2,
  OCT2               tAC
} with {
  variant "PRESENCE (elementIdentifier = '52'O)"
}

// 9.9.3.33
type record TrackingAreaIdentityListTLV
{
  OCT1                            elementIdentifier,
  TrackingAreaIdentityListLV      trackingAreaIdentityListsLV
} with {
  variant "PRESENCE (elementIdentifier = '54'O)"
} 

type record TrackingAreaIdentityListLV
{
  LIN1         lengthIndicator,
  TAI_Lists    trackingAreaIdentityLists
} with {
  variant (lengthIndicator) "LENGTHTO (trackingAreaIdentityLists)"
}

type record of TAI_List TAI_Lists; 

type union TAI_List {
  TAI_List000  list00,
  TAI_List001  list01,
  TAI_List010  list10     
} with {
  variant  "TAG
  (
   list00,   typeOfList = '00'B; 
   list01,   typeOfList = '01'B;
   list10,   typeOfList = '10'B;
  )"
} //only 00 is supported

type record TAI_List000
{
  integer     nrOfElements,
  BIT2        typeOfList,
  BIT1        spare,  //0
  HEX1        mccDigit1,
  HEX1        mccDigit2,
  HEX1        mccDigit3,
  HEX1        mncDigit3,
  HEX1        mncDigit1,
  HEX1        mncDigit2,
  OCT2        tAC1,
  TAC_List    additional_TACs optional    
} with {
  variant (nrOfElements) "FIELDLENGTH(5)";
  variant (nrOfElements) "LENGTHTO (additional_TACs)";
  variant (nrOfElements) "UNIT (elements)";
};

type record of OCT2 TAC_List;

type record TAI_List001
{
  integer     nrOfElements, //0
  BIT2        typeOfList,
  BIT1        spare,  //0
  HEX1        mccDigit1,
  HEX1        mccDigit2,
  HEX1        mccDigit3,
  HEX1        mncDigit3,
  HEX1        mncDigit1,
  HEX1        mncDigit2,  
  OCT2        tAC1  
} with {
  variant (nrOfElements) "FIELDLENGTH(5)"     
}

type record TAI_List010
{
  integer           nrOfElements,
  BIT2              typeOfList,
  BIT1              spare,  //0
  MCC_MNC_TAC       mCC_MNC_TAC1,     
  MCC_MNC_TAC_List  additional_MCC_MNC_TACs optional
} with {
  variant (nrOfElements) "FIELDLENGTH(5)";
  variant (nrOfElements) "LENGTHTO (additional_MCC_MNC_TACs)";
  variant (nrOfElements) "UNIT (elements)"
}

type record of MCC_MNC_TAC MCC_MNC_TAC_List;

type record MCC_MNC_TAC
{
  HEX1        mccDigit1,
  HEX1        mccDigit2,
  HEX1        mccDigit3,
  HEX1        mncDigit3,
  HEX1        mncDigit1,
  HEX1        mncDigit2,  
  OCT2        tAC  
}

// 9.9.3.34
type record UENetworkCapabilityTLV
{
  OCT1                            elementIdentifier,
  UENetworkCapabilityLV           uENetworkCapabilityLV
}with {
  variant "PRESENCE (elementIdentifier = '58'O)"
} 

type record UENetworkCapabilityLV
{
  LIN1                  lengthIndicator,    //2..13
  UENetworkCapabilityV  uENetworkCapabilityV
} with {
  variant (lengthIndicator) "LENGTHTO (uENetworkCapabilityV)"
}

type record UENetworkCapabilityV    // Supported algorithms are EEA0, EEA1 and EIA1
{
  BIT8     eEA,
  BIT8     eIA,  
  BIT8     uEA         optional,  
  BIT7     uIA         optional,
  BIT1     uCS2        optional,//4. octet
  BIT1     nF          optional,
  BIT1     vCC         optional,
  BIT1     lCS         optional,
  BIT1     lPP         optional,
  BIT1     aCC_CSFB    optional,
  BIT1     h245_ASH    optional,
  BIT1     proSe       optional,
  BIT1     proSe_dd    optional,//5. octet
  BIT1     proSe_dc    optional,
  BIT1     proSe_relay optional,
  BIT1     cP_CIoT     optional,
  BIT1     uP_CIoT     optional,
  BIT1     s1_Udata    optional,
  BIT1     eRwoPDN     optional, 
  BIT1     hC_CP_CIoT  optional,
  BIT1     ePCO        optional,//6. octet //0
  BIT1     multipleDRB optional,
  BIT1     v2XPC5      optional,
  BIT1     restrictEC  optional,
  BIT1     cPbackoff   optional,
  BIT1     dCNR        optional,
  BIT1     n1Mode      optional,
  BIT1     sGC         optional,
  BIT1     spare1      optional,
  octetstring spare length (0..6) optional //0
}

// 9.9.3.35
type record UE_RadioCapabilityInfoUpdateNeededTV
{
  BIT1    uRC_upd,
  BIT3    spare,
  BIT4    elementIdentifier   
} with{
  variant "PRESENCE (elementIdentifier = '1010'B)"
}

// 9.9.3.36
type record UESecurityCapabilityLV  // Supported algorithms are EEA0, EEA1 and EIA1
{
  LIN1              lengthIndicator,
  BIT8              eEA,    
  BIT8              eIA, 
  BIT8              uEA    optional,
  BIT7              uIA    optional,
  BIT1              spare2 optional,
  BIT7              gEA    optional,
  BIT1              spare3 optional
} with { 
  variant (lengthIndicator) "LENGTHTO (eEA,eIA,uEA,uIA,spare2,gEA,spare3)"
}

// 9.9.3.37 - 10.5.3.13/24.008
type record EmergencyNumber{
  LIN1        lengthOfEmergencyNumber,
  BIT5        emergencyServiceCategoryValue,
  BIT3        spare,
  octetstring emergencyNumberDigits  
} with { 
  variant (lengthOfEmergencyNumber) "LENGTHTO( emergencyServiceCategoryValue,spare,emergencyNumberDigits )"};

type record of EmergencyNumber EmergencyNumberList with { variant "" }; 

type record EmergencyNumberListTLV {
  OCT1                elementIdentifier,
  LIN1                lengthIndicator, //  
  EmergencyNumberList emergencyNumberList 
} with { 
  variant "PRESENCE (elementIdentifier = '34'O)"
  variant (lengthIndicator) "LENGTHTO( emergencyNumberList )"};

// 9.9.3.37A The decode and details of this IE are FFS
type record ExtendedEmergencyNumber{
  LIN1        lengthOfExtendedEmergencyNumber,
  octetstring extendedEmergencyNumber  
} with { 
  variant (lengthOfExtendedEmergencyNumber) "LENGTHTO( extendedEmergencyNumber )"};

type record of ExtendedEmergencyNumber ExtendedEmergencyNumberList with { variant "" }; 

type record ExtendedEmergencyNumberListTLV {
  OCT1                        elementIdentifier,
  LIN1                        lengthIndicator,
  ExtendedEmergencyNumberList extendedEmergencyNumberList
} with { 
  variant (lengthIndicator) "LENGTHTO( extendedEmergencyNumberList )"
};

// 9.9.3.38
type record CLITLV
{
  OCT1              elementIdentifier,
  CLILV             cLILV

} with { variant "PRESENCE (elementIdentifier = '60'O)"; };

type record CLILV
{
  LIN1              lengthIndicator,
  CLI_Value         cLI_Value
} with {
  variant (lengthIndicator) "LENGTHTO (cLI_Value)" 
}

type record CLI_Value  //10.5.4.9/24.008
{
  BIT4          numberingPlanId,
  BIT3          typeOfNumber,
  BIT1          extensionBit,
  BIT2          screeningIndicator optional,
  BIT3          spare optional, //'000'
  BIT2          presentationIndicator optional,
  BIT1          extensionBit2 optional,  //'1'B
  hexstring     digits optional
} with {
  variant (screeningIndicator,spare,presentationIndicator,extensionBit2)"PRESENCE(extensionBit = '0'B)"; 
  variant "PADDING(yes)";
  variant "PADDING_PATTERN('1111'B)"
}

// 9.9.3.39
type record SS_CodeTV
{
  OCT1        elementIdentifier,
  OCT1        sS_CodeValue
} with{
  variant "PRESENCE (elementIdentifier = '61'O)"
}

// 9.9.3.40
type record LCS_IndicatorTV
{
  OCT1         elementIdentifier,
  OCT1         lCS_IndicatorValue    
} with {
  variant "PRESENCE (elementIdentifier = '62'O)"
}; 

// 9.9.3.41
type record LCS_ClientIdentityTLV
{
  OCT1                      elementIdentifier,
  LCS_ClientIdentityLV      lCS_ClientIdentityLV

} with { variant "PRESENCE (elementIdentifier = '63'O)"; };

type record LCS_ClientIdentityLV
{
  LIN1            lengthIndicator,
  octetstring     LCS_ClientIdentity length (1..255)
} with {
  variant (lengthIndicator) "LENGTHTO (LCS_ClientIdentity)" 
}

// 9.9.3.42
type OCT1 Generic_MessageContainerTypeV

// 9.9.3.43
type record Generic_MessageContainerLVE
{
  LIN2_BO_LAST      lengthIndicator,
  octetstring       content length (1..65535)
} with { 
  variant (lengthIndicator) "LENGTHTO (content)"
}

// 9.9.3.44 - 10.5.5.28/24.008
type record VoiceDomainPrefandUEsettingsTLV {
  OCT1                elementIdentifier,
  LIN1                lengthIndicator,  
  BIT2                voiceDomainPrefforEUTRAN,
  BIT1                uEsUsageSettings,
  BIT5                spare 
} with { 
  variant "PRESENCE (elementIdentifier = '5D'O)"
  variant (lengthIndicator) "LENGTHTO(voiceDomainPrefforEUTRAN,uEsUsageSettings,spare)"
};

// 9.9.3.45 
type record GUTI_TypeTV
{
  BIT1      gUTI_Type,
  BIT3      spare,
  BIT4      elementIdentifier      
} with{
  variant "PRESENCE (elementIdentifier = '1110'B)"
}

// 9.9.3.46 - 10.5.5.32/24.008
type record ExtendedDRXParametersTLV
{
  OCT1       elementIdentifier,
  LIN1       lengthIndicator,
  BIT4       eDRXvalue,
  BIT4       pagingTimeWindow
} with{
  variant "PRESENCE (elementIdentifier = '6E'O)"
  variant (lengthIndicator) "LENGTHTO (eDRXvalue,pagingTimeWindow)";
}

// 9.9.3.47
type record ControlPlaneServiceTypeTV
{
  ControlPlaneServiceTypeV controlPlaneServiceType,
  BIT4             elementIdentifier  //??
}

type record ControlPlaneServiceTypeV
{
  BIT3 controlPlaneServiceTypeValue,
  BIT1 activeFlag
}

// 9.9.3.48 - 10.5.5.35/24.008
type record DCNIDTLV
{
  OCT1       elementIdentifier,
  LIN1       lengthIndicator,
  OCT2       dCNIDvalue
} with{
  variant "PRESENCE (elementIdentifier = '65'O)"
  variant (lengthIndicator) "LENGTHTO (dCNIDvalue)";
}

// 9.9.3.49- 10.5.5.37/24.008
type record Non3GPP_NW_ProvidedPoliciesTV
{
  BIT1       n3EN_Indicator,
  BIT3       spare,
  BIT4       elementIdentifier
} with{
  variant "PRESENCE (elementIdentifier = '1101'B)"
}

// 9.9.3.50
type record HashTLV
{
  OCT1       elementIdentifier,
  LIN1       lengthIndicator,
  OCT8       hashMMEvalue
} with{
  variant "PRESENCE (elementIdentifier = '4F'O)"
  variant (lengthIndicator) "LENGTHTO (hashMMEvalue)";
}

// 9.9.3.51
type record ReplayedNASMessageContainerTLVE
{
  OCT1        elementIdentifier,
  LIN1        lengthIndicator,
  octetstring contents length (1..65535)
} with{
  variant "PRESENCE (elementIdentifier = '79'O)"
  variant (lengthIndicator) "LENGTHTO (contents)" 
}

// 9.9.3.52
type record NetworkPolicyTV
{
  BIT1       redirPolicy,
  BIT3       spare,
  BIT4       elementIdentifier
} with{
  variant "PRESENCE (elementIdentifier = '1100'B)"
}

// 9.9.3.53
type record UEAdditionalSecurityCapabilityTLV
{
  OCT1        elementIdentifier,
  LIN1        lengthIndicator,
  UEAdditionalSecurityCapabilityV uEAdditionalSecurityCapabilityV
} with { 
  variant "PRESENCE (elementIdentifier = '6F'O)"
  variant (lengthIndicator) "LENGTHTO (uEAdditionalSecurityCapabilityV)"
}

type record UEAdditionalSecurityCapabilityV
{
  BIT1              fiveG_eA7,    
  BIT1              fiveG_eA6,    
  BIT1              fiveG_eA5,    
  BIT1              fiveG_eA4,    
  BIT1              fiveG_eA3_128,    
  BIT1              fiveG_eA2_128,    
  BIT1              fiveG_eA1_128,    
  BIT1              fiveG_eA0,    
  BIT1              fiveG_eA15,    
  BIT1              fiveG_eA14,    
  BIT1              fiveG_eA13,    
  BIT1              fiveG_eA12,    
  BIT1              fiveG_eA11,    
  BIT1              fiveG_eA10,    
  BIT1              fiveG_eA9,    
  BIT1              fiveG_eA8,    
  BIT1              fiveG_iA7,    
  BIT1              fiveG_iA6,    
  BIT1              fiveG_iA5,    
  BIT1              fiveG_iA4,    
  BIT1              fiveG_iA3_128,    
  BIT1              fiveG_iA2_128,    
  BIT1              fiveG_iA1_128,    
  BIT1              fiveG_iA0,    
  BIT1              fiveG_iA15,    
  BIT1              fiveG_iA14,    
  BIT1              fiveG_iA13,    
  BIT1              fiveG_iA12,    
  BIT1              fiveG_iA11,    
  BIT1              fiveG_iA10,    
  BIT1              fiveG_iA9,    
  BIT1              fiveG_iA8    
}

// 9.9.3.54 3GPP TS 24.501 9.10.3.52
type record UEStatusTLV
{
  OCT1        elementIdentifier,
  LIN1        lengthIndicator,
  UEStatusV   uEStatusV
} with { 
  variant "PRESENCE (elementIdentifier = '6D'O)"
  variant (lengthIndicator) "LENGTHTO (uEStatusV)"
}

type record UEStatusV
{
  BIT1 s1ModeReg,
  BIT1 n1ModeReg,
  BIT5 spare
}

//=================================================================    
// EPS Session Management (ESM) information elements - 9.9.4/24.301 
//=================================================================


// 9.9.4.1 - 10.5.6.1/24.008 
type record AccessPointNameTLV 
{
  OCT1                      elementIdentifier,
  AccessPointNameLV         accessPointNamevalue
} with{
  variant "PRESENCE (elementIdentifier = '28'O)"
}

type record AccessPointNameLV 
{ 
  LIN1               lengthIndicator,
  octetstring        accessPointNameValue length (1..100)
} with{ 
  variant (lengthIndicator) "LENGTHTO (accessPointNameValue)";
} 


// 9.9.4.2
type record APN_AggregateMaximumBitRateTLV
{ 
  OCT1                      elementIdentifier,
  LIN1                      lengthIndicator,
  AggregateMaximumBitRateV  aggregateMaximumBitRateV
} with{ 
  variant "PRESENCE (elementIdentifier = '5E'O)"
  variant (lengthIndicator) "LENGTHTO (aggregateMaximumBitRateV)";
} 

type record AggregateMaximumBitRateV
{
  OCT1         aPN_AMBR_Downlink,
  OCT1         aPN_AMBR_Uplink,
  OCT1         aPN_AMBR_DownlinkExt  optional,
  OCT1         aPN_AMBR_UplinkExt    optional,
  OCT1         aPN_AMBR_DownlinkExt2 optional,
  OCT1         aPN_AMBR_UplinkExt2   optional
}

// 9.9.4.2a 10.5.6.19/24.008
type record ConnectivityTypeTV
{
  BIT4     connectivityTypeValue,
  BIT4     elementIdentifier 
} with{
  variant "PRESENCE (elementIdentifier = '1011'B)"
}

// 9.9.4.3
type record EPS_QualityOfServiceTLV
{
  OCT1                      elementIdentifier,
  LIN1                      lengthIndicator,
  EPS_QualityOfServiceV     ePS_QualityOfServiceV
} with{ 
  variant "PRESENCE (elementIdentifier = '5B'O)"
  variant (lengthIndicator) "LENGTHTO (ePS_QualityOfServiceV)";
}


type record EPS_QualityOfServiceLV
{
  LIN1                      lengthIndicator,
  EPS_QualityOfServiceV     ePS_QualityOfServiceV
} with{ 
  variant (lengthIndicator) "LENGTHTO (ePS_QualityOfServiceV)";
}

type record EPS_QualityOfServiceV 
{ 
  OCT1   qCI, 
  OCT1   maxBitRateUplink              optional,  
  OCT1   maxBitRateDownlink            optional, 
  OCT1   guaranteedBitRateUplink       optional,
  OCT1   guaranteedBitRateDownlink     optional, 
  OCT1   maxBitRateUplinkExt           optional,
  OCT1   maxBitRateDownlinkExt         optional,
  OCT1   guaranteedBitRateUplinkExt    optional,
  OCT1   guaranteedBitRateDownlinkExt  optional,
  OCT1   maxBitRateUplinkExt2          optional,
  OCT1   maxBitRateDownlinkExt2        optional,
  OCT1   guaranteedBitRateUplinkExt2   optional,
  OCT1   guaranteedBitRateDownlinkExt2 optional
} 

// 9.9.4.4
type record ESM_CauseTV
{
  OCT1        elementIdentifier,
  ESM_CauseV  causeValue
} with{
  variant "PRESENCE (elementIdentifier = '58'O)"
}

type record ESM_CauseV
{
  OCT1    causeValue
}

// 9.9.4.5
type record ESM_InformationTransferFlagTV
{
  BIT1     eIT,
  BIT3     spare,
  BIT4     elementIdentifier
} with{
  variant "PRESENCE (elementIdentifier = '1101'B)"
}

// 9.9.4.6
type record Linked_EPS_BearerIdentityV
{
  BIT4     linked_EPS_BearerIdentityValue  
}

// 9.9.4.7 - 10.5.6.9/24.008
type record LLC_SAPITV
{
  OCT1               elementIdentifier,
  LLC_SAPIV          valueField
} with { variant "PRESENCE (elementIdentifier = '32'O)"; };


type record  LLC_SAPIV
{
  BIT4               valueField,
  BIT4               spare        //'0000'B
};

// 9.9.4.7A
type record NotificationIndicatorLV
{
  LIN1               lengthIndicator,
  BIT8               valueField
} with {
  variant (lengthIndicator) "LENGTHTO (valueField)"
};

// 9.9.4.8 - 10.5.6.11/24.008
type record PacketFlowIDTLV
{
  OCT1               elementIdentifier,
  LIN1               lengthIndicator,
  PacketFlowIDV      valueField
} with {
  variant "PRESENCE (elementIdentifier = '34'O)";
  variant (lengthIndicator) "LENGTHTO (valueField)"
};


type record PacketFlowIDV
{
  BIT7               valueField,
  BIT1               spare   // '0'B
};

// 9.9.4.9
type record PDN_AddressLV
{  
  LIN1                     lengthIndicator,
  BIT3                     typeValue,
  BIT5                     spare,
  octetstring              addressInformation length (4..12)
} with {
  variant (lengthIndicator) "LENGTHTO (typeValue,spare,addressInformation)"
}

// 9.9.4.10
type record PDN_TypeV
{
  BIT3                     pDN_TypeValue,
  BIT1                     spare  //'0'B
}

// 9.9.4.11 - 10.5.6.3/24.008
type record ProtocolConfigOptionsTLV
{
  OCT1                      elementIdentifier,
  ProtocolConfigOptionsLV   protocolConfigOptions
} with{
  variant "PRESENCE (elementIdentifier = '27'O)"
}

type record ProtocolConfigOptionsLV
{
  LIN1                    lengthIndicator,
  ProtocolConfigOptionsV  protocolConfigOptionsV
} with {
  variant (lengthIndicator) "LENGTHTO (protocolConfigOptionsV)"
}

type record ProtocolConfigOptionsV
{
  BIT3                          configProtocol,
  BIT4                          spare,
  BIT1                          extensionField,
  ProtocolIDs_and_ContainerIDs  protocolIDs_and_ContainerIDs optional
}

type record length (1..250) of  ProtocolID_or_ContainerID  ProtocolIDs_and_ContainerIDs;

type record ProtocolID_or_ContainerID
{
  OCT2         protocolID_or_ContainerID,
  LIN1         lengthIndicator,
  octetstring  protID_orContID_Contents
} with {
  variant (lengthIndicator) "LENGTHTO (protID_orContID_Contents)"
}

// 9.9.4.12 -10.5.6.5/24.008
type record  QoSTLV
{
  OCT1               elementIdentifier,
  QoSLV              qoSLV
} with { variant "PRESENCE (elementIdentifier = '30'O)"; };


type record  QoSLV
{
  LIN1               lengthIndicator,
  QoSV               qoSV
} with { variant (lengthIndicator) "LENGTHTO (qoSV)"};


type record QoSV
{
  BIT3               reliabilityClass,
  BIT3               delayClass,
  BIT2               spare1,  // '00'B
  BIT3               precedenceClass,
  BIT1               spare2, //'0'B
  BIT4               peakThroughput,
  BIT5               meanThroughput,
  BIT3               spare3, //'000'B
  BIT3               deliverErroneusSDU            optional, //opt because of V97
  BIT2               deliveryOrder                 optional, //opt because of V97
  BIT3               trafficClass                  optional, //opt because of V97
  OCT1               maxSDUSize                    optional, //opt because of V97
  OCT1               maxBitrateUplink              optional, //opt because of V97
  OCT1               maxBitrateDownlink            optional, //opt because of V97
  BIT4               sduErrorRatio                 optional, //opt because of V97
  BIT4               residualBER                   optional, //opt because of V97 //oct10
  BIT2               trafficHandlingPriority       optional, //opt because of V97
  BIT6               transferDelay                 optional, //opt because of V97
  OCT1               guaranteedBitRateUplink       optional, //opt because of V97
  OCT1               guaranteedBitRateDownlink     optional, //opt because of V97 //oct13
  BIT4               sourceStatisticsDescriptor    optional, //opt because of V97
  BIT1               signallingIndication          optional, //opt because of V97
  BIT3               spare4                        optional, //opt because of V97 // '000'B //oct14
  OCT1               maxBitrateDownlinkExt         optional, //opt because of V97
  OCT1               guaranteedBitRateDownlinkExt  optional, //opt because of V97
  OCT1               maxBitrateUplinkExt           optional, //opt because of V97
  OCT1               guaranteedBitRateUplinkExt    optional, //opt because of V97 //oct 18
  OCT1               maxBitrateDownlinkExt2        optional, 
  OCT1               guaranteedBitRateDownlinkExt2 optional, 
  OCT1               maxBitrateUplinkExt2          optional, 
  OCT1               guaranteedBitRateUplinkExt2   optional   //oct 22

};
// 9.9.4.13 - 10.5.7.2/24.008
type record RadioPriorityTV {
  RadioPriorityV     valueField,
  BIT4               elementIdentifier
} with { variant "PRESENCE (elementIdentifier = '1000'B)"; };


type record RadioPriorityV
{
  BIT3               priorityLevelValue,
  BIT1               spare  // '0'B
};

// 9.9.4.13A
type record ReAttemptIndicatorTLV
{
  OCT1                       elementIdentifier,
  ReAttemptIndicatorLV       reAttemptIndicatorLV 
} with {
  variant "PRESENCE (elementIdentifier = '6B'O)"
}

type record ReAttemptIndicatorLV
{
  LIN1                       lengthIndicator,
  ReAttemptIndicatorV        valueField
} with { variant (lengthIndicator) "LENGTHTO(valueField)"};

type record ReAttemptIndicatorV
{
  BIT1      rATC,
  BIT1      ePLMNC,
  BIT6      spare //O  
}

// 9.9.4.14 - 10.5.6.17/24.008
type record RequestTypeV
{
  BIT3         requestTypeValue,
  BIT1         spare  //'0'B
}

// 9.9.4.15
type TrafficFlowTemplateLV TrafficFlowAggregateDescriptionLV

// 9.9.4.16 - 10.5.6.12/24.008
type record TrafficFlowTemplateLV
{
  LIN1                         lengthIndicator,
  TrafficFlowTemplateV         valueField
} with { variant (lengthIndicator) "LENGTHTO(valueField)"};

type record TrafficFlowTemplateTLV
{
  OCT1                         elementIdentifier,
  LIN1                         lengthIndicator,
  TrafficFlowTemplateV         valueField
} with {
   variant (lengthIndicator) "LENGTHTO(valueField)"
   variant  "PRESENCE (elementIdentifier = '36'O)" 
};


type union TrafficFlowTemplateV
{
  TrafficFlowTemplateV_CreateAddReplaceTFT
  trafficFlowTemplateV_CreateAddReplaceTFT,
  TrafficFlowTemplateV_DeletePacketFilter
  trafficFlowTemplateV_DeletePacketFilter,
  TrafficFlowTemplateV_Delete_Existing_TFT_or_No_TFT_Operation
  trafficFlowTemplateV_Delete_Existing_TFT_or_No_TFT_Operation
};

type record TrafficFlowTemplateV_CreateAddReplaceTFT
{
  integer                                numberOfPacketFilters,
  BIT1                                   eBIT,
  BIT3                                   operationCodeTFT,  //'001'B or
  PacketFilterList_CreateAddReplaceTFT   packetFilterList_CreateAddReplaceTFT,
  ParametersList                         parametersList            optional
} with {
  variant "PRESENCE (operationCodeTFT  = '001'B, //  Create New TFT
                     operationCodeTFT  = '011'B, //  Add packet filters to existing TFT
                     operationCodeTFT  = '100'B  //  Replace packet filters in existing TFT
  )";
  variant(parametersList)       "PRESENCE(eBIT = '1'B)";
  variant(numberOfPacketFilters)"FIELDLENGTH(4)";
  variant(numberOfPacketFilters)"LENGTHTO(packetFilterList_CreateAddReplaceTFT)";
  variant(numberOfPacketFilters)"UNIT(elements)";
};

type record TrafficFlowTemplateV_DeletePacketFilter
{
  integer                                numberOfPacketFilters,
  BIT1                                   eBIT,
  BIT3                                   operationCodeTFT,
  PacketFilterList_DeletePacketFilter    packetFilterList_DeletePacketFilter,
  ParametersList                         parametersList         optional
} with {
  variant "PRESENCE (operationCodeTFT = '101'B)"  // Delete packet filters from existing TFT
  variant(parametersList) "PRESENCE(eBIT = '1'B)";
  variant(numberOfPacketFilters)"FIELDLENGTH(4)";
  variant(numberOfPacketFilters)"LENGTHTO(packetFilterList_DeletePacketFilter)";
  variant  (numberOfPacketFilters)"UNIT(elements)";
};


type record TrafficFlowTemplateV_Delete_Existing_TFT_or_No_TFT_Operation
{
  BIT4                         numberOfPacketFilters, //'0000'B
  // numberOfPacketFilters is meaningless here since there is no PacketFilterList
  BIT1                         eBIT,
  BIT3                         operationCodeTFT,      // '010'B  or '110'B
  ParametersList               parametersList   optional
} with {
  variant "PRESENCE (operationCodeTFT = '000'B,  // ignore this IE
                     operationCodeTFT = '010'B,  // delete existing TFT
                     operationCodeTFT = '110'B   // No TFT Operation
  )";
  variant (parametersList) "PRESENCE(eBIT = '1'B)"
};

type record of PacketFilter PacketFilterList_CreateAddReplaceTFT;

type record PacketFilter
{
  PacketFilterIdentifier       identifier,
  OCT1                         evaluationPrecedence,
  LIN1                         lengthIndicator,
  octetstring                  contents
} with { variant (lengthIndicator) "LENGTHTO (contents)"};


type record of PacketFilterIdentifier  PacketFilterList_DeletePacketFilter;


type OCT1  PacketFilterIdentifier;


type record of Parameter ParametersList;


type record Parameter
{
  OCT1               parameterIdentifier,
  LIN1               lengthIndicator,
  octetstring        contents
} with { variant (lengthIndicator) "LENGTHTO (contents)"};

// 9.9.4.17
// 24.008 Linked TI - 10.5.6.7
type record TransactionIdentifierTLV
{
  OCT1                            elementIdentifier,
  TransactionIdentifierLV         transactionIdentifierLV
} with {
  variant "PRESENCE (elementIdentifier = '5D'O)"
}

type record TransactionIdentifierLV
{
  LIN1                     lengthIndicator,
  TransactionIdentifierV   transactionIdentifierV
} with { variant (lengthIndicator) "LENGTHTO (transactionIdentifierV)"};

type record TransactionIdentifierV
{
  BIT4               spare,  //'0000'B
  BIT3               tio,
  BIT1               tiFlag,
  TI_Extension       tIExtension  optional
} with { variant (tIExtension)"PRESENCE(tio = '111'B)"}; //???

type record        TI_Extension
{
  BIT7               tI_Value,
  BIT1               tI_ExtBit         //'1'B
};

// 9.9.4.18
// 24.008 - 10.5.6.20
type record WLANOffloadAcceptabilityTV
{
  WLANOffloadAcceptabilityV valueField,
  BIT4                      elementIdentifier
} with { variant "PRESENCE (elementIdentifier = '1100'B)"; };

type record WLANOffloadAcceptabilityV
{
  BIT1 eUTRAN_offloadAcceptabilityValue,
  BIT1 uTRAN_offloadAcceptabilityValue,
  BIT2 spare
}

// 9.9.4.19
// 24.008 -  10.5.6.21 NBIFOM container
type record NBIFOM_ContainerTLV
{
  OCT1                   elementIdentifier,
  LIN1                   lengthIndicator,
  NBIFOM_ParameterList   contents
} with { variant "PRESENCE (elementIdentifier = '33'O)";
  variant (lengthIndicator) "LENGTHTO (contents)" };

// 6.1 - TS 24.161
type record of NBIFOM_Parameter NBIFOM_ParameterList;

type record NBIFOM_Parameter
{
  OCT1         parameterIdentifier,
  LIN1         lengthIndicator,
  NBIFOM_ParameterContents parameterContents
} with {  variant (lengthIndicator) "LENGTHTO (parameterContents)";
  variant (parameterContents) "CROSSTAG(
    nBIFOM_Mode, parameterIdentifier = '01'O;
    nBIFOM_DefaultAccess, parameterIdentifier = '02'O;
    nBIFOM_Status, parameterIdentifier = '03'O;
    nBIFOM_RoutingRules, parameterIdentifier = '04'O;
    nBIFOM_IPFlowMapping, parameterIdentifier = '05'O;
    nBIFOM_RANRulesHandling, parameterIdentifier = '06'O;
    nBIFOM_RANRulesStatus, parameterIdentifier = '07'O;
    nBIFOM_AccessUsabilityIndication, parameterIdentifier = '08'O;
    unknownParameter, OTHERWISE)"};

type union NBIFOM_ParameterContents
{
  OCT1 nBIFOM_Mode,
  OCT1 nBIFOM_DefaultAccess,
  OCT1 nBIFOM_Status,
  NBIFOM_RoutingRules nBIFOM_RoutingRules,
  NBIFOM_RoutingRules nBIFOM_IPFlowMapping,
  OCT1 nBIFOM_RANRulesHandling,
  OCT1 nBIFOM_RANRulesStatus,
  NBIFOM_AccessUsabilityIndication nBIFOM_AccessUsabilityIndication,
  octetstring unknownParameter
};

type record of NBIFOM_RoutingRule NBIFOM_RoutingRules
type record NBIFOM_RoutingRule
{
  LIN1         lengthIndicator,
  OCT1         routingRuleIdentifier,
  BIT3         operationCode,
  BIT3         spare,
  BIT2         routingAccess,
  OCT1         routingRulePrioroty,
  RoutingFilter routingFilter
} with {  variant (lengthIndicator) "LENGTHTO (routingRuleIdentifier,operationCode,
  spare,routingAccess,routingRulePrioroty,routingFilter)";}

type record RoutingFilter
{
  BIT1 flagA,
  BIT1 flagB,
  BIT1 flagC,
  BIT1 flagD,
  BIT1 flagE,
  BIT1 flagF,
  BIT1 flagG,
  BIT1 flagH,
  BIT1 flagI,
  BIT1 flagJ,
  BIT1 flagK,
  BIT1 flagL,
  BIT1 flagM,
  BIT1 flagN,
  bitstring flagsZ length(18),
  OCT4  sourceIPv4Address optional,
  OCT4  destinationIPv4Address optional,
  OCT16 sourceIPv6Address optional,
  OCT16 destinationIPv6Address optional,
  OCT1  sourceAddressPrefixLength optional,
  OCT1  destinationAddressPrefixLength optional,
  OCT4  iPSecSecurityParameterIndex optional,
  OCT1  protocolTypeNextHeader optional,
  OCT4  startSourcePortRange optional,
  OCT4  endSourcePortRange optional,
  OCT4  startDestinationPortRange optional,
  OCT4  endDestinationPortRange optional,
  OCT1  typeOfService optional,
  OCT4  flowLabel optional
}  with { variant (sourceIPv4Address)  "PRESENCE(flagA = '1'B)";
  variant (destinationIPv4Address)  "PRESENCE(flagB = '1'B)";
  variant (sourceIPv6Address)  "PRESENCE(flagC = '1'B)";
  variant (destinationIPv6Address)  "PRESENCE(flagD = '1'B)";
  variant (sourceAddressPrefixLength)  "PRESENCE(flagE = '1'B)";
  variant (destinationAddressPrefixLength)  "PRESENCE(flagF = '1'B)";
  variant (iPSecSecurityParameterIndex)  "PRESENCE(flagG = '1'B)";
  variant (protocolTypeNextHeader)  "PRESENCE(flagH = '1'B)";
  variant (startSourcePortRange)  "PRESENCE(flagI = '1'B)";
  variant (endSourcePortRange)  "PRESENCE(flagJ = '1'B)";
  variant (startDestinationPortRange)  "PRESENCE(flagK = '1'B)";
  variant (endDestinationPortRange)  "PRESENCE(flagL = '1'B)";
  variant (typeOfService)  "PRESENCE(flagM = '1'B)";
  variant (flowLabel)  "PRESENCE(flagN = '1'B)";
}

type record NBIFOM_AccessUsabilityIndication
{
  BIT2 threeGPPAccessUsableValue,
  BIT2 wLANAccessUsableValue,
  BIT4 spare
}

// 9.9.4.20
type record RemoteUEContextListTLVE
{
  OCT1                   elementIdentifier,
  LIN1                   lengthIndicator,
  LIN1                   nrOfContents,
  RemoteUEContextList    contents
} with {
  variant (lengthIndicator) "LENGTHTO (nrOfContents, contents)" 
  variant (nrOfContents) "LENGTHTO (contents)";
  variant (nrOfContents) "UNIT (elements)";
};

type record of RemoteUEContext RemoteUEContextList;

type record RemoteUEContext
{
  LIN1               lengthIndicator,
  LIN1               numberOfUserIDs,
  RemoteUserIDList   userIDList,
  BIT3               addressType optional,
  BIT5               spare optional,
  AddressInformation addressInformation optional
} with {
  variant (lengthIndicator) "LENGTHTO (numberOfUserIDs,userIDList,addressType,spare,addressInformation)";
  variant (numberOfUserIDs)"LENGTHTO(userIDList)";
  variant (numberOfUserIDs)"UNIT(elements)";
  variant (addressInformation) "CROSSTAG(
		ipv4, addressType = '001'B;
		ipv6, addressType = '010'B)";
  };

type record of RemoteUserID RemoteUserIDList;

type record RemoteUserID
{
  LIN1               lengthIndicator,
  BIT3               typeOfUserInfo,
  OddEvenInd_IdentityDigits   digits
} with {
  variant (lengthIndicator) "LENGTHTO (typeOfUserInfo,digits)";
  variant (digits) "CROSSTAG(
    encriptedIMSI, typeOfUserInfo = '001'B;
    iMSI, typeOfUserInfo = '010'B;
    mSISDN, typeOfUserInfo = '011'B;
    iMEI, typeOfUserInfo = '100'B;
    iMEI_SV, typeOfUserInfo = '101'B)";
  };

type union AddressInformation
{
  OCT6 ipv4,
  OCT8 ipv6
}

type union OddEvenInd_IdentityDigits
{
  EncriptedIMSI encriptedIMSI,
  IMSI iMSI,
  MSISDN mSISDN,
  IMEI iMEI,
  IMEI_SV iMEI_SV
}

type record MSISDN
{
  BIT1               oddevenIndicator,       
  hexstring          digits,
  BIT4               fillerDigit  optional   // filler '1111'B 
} with {
  variant (fillerDigit) "PRESENCE (oddevenIndicator   = '0'B) "
}

type record EncriptedIMSI
{
  BIT1       oddevenIndicator,       
  BIT4       spare,
  bitstring  encriptedIMSI length(128)
}

// 9.9.4.21
type record PKMF_AddressTLV
{
  OCT1               elementIdentifier,
  LIN1               lengthIndicator,
  BIT3               addressType,
  BIT5               spare,
  PKMF_Address       addressInformation optional
} with {
  variant (lengthIndicator) "LENGTHTO (addressType,spare,addressInformation)";
  variant (addressInformation) "CROSSTAG(
		ipv4, addressType = '001'B;
		ipv6, addressType = '010'B)";
}

type union PKMF_Address
{
  OCT4  ipv4,
  OCT16 ipv6
}

// 9.9.4.22
type record HeaderCompressinConfigurationTLV
{
  OCT1               elementIdentifier,
  LIN1               lengthIndicator,
  HeaderCompressinConfigurationV headerCompressinConfiguration
} with {
  variant "PRESENCE (elementIdentifier = '66'O)";
  variant (lengthIndicator) "LENGTHTO (headerCompressinConfiguration)"
  };

type record HeaderCompressinConfigurationV
{
  BIT1 p0x0002,
  BIT1 p0x0003,
  BIT1 p0x0004,
  BIT1 p0x0006,
  BIT1 p0x0102,
  BIT1 p0x0103,
  BIT1 p0x0104,
  BIT1 spare,
  OCT2 max_CID,
  octetstring additionalHeaderCompression optional
}

// 9.9.4.23
type record ControlPlaneOnlyIndicationTV
{
  BIT1 cPOI,
  BIT3 spare,
  BIT4 elementIdentifier
} with { 
  variant "PRESENCE (elementIdentifier = '1001'B)";
}

// 9.9.4.24
type record UserDataContainerLVE
{
  LIN2_BO_LAST       lengthIndicator,
  octetstring        contents
} with { variant (lengthIndicator) "LENGTHTO(contents)"};

// 9.9.4.25
type record ReleaseAssistanceIndicationTV
{
  BIT2             dDX,
  BIT2             spare,
  BIT4             elementIdentifier
} with { 
  variant "PRESENCE (elementIdentifier = '1111'B)";
}


// 9.9.4.26 24.008 / 10.5.6.3A
type record ExtendedProtocolConfigurationOptionsTLVE
{
  OCT1               elementIdentifier,
  LIN2_BO_LAST       lengthIndicator,
  octetstring        extendedProtocolConfigurationOptions length(1..65535)
} with {
  variant "PRESENCE (elementIdentifier = '7B'O)";
  variant (lengthIndicator) "LENGTHTO (extendedProtocolConfigurationOptions)"
  };

// 9.9.4.27
type record HeaderCompressionConfigurationStatusTLV
{
  OCT1               elementIdentifier,
  LIN1               lengthIndicator,
  HeaderCompressionConfigurationStatusV headerCompressionConfigurationStatus
} with {
  variant "PRESENCE (elementIdentifier = '68'O)";
  variant (lengthIndicator) "LENGTHTO (headerCompressionConfigurationStatus)"
};

type record HeaderCompressionConfigurationStatusV
{
  BIT1              ebi0,
  BIT1              ebi1,
  BIT1              ebi2,
  BIT1              ebi3,
  BIT1              ebi4,
  BIT1              ebi5,
  BIT1              ebi6,
  BIT1              ebi7,
  BIT1              ebi8,
  BIT1              ebi9,
  BIT1              ebi10,
  BIT1              ebi11,
  BIT1              ebi12,
  BIT1              ebi13,
  BIT1              ebi14,
  BIT1              ebi15
}

// 9.9.4.28
type record ServingPLMNRateControlTLV
{
  OCT1               elementIdentifier,
  LIN1               lengthIndicator,
  LIN2_BO_LAST       servingPLMNRateControlValue
} with {
  variant "PRESENCE (elementIdentifier = '6E'O)";
  variant (lengthIndicator) "LENGTHTO (servingPLMNRateControlValue)"
};

// 9.9.4.29
type record Extended_APN_AMBR_TLV
{
  OCT1               elementIdentifier,
  LIN1               lengthIndicator,
  Extended_APN_AMBR_V  extended_APN_AMBR_Value
} with {
  variant "PRESENCE (elementIdentifier = '5F'O)";
  variant (lengthIndicator) "LENGTHTO (extended_APN_AMBR_Value)"
};

type record Extended_APN_AMBR_V
{
  OCT1 unit_Extended_APN_AMBR_Downlink,
  OCT2 extended_APN_AMBR_Downlink,
  OCT1 unit_Extended_APN_AMBR_Uplink,
  OCT2 extended_APN_AMBR_Uplink
}

// 9.9.4.30
type record ExtendedEPSQoSTLV
{
  OCT1               elementIdentifier,
  LIN1               lengthIndicator,
  Extended_QoS_V     extended_QoS_Value
} with {
  variant "PRESENCE (elementIdentifier = '5C'O)";
  variant (lengthIndicator) "LENGTHTO (extended_QoS_Value)"
};

type record Extended_QoS_V
{
  OCT1 unit_MaxBitRate,
  OCT2 maxBitRate_Uplink,
  OCT2 maxBitRate_Downlink,
  OCT1 unit_GuaranteedBitRate,
  OCT2 guaranteedBitRate_Uplink,
  OCT2 guaranteedBitRate_Downlink
}

//=====================================
// 8.2 EPS mobility management messages
//=====================================

// 8.2.1
type record PDU_NAS_EPS_AttachAccept
{
  BIT4                           securityHeaderType,
  BIT8                           messageType,
  EPS_AttachResultV              ePS_AttachResult,
  BIT4                           spare,
  GPRSTimerV                     t3412,
  TrackingAreaIdentityListLV     tAI_List,                 
  ESM_MessageContainerLVE        eSM_MessageContainer,
  EPS_MobileIdentityTLV          gUTI                        optional,
  LocationAreaIdentificationTV   locationAreaIdentification  optional,
  MobileIdentityTLV              msIdentity                  optional,
  EMM_CauseTV                    eMMCause                    optional,
  GPRSTimerTV                    t3402                       optional,
  GPRSTimerTV                    t3423                       optional,
  PLMN_ListTLV                   equivalentPLMNs             optional,
  EmergencyNumberListTLV         emergencyNumberList         optional, 
  EPS_NetworkFeatureSupportTLV   ePS_NetworkFeatureSupport   optional, 
  AdditionalUpdateResultTV       additionalUpdateResult      optional,
  GPRSTimer3TLV                  t3412_Extended              optional, 
  GPRSTimer2TLV                  t3324                       optional,
  ExtendedDRXParametersTLV       extendedDRXParameters       optional,
  DCNIDTLV                       dNCID                       optional,
  SMS_ServiceStatusTV            sMS_ServiceStatus           optional,
  Non3GPP_NW_ProvidedPoliciesTV  non3GPP_NW_ProvidedPolicies optional,
  GPRSTimer2TLV                  t3448                       optional,
  NetworkPolicyTV                networkPolicy               optional,
  GPRSTimer3TLV                  t3447                       optional,
  ExtendedEmergencyNumberListTLV extendedEmergencyNumberList optional
} with {
  variant "TAG (t3402, elementIdentifier = '17'O;
                t3423, elementIdentifier = '59'O;
                t3412_Extended, elementIdentifier = '5E'O;
                t3324, elementIdentifier = '6A'O;
                t3448, elementIdentifier = '6B'O;
                t3447, elementIdentifier = '6C'O; )";
}

// 8.2.2
type record PDU_NAS_EPS_AttachComplete
{
  BIT4                             securityHeaderType,
  BIT8                             messageType,
  ESM_MessageContainerLVE          eSM_MessageContainer
}

// 8.2.3
type record PDU_NAS_EPS_AttachReject
{
  BIT4                             securityHeaderType,
  BIT8                             messageType,
  EMM_CauseV                       emmCause,
  ESM_MessageContainerTLVE         eSM_MessageContainer optional,
  GPRSTimer2TLV                    t3346 optional,
  GPRSTimer2TLV                    t3402 optional,
  ExtendedEMM_CauseTV              extendedEmmCause optional
} with {
  variant "TAG (t3402, elementIdentifier = '16'O;
                t3346, elementIdentifier = '5F'O;)";
}

// 8.2.4
type record PDU_NAS_EPS_AttachRequest
{
  BIT4                           securityHeaderType,
  BIT8                           messageType,
  EPS_AttachTypeV                ePS_attachType,
  NAS_KeySetIdentifierV          nasKeySetId,
  EPS_MobileIdentityLV           ePSMobileId,
  UENetworkCapabilityLV          uENetworkCapability,
  ESM_MessageContainerLVE        eSM_MessageContainer,
  P_TMSISignatureTV              old_P_TMSISignature           optional,
  EPS_MobileIdentityTLV          additionalGUTI                optional,
  TrackingAreaIdentityTV         lastVisitedRegisteredTAI      optional,
  DRXParameterTV                 dRXParameter                  optional,
  MSNetworkCapabilityTLV         mSNetworkCapability           optional,
  LocationAreaIdentificationTV   oldLocationAreaIdentification optional,
  TMSIStatusTV                   tMSIStatusTV                  optional,
  MobileStationClassmark2_TLV    mobileStationClassmark2       optional,
  MobileStationClassmark3_TLV    mobileStationClassmark3       optional,
  SupportedCodecListTLV          supportedCodecList            optional, 
  AdditionalUpdateTypeTV         additionalUpdateType          optional,
  VoiceDomainPrefandUEsettingsTLV voiceDomainPrefandUEsettings optional,
  DevicePropertiesTV             deviceProperties              optional,
  GUTI_TypeTV                    oldGUTI_Type                  optional,
  MS_NetworkFeatureSupportTV     mS_NetworkFeatureSupport      optional,
  NetworkResourceIdentifierContainerTLV tMSIBasedNRIContainer  optional,
  GPRSTimer2TLV                  t3324                         optional,
  GPRSTimer3TLV                  t3412_Extended                optional,
  ExtendedDRXParametersTLV       extendedDRXParameters         optional,
  UEAdditionalSecurityCapabilityTLV uEAdditionalSecurityCapability optional
} with {  
  variant "TAG (mS_NetworkFeatureSupport, elementIdentifier = '1100'B;
                deviceProperties, elementIdentifier = '1101'B; 
                t3324, elementIdentifier = '6A'O;
                t3412_Extended, elementIdentifier = '5E'O;)";
}

// 8.2.5
type record PDU_NAS_EPS_AuthenticationFailure
{
  BIT4                           securityHeaderType,
  BIT8                           messageType,
  EMM_CauseV                     emmCause,
  AuthenticationFailureParameterTLV authenticationFailureParameter  optional
} with {
  variant (authenticationFailureParameter) "PRESENCE (emmCause.causeValue ='15'O)"
}


// 8.2.6
type record PDU_NAS_EPS_AuthenticationReject
{
  BIT4                           securityHeaderType,
  BIT8                           messageType
}

// 8.2.7
type record PDU_NAS_EPS_AuthenticationRequest
{
  BIT4                           securityHeaderType,
  BIT8                           messageType,
  NAS_KeySetIdentifierV          nasKeySetId,
  BIT4                           spare,
  AuthenticationParameterRANDV   authenticationParameterRAND,
  AuthenticationParameterAUTNLV  authenticationParameterAUTN
}

// 8.2.8
type record PDU_NAS_EPS_AuthenticationResponse
{
  BIT4                               securityHeaderType,
  BIT8                               messageType,
  AuthenticationResponseParameterLV  authenticationResponseParameter
}

// 8.2.9 PDU_NAS_EPS_CS_Service_Notification
type record PDU_NAS_EPS_CS_ServiceNotification
{
  BIT4                             securityHeaderType,
  BIT8                             messageType,
  PagingIdentityV                  pagingIdentity,
  CLITLV                           cLI optional,
  SS_CodeTV                        sS_Code optional,
  LCS_IndicatorTV                  lCS_Indicator optional,
  LCS_ClientIdentityTLV            lCS_ClientIdentity optional
}

// 8.2.10.1 / 8.2.10.2
type record PDU_NAS_EPS_DetachAccept
{
  BIT4                             securityHeaderType,
  BIT8                             messageType
}

// Note: This PDU cannot be decoded
// 8.2.11.1
type record PDU_NAS_EPS_DetachRequest_UE_Orig
{
  BIT4                             securityHeaderType,
  BIT8                             messageType,
  DetachTypeV                      detachType,           
  NAS_KeySetIdentifierV            nAS_KeySetIdentifier,
  EPS_MobileIdentityLV             ePSMobileId
}

// 8.2.11.2
type record PDU_NAS_EPS_DetachRequest_UE_Term
{
  BIT4                      securityHeaderType,
  BIT8                      messageType,
  DetachTypeV               detachType,
  BIT4                      spareHalfOctet,
  EMM_CauseTV               emmCause  optional
}

// 8.2.12 PDU_NAS_EPS_Downlink_NAS_Transport
type record PDU_NAS_EPS_Downlink_NAS_Transport
{
  BIT4                      securityHeaderType,
  BIT8                      messageType,
  NAS_MessageContainerLV    nAS_MessageContainer
}

// 8.2.13 PDU_NAS_EPS_EMM_Information
type record PDU_NAS_EPS_EMM_Information
{
  BIT4                      securityHeaderType,
  BIT8                      messageType,
  NetworkNameTLV            fullNameForNetwork optional,             
  NetworkNameTLV            shortNameForNetwork optional, 
  TimeZoneTV                localTimeZone optional,
  TimeZoneAndTimeTV         universalTimeAndLocalTimeZone optional,
  DaylightSavingTimeTLV     networkDaylightSavingTime optional  
}  with { variant "TAG
  ( 
    fullNameForNetwork,                 elementIdentifier = '43'O;  
    shortNameForNetwork,                elementIdentifier = '45'O;  
  )"
};

// 8.2.14 PDU_NAS_EPS_EMM_Status
type record PDU_NAS_EPS_EMM_Status
{
  BIT4                      securityHeaderType,
  BIT8                      messageType,
  EMM_CauseV                eMMCause
}

// 8.2.15 PDU_NAS_EPS_ExtendedServiceRequest
type record PDU_NAS_EPS_ExtendedServiceRequest
{
  BIT4                      securityHeaderType,
  BIT8                      messageType,
  BIT4                      serviceType,
  NAS_KeySetIdentifierV     nAS_KeySetIdentifier,
  MobileIdentityLV          m_TMSI,
  CSFB_ResponseTV           cSFB_Response optional,
  EPS_BearerContextStatusTLV ePS_BearerContextStatus optional,
  DevicePropertiesTV        deviceProperties optional
}with {
  variant "TAG (deviceProperties, elementIdentifier = '1101'B;)";
}

// 8.2.16 PDU_NAS_EPS_GUTI_ReallocationCommand
type record PDU_NAS_EPS_GUTI_ReallocationCommand{
  BIT4                      securityHeaderType,
  BIT8                      messageType,
  EPS_MobileIdentityLV      guti,
  TrackingAreaIdentityListTLV tAI_list optional,
  DCNIDTLV                  dNCID      optional
}

// 8.2.17 PDU_NAS_EPS_GUTI_ReallocationComplete
type record PDU_NAS_EPS_GUTI_ReallocationComplete{
  BIT4                      securityHeaderType,
  BIT8                      messageType
}

// 8.2.18
type record PDU_NAS_EPS_IdentityRequest
{
  BIT4                             securityHeaderType,
  BIT8                             messageType, 
  IdentityType2V                   identityType,
  BIT4                             spareHalfOctet  
}

// 8.2.19
type record PDU_NAS_EPS_IdentityResponse
{
  BIT4                             securityHeaderType,
  BIT8                             messageType,
  MobileIdentityLV                 mobileIdentity
}  

// 8.2.20 
type record PDU_NAS_EPS_SecurityModeCommand
{
  BIT4                             securityHeaderType,
  BIT8                             messageType,
  NAS_SecurityAlgorithmsV          selected_NAS_SecurityAlgorithms, 
  NAS_KeySetIdentifierV            nasKeySetId, 
  BIT4                             spareHalfOctet, 
  UESecurityCapabilityLV           replayed_UE_SecurityCapability,
  IMEISV_RequestTV                 iMEISV_Request optional,
  NonceTV                          replayedNonceUE optional,
  NonceTV                          nonceMME optional,
  HashTLV                          hashMME optional,
  UEAdditionalSecurityCapabilityTLV uEAdditionalSecurityCapability optional
} with {
  variant "TAG(replayedNonceUE, elementIdentifier = '55'O;
               nonceMME, elementIdentifier = '56'O;)";
}

// 8.2.21
type record PDU_NAS_EPS_SecurityModeComplete
{
  BIT4                             securityHeaderType,
  BIT8                             messageType,
  MobileIdentityTLV                iMEISV optional,
  ReplayedNASMessageContainerTLVE  replayedNASMessageContainer optional
}

// 8.2.22
type record PDU_NAS_EPS_SecurityModeReject
{
  BIT4                             securityHeaderType,
  BIT8                             messageType,
  EMM_CauseV                       eMMCause 
}

// 8.2.23 
type record PDU_NAS_EPS_SecurityProtectedNASMessage
{
  BIT4                             securityHeaderType,
  OCT4                             messageAuthenticationCode,
  integer                          sequenceNumber,
  octetstring                      nAS_Message
}

// 8.2.24
type record PDU_NAS_EPS_ServiceReject
{
  BIT4                             securityHeaderType,
  BIT8                             messageType,
  EMM_CauseV                       eMMCause,
  GPRSTimerTV                      t3442 optional,
  GPRSTimer2TLV                    t3346 optional,
  GPRSTimer2TLV                    t3448 optional
} with {
  variant "TAG(t3442, elementIdentifier = '5B'O;
               t3346, elementIdentifier = '5F'O;
               t3448, elementIdentifier = '6B'O;)";
}


// 8.2.25
type record PDU_NAS_EPS_ServiceRequest
{
  BIT4                             securityHeaderType, 
  KSIandSequenceNumberV            ksiSequenceNumber, 
  ShortMACV                        mAC 
}

// 8.2.26
type record PDU_NAS_EPS_TrackingAreaUpdateAccept
{
  BIT4                             securityHeaderType,
  BIT8                             messageType,
  EPS_UpdateResultV                updateResult,
  BIT4                             spareHalfOctet,  
  GPRSTimerTV                      t3412                      optional,
  EPS_MobileIdentityTLV            gUTI                       optional,
  TrackingAreaIdentityListTLV      tAI_List                   optional,
  EPS_BearerContextStatusTLV       ePSBearerContextStatus     optional,
  LocationAreaIdentificationTV     locationAreaIdentification optional,
  MobileIdentityTLV                msIdentity                 optional,
  EMM_CauseTV                      eMMCause                   optional,
  GPRSTimerTV                      t3402                      optional, 
  GPRSTimerTV                      t3423                      optional,
  PLMN_ListTLV                     equivalentPLMNs            optional,
  EmergencyNumberListTLV           emergencyNumberList        optional,
  EPS_NetworkFeatureSupportTLV     ePS_NetworkFeatureSupport  optional,
  AdditionalUpdateResultTV         additionalUpdateResult     optional,
  GPRSTimer3TLV                    t3412_Extended             optional,
  GPRSTimer2TLV                    t3324                      optional,
  ExtendedDRXParametersTLV         extendedDRXParameters      optional,
  HeaderCompressionConfigurationStatusTLV headerCompressionConfigurationStatus optional,
  DCNIDTLV                         dNCID                      optional,
  SMS_ServiceStatusTV              sMS_ServiceStatus          optional,
  Non3GPP_NW_ProvidedPoliciesTV    non3GPP_NW_ProvidedPolicies optional,
  GPRSTimer2TLV                    t3448                       optional,
  NetworkPolicyTV                  networkPolicy               optional,
  GPRSTimer3TLV                    t3447                       optional,
  ExtendedEmergencyNumberListTLV   extendedEmergencyNumberList optional
} with {
  variant "TAG (t3412, elementIdentifier = '5A'O;
                t3402, elementIdentifier = '17'O;
                t3423, elementIdentifier = '59'O;
                t3412_Extended, elementIdentifier = '5E'O;
                t3324, elementIdentifier = '6A'O;
                t3448, elementIdentifier = '6B'O;
                t3447, elementIdentifier = '6C'O;)";
};

// 8.2.27
type record PDU_NAS_EPS_TrackingAreaUpdateComplete
{
  BIT4                             securityHeaderType,
  BIT8                             messageType
}

// 8.2.28
type record PDU_NAS_EPS_TrackingAreaUpdateReject
{
  BIT4                             securityHeaderType,
  BIT8                             messageType,
  EMM_CauseV                       emmCause,
  GPRSTimer2TLV                    t3346 optional,
  ExtendedEMM_CauseTV              extendedEmmCause optional
} with {
  variant "TAG(t3346, elementIdentifier = '5F'O;)";
}


// 8.2.29
type record PDU_NAS_EPS_TrackingAreaUpdateRequest
{ 
  BIT4                             securityHeaderType,
  BIT8                             messageType, 
  EPS_UpdateTypeV                  ePSupdateType,
  NAS_KeySetIdentifierV            nasKeySetId,
  EPS_MobileIdentityLV             oldGUTI, 
  NAS_KeySetIdentifierTV           nonCurrentNative_nasKeySetId   optional,
  CipheringKeySequenceNumberTV     gprsCipheringKeySequenceNumber optional,
  P_TMSISignatureTV                old_P_TMSISignature            optional,
  EPS_MobileIdentityTLV            additionalGUTI                 optional,
  NonceTV                          nonce                          optional,
  UENetworkCapabilityTLV           uENetworkCapability            optional,
  TrackingAreaIdentityTV           lastVisitedRegisteredTAI       optional,
  DRXParameterTV                   dRXParameter                   optional,
  UE_RadioCapabilityInfoUpdateNeededTV  uE_RadioCapabilityInfoUpdateNeeded optional,
  EPS_BearerContextStatusTLV       ePSBearerContextStatus         optional,
  MSNetworkCapabilityTLV           mSNetworkCapability            optional,
  LocationAreaIdentificationTV     oldLocationAreaIdentification  optional,
  TMSIStatusTV                     tMSIStatusTV                   optional,
  MobileStationClassmark2_TLV      mobileStationClassmark2        optional,
  MobileStationClassmark3_TLV      mobileStationClassmark3        optional, 
  SupportedCodecListTLV            supportedCodecList             optional,
  AdditionalUpdateTypeTV           additionalUpdateType           optional,
  VoiceDomainPrefandUEsettingsTLV  voiceDomainPrefandUEsettings   optional,
  GUTI_TypeTV                      oldGUTI_Type                   optional,
  DevicePropertiesTV               deviceProperties               optional,
  MS_NetworkFeatureSupportTV       mS_NetworkFeatureSupport       optional,  
  NetworkResourceIdentifierContainerTLV tMSIBasedNRIContainer     optional,       
  GPRSTimer2TLV                    t3324                          optional,
  GPRSTimer3TLV                    t3412_Extended                 optional,
  ExtendedDRXParametersTLV         extendedDRXParameters          optional,
  UEAdditionalSecurityCapabilityTLV uEAdditionalSecurityCapability optional,
  UEStatusTLV                      uEStatus                      optional
  } with {
  variant "TAG(nonce, elementIdentifier = '55'O;
               deviceProperties, elementIdentifier = '1101'B;
               mS_NetworkFeatureSupport, elementIdentifier = '1100'B;  
               t3324, elementIdentifier = '6A'O;
               t3412_Extended, elementIdentifier = '5E'O;)";
}

// 8.2.30 PDU_NAS_EPS_Uplink_NAS_Transport 
type record PDU_NAS_EPS_Uplink_NAS_Transport
{
  BIT4                      securityHeaderType,
  BIT8                      messageType,
  NAS_MessageContainerLV    nAS_MessageContainer
}

// 8.2.31 PDU_NAS_EPS_Downlink_Generic_NAS_Transport
type record PDU_NAS_EPS_Downlink_Generic_NAS_Transport
{
  BIT4                                  securityHeaderType,
  BIT8                                  messageType,
  BIT8                                  generic_MessageContainerType,
  Generic_MessageContainerLVE           generic_MessageConatiner,
  AdditionalInformationTLV              additionalInformation optional
} with {
  variant "PRESENCE(securityHeaderType='0000'B)"
}

// 8.2.32 PDU_NAS_EPS_Uplink_Generic_NAS_Transport
type record PDU_NAS_EPS_Uplink_Generic_NAS_Transport
{
  BIT4                                  securityHeaderType,
  BIT8                                  messageType,
  BIT8                                  generic_MessageContainerType,
  Generic_MessageContainerLVE           generic_MessageConatiner,
  AdditionalInformationTLV              additionalInformation optional
} with {
  variant "PRESENCE(securityHeaderType='0000'B)"
}

// 8.2.33 PDU_NAS_EPS_ControlPlaneServiceRequest
type record PDU_NAS_EPS_ControlPlaneServiceRequest
{
  BIT4                                  securityHeaderType,
  BIT8                                  messageType,
  ControlPlaneServiceTypeV              controlPlaneServiceType,
  NAS_KeySetIdentifierV                 nASKeySetIdentifier,
  ESM_MessageContainerTLVE              eSM_MessageContainer optional,
  NAS_MessageContainerTLV               nAS_MessageContainer optional,
  EPS_BearerContextStatusTLV            ePS_BearerContextStatus optional,
  DevicePropertiesTV                    deviceProperties optional
} with {  
  variant "TAG (nAS_MessageContainer, elementIdentifier = '67'O;)";
  variant "TAG (deviceProperties, elementIdentifier = '1101'B;)";
}

// 8.2.34 PDU_NAS_EPS_ServiceAccept
type record PDU_NAS_EPS_ServiceAccept
{
  BIT4                             securityHeaderType,
  BIT8                             messageType,
  EPS_BearerContextStatusTLV       ePS_BearerContextStatus optional,
  GPRSTimer2TLV                    t3448                   optional
} with {
  variant "TAG(t3448, elementIdentifier = '6B'O;)";
}

//==============================================
// EPS session management messages - 8.3/24.301
//==============================================

// 8.3.1 
type record PDU_NAS_EPS_ActDedEPSBearerContextAccept
{
  BIT4                             ePSBearerIdentity,
  BIT8                             procedureTransactionIdentifier,
  BIT8                             messageType, 
  ProtocolConfigOptionsTLV         protocolConfigOptions optional,
  NBIFOM_ContainerTLV              nBIFOMContainer optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional
}

// 8.3.2
type record PDU_NAS_EPS_ActDedEPSBearerContextReject
{
  BIT4                             ePSBearerIdentity,
  BIT8                             procedureTransactionIdentifier,
  BIT8                             messageType,   
  ESM_CauseV                       esmCause,  
  ProtocolConfigOptionsTLV         protocolConfigOptions optional,  
  NBIFOM_ContainerTLV              nBIFOMContainer optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional  
}

// 8.3.3
type record PDU_NAS_EPS_ActDedEPSBearerContextRequest
{
  BIT4                             ePSBearerIdentity,
  BIT8                             procedureTransactionIdentifier,
  BIT8                             messageType,   
  Linked_EPS_BearerIdentityV       linked_EPS_BearerIdentity,
  BIT4                             spareHalfOctet,   
  EPS_QualityOfServiceLV           ePS_QoS,
  TrafficFlowTemplateLV            trafficFlowTemplate,
  TransactionIdentifierTLV         transactionIdentifier optional, 
  QoSTLV                           negotiatedQoS         optional,
  LLC_SAPITV                       negotiated_LLC_SAPI   optional,
  RadioPriorityTV                  radioPriority         optional,
  PacketFlowIDTLV                  packetFlowID          optional,
  ProtocolConfigOptionsTLV         protocolConfigOptions optional,
  WLANOffloadAcceptabilityTV       wLANOffloadIndication optional,
  NBIFOM_ContainerTLV              nBIFOMContainer       optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional,
  ExtendedEPSQoSTLV                extendedQoS           optional
}

// 8.3.4
type record PDU_NAS_EPS_ActDefEPSBearerContextAccept
{
  BIT4                            ePSBearerIdentity,
  BIT8                            procedureTransactionIdentifier,
  BIT8                            messageType,
  ProtocolConfigOptionsTLV        protocolConfigOptions optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional    
}

// 8.3.5 PDU_NAS_EPS_ActDefEPSBearerContextReject
type record PDU_NAS_EPS_ActDefEPSBearerContextReject
{
  BIT4                            ePSBearerIdentity,
  BIT8                            procedureTransactionIdentifier,
  BIT8                            messageType,
  ESM_CauseV                      esmCause,  
  ProtocolConfigOptionsTLV        protocolConfigOptions optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional
}

// 8.3.6
type record PDU_NAS_EPS_ActDefEPSBearerContextRequest
{
  BIT4                                ePSBearerIdentity,
  BIT8                                procedureTransactionIdentifier,
  BIT8                                messageType,
  EPS_QualityOfServiceLV              ePS_QoS,  
  AccessPointNameLV                   accessPointName, 
  PDN_AddressLV                       pDN_Address,
  TransactionIdentifierTLV            transactionIdentifier optional,
  QoSTLV                              negotiatedQoS         optional,
  LLC_SAPITV                          negotiated_LLC_SAPI   optional,
  RadioPriorityTV                     radioPriority         optional,
  PacketFlowIDTLV                     packetFlowID          optional,
  APN_AggregateMaximumBitRateTLV      aPN_AMBR              optional,
  ESM_CauseTV                         esmCause              optional,
  ProtocolConfigOptionsTLV            protocolConfigOptions optional,
  ConnectivityTypeTV                  connectivityType      optional,
  WLANOffloadAcceptabilityTV          wLANOffloadIndication optional,
  NBIFOM_ContainerTLV                 nBIFOMContainer       optional,
  HeaderCompressinConfigurationTLV    headerCompressinConfiguration optional,
  ControlPlaneOnlyIndicationTV        controlPlaneOnlyIndication optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional,
  ServingPLMNRateControlTLV           servingPLMNRateControl optional,
  Extended_APN_AMBR_TLV               extended_APN_AMBR     optional,
  ExtendedEPSQoSTLV                   extendedQoS           optional
};

// 8.3.7 PDU_NAS_EPS_BearerResourceAllocationReject
type record PDU_NAS_EPS_BearerResourceAllocationReject
{
  BIT4                                ePSBearerIdentity,
  BIT8                                procedureTransactionIdentifier,
  BIT8                                messageType,
  ESM_CauseV                          esmCause,
  ProtocolConfigOptionsTLV            protocolConfigOptions optional,
  GPRSTimer3TLV                       backOffTimer          optional,
  ReAttemptIndicatorTLV               reAttemptIndicator    optional,
  NBIFOM_ContainerTLV                 nBIFOMContainer       optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional
}with { 
  variant "TAG (backOffTimer, elementIdentifier = '37'O;)";
};

// 8.3.8
type record PDU_NAS_EPS_BearerResourceAllocationRequest
{
  BIT4                                ePSBearerIdentity,
  BIT8                                procedureTransactionIdentifier,
  BIT8                                messageType,
  Linked_EPS_BearerIdentityV          linked_EPS_BearerIdentity,
  BIT4                                spareHalfOctet,   
  TrafficFlowAggregateDescriptionLV   trafficFlowAggregate,
  EPS_QualityOfServiceLV              requiredTrafficFlowQOS,
  ProtocolConfigOptionsTLV            protocolConfigOptions optional,
  DevicePropertiesTV                  deviceProperties      optional, 
  NBIFOM_ContainerTLV                 nBIFOMContainer       optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional,
  ExtendedEPSQoSTLV                   extendedQoS           optional
} with { 
  variant "TAG(deviceProperties, elementIdentifier = '1100'B;)";  
}

// 8.3.9
type record PDU_NAS_EPS_BearerResourceModificationReject
{
  BIT4                                ePSBearerIdentity,
  BIT8                                procedureTransactionIdentifier,
  BIT8                                messageType,
  ESM_CauseV                          esmCause,
  ProtocolConfigOptionsTLV            protocolConfigOptions optional,
  GPRSTimer3TLV                       backOffTimer          optional,
  ReAttemptIndicatorTLV               reAttemptIndicator    optional,
  NBIFOM_ContainerTLV                 nBIFOMContainer       optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional
}with { 
  variant "TAG (backOffTimer, elementIdentifier = '37'O;)";
};

// 8.3.10
type record PDU_NAS_EPS_BearerResourceModificationRequest
{
  BIT4                                ePSBearerIdentity,
  BIT8                                procedureTransactionIdentifier,
  BIT8                                messageType,
  Linked_EPS_BearerIdentityV          linked_EPS_BearerIdentity,
  BIT4                                spareHalfOctet,   
  TrafficFlowAggregateDescriptionLV   trafficFlowAggregate,
  EPS_QualityOfServiceTLV             requiredTrafficFlowQOS optional,
  ESM_CauseTV                         esmCause               optional,
  ProtocolConfigOptionsTLV            protocolConfigOptions  optional,
  DevicePropertiesTV                  deviceProperties       optional,
  NBIFOM_ContainerTLV                 nBIFOMContainer        optional,
  HeaderCompressinConfigurationTLV    headerCompressinConfiguration optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional,
  ExtendedEPSQoSTLV                   extendedQoS            optional
} with { 
  variant "TAG(deviceProperties, elementIdentifier = '1100'B;)";  
}

// 8.3.11
type record PDU_NAS_EPS_DeactEPSBearerContextAccept
{
  BIT4                                ePSBearerIdentity,
  BIT8                                procedureTransactionIdentifier,
  BIT8                                messageType,
  ProtocolConfigOptionsTLV            protocolConfigOptions optional, 
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional
}

// 8.3.12
type record PDU_NAS_EPS_DeactEPSBearerContextRequest
{
  BIT4                                ePSBearerIdentity,
  BIT8                                procedureTransactionIdentifier,
  BIT8                                messageType,
  ESM_CauseV                          esmCause,
  ProtocolConfigOptionsTLV            protocolConfigOptions optional,
  GPRSTimer3TLV                       t3396                 optional,
  WLANOffloadAcceptabilityTV          wLANOffloadIndication optional,
  NBIFOM_ContainerTLV                 nBIFOMContainer       optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional
}with { 
  variant "TAG (t3396, elementIdentifier = '37'O;)";
};

// 8.3.12A
type record PDU_NAS_EPS_ESM_DummyMessage
{
  BIT4                                ePSBearerIdentity,
  BIT8                                procedureTransactionIdentifier,
  BIT8                                messageType
}

// 8.3.13 PDU_NAS_EPS_ESM_InformationRequest
type record PDU_NAS_EPS_ESM_InformationRequest
{
  BIT4                                ePSBearerIdentity,
  BIT8                                procedureTransactionIdentifier,
  BIT8                                messageType 
}

// 8.3.14 PDU_NAS_EPS_ESM_InformationResponse 
type record PDU_NAS_EPS_ESM_InformationResponse
{
  BIT4                                ePSBearerIdentity,
  BIT8                                procedureTransactionIdentifier,
  BIT8                                messageType, 
  AccessPointNameTLV                  accessPointName optional,
  ProtocolConfigOptionsTLV            protocolConfigOptions optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional
}

// 8.3.15 PDU_NAS_EPS_ESM_Status
type record PDU_NAS_EPS_ESM_Status
{
  BIT4                                ePSBearerIdentity,
  BIT8                                procedureTransactionIdentifier,
  BIT8                                messageType, 
  ESM_CauseV                          esmCause  
}

// 8.3.16 PDU_NAS_EPS_ModifyEPSBearerContextAccept
type record PDU_NAS_EPS_ModifyEPSBearerContextAccept
{
  BIT4                                ePSBearerIdentity,
  BIT8                                procedureTransactionIdentifier,
  BIT8                                messageType,
  ProtocolConfigOptionsTLV            protocolConfigOptions optional,
  NBIFOM_ContainerTLV                 nBIFOMContainer       optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional
}

// 8.3.17 PDU_NAS_EPS_ModifyEPSBearerContextReject
type record PDU_NAS_EPS_ModifyEPSBearerContextReject
{
  BIT4                                ePSBearerIdentity,
  BIT8                                procedureTransactionIdentifier,
  BIT8                                messageType,
  ESM_CauseV                          esmCause,
  ProtocolConfigOptionsTLV            protocolConfigOptions optional,
  NBIFOM_ContainerTLV                 nBIFOMContainer       optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional
}

// 8.3.18 PDU_NAS_EPS_ModifyEPSBearerContextRequest
type record PDU_NAS_EPS_ModifyEPSBearerContextRequest
{
  BIT4                             ePSBearerIdentity,
  BIT8                             procedureTransactionIdentifier,
  BIT8                             messageType,     
  EPS_QualityOfServiceTLV          newEPS_QoS              optional,
  TrafficFlowTemplateTLV           trafficFlowTemplate     optional,
  QoSTLV                           new_QoS                 optional,
  LLC_SAPITV                       negotiated_LLC_SAPI     optional,
  RadioPriorityTV                  radioPriority           optional,
  PacketFlowIDTLV                  packetFlowID            optional,
  APN_AggregateMaximumBitRateTLV   aPN_AMBR                optional,    
  ProtocolConfigOptionsTLV         protocolConfigOptions   optional,
  WLANOffloadAcceptabilityTV       wLANOffloadIndication   optional,
  NBIFOM_ContainerTLV              nBIFOMContainer         optional,
  HeaderCompressinConfigurationTLV headerCompressinConfiguration optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional,
  Extended_APN_AMBR_TLV            extended_APN_AMBR       optional,
  ExtendedEPSQoSTLV                extendedQoS             optional
}

// 8.3.18A
type record PDU_NAS_EPS_Notification
{
  BIT4                             ePSBearerIdentity,
  BIT8                             procedureTransactionIdentifier,
  BIT8                             messageType,
  NotificationIndicatorLV          notificationIndicator
}

// 8.3.19
type record PDU_NAS_EPS_PDN_ConnectivityReject
{
  BIT4                            ePSBearerIdentity,
  BIT8                            procedureTransactionIdentifier,
  BIT8                            messageType,
  ESM_CauseV                      esmCause, 
  ProtocolConfigOptionsTLV        protocolConfigOptions optional,
  GPRSTimer3TLV                   backOffTimer optional,
  ReAttemptIndicatorTLV           reAttemptIndicator optional,
  NBIFOM_ContainerTLV             nBIFOMContainer         optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional
} with { 
  variant "TAG (backOffTimer, elementIdentifier = '37'O;)";
};

// 8.3.20
type record PDU_NAS_EPS_PDN_ConnectivityRequest
{
  BIT4                            ePSBearerIdentity,
  BIT8                            procedureTransactionIdentifier,
  BIT8                            messageType,
  RequestTypeV                    requestType,
  PDN_TypeV                       pDN_Type,
  ESM_InformationTransferFlagTV   eSM_InformationTransferFlag  optional,
  AccessPointNameTLV              accessPointName              optional,
  ProtocolConfigOptionsTLV        protocolConfigOptions        optional,
  DevicePropertiesTV              deviceProperties             optional,
  NBIFOM_ContainerTLV             nBIFOMContainer              optional,
  HeaderCompressinConfigurationTLV headerCompressinConfiguration optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional
} with { 
  variant "TAG(deviceProperties, elementIdentifier = '1100'B;)";  
}

// 8.3.21 PDU_NAS_EPS_PDN_DisconnectReject
type record PDU_NAS_EPS_PDN_DisconnectReject 
{
  BIT4                            ePSBearerIdentity,
  BIT8                            procedureTransactionIdentifier,
  BIT8                            messageType,
  ESM_CauseV                      esmCause, 
  ProtocolConfigOptionsTLV        protocolConfigOptions        optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional
}

// 8.3.22 PDU_NAS_EPS_PDN_DisconnectRequest
type record PDU_NAS_EPS_PDN_DisconnectRequest
{
  BIT4                            ePSBearerIdentity,
  BIT8                            procedureTransactionIdentifier,
  BIT8                            messageType,
  Linked_EPS_BearerIdentityV      linked_EPS_BearerIdentity,
  BIT4                            spareHalfOctet,
  ProtocolConfigOptionsTLV        protocolConfigOptions        optional,
  ExtendedProtocolConfigurationOptionsTLVE extendedProtocolConfigurationOptions optional
}

// 8.3.23 PDU_NAS_EPS_RemoteUEReport
type record PDU_NAS_EPS_RemoteUEReport
{
  BIT4                            ePSBearerIdentity,
  BIT8                            procedureTransactionIdentifier,
  BIT8                            messageType,
  RemoteUEContextListTLVE         remoteUEContextConnected optional,
  RemoteUEContextListTLVE         remoteUEContextDisconnected optional,
  PKMF_AddressTLV                 proSeKeyManagementFunctionAddress optional
} with { 
  variant "TAG(remoteUEContextConnected, elementIdentifier = '79'O;  
               remoteUEContextDisconnected, elementIdentifier = '7A'O;
               proSeKeyManagementFunctionAddress, elementIdentifier = '6F'O)";  
}

// 8.3.24 PDU_NAS_EPS_RemoteUEReportResponse
type record PDU_NAS_EPS_RemoteUEReportResponse
{
  BIT4                            ePSBearerIdentity,
  BIT8                            procedureTransactionIdentifier,
  BIT8                            messageType
}

// 8.3.25 PDU_NAS_EPS_ESMDataTransport
type record PDU_NAS_EPS_ESMDataTransport
{
  BIT4                            ePSBearerIdentity,
  BIT8                            procedureTransactionIdentifier,
  BIT8                            messageType,
  UserDataContainerLVE            userDataContainer,
  ReleaseAssistanceIndicationTV   releaseAssistanceIndication optional
}
//see table 9.8.2/24.301:
type union EPS_SessionManagement
{  
  PDU_NAS_EPS_ActDefEPSBearerContextRequest    pDU_NAS_EPS_ActDefEPSBearerContextRequest,
  PDU_NAS_EPS_ActDefEPSBearerContextAccept     pDU_NAS_EPS_ActDefEPSBearerContextAccept,
  PDU_NAS_EPS_ActDefEPSBearerContextReject     pDU_NAS_EPS_ActDefEPSBearerContextReject,

  PDU_NAS_EPS_BearerResourceAllocationReject   pDU_NAS_EPS_BearerResourceAllocationReject,
  PDU_NAS_EPS_BearerResourceAllocationRequest  pDU_NAS_EPS_BearerResourceAllocationRequest,

  PDU_NAS_EPS_BearerResourceModificationReject   pDU_NAS_EPS_BearerResourceModificationReject,
  PDU_NAS_EPS_BearerResourceModificationRequest  pDU_NAS_EPS_BearerResourceModificationRequest,


  PDU_NAS_EPS_ActDedEPSBearerContextRequest    pDU_NAS_EPS_ActDedEPSBearerContextRequest,
  PDU_NAS_EPS_ActDedEPSBearerContextAccept     pDU_NAS_EPS_ActDedEPSBearerContextAccept,
  PDU_NAS_EPS_ActDedEPSBearerContextReject     pDU_NAS_EPS_ActDedEPSBearerContextReject,

  PDU_NAS_EPS_ModifyEPSBearerContextRequest    pDU_NAS_EPS_ModifyEPSBearerContextRequest,  
  PDU_NAS_EPS_ModifyEPSBearerContextAccept     pDU_NAS_EPS_ModifyEPSBearerContextAccept, 
  PDU_NAS_EPS_ModifyEPSBearerContextReject     pDU_NAS_EPS_ModifyEPSBearerContextReject,

  PDU_NAS_EPS_DeactEPSBearerContextRequest     pDU_NAS_EPS_DeactEPSBearerContextRequest,
  PDU_NAS_EPS_DeactEPSBearerContextAccept      pDU_NAS_EPS_DeactEPSBearerContextAccept,

  PDU_NAS_EPS_PDN_ConnectivityRequest          pDU_NAS_EPS_PDN_ConnectivityRequest,
  PDU_NAS_EPS_PDN_ConnectivityReject           pDU_NAS_EPS_PDN_ConnectivityReject,

  PDU_NAS_EPS_PDN_DisconnectRequest            pDU_NAS_EPS_PDN_DisconnectRequest,
  PDU_NAS_EPS_PDN_DisconnectReject             pDU_NAS_EPS_PDN_DisconnectReject,

  PDU_NAS_EPS_ESM_InformationRequest           pDU_NAS_EPS_ESM_InformationRequest, 
  PDU_NAS_EPS_ESM_InformationResponse          pDU_NAS_EPS_ESM_InformationResponse, 

  PDU_NAS_EPS_Notification                     pDU_NAS_EPS_Notification,

  PDU_NAS_EPS_ESM_DummyMessage                 pDU_NAS_EPS_ESM_DummyMessage,

  PDU_NAS_EPS_ESM_Status                       pDU_NAS_EPS_ESM_Status,

  PDU_NAS_EPS_RemoteUEReport                   pDU_NAS_EPS_RemoteUEReport,
  PDU_NAS_EPS_RemoteUEReportResponse           pDU_NAS_EPS_RemoteUEReportResponse,

  PDU_NAS_EPS_ESMDataTransport                 pDU_NAS_EPS_ESMDataTransport
} with {
  variant "TAG (    
  pDU_NAS_EPS_ActDefEPSBearerContextRequest,   messageType = '11000001'B;
  pDU_NAS_EPS_ActDefEPSBearerContextAccept,    messageType = '11000010'B;
  pDU_NAS_EPS_ActDefEPSBearerContextReject,    messageType = '11000011'B;

  pDU_NAS_EPS_ActDedEPSBearerContextRequest,   messageType = '11000101'B;
  pDU_NAS_EPS_ActDedEPSBearerContextAccept,    messageType = '11000110'B;
  pDU_NAS_EPS_ActDedEPSBearerContextReject,    messageType = '11000111'B;
  
  pDU_NAS_EPS_BearerResourceAllocationReject,  messageType = '11010101'B;
  pDU_NAS_EPS_BearerResourceAllocationRequest,  messageType = '11010100'B;
  
  pDU_NAS_EPS_BearerResourceModificationReject,  messageType = '11010111'B;
  pDU_NAS_EPS_BearerResourceModificationRequest,  messageType = '11010110'B;
    
  pDU_NAS_EPS_ModifyEPSBearerContextRequest,   messageType = '11001001'B;
  pDU_NAS_EPS_ModifyEPSBearerContextAccept,    messageType = '11001010'B;
  pDU_NAS_EPS_ModifyEPSBearerContextReject,    messageType = '11001011'B;
  
  pDU_NAS_EPS_DeactEPSBearerContextRequest,    messageType = '11001101'B;
  pDU_NAS_EPS_DeactEPSBearerContextAccept,     messageType = '11001110'B;
  
  pDU_NAS_EPS_PDN_ConnectivityRequest,         messageType = '11010000'B;
  pDU_NAS_EPS_PDN_ConnectivityReject,          messageType = '11010001'B;
  
  pDU_NAS_EPS_PDN_DisconnectRequest,           messageType = '11010010'B;
  pDU_NAS_EPS_PDN_DisconnectReject,            messageType = '11010011'B;
  
  pDU_NAS_EPS_ESM_InformationRequest,          messageType = '11011001'B;
  pDU_NAS_EPS_ESM_InformationResponse,         messageType = '11011010'B;
  
  pDU_NAS_EPS_Notification,                    messageType = '11011011'B;
  
  pDU_NAS_EPS_ESM_DummyMessage,                messageType = '11011100'B;
  
  pDU_NAS_EPS_ESM_Status,                      messageType = '11101000'B;
  
  pDU_NAS_EPS_RemoteUEReport,                  messageType = '11101001'B;
  pDU_NAS_EPS_RemoteUEReportResponse,          messageType = '11101010'B;
  
  pDU_NAS_EPS_ESMDataTransport,                messageType = '11101011'B;)"
} 

//see Table 9.8.1/24.301:
type union EPS_MobilityManagement
{
  PDU_NAS_EPS_ServiceRequest              pDU_NAS_EPS_ServiceRequest,
  PDU_NAS_EPS_SecurityProtectedNASMessage pDU_NAS_EPS_SecurityProtectedNASMessage,

  PDU_NAS_EPS_AttachRequest               pDU_NAS_EPS_AttachRequest,
  PDU_NAS_EPS_AttachAccept                pDU_NAS_EPS_AttachAccept,
  PDU_NAS_EPS_AttachComplete              pDU_NAS_EPS_AttachComplete,
  PDU_NAS_EPS_AttachReject                pDU_NAS_EPS_AttachReject,

  PDU_NAS_EPS_DetachAccept                pDU_NAS_EPS_DetachAccept,
  PDU_NAS_EPS_DetachRequest_UE_Term       pDU_NAS_EPS_DetachRequest_UE_Term,
  PDU_NAS_EPS_DetachRequest_UE_Orig       pDU_NAS_EPS_DetachRequest_UE_Orig, // Note: This PDU cannot be decoded

  PDU_NAS_EPS_TrackingAreaUpdateRequest   pDU_NAS_EPS_TrackingAreaUpdateRequest,
  PDU_NAS_EPS_TrackingAreaUpdateAccept    pDU_NAS_EPS_TrackingAreaUpdateAccept,
  PDU_NAS_EPS_TrackingAreaUpdateComplete  pDU_NAS_EPS_TrackingAreaUpdateComplete,
  PDU_NAS_EPS_TrackingAreaUpdateReject    pDU_NAS_EPS_TrackingAreaUpdateReject,

  PDU_NAS_EPS_ExtendedServiceRequest      pDU_NAS_EPS_ExtendedServiceRequest,
  PDU_NAS_EPS_ControlPlaneServiceRequest  pDU_NAS_EPS_ControlPlaneServiceRequest,
  PDU_NAS_EPS_ServiceReject               pDU_NAS_EPS_ServiceReject,
  PDU_NAS_EPS_ServiceAccept               pDU_NAS_EPS_ServiceAccept,

  PDU_NAS_EPS_GUTI_ReallocationCommand    pDU_NAS_EPS_GUTI_ReallocationCommand,  
  PDU_NAS_EPS_GUTI_ReallocationComplete   pDU_NAS_EPS_GUTI_ReallocationComplete,  
  PDU_NAS_EPS_AuthenticationRequest       pDU_NAS_EPS_AuthenticationRequest,
  PDU_NAS_EPS_AuthenticationResponse      pDU_NAS_EPS_AuthenticationResponse,
  PDU_NAS_EPS_AuthenticationReject        pDU_NAS_EPS_AuthenticationReject,
  PDU_NAS_EPS_AuthenticationFailure       pDU_NAS_EPS_AuthenticationFailure,
  PDU_NAS_EPS_IdentityRequest             pDU_NAS_EPS_IdentityRequest,
  PDU_NAS_EPS_IdentityResponse            pDU_NAS_EPS_IdentityResponse,
  PDU_NAS_EPS_SecurityModeCommand         pDU_NAS_EPS_SecurityModeCommand,
  PDU_NAS_EPS_SecurityModeComplete        pDU_NAS_EPS_SecurityModeComplete,
  PDU_NAS_EPS_SecurityModeReject          pDU_NAS_EPS_SecurityModeReject,

  PDU_NAS_EPS_EMM_Status                  pDU_NAS_EPS_EMM_Status,
  PDU_NAS_EPS_EMM_Information             pDU_NAS_EPS_EMM_Information,
  PDU_NAS_EPS_Downlink_NAS_Transport      pDU_NAS_EPS_Downlink_NAS_Transport,
  PDU_NAS_EPS_Uplink_NAS_Transport        pDU_NAS_EPS_Uplink_NAS_Transport,
  PDU_NAS_EPS_CS_ServiceNotification      pDU_NAS_EPS_CS_ServiceNotification,

  PDU_NAS_EPS_Downlink_Generic_NAS_Transport    pDU_NAS_EPS_Downlink_Generic_NAS_Transport,
  PDU_NAS_EPS_Uplink_Generic_NAS_Transport      pDU_NAS_EPS_Uplink_Generic_NAS_Transport
} with {
  variant "TAG (
  
  pDU_NAS_EPS_ServiceRequest,                 securityHeaderType= '1100'B; 
  pDU_NAS_EPS_ServiceRequest,                 securityHeaderType= '1101'B;  
  pDU_NAS_EPS_ServiceRequest,                 securityHeaderType= '1110'B;  
  pDU_NAS_EPS_ServiceRequest,                 securityHeaderType= '1111'B;  
  
  pDU_NAS_EPS_SecurityProtectedNASMessage,    securityHeaderType= '0001'B;
  pDU_NAS_EPS_SecurityProtectedNASMessage,    securityHeaderType= '0010'B;
  pDU_NAS_EPS_SecurityProtectedNASMessage,    securityHeaderType= '0011'B;
  pDU_NAS_EPS_SecurityProtectedNASMessage,    securityHeaderType= '0100'B; 
  pDU_NAS_EPS_SecurityProtectedNASMessage,    securityHeaderType= '0101'B;
  
  pDU_NAS_EPS_AttachRequest,                  messageType = '01000001'B;
  pDU_NAS_EPS_AttachAccept,                   messageType = '01000010'B;
  pDU_NAS_EPS_AttachComplete,                 messageType = '01000011'B;
  pDU_NAS_EPS_AttachReject,                   messageType = '01000100'B;
  pDU_NAS_EPS_DetachRequest_UE_Term,          messageType = '01000101'B;
  pDU_NAS_EPS_DetachRequest_UE_Orig,          messageType = '01000101'B;
  pDU_NAS_EPS_DetachAccept,                   messageType = '01000110'B;

  pDU_NAS_EPS_TrackingAreaUpdateRequest,      messageType = '01001000'B;
  pDU_NAS_EPS_TrackingAreaUpdateAccept,       messageType = '01001001'B;
  pDU_NAS_EPS_TrackingAreaUpdateComplete,     messageType = '01001010'B;
  pDU_NAS_EPS_TrackingAreaUpdateReject,       messageType = '01001011'B;

  pDU_NAS_EPS_ExtendedServiceRequest,         messageType = '01001100'B;
  pDU_NAS_EPS_ControlPlaneServiceRequest,     messageType = '01001101'B;
  pDU_NAS_EPS_ServiceReject,                  messageType = '01001110'B;
  pDU_NAS_EPS_ServiceAccept,                  messageType = '01001111'B;
  
  pDU_NAS_EPS_GUTI_ReallocationCommand,       messageType = '01010000'B; 
  pDU_NAS_EPS_GUTI_ReallocationComplete,      messageType = '01010001'B; 
  pDU_NAS_EPS_AuthenticationRequest,          messageType = '01010010'B;
  pDU_NAS_EPS_AuthenticationResponse,         messageType = '01010011'B;
  pDU_NAS_EPS_AuthenticationReject,           messageType = '01010100'B;
  pDU_NAS_EPS_AuthenticationFailure,          messageType = '01011100'B;
  pDU_NAS_EPS_IdentityRequest,                messageType = '01010101'B;
  pDU_NAS_EPS_IdentityResponse,               messageType = '01010110'B;
  pDU_NAS_EPS_SecurityModeCommand,            messageType = '01011101'B;
  pDU_NAS_EPS_SecurityModeComplete,           messageType = '01011110'B;
  pDU_NAS_EPS_SecurityModeReject,             messageType = '01011111'B;
  
  pDU_NAS_EPS_EMM_Status,                     messageType = '01100000'B;
  pDU_NAS_EPS_EMM_Information,                messageType = '01100001'B;
  pDU_NAS_EPS_Downlink_NAS_Transport,         messageType = '01100010'B;
  pDU_NAS_EPS_Uplink_NAS_Transport,           messageType = '01100011'B;
  pDU_NAS_EPS_CS_ServiceNotification,         messageType = '01100100'B;
  
  pDU_NAS_EPS_Downlink_Generic_NAS_Transport, messageType = '01101000'B;
  pDU_NAS_EPS_Uplink_Generic_NAS_Transport,   messageType = '01101001'B;
  )"
};


type union EPS_messages
{
  EPS_SessionManagement  ePS_SessionManagement,
  EPS_MobilityManagement ePS_MobilityManagement 
};

//see 11.2.3.1.1/24.007
type record PDU_NAS_EPS
{
  BIT4                 protocolDiscriminator,
  EPS_messages         ePS_messages
} with { variant (ePS_messages)"CROSSTAG(
                          ePS_SessionManagement,  protocolDiscriminator='0010'B;
                          ePS_MobilityManagement, protocolDiscriminator='0111'B;
                          )"
};


} with { encode "RAW"} // End of module
