/******************************************************************************/
// @copyright   Copyright Notification
//   No part may be reproduced except as authorized by written permission.
//   The copyright and the foregoing restriction extend to reproduction in all media.
//   (c) 2023, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC).
//   All rights reserved.
// @version: IWD_23wk37
// $Date: 2023-06-08 15:55:51 +0200 (Thu, 08 Jun 2023) $
// $Rev: 36130 $
/******************************************************************************/

module NAS_CommonTemplates {

  import from CommonDefs all;
  import from NAS_CommonTypeDefs all;
  import from CommonIP all;
  import from Parameters all;

  //==============================================================================
  group NAS_CommonConstants {    // Constants being used for NAS_CommonTemplates

  const B1_Type tsc_Spare1 :=        '0'B;                /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, MCX, NBIOT, NR5GC, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
  const B2_Type tsc_Spare2 :=       '00'B;                /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS, UTRAN) */
  const B3_Type tsc_Spare3 :=      '000'B;                /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, MCX, NBIOT, NR5GC, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
  const B4_Type tsc_Spare4 :=     '0000'B;                /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS, UTRAN) */
  const B5_Type tsc_Spare5 :=    '00000'B;                /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
  const B6_Type tsc_Spare6 :=   '000000'B;                /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, MCX, NBIOT, NR5GC, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
  const B7_Type tsc_Spare7 :=   '0000000'B;               /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS) */
  const SpareHalfOctet tsc_SpareHalfOctet := '0'H;        /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS) */

  const SecurityHeaderType tsc_SHT_NoSecurityProtection                           := '0000'B; /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS, UTRAN) */
  const SecurityHeaderType tsc_SHT_IntegrityProtected                             := '0001'B; /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS, UTRAN) */
  const SecurityHeaderType tsc_SHT_IntegrityProtected_Ciphered                    := '0010'B; /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS, UTRAN) */
  const SecurityHeaderType tsc_SHT_IntegrityProtected_NewSecurityContext          := '0011'B; /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS) */
  const SecurityHeaderType tsc_SHT_IntegrityProtected_Ciphered_NewSecurityContext := '0100'B; /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS, UTRAN) */
  const SecurityHeaderType tsc_SHT_IntegrityProtected_PartiallyCiphered           := '0101'B; /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, UTRAN) */

  const NAS_IdType tsc_IdType_IMSI   := '001'B;           /* suitable for identity type 24.008 cl. 10.5.3.4 and identiy type 2 24.008 cl. 10.5.5.9
                                                             @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_R10_R11, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
  const NAS_IdType tsc_IdType_IMEI   := '010'B;           /* suitable for identity type 24.008 cl. 10.5.3.4 and identiy type 2 24.008 cl. 10.5.5.9
                                                             @status    APPROVED (LTE, LTE_A_R10_R11, NBIOT) */
  const NAS_IdType tsc_IdType_IMEI_24301 := '011'B;       /* suitable for identity type 24.301 cl. 9.9.3.12.1
                                                             @status    APPROVED (LTE) */
  const NAS_IdType tsc_IdType_IMEISV := '011'B;           /* @sic R5s130438 sic@ suitable for identity type 24.008 cl. 10.5.3.4 and identiy type 2 24.008 cl. 10.5.5.9
                                                             @status    APPROVED (LTE, NBIOT) */
  const NAS_IdType tsc_IdType_TMSI   := '100'B;           /* suitable for identity type 24.008 cl. 10.5.3.4 and identiy type 2 24.008 cl. 10.5.5.9
                                                             @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
  const NAS_IdType tsc_IdType_GUTI   := '110'B;           /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */

  const B3_Type tsc_IMEISV_Requested := '001'B;           /* @sic R5s130438 sic@ suitable for IMEISV request type 24.008 cl. 10.5.5.10
                                                             @status    APPROVED (IMS, LTE, NBIOT, NR5GC, NR5GC_IRAT, POS) */

  const NAS_CauseValue_Type tsc_EmmCause_IllegalUe                        := '00000011'B;   /* @status    APPROVED (LTE, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT) */
  const NAS_CauseValue_Type tsc_EmmCause_IllegalMe                        := '00000110'B;   /* @status    APPROVED (LTE, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT) */

  const NAS_CauseValue_Type tsc_Cause_MAC_Failure                         := '00010100'B;  /* @status    APPROVED ( LTE, NBIOT, NR5GC) */
  const NAS_CauseValue_Type tsc_Cause_SQN_Failure                         := '00010101'B;  /* @status    APPROVED ( LTE, NBIOT, NR5GC) */
  const NAS_CauseValue_Type tsc_Cause_nonEPS_AuthUnacceptable             := '00011010'B;  /* @status    APPROVED (LTE, NBIOT, NR5GC) */
  const NAS_CauseValue_Type tsc_Cause_TA_NotAllowed                       := '00001100'B;  /* @status    APPROVED (LTE, LTE_A_R10_R11, LTE_IRAT, NBIOT, NR5GC) */
  const NAS_CauseValue_Type tsc_EmmCause_SemanticallyIncorrect            := '01011111'B;  /* @status    APPROVED (LTE, NBIOT, NR5GC) */
  const NAS_CauseValue_Type tsc_Cause_Roaming_NotAllowed                  := '00001101'B;  /* @status    APPROVED (LTE, LTE_IRAT, NBIOT, NR5GC) */
  const NAS_CauseValue_Type tsc_Cause_PLMN_NotAllowed                     := '00001011'B;  /* @status    APPROVED (LTE, LTE_IRAT, NBIOT, NR5GC) */
  const NAS_CauseValue_Type tsc_Cause_NoNetworkSlices_Available           := '00111110'B;  /* @status    APPROVED (NR5GC) */
  const NAS_CauseValue_Type tsc_Cause_PLMN_NotAllowedToOperateAtPresentUELocation := '01001110'B;

  const NAS_KsiValue tsc_NasKsi_NoKey := '111'B;                                            /* @status    APPROVED (LTE, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT) */

  const TmsiStatusValue tsc_NoValidTmsi := '0'B;          /* @status    APPROVED (UTRAN) */

  const GprsTimerUnit tsc_GprsTimerUnit_2sec  := '000'B;  /* @status    APPROVED (LTE, NBIOT) */
  const GprsTimerUnit tsc_GprsTimerUnit_1min  := '001'B;  /* @status    APPROVED (LTE, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, UTRAN) */
  const GprsTimerUnit tsc_Gprs3TimerUnit_1min := '101'B;  /* @status    APPROVED (IMS, LTE_A_R10_R11, LTE_A_R12, NBIOT, NR5GC, SSNITZ, UTRAN) */
  const GprsTimerUnit tsc_GprsTimerUnit_6min  := '010'B;  /* @status    APPROVED (LTE, LTE_IRAT) */
  const GprsTimerUnit tsc_Gprs3TimerUnit_30sec := '100'B; /* @status    APPROVED (LTE_A_R12) */
  const GprsTimerUnit tsc_GprsTimerUnit_deact := '111'B;  /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
  const O2_Type tsc_PCO_Id_DSMIPv6 := '0007'O;
  const O2_Type tsc_PCO_Id_DSMIPv6_IPv4 := '0009'O;

  const O4_Type   tsc_IPv4Mask := 'FFFFFFFF'O;                           /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS, UTRAN) */
  const O16_Type  tsc_IPv6Mask := 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'O;   /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, UTRAN) */

  const B2_Type tsc_NonConsecutiveTacs := '00'B;  /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS) */
  const B2_Type tsc_ConsecutiveTacs    := '01'B;  /* @status    APPROVED (LTE, NBIOT, NR5GC) */
  const B2_Type tsc_MultiplePlmns      := '10'B;  /* @status    APPROVED (LTE, NBIOT) */

  const PdnTypeValue tsc_PdnType_IPv4   := '001'B;                      /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS) */
  const PdnTypeValue tsc_PdnType_IPv6   := '010'B;                      /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS) */
  const PdnTypeValue tsc_PdnType_IPv4v6 := '011'B;                      /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS) */

  // TS 24.007 clause 11.2.3.1a
  const ProcedureTransactionIdentifier tsc_PTI_Unassigned := '00'O;     /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS) */
  const ProcedureTransactionIdentifier tsc_PTI_1 := '01'O;              /* @status    APPROVED (LTE) */

  const B4_Type tsc_PayloadContainerESMMsg := '0001'B;                  /* @status    APPROVED (IMS, NR5GC, NR5GC_IRAT, POS) */

  const octetstring tsc_APN1 := '0541504E2D31'O;  /* Access Point Name APN-1;
                                                     @status    APPROVED (ENDC, IMS, LTE, LTE_A_R10_R11, NBIOT) */
  const charstring tsc_APN1_String := "APN-1";    /* Access Point Name APN-1; @sic R5s100466 sic@
                                                     @status    APPROVED (ENDC, LTE, LTE_A_R10_R11, NBIOT, NR5GC) */
  const octetstring tsc_APN2 := '0541504E2D32'O;  /* Access Point Name APN-2;
                                                     @status    APPROVED (LTE, NBIOT) */
  const charstring tsc_APN2_String := "APN-2";    /* Access Point Name APN-2; @sic R5s100748 sic@
                                                     @status    APPROVED (LTE, LTE_A_R10_R11, NBIOT) */
  const octetstring tsc_APN3 := '0541504E2D33'O;  /* Access Point Name APN-3;
                                                     @status    APPROVED (LTE_A_R10_R11) */
  const charstring tsc_APN3_String := "APN-3";    /* Access Point Name APN-3; @sic R5-143213 sic@
                                                     @status    APPROVED (LTE_A_R10_R11) */

  } // end group NAS_CommonConstants
  //------------------------------------------------------------------------------

  template (value) AccessPointName cs_AccessPointName(octetstring p_Name) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
    iei   := omit,
    iel   := int2oct(lengthof(p_Name), 1),
    nameValue := p_Name
  };

  template (present) AccessPointName cr_AccessPointName(octetstring p_Name) :=
  {  /* @status    APPROVED (ENDC, IMS, LTE, LTE_A_R10_R11, NBIOT) */
    iei   := '28'O,
    iel   := int2oct(lengthof(p_Name), 1),
    nameValue := p_Name
  };

  template (present) AccessPointName cr_AccessPointName_Any :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, UTRAN) */
    iei   := '28'O,
    iel   := ?,
    nameValue := ?
  };

  template (present) AdditionalUpdateType cr_AdditionalUpdateTypeAny :=
  { /* 24.301 cl. 9.9.3.0B */
    /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    /* @sic R5s100135 sic@ */
    iei       := 'F'H,                            // currently only used as TV
    pnb_CIOT  := ?, // @sic R5s160711 Baseline Moving, R5s210796 sic@
    signallingActiveFlag := tsc_Spare1, // @sic R5s160711 Baseline Moving sic@
    addUpdateTypeValue := ?
  };

  template (present) AuthenticationFailureParameter cr_AuthFailParam_Any :=
  { /* TLV format to be used in Authentication_Failure */
    /* @status    APPROVED (IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_IRAT, NBIOT, NR5GC, POS, SSNITZ, UTRAN) */
    iei             := '30'O, // version 110, and value used in GMM
    iel             := '0E'O,
    auts            := ?
  };

  template (present) AuthenticationFailureParameter cdr_AuthFailParamGSM_Any modifies cr_AuthFailParam_Any :=
  { /* @status    APPROVED (IMS, IMS_IRAT, LTE_A_IRAT, LTE_IRAT, POS, SSNITZ, UTRAN) */
    iei             := '22'O
  };

  template (value) RAND cs_RAND_v(B128_Type p_RAND) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
    iei := omit,
    randValue := p_RAND
  };

  template (value) RAND cs_GMM_AuthRAND(B128_Type p_Rand) :=
  { /* @status    APPROVED (IMS, IMS_IRAT, LTE_A_IRAT, LTE_IRAT, NR5GC, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei             := '21'O,
    randValue       := p_Rand
  };

  template (value) AUTN cs_AUTN_lv(B128_Type p_AUTN) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
    iei := omit,
    iel := '10'O,       /* AUTN has length of 128 bits i.e. 16 octets */
    aUTN := p_AUTN
  };

  template (value) AUTN cs_GSM_AUTN(template (value) B128_Type p_AUTN) :=
  { /* @status    APPROVED (IMS, IMS_IRAT, LTE_A_IRAT, LTE_IRAT, NR5GC, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei             := '20'O,
    iel             := '10'O,                        // Length of 16 octets
    aUTN            := p_AUTN                        // value of Authentication Parameter AUTN
  };

  template (value) AUTN cs_GMM_AUTN(B128_Type p_Autn) :=
  { /* @status    APPROVED (IMS, IMS_IRAT, LTE_A_IRAT, LTE_IRAT, POS, SSNITZ, UTRAN) */
    iei             := '28'O,
    iel             := '10'O,
    aUTN            := p_Autn
  };

  template (value) CiphKeySeqNum cs_CiphKeySeqNum(template (omit) IEI4_Type p_IEI,
                                                  template (value) KeySeq p_KeySeq) :=
  { /* @status    APPROVED (IMS, IMS_IRAT, LTE_A_IRAT, LTE_IRAT, POS, SSNITZ, UTRAN) */
    iei             := p_IEI,
    spare1          := '0'B,
    keySeq          := p_KeySeq
  };

  template (present) CiphKeySeqNum cr_CiphKeySeqNum(template (omit) IEI4_Type p_IEI,
                                                    template (present) KeySeq p_KeySeq) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei             := p_IEI,
    spare1          := '0'B,
    keySeq          := p_KeySeq
  };

  // =============================================================================
  // Structured Type Constraint
  // Codec
  // 3G TS 24.008 cl. 10.5.4.32
  // -----------------------------------------------------------------------------
  template (present) Codec cr_CodecAny :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    sysId           := ?,                            // system identifcation
    len             := ?,                            // length
    bitMap1to8      := ?,                            // codec bitmap bits 1-8
    bitMap9to16     := *                             // codec bitmap bits 9-16
  };

  // =============================================================================
  // Structured Type Constraint
  // Supported Codec List
  // 3G TS 24.008 cl. 10.5.3.32
  // -----------------------------------------------------------------------------
  template (present) CodecList cr_CodecListAny :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei             := '40'O,                        // '01000000'B (40 hex)
    iel             := ?,                            // length
    codec           := ({cr_CodecAny, cr_CodecAny, cr_CodecAny, *}, {cr_CodecAny, cr_CodecAny, *}, {cr_CodecAny, *}) // Codec list @sic R5s110278 sic@
  };

  template (value) DCN_ID cs_Dcn_Id (O2_Type p_DCNIdValue) :=
  { /* @status    APPROVED (IMS, SSNITZ, UTRAN) */
    iei := '41'O,
    iel := '02'O,
    dcnIdValue := p_DCNIdValue
  };

   template (value) DetachType cs_DetachType(NAS_AttDetValue_Type p_TypeOfDetach):=
  { /* @status    APPROVED (IMS_IRAT, LTE, LTE_A_R10_R11, NBIOT) */
    switchOff          := '0'B,
    typeOfDetach       := p_TypeOfDetach
  };

  template (present) DetachType cr_DetachType(template (present) B1_Type p_SwitchOff,
                                              template (present) NAS_AttDetValue_Type p_TypeOfDetach) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    switchOff          := p_SwitchOff,
    typeOfDetach       := p_TypeOfDetach
  };

  template (present) DetachType cr_DetachTypeOnSwitchOff := cr_DetachType('1'B, ?);                 /* @status    APPROVED (IMS, IMS_IRAT, LTE_A_IRAT, LTE_IRAT, POS, SSNITZ, UTRAN) */

  template (present) DeviceProperties cr_DeviceProperties(IEI4_Type p_IEI,
                                                          template (present) B1_Type p_LowPriority := ?) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei         := p_IEI,
    spare       := tsc_Spare3,
    lowPriority := p_LowPriority
  };

  template (present) DRXparameter cr_DRXparameter_Any (template (omit) IEI8_Type p_IEI) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei             := p_IEI,
    splitPGcycleCode := ?,                           // Split PG cycle code
    cnDRXcoef       := ?,                            // CN specific DRX cycle length coefficient
    splitOnCCCH     := ?,                            // Split on CCCCH
    nonDRXtimer     := ?                             // non-DRX timer
  };

  template (present) EDGE_Struct cr_EDGE_Struct_Any :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    modulationCapability := ?,
    pwrMask1        := ?,
    eDGE_RF_PowerCapability1 := *,                   // not present if pwrMask1 = 0
    pwrMask2        := ?,
    eDGE_RF_PowerCapability2 := *                    // not present if pwrMask2 = 0
  };

  // =============================================================================
  // Structured Type Constraint
  // Emergency Service Category
  // 3GPP 24.008 / 10.5.4.33
  // -----------------------------------------------------------------------------
  template (present) EmergServCat cr_EmergServCat (template (present) B7_Type p_Cat) :=
  {
    spare           := '0'B,
    emergSCValue    := p_Cat
  };

  template (value) EmergServCat cs_EmergServCat(B7_Type p_EmergSCValue) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NR5GC, NR5GC_IRAT, POS) */
    spare           := '0'B,
    emergSCValue    := p_EmergSCValue                // Emergency Service Category value
  };

  template (value) EmergNum cs_EmergencyLocalNumber(Type4Length_Type p_Length,
                                                    template (value) EmergServCat p_EmergSCValue,
                                                    octetstring p_Number) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NR5GC, NR5GC_IRAT, POS) */
    len := p_Length,                   // length
    emergServCat := p_EmergSCValue,    // Emergency Service Category
    digits := p_Number                 // BCD numbers
  };

  // =============================================================================
  // Structured Type Constraint
  // -----------------------------------------------------------------------------
  template (present) ExtdDRXParams cr_ExtdDRXParamsAny :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei          := '6E'O,
    iel          := ?,           // length
    pagingTimeWindow := ?,
    eDRXValue    := ?,
    extdPTW      := *   // @sic R5s221182 Baseline Moving Rel-17 sic@
  };

  template (value) GPRS_Timer cs_GprsTimer_tv(IEI8_Type p_IEI, // @sic R5s100662 sic@
                                              B3_Type p_Unit,
                                              B5_Type p_Value) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
    iei   := p_IEI,               // '1E'O
    unit  := p_Unit,
    timerValue := p_Value
  };

  template (value) GPRS_Timer cs_GprsTimer_v(GprsTimerUnit p_Unit,
                                             B5_Type p_Value) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei        := omit,
    unit       := p_Unit,
    timerValue := p_Value
  };

  template (value) GPRS_Timer cs_GprsTimer_v_deact := cs_GprsTimer_v(tsc_GprsTimerUnit_deact, tsc_Spare5);  /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */

  template (value) IdentityType cs_IdentityType(NAS_IdType p_NAS_IdType) :=
  { /* @status    APPROVED (ENDC, LTE, LTE_A_R10_R11, NBIOT, NR5GC) */
    spare           := '0'B,
    typeOfId        := p_NAS_IdType
  };

  template (present) LocAreaId cr_LAI(template (omit) IEI8_Type p_IEI,
                                      template (present) octetstring p_PLMN := ?,
                                      template (present) octetstring p_LAC := ?) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei      := p_IEI,
    plmn     := p_PLMN,                       // MCC + MNC
    lac      := p_LAC                         // location area code
  };

  template (present) LocAreaId cr_LAI_Any   := cr_LAI('13'O); /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
  template (present) LocAreaId cr_LAI_Any_v := cr_LAI(omit);  /* @status    APPROVED (IMS, IMS_IRAT, LTE_A_IRAT, LTE_IRAT, POS, SSNITZ, UTRAN) */

  template (value) LocAreaId cs_LAI(template (omit) IEI8_Type p_IEI,
                                    template (value) octetstring p_PLMN,
                                    template (value) octetstring p_LAC) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei      := p_IEI,
    plmn     := p_PLMN,                       // MCC + MNC
    lac      := p_LAC                         // location area code
  };

  template (value) LLC_SAPI cs_LLC_SAPI(template (omit) IEI8_Type p_IEI := omit,
                                        B4_Type p_LlcSapiValue) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, UTRAN) */
    iei             := p_IEI,
    spare           := '0000'B,
    llcSapiValue    := p_LlcSapiValue
  };

  template (value) LLC_SAPI cs_LLC_SAPI_11 (template (omit) IEI8_Type p_IEI := omit) := cs_LLC_SAPI(p_IEI, '1011'B);   /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
  template (value) LLC_SAPI cs_LLC_SAPI_03 (template (omit) IEI8_Type p_IEI := omit) := cs_LLC_SAPI(p_IEI, '0011'B);   /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, UTRAN) */

  template (present) MobileIdentity cr_MobileIdAny(template (omit) IEI8_Type p_IEI := omit) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei             := p_IEI,
    iel             := ?,
    idDigit1        := ?,
    oddEvenInd      := ?,
    typeOfId        := ?,
    otherDigits     := ?
  };

  template (value) MobileIdentity cs_MobileIdentityGuti(template (omit) IEI8_Type p_IEI,
                                                        octetstring p_Guti) :=
  {
    /* Reference: 24.301 cl. 9.9.3.12;
       @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
    iei         := p_IEI,
    iel         := int2oct(lengthof(p_Guti) + 1, 1),    // 11 octets in case of GUTI
    idDigit1    := '1111'B,                             // in case of the GUTI
    oddEvenInd  := '0'B,                                // in case of the GUTI
    typeOfId    := tsc_IdType_GUTI,                     // 3 bits
    otherDigits := p_Guti                               // 10 octets acc. to 24.301
  };

  template (value) MobileIdentity cs_MobileIdentityImsi(B4_Type p_FirstDigit,
                                                        B1_Type p_OddEvenInd,
                                                        octetstring p_OtherDigits) :=
  { /* @status    APPROVED (IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_R10_R11, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei         := '17'O,
    iel         := int2oct(lengthof(p_OtherDigits) + 1, 1),
    idDigit1    := p_FirstDigit,                        // 4 bits
    oddEvenInd  := p_OddEvenInd,                        // 1 bit
    typeOfId    := tsc_IdType_IMSI,                     // 3 bits
    otherDigits := p_OtherDigits
  };

  template (value) MobileIdentity cds_MobileIdentityImsi_lv(B4_Type p_FirstDigit,
                                                            B1_Type p_OddEvenInd,
                                                            octetstring p_OtherDigits)
    modifies cs_MobileIdentityImsi :=
  { /* @status    APPROVED (IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_R10_R11, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei   := omit
  };

  template (value) MobileIdentity cs_MobileIdTMSIorPTMSI(template (omit) IEI8_Type p_IEI,
                                                         O4_Type p_TmsiPtmsi) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei             :=  p_IEI,                          // for U/G this is '18'O
    iel             := '05'O,                           // TMSI consists of 4 octets
    idDigit1        := '1111'B,                         // special coding for TMSI
    oddEvenInd      := '0'B,                            // even
    typeOfId        := tsc_IdType_TMSI,                 // TMSI / P-TMSI
    otherDigits     := p_TmsiPtmsi
  };

  template (value) MobileIdentity cs_MobileIdTMSI(template (omit) IEI8_Type p_IEI,       // iei can be '17' (MM) or '13' (GMM) or omit
                                                  O4_Type p_Tmsi) :=
    /* @status    APPROVED (IMS_IRAT, LTE_IRAT, SSNITZ) */
    cs_MobileIdTMSIorPTMSI(p_IEI, p_Tmsi);

  template (present) MobileIdentity cr_MobileIdTMSI_lv(template (present) octetstring p_Tmsi := ?) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei             := omit,
    iel             := '05'O,                        // TMSI consists of 4 octets
    idDigit1        := '1111'B,                      // special coding for TMSI
    oddEvenInd      := '0'B,                         // even
    typeOfId        := tsc_IdType_TMSI,              // TMSI
    otherDigits     := p_Tmsi
  };

  template (present) MobileIdentity cdr_MobileIdTMSI_tlv(template (present) octetstring p_Tmsi := ?,
                                                         IEI8_Type p_IEI := '18'O)
    modifies cr_MobileIdTMSI_lv :=
  { /* @status    APPROVED (IMS_IRAT, LTE_A_IRAT, LTE_IRAT, POS, SSNITZ, UTRAN) */
    iei             := p_IEI
  };

  template (present) MobileIdentity cr_MobileIdentityImei(B4_Type p_FirstDigit,
                                                          B1_Type p_OddEvenInd,
                                                          octetstring p_OtherDigits,
                                                          NAS_IdType p_NAS_IdType := tsc_IdType_IMEI) := // @sic R5s130758 sic@
  {  /* @status    APPROVED (LTE, LTE_A_R10_R11, NBIOT) */
    iei         := omit,
    iel         := int2oct(lengthof(p_OtherDigits) + 1, 1),
    idDigit1    := p_FirstDigit,                        // 4 bits
    oddEvenInd  := p_OddEvenInd,                        // 1 bit
    typeOfId    := p_NAS_IdType,                        // 3 bits // @sic R5s130758 sic@
    otherDigits := p_OtherDigits
  };

  template (present) MobileIdentity cr_MobileIdentityImeisv(B4_Type p_FirstDigit, // @sic R5-131832 sic@
                                                            B1_Type p_OddEvenInd,
                                                            octetstring p_OtherDigits) :=
  {  /* @status    APPROVED (LTE, NBIOT) */
    iei         := omit,
    iel         := int2oct(lengthof(p_OtherDigits) + 1, 1),
    idDigit1    := p_FirstDigit,                        // 4 bits
    oddEvenInd  := p_OddEvenInd,                        // 1 bit
    typeOfId    := tsc_IdType_IMEISV,                   // 3 bits
    otherDigits := p_OtherDigits
  };

  template (present) MS_Clsmk2 cr_MS_Clsmk2_Any_tlv(template (omit) IEI8_Type p_IEI := '11'O) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei             := p_IEI, // @sic R5s100662, R5s110112 sic@
    iel             := '03'O,
    spare1_1        := '0'B,
    revLvl          := ?,
    eSIND           := ?,
    a5_1            := ?,
    rFPwrCap        := ?,
    spare1_2        := '0'B,
    pSCap           := ?,
    sSSI            := ?,
    sMCap           := ?,
    vBS             := ?,
    vGCS            := ?,
    fC              := ?,
    cM3             := ?,
    spare1_3        := '0'B,
    lCSVA           := ?,
    uCS2            := ?,
    soLSA           := ?,
    cMSP            := ?,
    a5_3            := ?,
    a5_2            := ?
  };

  template (present) MS_Clsmk2 cr_MS_Clsmk2_Any :=
  /* @status    APPROVED (IMS_IRAT, LTE_A_IRAT, LTE_IRAT, POS, SSNITZ, UTRAN) */
    cr_MS_Clsmk2_Any_tlv (omit);

  template (present) MS_Clsmk3 cr_MSCLSMK3_Any :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei             := '20'O,                        /* 0x20 */
    iel             := ?,                            /* OCTETSTRING [1] */
    spareBit        := '0'B,                         // spare bit */
    multibandSupported := ?,
    a5_7            := ?,                            /* a5/7 algorithm supported */
    a5_6            := ?,                            /* a5/6 algorithm supported */
    a5_5            := ?,                            /* a5/5 algorithm supported */
    a5_4            := ?,                            /* a5/4 algorithm supported */
    associatedRadioCapabilty2 := *,                  /* present if multibandSupported = 101 or 110 */
    spareBits1      := *,                            /* present if multibandSupported = 001 or 010 or 100 */
    associatedRadioCapabilty1 := *,                  /* present if multibandSupported = 001 or 010 or 100 or 101 or 110 */
    maskBit1        := ?,
    rGSM_RadioCapability := *,                       /* R-GSM band associated radio capability.
                                                        not present if maskB1 = 0 */
    maskBit2        := ?,
    multiSlotClass  := *,                            /* multi slot class.
                                                        not present if multiSlotClass = 0 */
    uCS2Treatment   := ?,
    extMeasurementCapability := ?,                   /* extended measurement capability */
    maskBit3        := ?,
    msMeasurementCapability := cr_MS_MeasCapability_Any ifpresent, /* MS measurement capability
    // not present if maskB3 = 0 */
    maskBit4        := ?,
    msPositioningMethod := *,                        /* MS positioning method capability
                                                        not present if maskB4 = 0 */
    maskBit5        := ?,
    eDGE_MultiSlot  := *,                            /* EDGE multi slot capability
                                                        not present if maskB5 = 0 */
    maskBit6        := ?,
    psk8_Struct     := cr_EDGE_Struct_Any ifpresent, /* EDGE struct
                                                        not present if maskB6 = 0 */
    maskBit7        := ?,
    gSM400BandsSupported := *,                       /* not present if maskBIt7 = 0 */
    gSM400AssociatedRadioCapability := *,            /* not present if gSM400BandsSupported = 00 or maskB7 = 0 */
    maskBit8        := ?,
    gSM850AssociatedRadiioCapability := *,           /* not present if maskBIt8 = 0 */
    maskBit9        := ?,
    pCS1900AssociatedRadiioCapability := *,          /* not present if maskBIt9 = 0 */
    uMTS_FDD_RAT_Capability := ?,
    uMTS384TDD_RAT_Capability := ?,
    cDMA2000_RAT_Capability := ?,
    maskBit10       := ?,
    dTM_GPRS_MultiSlotSubclass := *,                 /* not present if maskB10 = 0 */
    singleSlotDTM   := *,                            /* not present if maskB10 = 0 */
    maskBit11       := *,                            /* not present if maskB10 = 0 */
    dTM_EGPRS_MultiSlorSubclass := *,                /* not present if maskB10 = 0 or maskB11 = 0 */
    maskBit12       := ?,
    singleBandSupport := *,                          /* not present if maskB12 = 0 */
    maskBit13       := *,
    gSM700AssociatedRadioCapability := *,            /* not present if maskB13 = 0 */
    uMTS128TDD_RAT_Capability := *,
    gERANFeatPack1  := *,
    mask14          := *,
    extDTM_GPRS_MultiSlotSubclass := *,              /* not present if maskB14 = 0 */
    etxDTM_EGPRS_MultiSlotSubclass := *,             /* not present if maskB14 = 0 */
    mask15          := *,
    highMultislotCap := *,                           /* not present if mask15 = 0 */
    spare2          := tsc_Spare1,                   // @sic R5s150329 Baseline Moving sic@
    gERANFeatPack2  := *,
    gMSKMultislotPowerProfile := *,
    pSKMultislotPowerProfile := *,
    mask17          := *,                            /* rel 6 features */
    tGSM400BandsSupported := *,                      /* not present if maskB17 = 0 */
    tGSM400AssocRadioCap := *,                       /* not present if maskB17 = 0 */
    spare          := *,                              // @sic R5s110176 Baseline Moving sic@
    dlAdvancedRxPerf := *,
    dTMEhancCap     := *,
    mask19          := *,
    dTMGPRSHighMultislotClass := *,                  /* not present if maskB19 = 0 */
    offsetReq       := *,                            /* not present if maskB19 = 0 */
    mask20          := *,                            /* not present if maskB19 = 0 */
    dTMEGPRSHighMultislotClass := *,                 /* not present if maskB19 and maskB20 = 0 */
    rptdACCHCap     := *,
    mask21          := *,
    gsm710AssocRadioCap  := *, /* not present if maskBit21 = 0 */
    mask22          := *,
    tgsm810AssocRadioCap  := *, /* not present if maskBit22 = 0 */
    cipheringModeSettingCap  := *,
    addPositionCap  := *,
    eutraFDDSupport := *, /* rel 8 features */
    eutraTDDSupport := *,
    eutraMeasAndReporting := *,     /* @sic R5s100135 Baseline moving sic@ */
    priorityBasedReselection:= *,   // @sic R5s110176 Baseline Moving sic@
    utraCSGCellsReporting := *,     // @sic R5s110176 Baseline Moving sic@
    vamosLevel := *,                // @sic R5s110176 Baseline Moving sic@
    tighterCap := *, // @sic R5s120178 Baseline Moving sic@
    selectCipheringDLSACCH := *, // @sic R5s120178 Baseline Moving sic@
    csPS_SRVCC_G2U   := *, // @sic R5s130195 Baseline Moving sic@
    csPS_SRVCC_G2E   := *, // @sic R5s130195 Baseline Moving sic@
    geranNwkSharing  := *, // @sic R5s150329 Baseline Moving sic@
    eutraWidebandRSRQMeas  := *, // @sic R5s150329 Baseline Moving sic@
    erBandSupport  := *, // @sic R5s150329 Baseline Moving sic@
    utraMultipleFreqBandInd  := *, // @sic R5s150329 Baseline Moving sic@
    eutraMultipleFreqBandInd  := *, // @sic R5s150329 Baseline Moving sic@
    xtdTSCSetCap  := *, // @sic R5s150329 Baseline Moving sic@
    xtdEARFCNValueRange := *, // @sic R5s160712 Baseline Moving sic@
    spareBits2      := *
  };

  template (present) MS_Clsmk3 cdr_MSCLSMK3_EutraCheck (template (omit) IEI8_Type p_IEI) modifies cr_MSCLSMK3_Any :=
  { /* @status    APPROVED (LTE) */
    iei             := p_IEI, // @sic R5s110244, R5s140493 sic@
    iel             := omit, // @sic R5s110244 sic@
    eutraFDDSupport := ?,
    eutraTDDSupport := ?
  };

  template (present) MS_MeasCapability cr_MS_MeasCapability_Any :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    sMS_VALUE       := ?,
    sM_VALUE        := ?
  };

  template (present) MS_NetworkCap cr_MS_NetworkCap_Any :=
  { /* 24.301 cl. 9.9.3.18 -> 24.008 cl. 10.5.5.12;
       @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei  := '31'O,                                   /* present in case of TV; omit in case of V */
    iel  := ?,                                       /* present in case of LV or TLV; omit in case of V */
    gea1  := ?,
    smCapDedicated  := ?,
    smCapGPRS  := ?,
    ucs2  := ?,
    ssScreeningIndicator  := ?,
    soLSACap  := ?,
    revLevelIndicator  := ?,
    pfcFeatureMode  := ?,
    gea2  := ?,
    gea3  := ?,
    gea4  := ?,
    gea5  := ?,
    gea6  := ?,
    gea7  := ?,
    lcsVACap  := ?,
    psHOtoUTRAN_IuModeCap  := ?,
    psHOtoEUTRAN_S1ModeCap  := ?,
    emmCombinedCap  := ?,       // @sic R5s110176 Baseline Moving sic@
    isrSupport  := ?,
    srvccToGERAN_UTRANCap  := ?,
    epcCap  := ?,
    nfCap := *,       // @sic R5s110176 Baseline Moving R5s110242 sic@
    gERANNtwkShareCap := *, // @sic R5s130195 Baseline Moving sic@
    userPlaneIntegrityProtSupport  := *,         // @sic R5s160712 Baseline Moving, not present for Rel-12 sic@
    gia4  := *,         // @sic R5s160712 Baseline Moving, not present for Rel-12 sic@
    gia5  := *,         // @sic R5s160712 Baseline Moving, not present for Rel-12 sic@
    gia6  := *,         // @sic R5s160712 Baseline Moving, not present for Rel-12 sic@
    gia7  := *,         // @sic R5s160712 Baseline Moving, not present for Rel-12 sic@
    ePCOInd := *,       // @sic R5s170598 Baseline Moving sic@
    restrictEnhancedCoverageCap := *,  // @sic R5s170598 Baseline Moving sic@
    dualConnectivityEUTRA_NR := *, // @sic R5s180553 Baseline Moving sic@
    spareBits := *
  };

  template (present) MS_NetworkCap cdr_MS_NetworkCapAss_lv modifies cr_MS_NetworkCap_Any :=
  { /* @status    APPROVED (IMS, IMS_IRAT, LTE_A_IRAT, LTE_IRAT, POS, SSNITZ, UTRAN) */
    iei := omit
  };

  template (present) MS_NetworkFeatureSupport cr_MS_NetworkFeatureSupport(IEI4_Type p_IEI,
                                                                          template (present) B1_Type p_ExtdPeriodicTimers := ?) :=
  { /* 24.301 cl. 9.9.2.0A -> 24.008 cl. 10.5.5.15 */
    /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei                := p_IEI,
    spare              := tsc_Spare3,
    extdPeriodicTimers := p_ExtdPeriodicTimers
  };

  template (present) NBIFOMContainer cr_NBIFOMContainerAny :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, UTRAN) */
    iei    := '33'O,
    iel    := ?,           // length
    containerContents   := ?
  };

  template (present) NwkResourceId cr_NwkResourceIdAny (IEI8_Type p_IEI := '10'O) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei                := p_IEI,
    iel                := ?,
    nriContainerValue  := ?,
    spareBits          := tsc_Spare6          // @sic R5s140778 sic@
  };

  template (value) PacketFlowIdentifier cs_PktFlowId :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, UTRAN) */
    iei             := '34'O,
    iel             := '01'O,
    spare           := '0'B,
    idValue         := '0000000'B                       // Best effort
  };

  template (value) PLMN_List cs_PLMN_List(NAS_PlmnIdList_Type p_PlmnIdList) :=
  { /* @status    APPROVED (LTE, LTE_A_IRAT, LTE_A_R10_R11, NBIOT, NR5GC, UTRAN) */
    iei    := '4A'O,
    iel    := int2oct(lengthof(p_PlmnIdList) * 3, 1),
    plmnList := p_PlmnIdList
  };

  template (value) PLMN_List cs_PLMN_List_1PLMN(NAS_PlmnId p_Plmn1) :=
  /* @status    APPROVED (LTE, LTE_A_IRAT, LTE_A_R10_R11, NBIOT, NR5GC, UTRAN) */
    cs_PLMN_List({p_Plmn1});

  template (value) PLMN_List cs_PLMN_List_2PLMNs(NAS_PlmnId p_Plmn1,
                                                 NAS_PlmnId p_Plmn2) :=
  /* @status    APPROVED (LTE, LTE_A_R10_R11, NBIOT, NR5GC) */
    cs_PLMN_List({p_Plmn1, p_Plmn2});

  template (value) PLMN_List cs_PLMN_List_3PLMNs(NAS_PlmnId p_Plmn1,
                                                 NAS_PlmnId p_Plmn2,
                                                 NAS_PlmnId p_Plmn3) :=
  /* @status    APPROVED (LTE, NBIOT) */
    cs_PLMN_List({p_Plmn1, p_Plmn2, p_Plmn3});

  template (value) PLMN_List cs_PLMN_List_4PLMNs(NAS_PlmnId p_Plmn1,
                                                 NAS_PlmnId p_Plmn2,
                                                 NAS_PlmnId p_Plmn3,
                                                 NAS_PlmnId p_Plmn4) :=
  /* @status    APPROVED (LTE, NBIOT) */
    cs_PLMN_List({p_Plmn1, p_Plmn2, p_Plmn3, p_Plmn4});

  template (value) ProtocolContainer cs_ProtocolContainer_Common(O2_Type p_ContainerId,
                                                                 integer p_ContainerLength := 0,
                                                                 template (omit) octetstring p_Content := omit) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS, UTRAN) */
    protocolID := p_ContainerId,
    protocolLength := int2oct(p_ContainerLength, 1),
    protocolLongLength := omit,   // @sic R5s201386 Baseline Moving sic@
    content := p_Content
  };

  template (value) ProtocolContainer cs_ProtocolContainer(O2_Type p_ProtocolId,
                                                          octetstring p_Content) :=
  /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS, UTRAN) */
  /* @sic R5s141127 change 4 - MCC160 Comments: cs_ProtocolContainer_Common sic@ */
    cs_ProtocolContainer_Common(p_ProtocolId, lengthof(p_Content), p_Content);

  template (value) ProtocolConfigOptions cs_ProtocolConfigOptions_Common(Type4Length_Type p_Type4Length := '01'O,
                                                                         template (omit) ProtocolConfigOptions.pco p_ProtocolContainers := omit) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NR5GC_IRAT, POS, UTRAN) */
    iei            := '27'O,
    iel            := p_Type4Length,
    ext            := '1'B,
    spare          := '0000'B,
    configProtocol := '000'B,
    pco            := p_ProtocolContainers
  };

  template (value) ProtocolConfigOptions cs_ProtocolConfigOptions_PPP := cs_ProtocolConfigOptions_Common;      /* @status    APPROVED (LTE_IRAT) */

  /*
   * @desc      Common function to build up ProtocolConfigOptions acc. to 24.008 cl. 10.5.6.3
   * @param     p_ProtocolContainers
   * @return    template (value) ProtocolConfigOptions
   * @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NR5GC_IRAT, POS, UTRAN)
   */
  function f_NAS_ProtocolConfigOptionsTX(template (value) NAS_ProtocolConfigOptions_Type  p_ProtocolContainers) return template (value) ProtocolConfigOptions
  {
    var integer v_Length := 1;   // there are at least ext, spare, configProtocol
    var integer i;

    for (i:=0; i < lengthof(p_ProtocolContainers); i:=i+1) {
      v_Length := v_Length + oct2int(valueof(p_ProtocolContainers[i].protocolLength)) + 3; // 2 octets for protocolID and 1 octet for protocolLength
    }
    return cs_ProtocolConfigOptions_Common(int2oct(v_Length, 1), p_ProtocolContainers);
  }

  template (value) ProtocolConfigOptions cs_ProtocolConfigOptions_OneOption(template (value) ProtocolContainer p_ProtocolContainer) :=
    /* @status    APPROVED (UTRAN) */
    f_NAS_ProtocolConfigOptionsTX({p_ProtocolContainer});

  template (present) ProtocolConfigOptions cr_ProtocolConfigOptionsAny :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, UTRAN) */
    iei            := '27'O,
    iel            := ?,
    ext            := '1'B,
    spare          := '0000'B,
    configProtocol := ?,
    pco            := *  // @sic R5s100800 sic@
  };

  template (present) ExtdProtocolConfigOptions cr_ExtdPCOAny :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS, UTRAN) */
    iei         := '7B'O,
    iel         := ?,
    ext         := ?,
    spare       := tsc_Spare4,
    configProtocol := ?,
    pco         := *
  };

  template (value) PTMSI_Signature cs_PTMSI_Signature(octetstring p_Ptmsi) :=
  { /* @status    APPROVED (IMS, IMS_IRAT, LTE_A_IRAT, LTE_IRAT, POS, SSNITZ, UTRAN) */
    iei             := '19'O,
    iel             := omit,
    signatureValue  := p_Ptmsi
  };

  template (present) PTMSI_Signature cr_PTMSI_Signature(template (present) O3_Type p_PtmsiSig) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei             := '19'O,
    iel             := omit,
    signatureValue  := p_PtmsiSig
  };

  template (present) PTMSI_Signature cr_PTMSI_SignatureAny :=
    /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    cr_PTMSI_Signature(?);

  template (present) PTMSI_Signature cr_PTMSI_Signature2Any :=  // Only used in Detach Request MO
  { /* @status    APPROVED (IMS, IMS_IRAT, LTE_A_IRAT, LTE_IRAT, POS, SSNITZ, UTRAN) */
    iei             := '19'O,
    iel             := '03'O,
    signatureValue  := ?
  };

  template (value) QualityOfService cs_QoS_Negotiated_1 :=
  { /* TS 34.123-3 Table 8.10.2 */
    /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
    iei := '30'O,
    iel := '10'O,
    spare1 := '00'B,
    delayClass := '100'B,
    relabilityClass := '011'B,
    peakThroughput := '0100'B,
    spare2 := '0'B,
    precedenceClass := '011'B,
    spare3 := '000'B,
    meanThroughput := '11111'B,
    trafficClass := '100'B,
    deliveryOrder := '10'B,
    deliveryErrorSDU := '010'B,
    maxSduSize := '00100000'B,
    maxBitRateUL := '01000000'B,
    maxBitRateDL := '01000000'B,
    residualBER := '0111'B,
    sduErrorRatio := '0100'B,
    transferDelay := '000000'B,
    trafficHandlingPrio := '00'B,
    guaranteedBitRateUL := '00010000'B,
    guaranteedBitRateDL := '00010000'B,
    spare4 := '000'B,
    signallingInd := '0'B,
    sourceStatisticsDescriptor := '0000'B,
    maxBitRateDL_Ext := '00000000'B,
    guaranteedBitRateDL_Ext := '00000000'B,
    maxBitRateUL_Ext := '00000000'B,
    guaranteedBitRateUL_Ext := '00000000'B,
    maxBitRateDL_Ext2       := omit,  // @sic R5s1300195 Baseline Moving sic@
    guaranteedBitRateDL_Ext2  := omit,  // @sic R5s1300195 Baseline Moving sic@
    maxBitRateUL_Ext2         := omit,  // @sic R5s1300195 Baseline Moving sic@
    guaranteedBitRateUL_Ext2  := omit   // @sic R5s1300195 Baseline Moving sic@
  };

  template (value) QualityOfService cds_QoS_Negotiated_2 modifies cs_QoS_Negotiated_1 :=
  { /* TS 34.123-3 Table 8.10.2 */
    /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
    maxSduSize := '10010110'B,
    maxBitRateUL := '01001000'B,
    maxBitRateDL := '01001000'B,
    residualBER := '0100'B,
    sduErrorRatio := '0011'B
   };

  template (value) QualityOfService cds_QoS_Negotiated_3 modifies cs_QoS_Negotiated_1 :=
  { /* TS 34.123-3 Table 8.10.2 */
    /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
    trafficClass := '001'B,
    deliveryErrorSDU := '011'B,
    maxSduSize := '10001100'B,
    maxBitRateUL := '01101110'B,                //432 kbps
    maxBitRateDL := '01101110'B,                //432 kbps
    sduErrorRatio := '0010'B,
    transferDelay := '001101'B,
    guaranteedBitRateUL := '00000000'B,
    guaranteedBitRateDL := '00000000'B
  };

  template (value) QualityOfService cds_QoS_Negotiated_4  (template (omit) IEI8_Type p_IEI := '30'O) modifies cs_QoS_PDP2 :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
    relabilityClass := '101'B,
    trafficClass := '001'B,
    deliveryOrder := '10'B,    // @sic R5-133509 sic@
    maxSduSize := '00001111'B,
    maxBitRateUL := '01101000'B,
    maxBitRateDL := '01101000'B,
    residualBER := '0001'B,
    sduErrorRatio := '0001'B,
    transferDelay := '001000'B,
    sourceStatisticsDescriptor := '0001'B
  };

  template (value) QualityOfService cds_QoS_Negotiated_8 modifies cs_QoS_Negotiated_1 :=
  { /* See in TS 36.508 Table  6.6.2-1A - Context #8 */
    /* @status   */
    transferDelay := '000111'B // 70 msec - See 24.008 cl. 10.5.6.5
   };

  template (value) QualityOfService cs_QoS_PDP2 (template (omit) IEI8_Type p_IEI := '30'O) :=
  { /* TS 51.010-1 Table 40.5 */
    // @sic R5s120218 sic@
    /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
    iei := p_IEI,
    iel := '10'O,
    spare1 := '00'B,
    delayClass := '100'B,
    relabilityClass := '011'B,
    peakThroughput := '0101'B,
    spare2 := '0'B,
    precedenceClass := '010'B,
    spare3 := '000'B,
    meanThroughput := '10000'B,
    trafficClass := '100'B,
    deliveryOrder := '01'B,
    deliveryErrorSDU := '011'B,
    maxSduSize := '10010110'B,
    maxBitRateUL := '01001000'B,
    maxBitRateDL := '01001000'B,
    residualBER := '0111'B,
    sduErrorRatio := '0100'B,
    transferDelay := '000000'B,
    trafficHandlingPrio := '00'B,
    guaranteedBitRateUL := '00000000'B,
    guaranteedBitRateDL := '00000000'B,
    spare4 := '000'B,
    signallingInd := '0'B,
    sourceStatisticsDescriptor := '0000'B,
    maxBitRateDL_Ext := '00000000'B,
    guaranteedBitRateDL_Ext := '00000000'B,
    maxBitRateUL_Ext := '00000000'B,
    guaranteedBitRateUL_Ext := '00000000'B,
    maxBitRateDL_Ext2       := omit,  // @sic R5s1300195 Baseline Moving sic@
    guaranteedBitRateDL_Ext2  := omit,  // @sic R5s1300195 Baseline Moving sic@
    maxBitRateUL_Ext2         := omit,  // @sic R5s1300195 Baseline Moving sic@
    guaranteedBitRateUL_Ext2  := omit   // @sic R5s1300195 Baseline Moving sic@
  };

  template (value) QualityOfService cds_QoS_PDP3  (template (omit) IEI8_Type p_IEI := '30'O) modifies cs_QoS_PDP2 :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
    relabilityClass := '101'B,
    deliveryErrorSDU := '010'B,
    residualBER := '0100'B,
    sduErrorRatio := '0011'B
  };

  template (value) QualityOfService cds_QoS_Converstational  (template (omit) IEI8_Type p_IEI := '30'O) modifies cs_QoS_PDP2 :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
    relabilityClass := '101'B,
    trafficClass := '001'B,
    deliveryOrder := '10'B,      // @sic R5-133509 sic@
    maxSduSize := '00001111'B,   // @sic R5-120632 sic@
    maxBitRateUL := '01101000'B,
    maxBitRateDL := '01101000'B,
    residualBER := '0001'B,
    sduErrorRatio := '0001'B,
    transferDelay := '001000'B
  };

  template (present) TrafficFlowTemplate cr_Tft(template IEI8_Type p_IEI := omit,
                                                template (present) B3_Type p_Code := ?) :=
  { /* 24.301 cl. 9.9.4.13 -> 24.008 cl. 10.5.6.12 */
    /* @status    APPROVED (ENDC, LTE, LTE_A_R10_R11, NBIOT, UTRAN) */
    iei := p_IEI, /* present in case of TLV; omit in case of LV */
    iel := ?,
    tftOperationCode := p_Code,
    eBit := ?,
    noOfPktFilter := complement ('0000'B), // value must be greater than 0 and <= 16 (only 4 bits)
    packetFilterList := ?,
    parameterList := *
  };

  template (value) TrafficFlowTemplate cs_TrafficFlowTemplate(integer p_IeLength,
                                                              template (value) TrafficFlowTemplate.packetFilterList p_PacketFilterList):=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, UTRAN) */
    iei   := omit,
    iel   := int2oct(p_IeLength, 1),
    tftOperationCode := '001'B,  // Create new TFT
    eBit  := '0'B, // Parameter list not included
    noOfPktFilter := int2bit(lengthof(p_PacketFilterList), 4),
    packetFilterList := p_PacketFilterList,
    parameterList := omit
  };

  template (present) UE_Status cr_UEStatus_Any :=
  { // 24.501 cl. 9.11.3.56
    /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
    iei     := '6D'O,
    iel     := ?,
    spare   := tsc_Spare6,
    n1ModeRegistered    := ?,
    s1ModeRegistered    := ?
  };
  // =============================================================================
  // A value of 1 is the highest radio priority level
  // -----------------------------------------------------------------------------

  template (value) RadioPriority cs_RadioPriority (template (omit) IEI4_Type p_IEI,
                                                   B3_Type p_Val) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei := p_IEI,
    spare := '0'B,
    levelValue := p_Val
  };

  template (value) RadioPriority cs_RadioPriorityHigh (template (omit) IEI4_Type p_IEI) := cs_RadioPriority (p_IEI, '001'B);  /* @status    APPROVED (IMS, LTE_A_IRAT, LTE_IRAT, POS, UTRAN) */
  template (value) RadioPriority cs_RadioPriorityLow  (template (omit) IEI4_Type p_IEI) := cs_RadioPriority (p_IEI, '100'B);  /* @status    APPROVED (LTE_IRAT) */

  template (present) TMSI_Status cr_TMSI_Status(template (present) TmsiStatusValue p_TmsiStatus := ?) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei  := '9'H,
    spare3 := tsc_Spare3,
    flag := p_TmsiStatus
  };

  template (present) UE_NetworkCap cr_UENetworkCap_Any (template (omit) IEI8_Type p_IEI) :=
  { /* 24.301 cl. 9.9.3.34
       @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei := p_IEI,                     /* present in case of TLV; omit in case of LV */
    iel := ?,                         /* present in case of LV or TLV; omit in case of V */
    eeaCap := ?,                     // @sic R5s100135 sic@
    eiaCap := ?,                     // @sic R5s100135 sic@
    ueaCap := *,                     // @sic R5s100135 sic@
    uiaCap := *,                     // @sic R5s100135 sic@
    srvcc_LPP_ProSeCap := *,         // @sic R5s100135, R5s150329 Baseline Moving sic@
    cIoT_proSeCap := *,              // @sic R5s150329, R5s160711 Baseline Moving sic@
    cIoT_V2X := *,                   // @sic R5s170598 Baseline Moving sic@
    edt_WUS := *,                    // @sic R5s201386 Baseline Moving sic@
    musim := *,                      // Sep22 @sic R5s221179 Baseline Moving sic@
    spare := *                       // @sic R5s100135 sic@
  };

  template (present) UE_NetworkCap cdr_NR5GC_UENetworkCap (template (omit) IEI8_Type p_IEI)
           modifies cr_UENetworkCap_Any :=
  {  /* @status    APPROVED (ENDC, NR5GC_IRAT) */
    cIoT_proSeCap := '1???????'B,         // @sic R5-196647, R5-217714 sic@
    cIoT_V2X := '??1?????'B
   };

  template (present) VoiceDomainPref cr_VoiceDomainPref_Any :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei := ?,              // 01111110'B
    iel := ?,             // length
    spareBits             := ?,
    ueUsageSetting        := ?,
    voiceDomainPrefEUTRA  := ?
  };

  template (value) GPRS_Timer2 cs_GPRS_Timer2_3_IEI(template (omit) IEI8_Type p_IEI, // @sic R5s150329 Baseline Moving sic@
                                                    B3_Type p_Unit,
                                                    B5_Type p_Value) :=
  { /* @status    APPROVED (IMS, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei  := p_IEI,
    iel  := '01'O,                   // length
    unit := p_Unit,                  // Unit
    gprsTimerValue := p_Value           // Timer  value
  };

  template (value) GPRS_Timer3 cs_GprsTimer3(template (omit) IEI8_Type p_IEI := '5E'O, // @sic R5s150745 sic@
                                             GprsTimerUnit p_Unit,
                                             B5_Type p_Value) := cs_GPRS_Timer2_3_IEI(p_IEI, p_Unit, p_Value);  /* @status    APPROVED (LTE_A_R10_R11, NBIOT) */

  template (present) GPRS_Timer2 cr_GPRS_Timer2_3(IEI8_Type p_IEI, // @sic R5s150329 Baseline Moving sic@
                                                  template (present) B3_Type p_Unit := ?,
                                                  template (present) B5_Type p_Value := ?) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS, SSNITZ, UTRAN) */
    iei  := p_IEI,
    iel  := '01'O,                   // length
    unit := p_Unit,                  // Unit
    gprsTimerValue := p_Value           // Timer  value
  };

  template (value) TimeZoneAndTime cs_TimeZoneAndTime (O1_Type p_Year,
                                                       O1_Type p_Month,
                                                       O1_Type p_Day,
                                                       O1_Type p_Hour,
                                                       O1_Type p_Minute,
                                                       O1_Type p_Second,
                                                       O1_Type p_TimeZone):=
  { /* @status    APPROVED (LTE, NR5GC, SSNITZ) */
    iei      := '47'O, // @sic R5s110439 sic@
    year     := p_Year,
    month    := p_Month,
    day      := p_Day,
    hour     := p_Hour,
    minute   := p_Minute,
    second   := p_Second,
    timeZone := p_TimeZone
  };

  template (value) TimeZone cs_TimeZone (O1_Type p_TimeZone):=
  { /* @status    APPROVED (LTE, NR5GC, SSNITZ) */
    iei      := '46'O,
    timeZone := p_TimeZone
  };

  template (value) NetworkName cs_NetworkName (IEI8_Type p_Iei,
                                               charstring p_Name,
                                               Gsm7BitPacking_Type p_Packing := SMS_Packing, // default: GSM default 7
                                               B1_Type p_AddCI := '0'B) := // default: do not include the CI
  { /* @status    APPROVED (LTE, NR5GC, SSNITZ) */
    iei          := p_Iei,
    iel          := int2oct((lengthof(f_CharPacking_IA5toGsm7Bit(p_Name, p_Packing)) + 1),1),
    ext          := '1'B,
    codingScheme := f_ConvertPackingToCodingScheme (p_Packing),
    addCI        := p_AddCI,
    spareBitCnt  := int2bit((lengthof(p_Name) mod 8), 3),  // @sic R5s140651 sic@
    text         := f_CharPacking_IA5toGsm7Bit(p_Name, p_Packing)
  };

  //----------------------------------------------------------------------------
  /*
   * @desc      Conversion of the packing type per TS 23.040 into the coding scheme parameter used in the Network Name IE
   * @param     p_Gsm7BitPacking_Type
   * @return    B3_Type
   * @status    APPROVED (LTE, NR5GC, SSNITZ)
   */
  function f_ConvertPackingToCodingScheme(Gsm7BitPacking_Type p_Gsm7BitPacking_Type) return B3_Type
  {
    var B3_Type v_CodingScheme := '000'B;

    if (p_Gsm7BitPacking_Type == SMS_Packing) {v_CodingScheme := '000'B } else {FatalError (__FILE__, __LINE__, "Unexpected Packing for conversion to Coding Scheme")};
    //if (p_Gsm7BitPacking_Type == CBS_Packing) {v_CodingScheme := '000'B };
    //if (p_Gsm7BitPacking_Type == USSD_Packing) {v_CodingScheme := '000'B };

    return v_CodingScheme;
  }

  template (value) DaylightSavingTime cs_DaylightSavingTime_tlv (B2_Type p_DaylightSavingTime) :=
  { /* 24.301 cl. 9.9.3.6; */
    /* @status    APPROVED (LTE, NR5GC, SSNITZ) */
    iei   := '49'O,
    iel   := '01'O, // @sic R5s120508 sic@
    spare := tsc_Spare6,
    val   := p_DaylightSavingTime
  };

  //============================================================================
  // Packet filters
  //----------------------------------------------------------------------------
  template (value) PacketFilterComponent cs_PktFilterCompIPv4RemoteAddress(charstring p_RemoteAddress,
                                                                           O4_Type p_Mask := tsc_IPv4Mask) :=
  { // 9 octets
    /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS, UTRAN) */
    /* @sic R5s110604: optional parameters sic@ */
    id := '10'O, // IPv4 remote address
    packetFilterComponentValue := {
      ipv4RemoteAddress := f_Convert_IPv4Addr2OctString(p_RemoteAddress) & p_Mask // @sic R5s100189, R5-113734 sic@
    }
  };

  template (value) PacketFilterComponent cs_PktFilterCompIPv6RemoteAddress(charstring p_RemoteAddress,
                                                                           O16_Type p_Mask := tsc_IPv6Mask) :=
  { // 33 octets
    /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, UTRAN) */
    id := '20'O,
    packetFilterComponentValue := {
      ipv6RemoteAddress := f_Convert_IPv6Addr2OctString(p_RemoteAddress) & p_Mask // @sic R5s100189, R5-113734 sic@
    }
  };

  template (value) PacketFilterComponent cs_PktFilterCompProtocolIdNextHeader(O1_Type p_ProtocolIdNextHeader) :=
  { // 2 octets
    /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, UTRAN) */
    id := '30'O, // Protocol Identifier / Next header type
    packetFilterComponentValue := {
      protocolIdNextHeader := p_ProtocolIdNextHeader
    }
  };

  template (value) PacketFilterComponent cs_PktFilterCompProtocolIdNextHeaderICMP := cs_PktFilterCompProtocolIdNextHeader('01'O);   /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT) */
  template (value) PacketFilterComponent cs_PktFilterCompProtocolIdNextHeaderICMPv6 := cs_PktFilterCompProtocolIdNextHeader('3A'O); /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT) */
  template (value) PacketFilterComponent cs_PktFilterCompProtocolIdNextHeaderUDP := cs_PktFilterCompProtocolIdNextHeader('11'O);    /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, UTRAN) */
  template (value) PacketFilterComponent cs_PktFilterCompProtocolIdNextHeaderTCP := cs_PktFilterCompProtocolIdNextHeader('06'O);    /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT) */
  template (value) PacketFilterComponent cs_PktFilterCompProtocolIdNextHeaderIPSec := cs_PktFilterCompProtocolIdNextHeader('32'O);  /* @status    APPROVED (LTE, NBIOT, UTRAN) */

  template (value) PacketFilterComponent cs_PktFilterCompSingleLocalPort(UInt16_Type p_PortNumber) :=
  { // 3 octets
    /* @status    APPROVED (LTE, NBIOT, UTRAN) */
    id := '40'O, // Single local port
    packetFilterComponentValue := {
      singleLocalPort := int2oct(p_PortNumber, 2)
    }
  };

  template (value) PacketFilterComponent cs_PktFilterCompLocalPortRange(UInt16_Type p_PortLow,
                                                                        UInt16_Type p_PortHigh) :=
  { // 3 octets
    /* @status    APPROVED (LTE, NBIOT, UTRAN) */
    id := '41'O, // Local port range
    packetFilterComponentValue := {
      localPortRange := int2oct(p_PortLow, 2) & int2oct(p_PortHigh, 2)
    }
  };

  template (value) PacketFilterComponent cs_PktFilterCompSingleRemotePort(UInt16_Type p_PortNumber) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, UTRAN) */
    id := '50'O, // Single remote port
    packetFilterComponentValue := {
      singleRemotePort := int2oct(p_PortNumber, 2)
    }
  };

  template (value) PacketFilterComponent cs_PktFilterCompRemotePortRange(UInt16_Type p_PortLow,
                                                                         UInt16_Type p_PortHigh) :=
  { // 3 octets
    /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, UTRAN) */
    id := '51'O, // Remote port range
    packetFilterComponentValue := {
      remotePortRange := int2oct(p_PortLow, 2) & int2oct(p_PortHigh, 2)
    }
  };

  template (value) PacketFilterComponent cs_PktFilterCompTOSTrafficClass(O2_Type p_TOSTrafficClass) :=
  { // 3 octets
    /* @status    APPROVED (LTE, NBIOT, UTRAN) */
    id := '70'O, // Type of service / Traffic class type
    packetFilterComponentValue := {
      typeOfServiceTrafficClass := p_TOSTrafficClass
    }
  };

  template (value) PacketFilterComponent cs_PktFilterCompIPSecSPI(O4_Type p_IPSecSPI) :=
  { // 5 octets
    /* @status    APPROVED (LTE, NBIOT, UTRAN) */
    id := '60'O, // Security parameter index type
    packetFilterComponentValue := {
      securityParameterIndex := p_IPSecSPI
    }
  };

  template (value) PacketFilterComponent cs_PktFilterCompFlowLabel(O3_Type p_FlowLabel) :=
  { // 4 octets
    /* @status    APPROVED (LTE, NBIOT, UTRAN) */
    id := '80'O, // Flow label type
    packetFilterComponentValue := {
      flowLabel := p_FlowLabel
    }
  };

  /*
   * @desc      Calculate Packet Filters applied in test case 10.9.1 of 36.523-1
   * @param     p_PacketFilterByRef (by reference)
   * @param     p_PacketFilterLengthByRef (by reference)
   * @param     p_IpTypeIsIPv4
   * @param     p_PacketFilterID
   * @status    APPROVED (LTE, NBIOT, UTRAN)
   */
  function f_Get_PacketFilter_10_9_1(out template (value) PacketFilter p_PacketFilterByRef,
                                     out integer p_PacketFilterLengthByRef,
                                     boolean p_IpTypeIsIPv4,
                                     integer p_PacketFilterID)
  {
    var charstring v_IPv4RemoteAddress := "172.168.8.0"; // @sic R5s110776 sic@
    var O4_Type  v_IPv4SubnetMask := 'FFFFFF00'O;
    var charstring v_IPv6RemoteAddress := "2001:0ba0::";  // @sic R5s110776 sic@
    var O16_Type  v_IPv6SubnetMask := 'FFFFFFFF000000000000000000000000'O;  // @sic R5s110776 sic@

    var integer v_FilterCount := 0;
    var template (value) PacketFilter v_Filter;

    select (p_PacketFilterID) {  // @sic R5-110779 sic@
      case (1) {
        // UL only filter, ID=1
        v_Filter.spare       := '00'B; //  @sic R5s130195 Baseline Moving sic@
        v_Filter.direction   := '10'B; //  @sic R5s130195 Baseline Moving sic@
        v_Filter.iei         := '1'H;  //  @sic R5s130195 Baseline Moving sic@
        v_Filter.precedence  := int2bit(6, 8);
        v_Filter.contents[0] := cs_PktFilterCompProtocolIdNextHeaderUDP;
        v_FilterCount := v_FilterCount + 2;
        if (p_IpTypeIsIPv4) {
          v_Filter.contents[1] := cs_PktFilterCompIPv4RemoteAddress(v_IPv4RemoteAddress, v_IPv4SubnetMask);
          v_FilterCount := v_FilterCount + 9;
        }
        else { // IPv6
          v_Filter.contents[1] := cs_PktFilterCompIPv6RemoteAddress(v_IPv6RemoteAddress, v_IPv6SubnetMask);
          v_FilterCount := v_FilterCount + 33;
        }
        v_Filter.contents[2] := cs_PktFilterCompSingleLocalPort(60001);
        v_FilterCount := v_FilterCount + 3;
        v_Filter.contents[3] := cs_PktFilterCompRemotePortRange(60350, 60450);
        v_FilterCount := v_FilterCount + 5;
        v_Filter.contents[4] := cs_PktFilterCompTOSTrafficClass('A8FC'O);
        v_FilterCount := v_FilterCount + 3;
      }
      case (2) {
        v_Filter.spare       := '00'B; //  @sic R5s130195 Baseline Moving sic@
        v_Filter.direction   := '10'B; //  @sic R5s130195 Baseline Moving sic@
        v_Filter.iei         := '2'H;  //  @sic R5s130195 Baseline Moving sic@
        v_Filter.precedence  := int2bit(7, 8);
        v_Filter.contents[0] := cs_PktFilterCompProtocolIdNextHeaderUDP;
        v_FilterCount := v_FilterCount + 2;
        if (p_IpTypeIsIPv4) {
          v_Filter.contents[1] := cs_PktFilterCompIPv4RemoteAddress(v_IPv4RemoteAddress, v_IPv4SubnetMask);
          v_FilterCount := v_FilterCount + 9;
        }
        else { // IPv6
          v_Filter.contents[1] := cs_PktFilterCompIPv6RemoteAddress(v_IPv6RemoteAddress, v_IPv6SubnetMask);
          v_FilterCount := v_FilterCount + 33;
        }
        v_Filter.contents[2] := cs_PktFilterCompLocalPortRange(60000, 60100);
        v_FilterCount := v_FilterCount + 5;
        v_Filter.contents[3] := cs_PktFilterCompSingleRemotePort(60350);
        v_FilterCount := v_FilterCount + 3;
        v_Filter.contents[4] := cs_PktFilterCompTOSTrafficClass('A8FC'O);
        v_FilterCount := v_FilterCount + 3;
      }
      case (3) {
        v_Filter.spare       := '00'B; //  @sic R5s130195 Baseline Moving sic@
        v_Filter.direction   := '10'B; //  @sic R5s130195 Baseline Moving sic@
        v_Filter.iei         := '3'H;  //  @sic R5s130195 Baseline Moving sic@
        v_Filter.precedence  := int2bit(5, 8);
        v_Filter.contents[0] := cs_PktFilterCompProtocolIdNextHeaderIPSec;
        v_FilterCount := v_FilterCount + 2;
        if (p_IpTypeIsIPv4) {
          v_Filter.contents[1] := cs_PktFilterCompIPv4RemoteAddress(v_IPv4RemoteAddress, v_IPv4SubnetMask);
          v_FilterCount := v_FilterCount + 9;
        }
        else { // IPv6
          v_Filter.contents[1] := cs_PktFilterCompIPv6RemoteAddress(v_IPv6RemoteAddress, v_IPv6SubnetMask);
          v_FilterCount := v_FilterCount + 33;
        }
        v_Filter.contents[2] := cs_PktFilterCompIPSecSPI('0F80F000'O); // @sic R5s110778 sic@
        v_FilterCount := v_FilterCount + 5;
        v_Filter.contents[3] := cs_PktFilterCompTOSTrafficClass('A0FC'O);
        v_FilterCount := v_FilterCount + 3;
      }
      case (4) {
        v_Filter.spare       := '00'B; //  @sic R5s130195 Baseline Moving sic@
        v_Filter.direction   := '10'B; //  @sic R5s130195 Baseline Moving sic@
        v_Filter.iei         := '4'H;  //  @sic R5s130195 Baseline Moving sic@
        v_Filter.precedence  := int2bit(2, 8);
        if (p_IpTypeIsIPv4) {
          v_Filter.contents[0] := cs_PktFilterCompIPv4RemoteAddress(v_IPv4RemoteAddress, v_IPv4SubnetMask);
          v_FilterCount := v_FilterCount + 9;
        }
        else { // IPv6
          v_Filter.contents[0] := cs_PktFilterCompIPv6RemoteAddress(v_IPv6RemoteAddress, v_IPv6SubnetMask);
          v_FilterCount := v_FilterCount + 33;
        }
        v_Filter.contents[1] := cs_PktFilterCompTOSTrafficClass('B0FC'O);
        v_FilterCount := v_FilterCount + 3;
        v_Filter.contents[2] := cs_PktFilterCompFlowLabel('000005'O);
        v_FilterCount := v_FilterCount + 4;
      }
      case (5) {
        v_Filter.spare       := '00'B; //  @sic R5s130195 Baseline Moving sic@
        v_Filter.direction   := '10'B; //  @sic R5s130195 Baseline Moving sic@
        v_Filter.iei         := '5'H;  //  @sic R5s130195 Baseline Moving sic@
        v_Filter.precedence  := int2bit(255, 8);
        if (p_IpTypeIsIPv4) {
          v_Filter.contents[0] := cs_PktFilterCompIPv4RemoteAddress(v_IPv4RemoteAddress, v_IPv4SubnetMask);
          v_FilterCount := v_FilterCount + 9;
        }
        else { // IPv6
          v_Filter.contents[0] := cs_PktFilterCompIPv6RemoteAddress(v_IPv6RemoteAddress, v_IPv6SubnetMask);
          v_FilterCount := v_FilterCount + 33;
        }
      }
      case else {
        // out of supported range
        FatalError(__FILE__, __LINE__, "unsupported packet filter id");
      }
    }
    v_Filter.iel := int2oct(v_FilterCount, 1);

    p_PacketFilterByRef := v_Filter;
    p_PacketFilterLengthByRef := v_FilterCount + 3;
  }
  //----------------------------------------------------------------------------
   template (present) Extd_EPS_QOS cr_Extd_EPS_QOS_Any :=
   { /* @status    APPROVED (ENDC, IMS, LTE, LTE_A_IRAT, LTE_A_R10_R11, LTE_IRAT, NBIOT, POS, UTRAN) */
    iei               := '5C'O,
    iel               := ?,
    unitMaxBitRate    := ?,
    maxBitRateUl_1    := ?,
    maxBitRateUl_2    := ?,
    maxBitRateDl_1    := ?,
    maxBitRateDl_2    := ?,
    unitGuaranteedBitRate    := ?,
    guaranteedBitRateUl_1    := ?,
    guaranteedBitRateUl_2    := ?,
    guaranteedBitRateDl_1    := ?,
    guaranteedBitRateDl_2    := ?
  };

  const B1_Type tsc_NasKsi_NativeSecurityContext := '0'B; /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS) */
  const B1_Type tsc_NasKsi_MappedSecurityContext := '1'B; /* @status    APPROVED (LTE_A_IRAT, LTE_IRAT, NR5GC_IRAT) */

  template (value) NAS_KeySetIdentifier cs_NAS_KeySetIdentifier_lv(NAS_KsiValue p_NasKeySetId,
                                                                   B1_Type p_Tsc) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS) */
    iei := omit,
    tsc := p_Tsc,
    nasKeySetId := p_NasKeySetId
  };

  template (present) NAS_KeySetIdentifier cr_NAS_KeySetIdentifier(template (present) NAS_KsiValue p_KsiValue,
                                                                  template (present) B1_Type p_Tsc) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS) */
    iei := omit,
    tsc := p_Tsc,
    nasKeySetId := p_KsiValue
  };

  template (present) NAS_KeySetIdentifier cdr_NAS_KeySetIdentifier_tlv(template (present) NAS_KsiValue p_KsiValue,
                                                                       template (present) B1_Type p_Tsc)
    modifies cr_NAS_KeySetIdentifier :=
  { /* @status    APPROVED (LTE_A_IRAT, LTE_IRAT, NR5GC_IRAT) */
    iei := 'B'H
  };

  template (present) AuthenticationResponseParameter cr_AuthenticationResponseParameter_lv(template (present) B32_128_Type p_ExpectedRES) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
    iei := omit,
    iel := ?,        /* RES has length of 32..128 bits i.e. 4..16 octets */
    res := p_ExpectedRES
  };

  template (value) IMEISV_Request cs_IMEISV_Request_WithIEI(B3_Type p_Value) :=
  { /* @status    APPROVED (IMS, LTE, NBIOT, NR5GC, NR5GC_IRAT, POS) */
    iei             := 'C'H, //@sic R5s090210 sic@
    spare           := '0'B,
    requestValue    := p_Value
  };

  template (value) NAS_SecurityAlgorithms cs_NAS_SecurityAlgorithms(B3_Type p_CipheringType,
                                                                    B3_Type p_IntegrityType,
                                                                    template (omit) IEI8_Type p_IEI := omit) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS) */
    iei := p_IEI, // @sic R5s190285 sic@
    spare1 := tsc_Spare1,
    cipheringType := p_CipheringType,
    spare2 := tsc_Spare1,
    integrityType := p_IntegrityType
  };

  template (value) ExtdProtocolConfigOptions cs_ExtdPCO(Type6Length_Type p_Length,
                                                        template (omit) NAS_ExtdProtocolConfigOptions_Type p_ProtocolContainers) :=
  { /* 24.301 cl. 9.9.4.26 */
    /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS) */
    iei         := '7B'O,
    iel         := p_Length,
    ext         := '1'B,
    spare       := tsc_Spare4,
    configProtocol := tsc_Spare3,
    pco         := p_ProtocolContainers
  };

  template (present) DRXParamCommon cr_DRXParamCommonAny (IEI8_Type p_IEI):=
  { /* 24.301 cl. 9.9.3.63 */
    /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
    iei         := p_IEI,
    iel         := ?,
    spare       := tsc_Spare4,
    drxValue    := ?
  };

  template (present) WUSAssistInfo cr_WUSAssistInfoAny :=
  { /* 24.301 cl. 9.9.3.62 */
    /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
    iei      := '35'O,
    iel      := ?,
    infoType := ?
  };

  template (present) WusInfoType cr_WusInfoTypeAny :=
  {
    wusType             := ?,
    pagingProbability   := ?,
    wusValue            := ?
  };

  template (value) UERadioCapIdDeletion cs_UERadioCapIdDeletion(template (omit) IEI4_Type p_IEI:= 'A'H, B3_Type p_DeleteReq:='001'B):=
  { /* 24.301 cl. 9.11.3.69 */
    /* @status    APPROVED (NR5GC) */
    iei:=p_IEI,
    spare:='0'B,
    deleteReq:= p_DeleteReq
  };

  template (present) UE_RequestType cr_UE_RequestType (template (present) B4_Type p_ReqType := ?) :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC_IRAT, POS) */
    /* 24.301 cl. 9.9.3.65 */
    iei         := '29'O,
    iel         := '01'O,
    spare       := tsc_Spare4,
    requestType := p_ReqType
  };


  //----------------------------------------------------------------------------
  template (value) QosFlow_Identification_Type cs_IP_QosFlowId(integer p_PDU_SessionId,
                                                               integer p_QFI) :=
  { /* @status    APPROVED (IMS, NR5GC, NR5GC_IRAT, POS) */
    PDU_SessionId := p_PDU_SessionId,
    QFI := p_QFI
  };

  /*
   * @desc      To convert the maximum bit rate for the QoS
   * @param     p_Val
   * @return    integer
   * @status    APPROVED (ENDC, LTE, LTE_A_IRAT, LTE_A_R10_R11, LTE_IRAT, NBIOT, POS, SSNITZ, UTRAN)
   */
  function f_QoS_MaximumBitRate(B8_Type p_Val) return integer
  {
    var integer v_Val := bit2int(p_Val);
    if ((v_Val >= bit2int('00000001'B)) and (v_Val <= bit2int('00111111'B))) {
      return v_Val;
    }
    if ((v_Val >= bit2int('01000000'B)) and (v_Val <= bit2int('01111111'B))) {
      return (64 + ((v_Val - 64)*8));
    }
    if ((v_Val >= bit2int('10000000'B)) and (v_Val <= bit2int('11111110'B))) {
      return (576 + ((v_Val - 128)*64));
    }
    if (v_Val == bit2int('11111111'B)) {
      return 0;
    }
    return 0;
  }
  /*
   * @desc      To convert the transfer delay for the QoS
   * @param     p_Val
   * @return    integer
   * @status    APPROVED (LTE_A_IRAT, LTE_IRAT, POS, SSNITZ, UTRAN)
   */
  function fl_QoS_TransferDelay(B6_Type p_Val) return integer
  {
    var integer v_Val := bit2int(p_Val);
    if ((v_Val >= bit2int('000001'B)) and (v_Val <= bit2int('001111'B))) {
      return (v_Val*10);
    }
    if ((v_Val >= bit2int('010000'B)) and (v_Val <= bit2int('011111'B))) {
      return (200 + ((v_Val - 16)*50));
    }
    if ((v_Val >= bit2int('100000'B)) and (v_Val <= bit2int('111110'B))) {
      return (1000 + ((v_Val - 32)*100));
    }
    return 0;
  }

  /*
   * @desc      To convert the SDU Error Ratio for the QoS
   * @param     p_Val
   * @return    charstring
   * @status    APPROVED (LTE_A_IRAT, LTE_IRAT, POS, SSNITZ, UTRAN)
   */
  function fl_QoS_SDUErrorRatio(B4_Type p_Val) return charstring
  {
    select (p_Val) {
      case ('0001'B) { return ("1E2"); }
      case ('0010'B) { return ("7E3"); }
      case ('0011'B) { return ("1E3"); }
      case ('0100'B) { return ("1E4"); }
      case ('0101'B) { return ("1E5"); }
      case ('0110'B) { return ("1E6"); }
      case ('0111'B) { return ("1E1"); }
    }
    return "";
  }

  /*
   * @desc      To convert the Residual BER for the QoS
   * @param     p_Val
   * @return    charstring
   * @status    APPROVED (LTE_A_IRAT, LTE_IRAT, POS, SSNITZ, UTRAN)
   */
  function fl_QoS_ResidualBER(B4_Type p_Val) return charstring
  {
    select (p_Val) {
      case ('0001'B) { return ("5E2"); }
      case ('0010'B) { return ("1E2"); }
      case ('0011'B) { return ("5E3"); }
      case ('0100'B) { return ("4E3"); }
      case ('0101'B) { return ("1E3"); }
      case ('0110'B) { return ("1E4"); }
      case ('0111'B) { return ("1E5"); }
      case ('1000'B) { return ("1E6"); }
      case ('1001'B) { return ("6E8"); }
    }
    return "";
  }

  /*
   * @desc      To convert the QualityOfService into a charstring for the UT command
   * @param     p_QoS
   * @return    charstring
   * @status    APPROVED (LTE_A_IRAT, LTE_IRAT, POS, SSNITZ, UTRAN)
   */
  function f_ConvertQoS_ForATCommand(template (value) QualityOfService p_QoS) return charstring
  {
    var QualityOfService v_QoS := valueof(p_QoS);  // need to do this to then manipulate the string
    var charstring v_QoSstring := "";
    var integer v_SSDesc := bit2int(v_QoS.sourceStatisticsDescriptor);
    var integer v_TrafficClass := bit2int(v_QoS.trafficClass);
    var integer v_DelOrder := bit2int(v_QoS.deliveryOrder);
    var integer v_DeliveryErrorSDU := bit2int(v_QoS.deliveryErrorSDU);

    if (v_SSDesc > 1) {
      v_SSDesc := 1;  // Only allowed values are 0 or 1
    }

    v_TrafficClass := v_TrafficClass - 1; // in AT command value is one less than in PDP Context
    if (v_TrafficClass < 0) {
      v_TrafficClass := 0;
    }

    select (v_DelOrder) {
      case (1)  { v_DelOrder := 1; }
      case (2)  { v_DelOrder := 0; }
      case else { v_DelOrder := 2; }
    }

    select (v_DeliveryErrorSDU) {
      case (1)  { v_DeliveryErrorSDU := 2; }
      case (2)  { v_DeliveryErrorSDU := 1; }
      case (3)  { v_DeliveryErrorSDU := 0; }
      case else { v_DeliveryErrorSDU := 3; }
    }

    v_QoSstring := v_QoSstring & int2str(v_TrafficClass);
    v_QoSstring := v_QoSstring & "," & int2str(f_QoS_MaximumBitRate(v_QoS.maxBitRateUL));
    v_QoSstring := v_QoSstring & "," & int2str(f_QoS_MaximumBitRate(v_QoS.maxBitRateDL));
    v_QoSstring := v_QoSstring & "," & "," & "," & int2str(v_DelOrder);
    v_QoSstring := v_QoSstring & "," & int2str(bit2int(v_QoS.maxSduSize)*10);
    v_QoSstring := v_QoSstring & ",""" & fl_QoS_SDUErrorRatio(v_QoS.sduErrorRatio)& """";
    v_QoSstring := v_QoSstring & ",""" & fl_QoS_ResidualBER(v_QoS.residualBER)& """";
    v_QoSstring := v_QoSstring & "," & int2str(v_DeliveryErrorSDU);
    v_QoSstring := v_QoSstring & "," & int2str(fl_QoS_TransferDelay(v_QoS.transferDelay));
    v_QoSstring := v_QoSstring & "," & int2str(bit2int(v_QoS.trafficHandlingPrio));
    v_QoSstring := v_QoSstring & "," & int2str(v_SSDesc);
    v_QoSstring := v_QoSstring & "," & int2str(bit2int(v_QoS.signallingInd));
    return v_QoSstring;
  }

  type enumerated BEARER_CONTEXT_TYPE {                /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS) */
    DEF_1, // EPS Default Bearer#1 defined in the first column of table 6.6.1
    DEF_2, // EPS Default Bearer#2 defined in the second column of table 6.6.1
    DEF_3, // EPS Default Bearer#3 defined in the third column of table 6.6.1
    DED_1, // EPS Dedicated Bearer#1 defined in the first column of table 6.6.2
    DED_2, // EPS Dedicated Bearer#2 defined in the second column of table 6.6.2
    DED_3, // EPS Dedicated Bearer#3 defined in the third column of table 6.6.2
    DED_4, // EPS Dedicated Bearer#4 defined in the fourth column of table 6.6.2 @sic R5-123632 sic@
    DED_5  // EPS Dedicated Bearer#5 defined in the fifth column of table 6.6.2  @sic R5-210201 sic@
  };

  /*
   * @desc      return bearer context number: if p_BearerContextNumber is not present bearer context number acc. to UE capabilities
   * @param     p_BearerContextNumber
   * @return    BEARER_CONTEXT_TYPE
   * @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS)
   */
  function fl_BearerContextNumber_Def(template (omit) BEARER_CONTEXT_TYPE p_BearerContextNumber) return BEARER_CONTEXT_TYPE
  {
    var BEARER_CONTEXT_TYPE v_BearerContextNumber;

    if (isvalue(p_BearerContextNumber)) {
      v_BearerContextNumber := valueof(p_BearerContextNumber);
    } else {
      if (pc_IMS) {
        v_BearerContextNumber := DEF_2;     /* @sic R5s141367: DEF_2 instead of DEF_1 sic@ */
      } else {
        v_BearerContextNumber := DEF_1;     /* @sic R5s141367: DEF_1 instead of DEF_2 sic@ */
      }
    }
    return v_BearerContextNumber;
  }

  template (value) EPS_QualityOfService cs_508_EPS_QoS_Default_1 :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS) */
    iei := omit,
    iel := '09'O,
    qci                    := '00001001'B,
    maxBitRateUl           := '01000000'B,                //64 kbps
    maxBitRateDl           := '01000000'B,                //64 kbps
    guaranteedBitRateUl    := '01000000'B,                //64 kbps
    guaranteedBitRateDl    := '01000000'B,                //64 kbps
    maxBitRateUlExt        := '00000000'B,
    maxBitRateDlExt        := '00000000'B,
    guaranteedBitRateUlExt := '00000000'B,
    guaranteedBitRateDlExt := '00000000'B,
    maxBitRateUL_Ext2         := omit,  // @sic R5s1300195 Baseline Moving, R5s180640 sic@
    maxBitRateDL_Ext2       := omit,  // @sic R5s1300195 Baseline Moving sic@
    guaranteedBitRateUL_Ext2  := omit,  // @sic R5s1300195 Baseline Moving sic@
    guaranteedBitRateDL_Ext2  := omit   // @sic R5s1300195 Baseline Moving sic@
  };

  template (value) EPS_QualityOfService cds_508_EPS_QoS_Default_1_tlv
  modifies cs_508_EPS_QoS_Default_1 :=
  { /* according to table 6.6.2.1 in 36.508, including iei */
    /* @status    APPROVED (LTE, NBIOT) */
    iei     := '5B'O
  };

  template (value) EPS_QualityOfService cds_EPS_QoS_Def_nonGBR_QCI
  modifies cs_508_EPS_QoS_Default_1 :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS) */
    qci     := '00000101'B // non-GBR QCI
  };

  template (value) EPS_QualityOfService cds_EPS_QoS_Def_nonGBR_QCI_tlv
  modifies cs_508_EPS_QoS_Default_1 :=
  { /* 10.7.2 specifies According to reference default Bearer context#2 except for GCI */
    iei     := '5B'O,
    qci     := '00000101'B // non-GBR QCI
  };

  template (value) EPS_QualityOfService cds_508_EPS_QoS_Default_3
  modifies cs_508_EPS_QoS_Default_1 :=
  { /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS) */
    qci     := '01000101'B // 69 for MCPTT
  };


  /* @desc      Get the Default QoS according to 36.508 clause 4.7.3-6
   * @param     p_BearerContextNumber
   * @return    template (value) EPS_QualityOfService
   * @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT, POS)
   */
  function f_Get_508_EPSQoS(template (omit) BEARER_CONTEXT_TYPE p_BearerContextNumber) return template (value) EPS_QualityOfService
  { /* @sic R5-144797: parameter p_BearerContextNumber sic@ */
    var template (value) EPS_QualityOfService v_QoS;
    var BEARER_CONTEXT_TYPE v_BearerContextNumber := fl_BearerContextNumber_Def(p_BearerContextNumber);

    select (v_BearerContextNumber){   /* @sic R5-144797: v_QoS does not depend on pc_IMS anymore sic@ */
      case (DEF_1) {
        v_QoS := cs_508_EPS_QoS_Default_1;        /* Qos acc. to 36.508 Table 6.6.1-1 column 1 */
      }
      case (DEF_3) {                              /* @sic R5-210201, R5s211690 sic@ */
        v_QoS := cds_508_EPS_QoS_Default_3;       /* Qos acc. to 36.508 Table 6.6.1-1 column 3 */
      }
      case else {
        v_QoS := cds_EPS_QoS_Def_nonGBR_QCI;      /* Qos acc. to 36.508 Table 6.6.1-1 column 2 */
      }
    }
    return v_QoS;
  }

  template (value) UERadioCapId cs_UERadioCapId (IEI8_Type p_IEI, octetstring p_Id) :=
  { /* @status    APPROVED (NR5GC, NR5GC_IRAT) */
    iei := p_IEI,
    iel := int2oct(lengthof(p_Id), 1),
    id := p_Id
  };

  //============================================================================
  // Packet filters
  //----------------------------------------------------------------------------

  /*
   * @desc      local function to calculate single remote port acc. to reference packet filters in 36.508
   * @param     p_PortNumber
   * @param     p_EPS_BearerId
   * @return    UInt16_Type
   * @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT)
   */
  function fl_SingleRemoteport508(UInt16_Type p_PortNumber,
                                  HalfOctet_Type p_EPS_BearerId) return UInt16_Type
  {
    return (p_PortNumber + hex2int(p_EPS_BearerId) - 6);
  }

  template (value) PacketFilterComponent cs_PktFilterCompSingleRemotePort61000(HalfOctet_Type p_EPS_BearerId) :=
  /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT) */
    cs_PktFilterCompSingleRemotePort(fl_SingleRemoteport508(61000, p_EPS_BearerId));

  template (value) PacketFilterComponent cs_PktFilterCompSingleRemotePort31160(HalfOctet_Type p_EPS_BearerId) :=
  /* @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT) */
    cs_PktFilterCompSingleRemotePort(fl_SingleRemoteport508(31160, p_EPS_BearerId));

  /*
   * @desc      Get the Dedicated TFT according to 36.508 clause 6.6.2
   * @param     p_PacketFilterByRef (by reference)
   * @param     p_PacketFilterLengthByRef (by reference)
   * @param     p_PacketFilterNumber ... is the reference packet filter in Table 6.6.2-x
   * @param     p_EPS_BearerId
   * @param     p_PdnTypeValue
   * @param     p_PdnIndex
   * @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT)
   */
  function fl_Get_508_PacketFilter(out template (value) PacketFilter p_PacketFilterByRef,
                                   out integer p_PacketFilterLengthByRef,
                                   integer p_PacketFilterNumber,
                                   HalfOctet_Type p_EPS_BearerId,
                                   B3_Type p_PdnTypeValue,
                                   PDN_Index_Type p_PdnIndex)
  { /* @sic R5-112600 new parameter p_PdnTypeValue to determine whether IPv4 or IPv6 address to be used sic@ */
    /* @sic R5s130362 - MCC160 Implementation: tsc_PDN_AddressInfo; new parameter p_PdnIndex sic@ */
    var integer v_ContentsLength := 0;
    var template (value) PacketFilter v_Filter;
    var PDN_AddressInfo_Type v_PDN_AddressInfo := f_PDN_AddressInfo_Get(p_PdnIndex);
    var charstring v_NetworkIpAddrv4 := v_PDN_AddressInfo.PCSCF_IPAddressIPv4;
    var charstring v_NetworkIpAddrv6 := v_PDN_AddressInfo.PCSCF_IPAddressIPv6;
    var template (value) PacketFilterComponent v_PacketFilterProtocolId;
    var integer v_PortNumber;  // kept for readability

    if ((p_PacketFilterNumber != 4) and (p_PacketFilterNumber != 5) and (p_PacketFilterNumber != 10)) {   // @sic R5-132085 sic@ in case (4, 5) no addresses used @sic R5s130495, R5s211690 sic@
      if (p_PdnTypeValue == tsc_PdnType_IPv4) {  // IPv4 only; @sic R5s110168 change 8.3; R5-112600 sic@
        v_Filter.contents[0] := cs_PktFilterCompIPv4RemoteAddress(v_NetworkIpAddrv4);
        v_ContentsLength := v_ContentsLength + 9;
      }
      else { // IPv4v6 or IPv6 only
        v_Filter.contents[0] := cs_PktFilterCompIPv6RemoteAddress(v_NetworkIpAddrv6);
        v_ContentsLength := v_ContentsLength + 33;
      }
    }

    select (p_PacketFilterNumber){
      case (1, 6) { // @sic R5-183239 sic@
        v_Filter.spare       := '00'B; //  @sic R5s130195 Baseline Moving sic@
        v_Filter.direction   := '01'B; //  @sic R5s130195 Baseline Moving sic@
        v_Filter.iei         := '0'H;  //  @sic R5s130195 Baseline Moving sic@
        if (hex2int(p_EPS_BearerId) > 5) {
          v_Filter.precedence  := int2bit((hex2int(p_EPS_BearerId)-6), 8); // @sic R5-174469 sic@
        } else {
          v_Filter.precedence  := int2bit(0, 8);
        }
        if (p_PacketFilterNumber == 6) {  // @sic R5-183239, R5-193982 sic@
          if (p_PdnTypeValue == tsc_PdnType_IPv4) {  // IPv4 only
            v_Filter.contents[1] := cs_PktFilterCompProtocolIdNextHeaderICMP;
          } else {
            v_Filter.contents[1] := cs_PktFilterCompProtocolIdNextHeaderICMPv6;
          }
        } else {
          v_Filter.contents[1] := cs_PktFilterCompSingleRemotePort31160(p_EPS_BearerId);
          v_ContentsLength := v_ContentsLength + 3;
          v_Filter.contents[2] := cs_PktFilterCompProtocolIdNextHeaderUDP;
        }
        v_ContentsLength := v_ContentsLength + 2;
      }
      case (2, 7) { // @sic R5-183239 sic@
        // Update to values in Reference packet filter #2
        // UL only filter, ID=1          @sic R5-104702 sic@
        v_Filter.spare       := '00'B; //  @sic R5s130195 Baseline Moving sic@
        v_Filter.direction   := '10'B; //  @sic R5s130195 Baseline Moving sic@
        v_Filter.iei         := '1'H;  //  @sic R5s130195 Baseline Moving sic@
        v_Filter.precedence  := int2bit((hex2int(p_EPS_BearerId)-6+8), 8); // @sic R5-104702 sic@

        if (p_PacketFilterNumber == 7) {// @sic R5-183239, R5-193982 sic@
          if (p_PdnTypeValue == tsc_PdnType_IPv4) {  // IPv4 only
            v_Filter.contents[1] := cs_PktFilterCompProtocolIdNextHeaderICMP;
          } else {
            v_Filter.contents[1] := cs_PktFilterCompProtocolIdNextHeaderICMPv6;
          }
        } else {
          v_Filter.contents[1] := cs_PktFilterCompSingleRemotePort61000(p_EPS_BearerId);
          v_ContentsLength := v_ContentsLength + 3;
          v_Filter.contents[2] := cs_PktFilterCompProtocolIdNextHeaderUDP;
        }
        v_ContentsLength := v_ContentsLength + 2;
      }
      case (3){
        // Update to values in Reference packet filter #3
        // Bidirectional filter, ID=2  @sic R5-104702 sic@
        v_Filter.spare       := '00'B; //  @sic R5s130195 Baseline Moving sic@
        v_Filter.direction   := '11'B; //  @sic R5s130195 Baseline Moving sic@
        v_Filter.iei         := '2'H;  //  @sic R5s130195 Baseline Moving sic@
        v_Filter.precedence  := '00001111'B;
      }
      case (4){  // @sic R5-132085 sic@
        // Update to values in Reference packet filter #4
        // Bidirectional filter, ID=3
        v_Filter.spare       := '00'B;
        v_Filter.direction   := '11'B;
        v_Filter.iei         := '3'H;
        if (hex2int(p_EPS_BearerId)>5)
        {
          v_Filter.precedence  := int2bit((hex2int(p_EPS_BearerId)-6), 8); // @sic R5-174469 sic@
        } else {
          v_Filter.precedence  := int2bit(0, 8);
        }
        v_Filter.contents[0] := cs_PktFilterCompRemotePortRange(tsc_IMS_MediaPort_M1, tsc_IMS_MediaPort_M1+1);  // @sic R5s130495 sic@
        v_ContentsLength := v_ContentsLength + 5;
        v_Filter.contents[1] := cs_PktFilterCompProtocolIdNextHeaderUDP;
        v_ContentsLength := v_ContentsLength + 2;
      }
      case (5){  // @sic R5-132085 sic@
        // Update to values in Reference packet filter #5
        // Bidirectional filter, ID=3
        v_Filter.spare       := '00'B;
        v_Filter.direction   := '11'B;
        v_Filter.iei         := '4'H;
        if (hex2int(p_EPS_BearerId)>5)
        {
          v_Filter.precedence  := int2bit((hex2int(p_EPS_BearerId)-6), 8); // @sic R5-174469 sic@
        } else {
          v_Filter.precedence  := int2bit(0, 8);
        }
        v_Filter.contents[0] := cs_PktFilterCompRemotePortRange(tsc_IMS_MediaPort_M2, tsc_IMS_MediaPort_M2+1);  // @sic R5s130495 sic@
        v_ContentsLength := v_ContentsLength + 5;
        v_Filter.contents[1] := cs_PktFilterCompProtocolIdNextHeaderUDP;
        v_ContentsLength := v_ContentsLength + 2;
      }
      case (8) { // @sic R5-187765 sic@
        // Update to values in Reference packet filter #8
        // UL only filter, ID=1
        v_Filter.spare       := '00'B;
        v_Filter.direction   := '10'B;
        v_Filter.iei         := '1'H;
        v_Filter.precedence  := int2bit((hex2int(p_EPS_BearerId)-6+8), 8);
      }
      case (9) { // @sic R5-187765 sic@
        // Update to values in Reference packet filter #9
        // Bidirectional filter, ID=5
        v_Filter.spare       := '00'B;
        v_Filter.direction   := '11'B;
        v_Filter.iei         := '5'H;
        if (hex2int(p_EPS_BearerId)>5)
        {
          v_Filter.precedence  := int2bit((hex2int(p_EPS_BearerId)-6), 8);
        } else {
          v_Filter.precedence  := int2bit(0, 8);
        }
        v_Filter.contents[0] := cs_PktFilterCompRemotePortRange(tsc_IMS_MediaPort_M2, tsc_IMS_MediaPort_M2+1);
        v_ContentsLength := v_ContentsLength + 5;
        v_Filter.contents[1] := cs_PktFilterCompProtocolIdNextHeaderUDP;
        v_ContentsLength := v_ContentsLength + 2;
      }
      case (10, 11) { // @sic R5-210201, R5s211690, R5-222015 sic@
        // Update to values in Reference packet filter #10
        // Bidirectional filter, ID=4
        v_Filter.spare       := '00'B;
        v_Filter.direction   := '11'B;          // Bidirectional
        v_Filter.iei         := '4'H;           // ID=4
        if (hex2int(p_EPS_BearerId)>5)
        {
          v_Filter.precedence  := int2bit((hex2int(p_EPS_BearerId)-6), 8);
        } else {
          v_Filter.precedence  := int2bit(0, 8);
        }
        if (p_PacketFilterNumber == 10) {
          v_PortNumber := tsc_IMS_MediaPort_M3;  // same portnumber as tsc_MCX_MediaControlPortNW
          v_PacketFilterProtocolId := cs_PktFilterCompProtocolIdNextHeaderUDP;
        } else {                                 // @sic R5-222015: Table 6.6.2-12: Reference packet filter #11 for TCP sic@
          v_PortNumber := tsc_IMS_MediaPort_M1;  // same portnumber as tsc_MCData_MediaPort_MSRP
          v_PacketFilterProtocolId := cs_PktFilterCompProtocolIdNextHeaderTCP;
        }
        v_Filter.contents[0] := cs_PktFilterCompSingleRemotePort(tsc_IMS_MediaPort_M3);
        v_ContentsLength := v_ContentsLength + 3;
        v_Filter.contents[1] := v_PacketFilterProtocolId;
        v_ContentsLength := v_ContentsLength + 2;
      }
    }
    v_Filter.iel := int2oct(v_ContentsLength, 1);

    p_PacketFilterByRef := v_Filter;
    p_PacketFilterLengthByRef := v_ContentsLength + 3; // length of the filter contents + 3 octets for iei, precedence and iel
  }

  //----------------------------------------------------------------------------
  /*
   * @desc      Create TFT acc. to 36.508 Table 6.6.2-1
   * @param     p_BearerContext   .. Reference dedicated EPS bearer context #1, #2
   * @param     p_EPS_BearerId
   * @param     p_PdnTypeValue
   * @param     p_PdnIndex
   * @return    template (value) TrafficFlowTemplate
   * @status    APPROVED (ENDC, IMS, IMS_IRAT, LTE, LTE_A_IRAT, LTE_A_PRO, LTE_A_R10_R11, LTE_A_R12, LTE_IRAT, NBIOT, NR5GC, NR5GC_IRAT)
   */
  function f_EUTRA_NB_Get_508_TrafficFlowTemplate(integer p_BearerContext,
                                                  HalfOctet_Type p_EPS_BearerId,
                                                  B3_Type p_PdnTypeValue,
                                                  PDN_Index_Type p_PdnIndex := PDN_1) return template (value) TrafficFlowTemplate
  { /* @sic R5-112600: to replace cs_508_Tft_Dedicated_1 and cs_508_Tft_Dedicated_2 sic@ */
    var integer v_PacketFilterLen1ByRef;
    var integer v_PacketFilterLen2ByRef;
    var integer v_PacketFilterLen3ByRef;
    var template (value) PacketFilter v_PacketFilter1ByRef;
    var template (value) PacketFilter v_PacketFilter2ByRef;
    var template (value) PacketFilter v_PacketFilter3ByRef;
    var template (value) TrafficFlowTemplate.packetFilterList v_PacketFilterList;
    var integer v_IeLength;

    select (p_BearerContext) {
      case (1) {        // @sic R5-123632 sic@
        fl_Get_508_PacketFilter(v_PacketFilter1ByRef, v_PacketFilterLen1ByRef, 1, p_EPS_BearerId, p_PdnTypeValue, p_PdnIndex);  // get packet filter #1 acc. to 36.508 Table 6.6.2-2 @sic R5s130495 sic@
        fl_Get_508_PacketFilter(v_PacketFilter2ByRef, v_PacketFilterLen2ByRef, 2, p_EPS_BearerId, p_PdnTypeValue, p_PdnIndex);  // get packet filter #2 acc. to 36.508 Table 6.6.2-3 @sic R5s130495 sic@

        v_IeLength := v_PacketFilterLen1ByRef + v_PacketFilterLen2ByRef + 1;  // packet filter 1 + packet filter 2 + one octet for tftOperationCode, eBit and noOfPktFilter
        v_PacketFilterList := {v_PacketFilter1ByRef, v_PacketFilter2ByRef};
      }
      case (2) {        // @sic R5-123632, R5-132085 sic@
        fl_Get_508_PacketFilter(v_PacketFilter1ByRef, v_PacketFilterLen1ByRef, 3, p_EPS_BearerId, p_PdnTypeValue, p_PdnIndex);  // get packet filter #3 acc. to 36.508 Table 6.6.2-4 @sic R5s130495 sic@

        v_IeLength := v_PacketFilterLen1ByRef + 1;                           // packet filter 1 + one octet for tftOperationCode, eBit and noOfPktFilter
        v_PacketFilterList := {v_PacketFilter1ByRef};
      }
      case (3) {        // @sic R5-132085 sic@
        fl_Get_508_PacketFilter(v_PacketFilter1ByRef, v_PacketFilterLen1ByRef, 5, p_EPS_BearerId, p_PdnTypeValue, p_PdnIndex);  // get packet filter #3 acc. to 36.508 Table 6.6.2-4 @sic R5s130495 sic@

        v_IeLength := v_PacketFilterLen1ByRef + 1;                           // packet filter 1 + one octet for tftOperationCode, eBit and noOfPktFilter
        v_PacketFilterList := {v_PacketFilter1ByRef};
      }
      case (4) {        // @sic R5-132085 sic@
        fl_Get_508_PacketFilter(v_PacketFilter1ByRef, v_PacketFilterLen1ByRef, 4, p_EPS_BearerId, p_PdnTypeValue, p_PdnIndex);  // get packet filter #4 acc. to 36.508 Table 6.6.2-4 @sic R5s130495 sic@

        v_IeLength := v_PacketFilterLen1ByRef + 1;                           // packet filter 1 + one octet for tftOperationCode, eBit and noOfPktFilter
        v_PacketFilterList := {v_PacketFilter1ByRef};
      }
      case (5) {        // @sic R5-210201, R5s211690 sic@
        fl_Get_508_PacketFilter(v_PacketFilter1ByRef, v_PacketFilterLen1ByRef, 4, p_EPS_BearerId, p_PdnTypeValue, p_PdnIndex);  // get packet filter #4 acc. to 36.508 Table 6.6.2-1
        fl_Get_508_PacketFilter(v_PacketFilter2ByRef, v_PacketFilterLen2ByRef, 10, p_EPS_BearerId, p_PdnTypeValue, p_PdnIndex); // get packet filter #10 acc. to 36.508 Table 6.6.2-1

        v_IeLength := v_PacketFilterLen1ByRef + v_PacketFilterLen2ByRef + 1;  // packet filter 1 + packet filter 2 + one octet for tftOperationCode, eBit and noOfPktFilter @sic R5s180640 sic@
        v_PacketFilterList := {v_PacketFilter1ByRef, v_PacketFilter2ByRef};
      }
      case (6) { // @sic R5-183239 sic@
        fl_Get_508_PacketFilter(v_PacketFilter1ByRef, v_PacketFilterLen1ByRef, 6, p_EPS_BearerId, p_PdnTypeValue, p_PdnIndex);  // get packet filter #6 acc. to 36.508 Table 6.6.2-1A
        fl_Get_508_PacketFilter(v_PacketFilter2ByRef, v_PacketFilterLen2ByRef, 7, p_EPS_BearerId, p_PdnTypeValue, p_PdnIndex);  // get packet filter #7 acc. to 36.508 Table 6.6.2-1A

        v_IeLength := v_PacketFilterLen1ByRef + v_PacketFilterLen2ByRef + 1;  // packet filter 1 + packet filter 2 + one octet for tftOperationCode, eBit and noOfPktFilter @sic R5s180640 sic@
        v_PacketFilterList := {v_PacketFilter1ByRef, v_PacketFilter2ByRef}; // @sic R5s180640 sic@
      }
      case (7) {        // @sic R5-187765 sic@
        fl_Get_508_PacketFilter(v_PacketFilter1ByRef, v_PacketFilterLen1ByRef, 8, p_EPS_BearerId, p_PdnTypeValue, p_PdnIndex);  // get packet filter #8 acc. to 36.508 Table 6.6.2-1A

        v_IeLength := v_PacketFilterLen1ByRef + 1;  // packet filter 1 + one octet for tftOperationCode, eBit and noOfPktFilter
        v_PacketFilterList := {v_PacketFilter1ByRef};
      }
      case (8) {        // @sic R5-187765 sic@
        fl_Get_508_PacketFilter(v_PacketFilter1ByRef, v_PacketFilterLen1ByRef, 9, p_EPS_BearerId, p_PdnTypeValue, p_PdnIndex);  // get packet filter #9 acc. to 36.508 Table 6.6.2-1A

        v_IeLength := v_PacketFilterLen1ByRef + 1;    // packet filter 1 + one octet for tftOperationCode, eBit and noOfPktFilter
        v_PacketFilterList := {v_PacketFilter1ByRef};
      }
      case (9) { // @sic R5-222015: MCData sic@
        fl_Get_508_PacketFilter(v_PacketFilter1ByRef, v_PacketFilterLen1ByRef, 11, p_EPS_BearerId, p_PdnTypeValue, p_PdnIndex);  // get packet filter #11 acc. to 36.508 Table 6.6.2-1A

        v_IeLength := v_PacketFilterLen1ByRef + 1;    // packet filter 1 + one octet for tftOperationCode, eBit and noOfPktFilter
        v_PacketFilterList := {v_PacketFilter1ByRef};
      }
      case (10) { // @sic R5-222015: MCVideo sic@
        fl_Get_508_PacketFilter(v_PacketFilter1ByRef, v_PacketFilterLen1ByRef,  4, p_EPS_BearerId, p_PdnTypeValue, p_PdnIndex);  // get packet filter #4 acc. to 36.508 Table 6.6.2-1A
        fl_Get_508_PacketFilter(v_PacketFilter2ByRef, v_PacketFilterLen2ByRef,  5, p_EPS_BearerId, p_PdnTypeValue, p_PdnIndex);  // get packet filter #5 acc. to 36.508 Table 6.6.2-1A
        fl_Get_508_PacketFilter(v_PacketFilter3ByRef, v_PacketFilterLen3ByRef, 10, p_EPS_BearerId, p_PdnTypeValue, p_PdnIndex);  // get packet filter #10 acc. to 36.508 Table 6.6.2-1A

        v_IeLength := v_PacketFilterLen1ByRef + v_PacketFilterLen2ByRef + v_PacketFilterLen3ByRef + 1;  // packet filter 1 + packet filter 2 + packet filter 3 + one octet for tftOperationCode, eBit and noOfPktFilter
        v_PacketFilterList := {v_PacketFilter1ByRef, v_PacketFilter2ByRef, v_PacketFilter3ByRef};
      }
      case else {
        FatalError(__FILE__, __LINE__, "invalid bearer context");
      }
    }
    return cs_TrafficFlowTemplate(v_IeLength, v_PacketFilterList);
  }

}
