///////////////////////////////////////////////////////////////////////////////
//
// 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_MM_Types.ttcn
//  Rev:                R2A
//  Prodnr:             CNL 113 832
//  Contact:            http://ttcn.ericsson.se
//  Reference:          3GPP TS 24.008 v13.4.0


module  MobileL3_MM_Types
{

import from General_Types           all;
import from MobileL3_CommonIE_Types all;

//============================================================================
// 24.008/ 10.5.3  Mobility Management information elements
//============================================================================

//10.5.3.1  AuthenticationParRAND
//**********************************************************************
type record AuthenticationParameterRANDTV
{
  OCT1               elementIdentifier,
  OCT16              randValue
} with { variant "PRESENCE (elementIdentifier = '21'O)"; };

//10.5.3.1.1 Authentication Par AUTN (UMTS auth. ch. only)
//**********************************************************************
type record AuthenticationParameterAUTNTLV
{
  OCT1               elementIdentifier,
  LIN1               lengthIndicator,
  OCT16              autnValue
} with { variant (lengthIndicator) "LENGTHTO (autnValue)"};

//10.5.3.2 Authentication Response parameter
//**********************************************************************
type record  AuthenticationResponseParameterTV
{
  OCT1               elementIdentifier,
  OCT4               valueField   length (4)
} with { variant "PRESENCE (elementIdentifier = '22'O)"; };

//10.5.3.2.1 Authentication Response parameter (extension)
//**********************************************************************
type record AuthenticationResponseParameterUMTSTLV
{
  OCT1               elementIdentifier,
  LIN1               lengthIndicator,
  octetstring        valueField     length (1..12)
} with { variant (lengthIndicator) "LENGTHTO (valueField)"};


//10.5.3.2.2 Authentication Failure parameter (UMTS authentication challenge only)
//**********************************************************************
type record AuthenticationFailureParametersTLV
{
  OCT1               elementIdentifier,
  LIN1               lengthIndicator,
  octetstring        valueField     length (14)
} with { variant "PRESENCE (elementIdentifier = '30'O)";
         variant (lengthIndicator) "LENGTHTO (valueField)"};

//10.5.3.5 Location Update Type
//****************************************************************************
type record LocationUpdatingType
{
  BIT2               lut, // LU  Normal  (00)
                          // LU  Periodic  (01)
                          // Attach  IMSI  (10)
                          // reserved    (11)
  BIT1               spare1_1, // 0
  BIT1               fop   // Follow Pending on (1), not (0)
};

//10.5.3.5a Network Name
//****************************************************************************
type record  NetworkNameTLV
{
  BIT7               elementIdentifier,
  BIT1               spare1,
  LIN1               lengthIndicator,
  NetworkNameV       valueField
} with { variant (lengthIndicator) "LENGTHTO (valueField)"};


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

//10.5.3.7 Follow-on Proceed
//****************************************************************************
type Type2 FollowOnProceed; //'A1'O

//10.5.3.8 TimeZone
//****************************************************************************
type record TimeZoneTV
{
  BIT7               elementIdentifier,
  BIT1               spare,
  TimeZoneV          valueField
} with { variant "PRESENCE (elementIdentifier = '1000110'B)"; };  //'46'O  7 bits

type record TimeZoneV
{
  OCT1               timeZone
};

//10.5.3.9 Time Zone And Time
//****************************************************************************
type record TimeZoneAndTimeTV
{
  BIT7               elementIdentifier,
  BIT1               spare,
  TimeZoneAndTimeV   valueField
} with { variant "PRESENCE (elementIdentifier = '1000111'B)"; };  //'47'O  7 bits;


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

//10.5.3.10 CTS permission
//**********************************************************************
type Type2 CTS_Permission;

//10.5.3.11 LSA identifier (Localised Service Area)
//**********************************************************************
type record  LSA_IdentifierTLV
{
  BIT7               elementIdentifier,
  BIT1               spare,
  LIN1               lengthIndicator,
  LSA_IdentifierV    valueField
} with { variant "PRESENCE (elementIdentifier = '1001000'B)";  //'48'O  7 bits
         variant (lengthIndicator) "LENGTHTO (valueField)"};

type record LSA_IdentifierV
{
  octetstring lsa_id length (0..3)
};

//10.5.3.12 Daylight Saving Time
//**********************************************************************
type record DaylightSavingTimeTLV
{
  OCT1               elementIdentifier,
  LIN1               lengthIndicator,
  DaylightSavingTimeV valueField
} with { variant "PRESENCE (elementIdentifier = '49'O)";
         variant (lengthIndicator) "LENGTHTO (valueField)"};

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

//10.5.3.13 Emergency Number List
//**********************************************************************
type record EmergencyNumberListTLV
{
  OCT1                 elementIdentifier,
  LIN1                 lengthIndicator,
  EmergencyNumberListV emergencyNumberListV
} with { variant "PRESENCE (elementIdentifier = '34'O)";
         variant (lengthIndicator) "LENGTHTO (emergencyNumberListV)"};

type record of EmergencyNumber EmergencyNumberListV

type record EmergencyNumber
{
  LIN1                     lengthIndicator,
  EmergencyServiceCategory emergencyServiceCategory,
  hexstring                emergencyNumber        length (1..44)
} with { variant (lengthIndicator) "LENGTHTO (emergencyServiceCategory,emergencyNumber)";
         variant "PADDING(yes)";
         variant "PADDING_PATTERN('1111'B)"};

type record EmergencyServiceCategory
{
  BIT5               valueFiled,
  BIT3               spare   //'000'B
};

//10.5.3.14 Additional Update Parameter
//moved into MobileL3_CommonIE_Types


//10.5.3.16 MM Timer
//**********************************************************************
type record MM_TimerTLV
{
  OCT1                 elementIdentifier,
  LIN1                 lengthIndicator,
  MM_TimerV            valueField
} with { variant "PRESENCE (elementIdentifier = '36'O)";
         variant (lengthIndicator) "LENGTHTO (valueField)"};

type record MM_TimerV
{
  BIT5               timerValue,
  BIT3               unit
}

//============================================================================
// 24.008/9.2 Messages for mobility management (MM)
//============================================================================

//**********************************************************************
// Security Messages
//**********************************************************************

// 9.2.1 Authentication Reject
//**********************************************************************
type record PDU_ML3_AuthenticationReject
{
  BIT6  messageType, // '010001'B  (AuthenticationReject)
  BIT2  nsd
};

// 9.2.2 Authentication Request
//**********************************************************************
type record PDU_ML3_AuthenticationRequest
{
  BIT6  messageType, // '010010'B
  BIT2  nsd,
  CipheringKeySequenceNumberV   cipheringKeySequenceNumber,
  BIT4                          spare2_4, // B'0000
  OCT16                         authenticationParRAND,
  AuthenticationParameterAUTNTLV  authenticationParAUTN    optional
      // added by ethcky acc to 10/155 17_1/APT 210 26/1 Uen Rev A
} with { variant "TAG (
                authenticationParAUTN, elementIdentifier = '20'O ) "};

// 9.2.3 Authentication Response
//****************************************************************************
type record PDU_ML3_AuthenticationResponse
{
  BIT6  messageType, // '010100'B  (AuthenticationResponse)
  BIT2  nsd,
  OCT4  authenticationParSRES, //10.5.3.2
  AuthenticationResponseParameterUMTSTLV  authenticationParSRESext  optional
} with { variant "TAG (authenticationParSRESext, elementIdentifier = '21'O )"};

// 9.2.3a Authentication Failure
//****************************************************************************
type record PDU_ML3_AuthenticationFailure
{
  BIT6  messageType, // '011100'B  (AuthenticationFailure)
  BIT2  nsd,
  OCT1  rejectCause, //10.5.3.6
  AuthenticationFailureParametersTLV  authenticationParFailure  optional
} with { variant "TAG (authenticationParFailure , elementIdentifier = '22'O ) " };

//**********************************************************************
// Mobility Management Message Types (TS 24.008/ chapter 9)
// Connection management (CM) messages
//**********************************************************************

// 9.2.4 CM Re-establishment Request
//**********************************************************************
type record PDU_ML3_CMReestablishmentRequest
{
  BIT6                          messageType,      // '101000'B
  BIT2                          nsd,
  CipheringKeySequenceNumberV   cipheringKeySequenceNumber,
  BIT4                          spare,
  MobileStationClassmark2_LV    mobileStationClassmark2,
  MobileIdentityLV              mobileIdentityLV,
  LocationAreaIdentification_TV locationAreaIdentification optional,
  DevicePropertiesTV            deviceProperties  optional  
} with { variant "TAG (locationAreaIdentification, elementIdentifier = '13'O;
                       deviceProperties,           elementIdentifier = '1101'B;) 
"};

// 9.2.5 CM Service Accept (NW->MS)
//**********************************************************************
type record PDU_ML3_CMServiceAccept
{
  BIT6  messageType, //    '100001'B
  BIT2  nsd
};

// 9.2.5a CMServicePrompt (NW->MS)
//**********************************************************************
type record PDU_ML3_CMServicePrompt
{
  BIT6  messageType, //    '100101'B
  BIT2  nsd,
  PdAndSapi pd_sapi
};

// 9.2.6 CMServiceReject (NW->MS)
//**********************************************************************
type record PDU_ML3_CMServiceReject
{
  BIT6  messageType, //    '100010'B
  BIT2  nsd,
  OCT1  rejectCause, //10.5.3.6
  MM_TimerTLV t3246_Value optional     
};

// 9.2.7 CM Service Abort (MS->NW to request the abortion)
//**********************************************************************
type record PDU_ML3_CMServiceAbort
{
  BIT6  messageType, //   '100011'B
  BIT2  nsd
};

// 9.2.8  Abort (NW->MS to initiate the abortion)
//**********************************************************************
type record PDU_ML3_Abort
{
  BIT6  messageType, //    '100010'B
  BIT2  nsd,
  OCT1  rejectCause //10.5.3.6
};

// 9.2.9 CM Service Request (MS->NW)
//**********************************************************************
type record PDU_ML3_CMServiceRequest
{
  BIT6  messageType,//    '100100'B
  BIT2  nsd,
  BIT4  cm_ServiceType,  // '0001'B establishment  MOC
                         // '0010'B Emergency Call
                         // '0100'SMS  B
                         // '1000'B SS activation
  CipheringKeySequenceNumberV cipheringKeySequenceNumber,
  MobileStationClassmark2_LV  mobileStationClassmark2,
  MobileIdentityLV            mobileIdentity,
  PriorityLevel_ML3           priorityLevel   optional,
  AdditionalUpdateParameterTV additionalUpdateParameterTV optional,
  DevicePropertiesTV          deviceProperties optional
} with { variant "TAG (priorityLevel,    elementIdentifier = '1000'B; 
                       deviceProperties, elementIdentifier = '1101'B;) 
"};

//9.2.10 Identity Request
//**********************************************************************
type record PDU_ML3_IdentityRequest
{
  BIT6  messageType, //   '011000'B ( IdentityRequest )
  BIT2  nsd,
  BIT3  identityType,  // IMSI:'001'B IMEI:'010'B IMEISV:'011'B
                       //(TMSI:'100'B not allowed?) 10.5.3.4
  BIT5  spare1_5       // '00000'B
};

//9.2.11 Identity Response
//**********************************************************************
type record PDU_ML3_IdentityResponse
{
  BIT6  messageType,  //    '011001'B (IdentityResponse)
  BIT2  nsd,
  MobileIdentityLV  mobileIdentityLV,
  P_TMSI_TypeTV     p_TMSI_TypeTV optional,
  RoutingAreaIdentification2TLV routingAreaIdentification2TLV optional,
  P_TMSISignature2TLV p_TMSISignature2TLV optional
};

//9.2.12 IMSI Detach Indication
//**********************************************************************
type record PDU_ML3_IMSI_DetachIndication
{
   BIT6  messageType, //    '000001'IMSI Detach Indication
   BIT2  nsd,
   MobileStationClassmark1_V    mobileStationClassmark1,
   MobileIdentityLV             mobileIdentityLV
};

//****************************************************************************
// 24.008/9 Mobility Management message contents
//****************************************************************************

// 9.2.13 Location Update Accept
//****************************************************************************
type record PDU_ML3_LocationUpdateAccept
{
  BIT6  messageType, // '000010'B  (LocationUpdateRequest)
  BIT2  nsd,
  LocationAreaIdentification_V  locationAreaIdentification,
  MobileIdentityTLV             mobileIdentityTLV           optional,
  Type2                         followOnProceed             optional,
  CTS_Permission                cTS_Permission              optional,
  PLMNListTLV                   equivalentPLMNs             optional,
  EmergencyNumberListTLV        emergencyNumberList         optional,
  GPRSTimer3TLV                 perMS_T3212                 optional
} with { variant "TAG ( mobileIdentityTLV,  elementIdentifier = '0010111'B;  //'17'O;
                        followOnProceed,    elementIdentifier = 'A1'O;
                        cTS_Permission,     elementIdentifier = 'A2'O;
                        equivalentPLMNs,    elementIdentifier = '1001010'B;  //'4A'O;
                        emergencyNumberList,  elementIdentifier = '34'O;) "};

// 9.2.14 Location Update Reject (NW->MS)
//****************************************************************************
type record PDU_ML3_LocationUpdateReject
{
  BIT6  messageType,  // '000100'B (LocationUpdateReject)
  BIT2  nsd,
  OCT1  rejectCause,   // see 10.5.3.6
  MM_TimerTLV  t3246_Value optional
};

//9.2.15 Location Update Request (MS->NW)
//****************************************************************************
type record PDU_ML3_LocationUpdateRequest
{
  BIT6  messageType, // B'_001000  (LocationUpdateRequest)
  BIT2  nsd,
  LocationUpdatingType               locationUpdatingType,
  CipheringKeySequenceNumberV        cipheringKeySequenceNumber,
  LocationAreaIdentification_V       locationAreaIdentification,
  MobileStationClassmark1_V          mobileStationClassmark1,
  MobileIdentityLV                   mobileIdentityLV,
  ClassmarkInformationType2_forUMTS  classmarkInformationType2_forUMTS  optional,
  AdditionalUpdateParameterTV        additionalUpdateParameterTV        optional,
  DevicePropertiesTV                 deviceProperties                   optional,
  MS_NetworkFeatureSupportTV         mS_NetworkFeatureSupport           optional
} with {
  variant "TAG (
    deviceProperties,                elementIdentifier = '1101'B;
    mS_NetworkFeatureSupport,        elementIdentifier = '1110'B;  //E
  )"
};

