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

module  MobileL3_CommonIE_Types {

import from General_Types all;

// This type is a container for all necessary MS related parameters
type record MS_parameters
{
  integer       imsi_length,  //in
  BIT4          imsi_firstdigit,
  octetstring   imsi,
  octetstring   number,
  integer       SCCP_connId, //connection Id of currently used SCCP connection
  integer       L3_NSD,  // actual value of L3 NSD
  BIT1          tiFlag   // '0'B for call originator, '1' for call destination
  // this is an example how to set the value
  // tsp_imsi_1_firstdigit := '0010'B
  // tsp_imsi_1 :=  '26200103000015'O;   // '262021030000051'O;
  // tsp_calledPartyBCD_Number_digits := '7112300020'O  ;   // '1721030002'O
}

// Use these Types instead of repeating it !

type record Type1_V
{
  BIT4  dummy,
  BIT4  valuePart
};

type record Type1_TV
{
  BIT4  valuePart,
  BIT4  elementIdentifier
};

type record Type2
{
  OCT1  elementIdentifier
};

type record Type3_V
{
  OCTN  valuePart
};

type record Type3_TV
{
  OCT1  elementIdentifier,
  OCTN  valuePart
};

type record Type4_LV
{
  LIN1  lengthIndicator,
  OCTN  valuePart
} with { variant (lengthIndicator) "LENGTHTO (valuePart)"};

type record Type4_TLV
{
  OCT1  elementIdentifier,
  LIN1  lengthIndicator,
  OCTN  valuePart
} with { variant (lengthIndicator) "LENGTHTO (valuePart)"};

///////////////////////////////////////
//   IE Type definitions
///////////////////////////////////////

type record ML3_NotifySS_Arg
{
  OCT1  sequenceTag,
  OCT1  sequenceLength,
  OCT1  ssCodeTag,
  OCT1  ssCodeLength,
  OCT1  ssCodeValue,
  OCT1  ssIndicatorTag,
  OCT1  ssIndicatorLength,
  OCT1  ssIndicatorValue
};


//============================================================================
// 10.5.1 Common Information elements
//============================================================================

// 10.5.1.1 Cell Identity
type record CellIdentity
{
  OCT1  elementIdentifier,
  OCT2  cIvalue
};

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

type record CipheringKeySequenceNumberV
{
  BIT3               keySequence,
  BIT1               spare
};

//24.008/10.5.1.3 Location Area Identification
type record LocationAreaIdentification_V
{
  OCT3  mcc_mnc,
  OCT2  lac
};

type record LocationAreaIdentification_TV
{
  OCT1  elementIdentifier,
  OCT3  mcc_mnc,
  OCT2  lac
};

// 24.008/ 10.5.1.4 Mobile Identity
type record MobileIdentityTLV
{
  BIT7               elementIdentifier,
  BIT1               spare1,
  MobileIdentityLV   mobileIdentityLV
};

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

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


type union OddEvenInd_Identity
{
  IMSI_L3                  imsi,  // avoid name conflict with RANAP
  IMEI_L3                  imei,     // avoid name conflict with RANAP
  IMEI_SV                  imei_sv,
  TMSI_PTMSI               tmsi_ptmsi,
  TMGI_and_MBMS_SessionID  tmgi_and_MBMS_SessionID,
  No_Identity              no_identity
};

type record IMSI_L3
{
  BIT1               oddevenIndicator,       // '1'B or '0'B
  hexstring          digits  length(5..15),
  BIT4               fillerDigit  optional   // B'1111, fillerDigit is present
  // if oddevenIndicator=0
} with { variant (fillerDigit) "PRESENCE (oddevenIndicator   = '0'B) ";};

type record IMEI_L3
{
  BIT1               oddevenIndicator,   // '1'B
  hexstring          digits  length(15)
};

type record TMSI_PTMSI
{
  BIT1               oddevenIndicator, // '0'B
  BIT4               fillerDigit, // B'1111
  OCT4               octets
};

type record IMEI_SV
{
  BIT1               oddevenIndicator,  // '0'B
  hexstring          digits length(16),
  BIT4               fillerDigit    // filler '1111'B
};

type record TMGI_and_MBMS_SessionID
{
  BIT1               oddevenIndicator,
  BIT1               mCC_MNCIndicator,  // 1: present
  BIT1               mBMS_SessionIdentityIndicator,  // 1: present
  BIT2               spare,
  OCT3               mBMS_ServiceID,
  HEX1               mccDigit1,
  HEX1               mccDigit2,
  HEX1               mccDigit3,
  HEX1               mncDigit3,
  HEX1               mncDigit1,
  HEX1               mncDigit2,
  OCT1               mBMS_SessionIdentity
}

type record No_Identity
{
  BIT1               oddevenIndicator,  // '0'B (guessed)
  // MI length to be "3" if the GMM/EMM identification procedure is used,
  // or "1" otherwise. The Identity digit bits shall be encoded with all 0s.
  hexstring          fillerDigits length(1..5)
};

// 24.008/ 10.5.1.5 MobileStationClassmark1
type record MobileStationClassmark1_TV
{
  OCT1   elementIdentifier, //'???'H
  BIT3   rf_PowerCapability,
  BIT1   a5_1,
  BIT1   esind,
  BIT2   revisionLevel,
  BIT1   spare1_1
};

type record MobileStationClassmark1_V
{
  BIT3  rf_PowerCapability,
  // class1 (000) (for GSM+DCS+PCS)
  // class2 (001) (for GSM+DCS+PCS)
  // class3 (010) (for GSM+DCS+PCS)
  // class4 (011) (only for GSM)
  // class5 (100) (only for GSM)
  BIT1  a5_1,
  // encryption algor. A5/available  1  (1)
  // encryption algor. A5/1 available  not  (0)
  BIT1  esind,
  BIT2  revisionLevel,
  BIT1  spare1_1
};

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


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

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

type record MobileStationClassmark2_TLV
{
  OCT1                        elementIdentifier,
  MobileStationClassmark2_LV  mobileStationClassmark2LV
} with {
  variant "PRESENCE (elementIdentifier = '11'O)";
};



//**********************************************************************
// 24.008/ 10.5.1.6 5th octet ( Table 10.5.6a ):
// almost the same as MobileStationClassmark2_LV, but
// _TLV ie elementIdentifier is present
// oct4 and oct5 is mandatory
// The record name is inherited from (and used in) old test cases
//**********************************************************************
type record ClassmarkInformationType2_forUMTS
{
  OCT1  elementIdentifier,
  //'33'O instead of '12'O (normal Classmark2)
  LIN1  lengthIndicator,
  //always '03'O (unlike normal ClassMark2, which can be 2 or 3)
  BIT3  rf_PowerCapability,   //  '000'B class1 (for GSM+DCS+PCS)
  //      '001'B class2 (for GSM+DCS+PCS)
  //      '010'B class3 (for GSM+DCS+PCS)
  //      '011'class4  B  (only for GSM)
  //      '100'class5  B  (only for GSM)
  BIT1  a5_1, //  '0'B encryption algorithm A5/1 available not (0)
  //  '1'B encryption algorithm A5/available  1  (1)
  BIT1  esind,
  //'0'B controlled early classmark sending option implemented not (0)
  //  '1'B controlled early classmark sending implemented  option  (1)
  BIT2  revisionLevel, //  '00'B reserved for phase1 (GSM+DCS)
  //  '00'reserved  B  (PCS)
  //  '01'B used by phase2 MSs  (GSM+DCS)
  //  '01'B used by PCS1900 MSs  phase1  (PCS)
  BIT1  spare1_1, // '0'B
  BIT1  fc, //         '0'B  no MS' support of E/R_GSM
  //   '1'B       MS' support of E/R_GSM
  BIT1  vgcs,//'0'B no VGCS capability
  //'1'B  VGCS capability and notifications wanted
  BIT1  vbs, //'0'B no VBS capability,
  //  '1'B VBS capability and notifications wanted
  BIT1  sm_Capability, //     '0'B SM capbility present  not
  // '1'B SM capability     present
  BIT2  ss_ScreenIndicator, //  '00'B default value of phase1 (GSM+DCS)
  //  '00'reserved  B  (PCS)
  //  '01'B capability of notation  ellipsis
  //  '10'B for future use
  //  '11'B for use  future
  BIT1  ps_Capability, // '0'B or '1'B ignored, received  if
  BIT1  spare2_1,  // '0'B,
  BIT1  a5_2, // '0'B encryption algorithm A5/2 available  not  (0)
  // '1'B encryption algorithm A5/available  2  (1)
  BIT1  a5_3, // '0'B encryption algorithm A5/3 available  not  (0)
  // '1'B encryption algorithm A5/available  3  (1)
  //BIT5  spare3_5, // '00000'B
  BIT1  cmsp,
  BIT1  solsa,
  BIT1  ucs2,
  BIT1  lcsva_cap,
  BIT1  spare5_7,
  BIT1  cm3   // '0'B no additional capability info
  // '1'B   additional info  capability
} with { variant (lengthIndicator) "LENGTHTO (rf_PowerCapability, a5_1, esind,
  revisionLevel, spare1_1, fc, vgcs, vbs,
  sm_Capability, ss_ScreenIndicator,
  ps_Capability, spare2_1, a5_2, a5_3,
  //spare3_5,
  cmsp,solsa,ucs2,lcsva_cap,spare5_7,
  cm3)"};



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


type record MobileStationClassmark3_LV
{
  LIN1  lengthIndicator,
  OCTN  valuePart
} with { variant (lengthIndicator) "LENGTHTO (valuePart)"};
// used in: PDU_ML3_Setup_MSC_MS, PDU_ML3_CallProceeding,
//          PDU_ML3_CMServiceRequest

type record UTRACSGCellsReporting
{
  BIT1                  reportingofUTRANCSGCellsSupport
} with {
  variant "FIELDORDER(msb)"
}

type record VAMOSLevel
{
  BIT2                  vAMOSSupport
} with {
  variant "FIELDORDER(msb)"
}

//24.008/ 10.5.1.8 Spare half octet ---- not used

//24.008/ 10.5.1.9 Descriptive group or broadcast call reference
type record DescriptiveGroupOrBroadcastCallReference_V
{
  bitstring         binaryCodingOfGroupOrBroadcastCallReference length (27),
  BIT1              sF,
  BIT1              aF,
  BIT3              callPriority,
  BIT4              cipheringInformation,
  BIT4              spare
} with {  variant (binaryCodingOfGroupOrBroadcastCallReference,sF,aF,
    callPriority,cipheringInformation,spare)  "FIELDORDER(msb)"};

//10.5.1.10 Group Cipher Key Number
type record groupCipherKeyNumber_TV
{
  BIT4 valuePart,
  BIT4 elementIdentifier
};

type BIT4 groupCipherKeyNumber_V;


//24.008/10.5.1.10a
type record PdAndSapi
{
  BIT4 protocolDiscriminator,
  BIT2 sapi,
  BIT2 spare2
};

//10.5.1.11 Priority Level
type record PriorityLevel_ML3
{
  BIT3  callPriority, // B'...._000 no applied  priority
  // B'...._001 call priority level 4
  // B'...._010 call priority level 3
  // B'...._011 call priority level 2
  // B'...._100 call priority level 1
  // B'...._101 call priority level 0
  // B'...._110 call priority level B
  // B'...._111 call priority level A
  BIT1  spare1_1,      // B'....0.._
  // modified by ethbaat:OCT1  elementIdentifier for...
  BIT4  elementIdentifier       // B'1000' type 1 IEI Priority level
};
//ending "_ML3" added, because ambiguities of (RANAP is also using this name)


//10.5.1.12 Core Network System Information
// not implemented yet

//10.5.1.13 PLMN List
type record PLMNListTLV
{
  BIT7               elementIdentifier,
  BIT1               spare1,
  LIN1               lengthIndicator,
  octetstring        digits  length(3..45) // collapsed into one octetstring
  // instead of digits
} with { variant "PRESENCE (elementIdentifier = '1001010'B)";
  variant (lengthIndicator) "LENGTHTO (digits)"};
  
//10.5.1.15
type record MS_NetworkFeatureSupportTV
{
  BIT1      extendedPeriodicTimers,
  BIT3      spare,
  BIT4      elementIdentifier
}

// GPRS Timer3 - 10.5.7.4a
type record GPRSTimer3TLV
{
  OCT1               elementIdentifier,
  LIN1               lengthIndicator,
  GPRSTimer3V        gprsTimer3V
} with { 
   variant (lengthIndicator) "LENGTHTO (gprsTimer3V)"
}; 

type record GPRSTimer3V
{
  BIT5               timerValue,
  BIT3               unit
};

//****************************************************************************
// Common elements in CC and SS:
//****************************************************************************

//24.008/10.5.4.11 Cause
type record Diagnostics
{
  octetstring data   // to split into pieces????
} with { variant "EXTENSION_BIT (yes)"};

// This type is added for handling extension bit in octet 3 of Cause IE
type record ML3_Cause_oct3
{
  BIT4  location,   //      '0000'user  B
  //      '0001'B private network, local user
  //      '0010'B public  network, user  local
  //      '0011'B transit network
  //      '0100'B public  network, user  remote
  //      '0101'B private network, remote user
  //      '0111'B network  international
  //      '1010'B Network beyond interworking pt.
  BIT1  spare1_1, //     '0'B
  BIT2  codingStandard, // '00'B coding according Q.931
  // '01'B reserved for standards  other
  // '10'B National standard
  // '11'B standard  other  (e.g. one defined for GSM PLMNs)
  BIT1  ext1, // '0'B or '1'B
  //octet3a:
  BIT7  recommendation  optional,
  BIT1  ext2            optional // B'1......
} with { variant "EXTENSION_BIT (yes)"};

type record ML3_Cause_oct4
{
  BIT7  causeValue, // see 12/FS
  BIT1  ext3 // B'1......
} with { variant "EXTENSION_BIT (yes)"};

type record ML3_Cause_LV
{
  LIN1  lengthIndicator, // 2..30
  ML3_Cause_oct3 oct3,
  ML3_Cause_oct4 oct4,
  Diagnostics  diagnostics  optional  // size: 1..27
} with { variant (lengthIndicator) "LENGTHTO (oct3, oct4, diagnostics) "};

//24.008/10.5.4.11
type record ML3_Cause_TLV
{
  OCT1   elementIdentifier,
  LIN1  lengthIndicator, // 2..30
  ML3_Cause_oct3 oct3,
  ML3_Cause_oct4 oct4,
  Diagnostics  diagnostics  optional  // size: 1..27
} with { variant (lengthIndicator) "LENGTHTO (oct3, oct4, diagnostics) "};

//10.5.4.15 Facility IE (see also 24.080/3.6)
type record Facility_TLV
{
  OCT1  elementIdentifier, // H'1C
  LIN1  lengthIndicator, // 0..?
  OCTN  facilityInformation  optional //see 24.080/3.6
} with { variant (lengthIndicator) "LENGTHTO (facilityInformation)"};

type record Facility_LV
{
  LIN1  lengthIndicator, // 0..?
  OCTN  facilityInformation  optional  //see 24.080/3.6
} with { variant (lengthIndicator) "LENGTHTO (facilityInformation)"};

//24.008/10.5.4.24 SS Version Indicator
// used by SS and CC
type record SS_VersionIndicator
{
  OCT1  elementIdentifier, // H'7F
  LIN1  lengthIndicator, // 0..?
  OCTN  ss_VersionIndicatorContents  optional //see 24.080 !!!
} with { variant (lengthIndicator) "LENGTHTO (ss_VersionIndicatorContents)"};

//10.5.4.32 Supported Codec List
type record codec
{
  OCT1  systemIdentification1,
  OCT1  lengthOfBitmap1,
  OCT1  codecBitmap1_bits1to8,
  OCT1  codecBitmap1_bits9to16
}; 

type record of codec CodecList_ML3; 

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

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

//****************************************************************************
// Common elements in GMM and MM:
//****************************************************************************
// 10.5.5.8a - P-TMSI Signature 2
type record P_TMSISignature2TLV
{
  OCT1               elementIdentifier,
  LIN1               lengthIndicator,
  OCT3               valueField
} with {
  variant "PRESENCE (elementIdentifier = '19'O)";
  variant (lengthIndicator) "LENGTHTO (valueField)"
};

// 10.5.5.29 - P-TMSI Type
type record P_TMSI_TypeTV
{
  BIT1     pTMSI_TypeValue,
  BIT3     spare,
  BIT4     elementIdentifier
} with { variant "PRESENCE (elementIdentifier = '1110'B)" }; 

//10.5.5.15a - Routing Area Identification
type record RoutingAreaIdentification2TLV
{
  OCT1               elementIdentifier,
  LIN1               lengthIndicator,
  OCT6               routingAreaIdentification2
} with {
  variant "PRESENCE (elementIdentifier = '1B'O)";
  variant (lengthIndicator) "LENGTHTO (routingAreaIdentification2)"
};


//****************************************************************************
// Common elements in RRM and MM:
//****************************************************************************

//10.5.3.14 Additional Update Parameter
type record AdditionalUpdateParameterTV
{
  BIT1               cSMT,
  BIT1               cSMO,
  BIT1               spare2,
  BIT1               spare3,
  BIT4               elementIdentifier
} with {
  variant "PRESENCE (elementIdentifier = '1100'B)"
}

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