//9.2.15a MM information
//****************************************************************************
type record PDU_ML3_MMInformation
{
  BIT6  messageType,    //
  BIT2  nsd,
  NetworkNameTLV        fullNetworkName     optional,
  NetworkNameTLV        shortNetworkName    optional,
  TimeZoneTV            localtimeZone       optional,
  TimeZoneAndTimeTV     univTime            optional,
  LSA_IdentifierTLV     lSAIdentity         optional,
  DaylightSavingTimeTLV networkDST          optional
} with { variant "TAG (
              fullNetworkName,  elementIdentifier = '1000011'B;   // '43'O;
              shortNetworkName, elementIdentifier = '1000101'B;   // '45'O;
              localtimeZone,    elementIdentifier = '1000110'B;   // '46'O;
              univTime,         elementIdentifier = '1000111'B;   // '47'O;
              lSAIdentity,      elementIdentifier = '1001000'B;   //' 48'O;
              networkDST,       elementIdentifier = '49'O;)"};

//9.2.16 MM Status
//****************************************************************************
type record PDU_ML3_MMStatus
{
  BIT6  messageType,
  BIT2  nsd,
  OCT1  rejectCause //10.5.3.6
 };

//9.2.17 TMSI reallocation command (NW->MS)
//****************************************************************************
type record PDU_ML3_TMSI_ReallocationCommand
{
  BIT6  messageType,    // '011010'B
  BIT2  nsd,
  LocationAreaIdentification_V  locationAreaIdentification,
  MobileIdentityLV              mobileIdentity
};

//9.2.18 TMSI reallocation complete (MS->NW)
//****************************************************************************
type record PDU_ML3_TMSI_ReallocationComplete
{
  BIT6  messageType,    //  '011011'B
  BIT2  nsd
};

//9.2.19 MM Null (MS->NW)
//****************************************************************************
type record PDU_ML3_MMNull
{
  BIT6  messageType,    //  '110000'B
  BIT2  nsd
};


// ***************************************************************************
// *     Mobility Management Messages
// ***************************************************************************
// 24.008/ Table 10.2
type union PDU_ML3_MM
{
  PDU_ML3_IMSI_DetachIndication    imsiDetachIndication,
  PDU_ML3_LocationUpdateAccept     locationUpdateAccept,
  PDU_ML3_LocationUpdateReject     locationUpdateReject,
  PDU_ML3_LocationUpdateRequest    locationUpdateRequest,

  PDU_ML3_AuthenticationReject       authenticationReject,
  PDU_ML3_AuthenticationRequest      authenticationRequest,
  PDU_ML3_AuthenticationResponse     authenticationResponse,
  PDU_ML3_AuthenticationFailure      authenticationFailure,
  PDU_ML3_IdentityRequest            identityRequest,
  PDU_ML3_IdentityResponse           identityResponse,
  PDU_ML3_TMSI_ReallocationCommand   tmsiReallocCommand,
  PDU_ML3_TMSI_ReallocationComplete  tmsiReallocComplete,

  PDU_ML3_CMServiceAbort           cMServiceAbort,
  PDU_ML3_CMServiceAccept          cMServiceAccept,
  PDU_ML3_CMServiceReject          cMServiceReject,
  PDU_ML3_CMServiceRequest         cMServiceRequest,
  PDU_ML3_CMServicePrompt          cMServicePrompt,
  PDU_ML3_CMReestablishmentRequest cMReEstablReq,
  PDU_ML3_Abort                    abort,

  PDU_ML3_MMNull                   mMNull,
  PDU_ML3_MMStatus                 mMStatus,
  PDU_ML3_MMInformation            mMInformation
} with { variant "TAG (
                imsiDetachIndication,   messageType ='000001'B; //registration msgs
                locationUpdateAccept,   messageType ='000010'B;
                locationUpdateReject,   messageType ='000100'B;
                locationUpdateRequest,  messageType ='001000'B;

                authenticationReject,   messageType ='010001'B;//security msgs
                authenticationRequest,  messageType ='010010'B;
                authenticationResponse, messageType ='010100'B;
                authenticationFailure,  messageType ='011100'B;
                identityRequest,        messageType ='011000'B;
                identityResponse,       messageType ='011001'B;
                tmsiReallocCommand,     messageType ='011010'B;
                tmsiReallocComplete,    messageType ='011011'B;

                cMServiceAbort,         messageType ='100011'B; //conn, mgmt
                cMServiceAccept,        messageType ='100001'B;
                cMServiceReject,        messageType ='100010'B;
                cMServiceRequest,       messageType ='100100'B;
                cMServicePrompt,        messageType ='100101'B;
                cMReEstablReq,          messageType ='101000'B;
                abort,                  messageType ='101001'B;

                mMNull,               messageType ='110000'B; //misc
                mMStatus,             messageType ='110001'B;
                mMInformation,        messageType ='110010'B;
              )"};

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

