Commit c1c71c38 authored by luhan Wang's avatar luhan Wang

add test ngap

parent 849196b0
......@@ -328,13 +328,30 @@ set(protobuf_generated_dir ${OPENAIR_BIN_DIR})
include_directories(${OPENAIR_DIR}/ngap/libngap)
include_directories(${OPENAIR_DIR}/ngap/ngapMsgs)
include_directories(${OPENAIR_DIR}/ngap/ngapIEs)
include_directories(${OPENAIR_DIR}/test-ly)
include_directories(${OPENAIR_DIR}/nas/common)
include_directories(${OPENAIR_DIR}/nas/msgs)
include_directories(${OPENAIR_DIR}/nas/ies)
include_directories(${OPENAIR_DIR}/nas/utils)
include_directories(${OPENAIR_DIR}/utils)
include_directories(${OPENAIR_DIR}/utils/bstr)
file(GLOB NGAP_source ${OPENAIR_DIR}/ngap/libngap/*.c)
file(GLOB NGAP_Message ${OPENAIR_DIR}/ngap/ngapMsgs/*.cpp)
file(GLOB NGAP_IE ${OPENAIR_DIR}/ngap/ngapIEs/*.cpp)
file(GLOB NAS_utils ${OPENAIR_DIR}/nas/utils/*.c)
file(GLOB NAS_msgs ${OPENAIR_DIR}/nas/msgs/*.cpp)
file(GLOB NAS_IE ${OPENAIR_DIR}/nas/ies/*.cpp)
file(GLOB UTILS_cpp ${OPENAIR_DIR}/utils/*.cpp)
file(GLOB UTILS_c ${OPENAIR_DIR}/utils/*.c)
file(GLOB UTILS_bstr ${OPENAIR_DIR}/utils/bstr/*.c)
#file(GLOB SCTP_SRC ${OPENAIR_DIR}/test-ly/ue_gnb.cpp)
file(GLOB SCTP_SRC ${OPENAIR_DIR}/test-ly/*.cpp)
add_library(NGAP_LIB
${NGAP_source}
${NGAP_Message}
${NGAP_IE}
${SCTP_SRC}
)
# RRC
......@@ -2761,6 +2778,7 @@ add_executable(nr-softmodem
${T_SOURCE}
${CONFIG_SOURCES}
${SHLIB_LOADER_SOURCES}
#${OPENAIR_DIR}/test-ly/ue_gnb.cpp
)
target_link_libraries (nr-softmodem
......
This source diff could not be displayed because it is too large. You can view the blob instead.
/*
* Copyright (c) 2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#ifndef OER_ENCODER_H
#define OER_ENCODER_H
#include <asn_application.h>
#ifdef __cplusplus
extern "C" {
#endif
struct asn_TYPE_descriptor_s; /* Forward declaration */
/*
* The Octet Encoding Rules (OER, X.696 08/2015) encoder for any type.
* This function may be invoked directly by the application.
* Produces CANONICAL-OER output compatible with CANONICAL-OER
* and BASIC-OER decoders.
*/
asn_enc_rval_t oer_encode(const struct asn_TYPE_descriptor_s *type_descriptor,
const void *struct_ptr, /* Structure to be encoded */
asn_app_consume_bytes_f *consume_bytes_cb,
void *app_key /* Arbitrary callback argument */
);
/* A variant of oer_encode() which encodes data into the pre-allocated buffer */
asn_enc_rval_t oer_encode_to_buffer(
const struct asn_TYPE_descriptor_s *type_descriptor,
const asn_oer_constraints_t *constraints,
const void *struct_ptr, /* Structure to be encoded */
void *buffer, /* Pre-allocated buffer */
size_t buffer_size /* Initial buffer size (maximum) */
);
/*
* Type of the generic OER encoder.
*/
typedef asn_enc_rval_t(oer_type_encoder_f)(
const struct asn_TYPE_descriptor_s *type_descriptor,
const asn_oer_constraints_t *constraints,
const void *struct_ptr, /* Structure to be encoded */
asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */
void *app_key /* Arbitrary callback argument */
);
/*
* Write out the Open Type (X.696 (08/2015), #30).
* RETURN VALUES:
* -1: Fatal error encoding the type.
* >0: Number of bytes serialized.
*/
ssize_t oer_open_type_put(const struct asn_TYPE_descriptor_s *td,
const asn_oer_constraints_t *constraints,
const void *struct_ptr,
asn_app_consume_bytes_f *consume_bytes_cb,
void *app_key);
/*
* Length-prefixed buffer encoding for primitive types.
*/
oer_type_encoder_f oer_encode_primitive;
#ifdef __cplusplus
}
#endif
#endif /* OER_ENCODER_H */
......@@ -84,6 +84,8 @@ unsigned short config_frames[4] = {2,9,11,13};
#include "NB_IoT_interface.h"
#include "x2ap_eNB.h"
//extern "C" int ue_gnb_simulator();
pthread_cond_t nfapi_sync_cond;
pthread_mutex_t nfapi_sync_mutex;
int nfapi_sync_var=-1; //!< protected by mutex \ref nfapi_sync_mutex
......@@ -795,6 +797,12 @@ void init_pdcp(void) {
int main( int argc, char **argv )
{
/**************************liuyu test*****************/
printf("-------------------------liuyu test ngap--------------------\n");
int ret = ue_gnb_simulator();
printf("-------------------------liuyu test ngap--------------------\n");
/**************************liuyu test*****************/
#if 0
int ru_id, CC_id = 0;
start_background_system();
......@@ -974,6 +982,10 @@ if(!IS_SOFTMODEM_NOS1)
printf("ALL RUs ready - ALL gNBs ready\n");
// connect the TX/RX buffers
printf("Sending sync to all threads\n");
pthread_mutex_lock(&sync_mutex);
sync_var=0;
......@@ -1012,7 +1024,7 @@ if(!IS_SOFTMODEM_NOS1)
}
}
#endif*/
//#endif*/
printf("stopping MODEM threads\n");
// cleanup
stop_gNB(NB_gNB_INST);
......@@ -1049,5 +1061,6 @@ if(!IS_SOFTMODEM_NOS1)
logClean();
printf("Bye.\n");
#endif
return 0;
}
/*
* Copyright (c) 2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#ifndef OER_ENCODER_H
#define OER_ENCODER_H
#include <asn_application.h>
#ifdef __cplusplus
extern "C" {
#endif
struct asn_TYPE_descriptor_s; /* Forward declaration */
/*
* The Octet Encoding Rules (OER, X.696 08/2015) encoder for any type.
* This function may be invoked directly by the application.
* Produces CANONICAL-OER output compatible with CANONICAL-OER
* and BASIC-OER decoders.
*/
asn_enc_rval_t oer_encode(const struct asn_TYPE_descriptor_s *type_descriptor,
const void *struct_ptr, /* Structure to be encoded */
asn_app_consume_bytes_f *consume_bytes_cb,
void *app_key /* Arbitrary callback argument */
);
/* A variant of oer_encode() which encodes data into the pre-allocated buffer */
asn_enc_rval_t oer_encode_to_buffer(
const struct asn_TYPE_descriptor_s *type_descriptor,
const asn_oer_constraints_t *constraints,
const void *struct_ptr, /* Structure to be encoded */
void *buffer, /* Pre-allocated buffer */
size_t buffer_size /* Initial buffer size (maximum) */
);
/*
* Type of the generic OER encoder.
*/
typedef asn_enc_rval_t(oer_type_encoder_f)(
const struct asn_TYPE_descriptor_s *type_descriptor,
const asn_oer_constraints_t *constraints,
const void *struct_ptr, /* Structure to be encoded */
asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */
void *app_key /* Arbitrary callback argument */
);
/*
* Write out the Open Type (X.696 (08/2015), #30).
* RETURN VALUES:
* -1: Fatal error encoding the type.
* >0: Number of bytes serialized.
*/
ssize_t oer_open_type_put(const struct asn_TYPE_descriptor_s *td,
const asn_oer_constraints_t *constraints,
const void *struct_ptr,
asn_app_consume_bytes_f *consume_bytes_cb,
void *app_key);
/*
* Length-prefixed buffer encoding for primitive types.
*/
oer_type_encoder_f oer_encode_primitive;
#ifdef __cplusplus
}
#endif
#endif /* OER_ENCODER_H */
#ifndef _3GPP_TS_24501_H_
#define _3GPP_TS_24501_H_
/********** epd type **************/
#define EPD_5GS_MM_MSG 0b01111110
#define EPD_5GS_SM_MSG 0b00101110
/********** security header type **************/
#define PLAIN_5GS_MSG 0b0000
#define INTEGRITY_PROTECTED 0b0001
#define INTEGRITY_PROTECTED_AND_CIPHERED 0b0010
#define INTEGRITY_PROTECTED_WITH_NEW_SECU_CTX 0b0011 // only for SECURITY MODE COMMAND
#define INTEGRITY_PROTECTED_AND_CIPHERED_WITH_NEW_SECU_CTX 0b0100 // only for SECURITY MODE COMPLETE
/********** message type ********************/
#define REGISTRATION_REQUEST 0b01000001
#define REGISTRATION_REJECT 0b01000100
#define AUTHENTICATION_REQUEST 0b01010110
#define AUTHENTICATION_RESPONSE 0b01010111
#define AUTHENTICATION_RESULT 0b01011010
#define AUTHENTICATION_FAILURE 0b01011001
#define AUTHENTICATION_REJECT 0b01011000
#define SECURITY_MODE_COMMAND 0b01011101
#define SECURITY_MODE_COMPLETE 0b01011110
#define SECURITY_MODE_REJECT 0b01011111
#define REGISTRATION_COMPLETE 0b01000011
#define REGISTRATION_ACCEPT 0b01000010
#define IDENTITY_REQUEST 0b01011011
#define IDENTITY_RESPONSE 0b01011100
#define UL_NAS_TRANSPORT 0b01100111
#define DL_NAS_TRANSPORT 0b01101000
#define SERVICE_REQUEST 0b01001100
#define SERVICE_REJECT 0b01001101
#define SERVICE_ACCEPT 0b01001110
#define UE_INIT_DEREGISTER 0b01000101
/********* registration type ***************/
#define NO_FOLLOW_ON_REQ_PENDING false
#define FOLLOW_ON_REQ_PENDING true
#define INITIAL_REGISTRATION 0b001
#define MOBILITY_REGISTRATION_UPDATING 0b010
#define PERIODIC_REGISTRATION_UPDATING 0b011
#define EMERGENCY_REGISTRATION 0b100
/********* NAS Key Set identifier **********/
#define NAS_KEY_SET_IDENTIFIER_NATIVE 0b0
#define NAS_KEY_SET_IDENTIFIER_MAPPED 0b1
#define NAS_KEY_SET_IDENTIFIER_NOT_AVAILABLE 0b111
/********* 5GSMobilityIdentity **********/
#define NO_IDENTITY 0b000
#define SUCI 0b001
#define _5G_GUTI 0b010
#define IMEI 0b011
#define _5G_S_TMSI 0b100
#define IMEISVI 0b101
#define MAC_ADDRESS 0b110
#define EVEN_IENTITY 0
#define ODD_IDENTITY 1
#define SUPI_FORMAT_IMSI 0b000
#define SUPI_FORMAT_NETWORK_SPECIFIC_IDENTIFIER 0b001
#define NULL_SCHEME 0b0000
#define ECIES_SCHEME_PROFILE_A 0b0001
#define ECIES_SCHEME_PROFILE_B 0b0010
#define HOME_NETWORK_PKI_0_WHEN_PSI_0 0b00000000
#define HOME_NETWORK_PKI_RESERVED 0b11111111
/************************** security algorithms ***********************************************************/
#define IA0_5G 0b000
#define IA1_128_5G 0b001
#define IA2_128_5G 0b010
#define EA0_5G 0b000
#define EA1_128_5G 0b001
#define EA2_128_5G 0b010
/************************** cause value for 5g mobility management(Annex A) ********************************/
#define _5GMM_CAUSE_ILLEGAL_UE 3
#define _5GMM_CAUSE_SYNCH_FAILURE 0b00010101
// A.5 Causes related to invalid messages
//------------------------------------------------------------------------------
#define _5GMM_CAUSE_SEMANTICALLY_INCORRECT 95
#define _5GMM_CAUSE_INVALID_MANDATORY_INFO 96
#define _5GMM_CAUSE_MESSAGE_TYPE_NOT_IMPLEMENTED 97
#define _5GMM_CAUSE_MESSAGE_TYPE_NOT_COMPATIBLE 98
#define _5GMM_CAUSE_IE_NOT_IMPLEMENTED 99
#define _5GMM_CAUSE_CONDITIONAL_IE_ERROR 100
#define _5GMM_CAUSE_MESSAGE_NOT_COMPATIBLE 101
#define _5GMM_CAUSE_PROTOCOL_ERROR 111
/********************* UL NAS TRANSPORT payload container type **************************/
#define N1_SM_INFORMATION 0x01
#define SMS_CONTAINER 0x02
#define LTE_POSITIONING_PROTOCOL 0x03
#define SOR_TRANSPARENT_CONTAINER 0x04
#define UE_POLICY_CONTAINER 0x05
#define UE_PARAMETERS_UPDATE 0x06
#define MULTIPLE_PAYLOADS 0x0f
#define PDU_SESSION_INITIAL_REQUEST 0b001
#define EXISTING_PDU_SESSION 0b010
#define PDU_SESSION_INITIAL_EMERGENCY_REQUEST 0b011
#define EXISTING_EMERGENCY_PDU_SESSION 0b100
#define PDU_SESSION_MODIFICATION_REQUEST 0b101
#define MA_PDU_REQUEST 0b110
#endif
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file common_defs.h
\brief
\author Sebastien ROUX, Lionel Gauthier
\company Eurecom
\email: lionel.gauthier@eurecom.fr
*/
#ifndef FILE_COMMON_DEFS_SEEN
#define FILE_COMMON_DEFS_SEEN
#include <arpa/inet.h>
#include <stdint.h>
#define RETURNclear (int)2
#define RETURNerror (int)1
#define RETURNok (int)0
typedef enum {
/* Fatal errors - received message should not be processed */
TLV_MAC_MISMATCH = -14,
TLV_BUFFER_NULL = -13,
TLV_BUFFER_TOO_SHORT = -12,
TLV_PROTOCOL_NOT_SUPPORTED = -11,
TLV_WRONG_MESSAGE_TYPE = -10,
TLV_OCTET_STRING_TOO_LONG_FOR_IEI = -9,
TLV_VALUE_DOESNT_MATCH = -4,
TLV_MANDATORY_FIELD_NOT_PRESENT = -3,
TLV_UNEXPECTED_IEI = -2,
// RETURNerror = -1,
// RETURNok = 0,
TLV_ERROR_OK = RETURNok,
/* Defines error code limit below which received message should be discarded
* because it cannot be further processed */
TLV_FATAL_ERROR = TLV_VALUE_DOESNT_MATCH
} error_code_e;
//------------------------------------------------------------------------------
#define DECODE_U8(bUFFER, vALUE, sIZE) \
vALUE = *(uint8_t*)(bUFFER); \
sIZE += sizeof(uint8_t)
#define DECODE_U16(bUFFER, vALUE, sIZE) \
vALUE = ntohs(*(uint16_t*)(bUFFER)); \
sIZE += sizeof(uint16_t)
#define DECODE_U24(bUFFER, vALUE, sIZE) \
vALUE = ntohl(*(uint32_t*)(bUFFER)) >> 8; \
sIZE += sizeof(uint8_t) + sizeof(uint16_t)
#define DECODE_U32(bUFFER, vALUE, sIZE) \
vALUE = ntohl(*(uint32_t*)(bUFFER)); \
sIZE += sizeof(uint32_t)
#if (BYTE_ORDER == LITTLE_ENDIAN)
# define DECODE_LENGTH_U16(bUFFER, vALUE, sIZE) \
vALUE = ((*(bUFFER)) << 8) | (*((bUFFER) + 1)); \
sIZE += sizeof(uint16_t)
#else
# define DECODE_LENGTH_U16(bUFFER, vALUE, sIZE) \
vALUE = (*(bUFFER)) | (*((bUFFER) + 1) << 8); \
sIZE += sizeof(uint16_t)
#endif
#define ENCODE_U8(buffer, value, size) \
*(uint8_t*)(buffer) = value; \
size += sizeof(uint8_t)
#define ENCODE_U16(buffer, value, size) \
*(uint16_t*)(buffer) = htons(value); \
size += sizeof(uint16_t)
#define ENCODE_U24(buffer, value, size) \
*(uint32_t*)(buffer) = htonl(value); \
size += sizeof(uint8_t) + sizeof(uint16_t)
#define ENCODE_U32(buffer, value, size) \
*(uint32_t*)(buffer) = htonl(value); \
size += sizeof(uint32_t)
#define IPV4_STR_ADDR_TO_INT_NWBO(AdDr_StR,NwBo,MeSsAgE ) do {\
struct in_addr inp;\
if ( inet_aton(AdDr_StR, &inp ) < 0 ) {\
AssertFatal (0, MeSsAgE);\
} else {\
NwBo = inp.s_addr;\
}\
} while (0)
#define NIPADDR(addr) \
(uint8_t)(addr & 0x000000FF), \
(uint8_t)((addr & 0x0000FF00) >> 8), \
(uint8_t)((addr & 0x00FF0000) >> 16), \
(uint8_t)((addr & 0xFF000000) >> 24)
#define HIPADDR(addr) \
(uint8_t)((addr & 0xFF000000) >> 24),\
(uint8_t)((addr & 0x00FF0000) >> 16),\
(uint8_t)((addr & 0x0000FF00) >> 8), \
(uint8_t)(addr & 0x000000FF)
#define NIP6ADDR(addr) \
ntohs((addr)->s6_addr16[0]), \
ntohs((addr)->s6_addr16[1]), \
ntohs((addr)->s6_addr16[2]), \
ntohs((addr)->s6_addr16[3]), \
ntohs((addr)->s6_addr16[4]), \
ntohs((addr)->s6_addr16[5]), \
ntohs((addr)->s6_addr16[6]), \
ntohs((addr)->s6_addr16[7])
#define IN6_ARE_ADDR_MASKED_EQUAL(a,b,m) \
(((((__const uint32_t *) (a))[0] & (((__const uint32_t *) (m))[0])) == (((__const uint32_t *) (b))[0] & (((__const uint32_t *) (m))[0]))) \
&& ((((__const uint32_t *) (a))[1] & (((__const uint32_t *) (m))[1])) == (((__const uint32_t *) (b))[1] & (((__const uint32_t *) (m))[1]))) \
&& ((((__const uint32_t *) (a))[2] & (((__const uint32_t *) (m))[2])) == (((__const uint32_t *) (b))[2] & (((__const uint32_t *) (m))[2]))) \
&& ((((__const uint32_t *) (a))[3] & (((__const uint32_t *) (m))[3])) == (((__const uint32_t *) (b))[3] & (((__const uint32_t *) (m))[3]))))
////////////
#define IPV4_STR_ADDR_TO_INADDR(AdDr_StR,InAdDr,MeSsAgE ) do {\
if ( inet_aton(AdDr_StR, &InAdDr ) <= 0 ) {\
throw (MeSsAgE);\
}\
} while (0)
#ifndef UNUSED
#define UNUSED(x) (void)(x)
#endif
#endif /* FILE_COMMON_DEFS_SEEN */
#include "nas_mm_plain_header.hpp"
#include "5GSRegistrationType.hpp"
#include "NasKeySetIdentifier.hpp"
#include "5GSMobilityIdentity.hpp"
#include "5GMMCapability.hpp"
#include "UESecurityCapability.hpp"
#include "UENetworkCapability.hpp"
#include "UplinkDataStatus.hpp"
#include "NSSAI.hpp"
#include "_5GS_Tracking_Area_Identity.hpp"
#include "PDU_Session_Status.hpp"
#include "MICO_Indication.hpp"
#include "UE_Status.hpp"
#include "Allowed_PDU_Session_Status.hpp"
#include "UES_Usage_Setting.hpp"
#include "_5GS_DRX_arameters.hpp"
#include "EPS_NAS_Message_Container.hpp"
#include "LADN_Indication.hpp"
#include "Payload_Container_Type.hpp"
#include "Payload_Container.hpp"
#include "Network_Slicing_Indication.hpp"
#include "_5GS_Update_Type.hpp"
#include "NAS_Message_Container.hpp"
#include "EPS_Bearer_Context_Status.hpp"
#include "_5GMM_Cause.hpp"
#include "GPRS_Timer_2.hpp"
#include "EAP_Message.hpp"
#include "Rejected_NSSAI.hpp"
#include "ABBA.hpp"
#include "Authentication_Parameter_RAND.hpp"
#include "Authentication_Parameter_AUTN.hpp"
#include "Authentication_Response_Parameter.hpp"
#include "Authentication_Failure_Parameter.hpp"
#include "NAS_Security_Algorithms.hpp"
#include "IMEISV_Request.hpp"
#include "EPS_NAS_Security_Algorithms.hpp"
#include "Additional_5G_Security_Information.hpp"
#include "S1_UE_Security_Capability.hpp"
#include "SOR_Transparent_Container.hpp"
#include "_5GS_Registration_Result.hpp"
#include "GPRS_Timer_3.hpp"
#include "PLMN_List.hpp"
#include "_5GS_Network_Feature_Support.hpp"
#include "PDU_Session_Reactivation_Result.hpp"
#include "PDU_Session_Reactivation_Result_Error_Cause.hpp"
#include "NSSAI_Inclusion_Mode.hpp"
#include "Non_3GPP_NW_Provided_Policies.hpp"
#include "UE_Radio_Capability_ID.hpp"
#include "_5GS_Identity_Type.hpp"
#include "PDU_Session_Identity_2.hpp"
#include "Request_Type.hpp"
#include "S_NSSAI.hpp"
#include "DNN.hpp"
#include "Additional_Information.hpp"
#include "MA_PDU_Session_Information.hpp"
#include "Release_Assistance_Indication.hpp"
#include "Extended_DRX_Parameters.hpp"
#include "struct.hpp"
#include "ServiceType.hpp"
#include "_5GSTrackingAreaIdList.hpp"
#include "5GMMCapability.hpp"
#include "logger.hpp"
using namespace nas;
_5GMMCapability::_5GMMCapability(const uint8_t iei, uint8_t value){
m_iei = iei;
m_value = value;
length = 3;
}
_5GMMCapability::_5GMMCapability(){}
_5GMMCapability::~_5GMMCapability(){}
void _5GMMCapability::setValue(uint8_t iei, uint8_t value){
m_iei = iei;
m_value = value;
}
uint8_t _5GMMCapability::getValue(){
return m_value;
}
int _5GMMCapability::encode2buffer(uint8_t *buf, int len){
Logger::nas_mm().debug("encoding _5GMMCapability iei(0x%x)",m_iei);
if(len < length){
Logger::nas_mm().error("len is less than %d",length);
return 0;
}
int encoded_size = 0;
if(m_iei){
*(buf+encoded_size) = m_iei; encoded_size ++;
*(buf+encoded_size) = length - 2; encoded_size ++;
*(buf+encoded_size) = m_value; encoded_size ++;
}else{
*(buf+encoded_size) = length - 1; encoded_size ++;
*(buf+encoded_size) = m_value; encoded_size ++;
}
Logger::nas_mm().debug("encoded _5GMMCapability len(%d)",encoded_size);
return encoded_size;
}
int _5GMMCapability::decodefrombuffer(uint8_t *buf, int len, bool is_option){
Logger::nas_mm().debug("decoding _5GMMCapability iei(0x%x)",*buf);
int decoded_size = 0;
if(is_option){
decoded_size ++;
}
length = *(buf+decoded_size); decoded_size ++;
m_value = *(buf+decoded_size); decoded_size ++;
Logger::nas_mm().debug("decoded _5GMMCapability value(0x%x)",m_value);
Logger::nas_mm().debug("decoded _5GMMCapability len(%d)",decoded_size);
return decoded_size;
}
#ifndef __5GMMCapability_H_
#define __5GMMCapability_H_
#include <stdint.h>
namespace nas{
class _5GMMCapability{
public:
_5GMMCapability();
_5GMMCapability(const uint8_t iei, uint8_t value);
~_5GMMCapability();
void setValue(uint8_t iei, uint8_t value);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
uint8_t getValue();
private:
uint8_t m_iei;
uint8_t m_value;
int length;
};
}
#endif
This diff is collapsed.
#ifndef _5GSMobilityIdentity_H_
#define _5GSMobilityIdentity_H_
#include <iostream>
#include <stdint.h>
#include "struct.hpp"
extern "C" {
#include "bstrlib.h"
#include "TLVEncoder.h"
#include "TLVDecoder.h"
}
using namespace std;
namespace nas{
typedef struct _5G_GUTI_s{
string mcc;
string mnc;
uint8_t amf_region_id;
uint16_t amf_set_id;
uint16_t amf_pointer;
uint32_t _5g_tmsi;
}_5G_GUTI_t;
typedef struct IMEI_or_IMEISV_s{
uint8_t typeOfIdentity:3;
bool odd_even_indic;// for imei, even means bits 5 to 8 of last octet is "1111", for imeisv, bits 5 to 8 of last octet is "1111"
string identity;// "46011000001"
}IMEI_IMEISV_t;
typedef struct SUCI_imsi_s{
uint8_t supi_format:3;
string mcc;
string mnc;
string routingIndicator; //"1234"
uint8_t protectionSchemeId:4;// 0000
uint8_t homeNetworkPKI;// 00000000
string msin; // two types of coding; BCD & hexadecimal
}SUCI_imsi_t;// SUPI format "IMSI"
//don't define suci and supi format "Network specific identifier"
typedef struct _5G_S_TMSI_s{
uint16_t amf_set_id;
uint8_t amf_pointer;
string _5g_tmsi;
}_5G_S_TMSI_t;
class _5GSMobilityIdentity{
public:
_5GSMobilityIdentity(uint8_t _iei, const uint16_t amfSetId, const uint8_t amfPointer, const string tmsi);
_5GSMobilityIdentity(const string mcc, const string mnc, const string routingInd, uint8_t protection_sch_id, const string msin);
_5GSMobilityIdentity();
~_5GSMobilityIdentity();
void setIEI(uint8_t _iei);
int encode2buffer(uint8_t *buf, int len);
int suci_encode2buffer(uint8_t *buf, int len);
int _5g_guti_encode2buffer(uint8_t *buf, int len);
int encodeMssMnc2buffer(string mcc, string mnc, uint8_t *buf);
int encodeRoutid2buffer(string routid, uint8_t *buf);
int encodeMSIN2buffer(string msinstr, uint8_t *buf);
int _5g_s_tmsi_encode2buffer(uint8_t *buf, int len);
int _5g_s_tmsi_decodefrombuffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
int suci_decodefrombuffer(uint8_t *buf, int len, int length);
int _5g_guti_decodefrombuffer(uint8_t *buf, int len);
void set5GGUTI(const string mcc, const string mnc, uint8_t amf_region_id, uint16_t amf_set_id, uint8_t amf_pointer, const uint32_t _5g_tmsi);
void setSuciWithSupiImsi(const string &mcc, const string &mnc, const string &routingInd, uint8_t protecSchId ,uint8_t home_pki, const string &msin_digits);
void setSuciWithSupiImsi(const string &mcc, const string &mnc, const string &routingInd, uint8_t protecSchId ,const string &msin_digits);
void getSuciWithSupiImsi(SUCI_imsi_t &);
void get5GGUTI(_5G_GUTI_t &);
uint8_t gettypeOfIdentity() { return typeOfIdentity; };
bool get5G_S_TMSI(uint16_t &amfSetId, uint8_t &amfPointer, string &tmsi);
void setIMEISV(IMEISV_t imeisv);
void getIMEISV(IMEISV_t &imeisv);
int imeisv_encode2buffer(uint8_t *buf, int len);
int imeisv_decodefrombuffer(uint8_t *buf, int len);
private:
uint8_t iei;
_5G_GUTI_t *_5g_guti;
IMEI_IMEISV_t *imei_imeisv;
SUCI_imsi_t *supi_format_imsi;
_5G_S_TMSI_t *_5g_s_tmsi;
bool is_no_identity;
uint16_t length;
uint8_t typeOfIdentity:3;
IMEISV_t _IMEISV;
};
}
#endif
#include "5GSRegistrationType.hpp"
#include "3gpp_ts24501.hpp"
#include "logger.hpp"
using namespace nas;
_5GSRegistrationType::_5GSRegistrationType(){
iei = 0;
is_for = false;
reg_type = 0;
}
_5GSRegistrationType::_5GSRegistrationType(bool is_for, uint8_t type){
this->is_for = is_for;
this->reg_type = 0x07 & type;
this->iei = 0;
}
_5GSRegistrationType::_5GSRegistrationType(uint8_t iei, bool is_for, uint8_t type){
this->is_for = is_for;
this->reg_type = 0x07 & type;
this->iei = 0x0f & iei;
}
_5GSRegistrationType::~_5GSRegistrationType(){}
int _5GSRegistrationType::encode2buffer(uint8_t *buf, int len){
Logger::nas_mm().error("encoding 5gsregistrationtype IE");
if(len < 1) {
Logger::nas_mm().error("encoding 5gsregistrationtype error(len is less than one)");
return -1;
}
uint8_t octet = 0;
if(is_for)
octet = 0x08;
octet |= reg_type;
if(!(iei & 0x0f)){
*buf = 0x0f & octet;
Logger::nas_mm().debug("encoded 5GSRegistrationType IE(len(1/2 octet))");
return 0;
}else{
*buf = (iei<<4) | octet;
Logger::nas_mm().debug("encoded 5GSRegistrationType IE(len(1 octet))");
return 1;
}
}
int _5GSRegistrationType::decodefrombuffer(uint8_t *buf, int len, bool is_option){
if(is_option){
return -1;
}
Logger::nas_mm().debug("decoding 5GSRegistrationType");
uint8_t octet = *buf;
if(octet & 0x08)
is_for = FOLLOW_ON_REQ_PENDING;
else
is_for = NO_FOLLOW_ON_REQ_PENDING;
reg_type = 0x07 & octet;
Logger::nas_mm().debug("decoded 5GSRegistrationType len(1/2 octet)");
return 0;
}
void _5GSRegistrationType::setFollowOnReq(const bool is){
is_for = is;
}
void _5GSRegistrationType::setRegType(const uint8_t type){
reg_type = 0x07 & type;
}
bool _5GSRegistrationType::isFollowOnReq(){
return is_for;
}
uint8_t _5GSRegistrationType::getRegType(){
return reg_type;
}
#ifndef _5GS_REGISTRATION_TYPE_H_
#define _5GS_REGISTRATION_TYPE_H_
#include <stdint.h>
namespace nas{
class _5GSRegistrationType{
public:
_5GSRegistrationType();
_5GSRegistrationType(bool is_for, uint8_t type);
_5GSRegistrationType(uint8_t iei, bool is_for, uint8_t type);
~_5GSRegistrationType();
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
int encode2buffer(uint8_t *buf, int len);
void setFollowOnReq(const bool is);
void setRegType(const uint8_t type);
bool isFollowOnReq();
uint8_t getRegType();
private:
uint8_t iei:4;
bool is_for;
uint8_t reg_type:3;
};
}
#endif
#include "ABBA.hpp"
#include "logger.hpp"
using namespace nas;
ABBA::ABBA(uint8_t iei) {
_iei = iei;
}
ABBA::ABBA(const uint8_t iei, uint8_t length, uint8_t *value) {
_iei = iei;
for(int i=0;i<length;i++){
this->_value[i] =value[i];}
_length = length;
}
ABBA::ABBA() {}
ABBA::~ABBA() {}
uint8_t ABBA::getValue() {
for (int j = 0; j < _length; j++) {
Logger::nas_mm().debug("decoded ABBA value(0x%2x)", _value[j]);
}
return 1;
}
int ABBA::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding ABBA iei(0x%x)", _iei);
if (len < _length) {
Logger::nas_mm().error("len is less than %d", _length);
return 0;
}
int encoded_size = 0;
if (_iei) { //option
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = _length - 2; encoded_size++;
int i = 0;
while ((_length - 2) != 0) {
*(buf + encoded_size) = _value[i]; encoded_size++;
_length--; i++;
}
}
else {
Logger::nas_mm().debug("length(%d)", _length);
*(buf + encoded_size) = _length; encoded_size++;
int i = 0;
while (_length != 0) {
*(buf + encoded_size) = _value[i]; encoded_size++;
_length--; i++;
}
}
Logger::nas_mm().debug("encoded ABBA len(%d)", encoded_size);
return encoded_size;
}
int ABBA::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding ABBA iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
_length=0x00;
_value[255]={} ;
_length = *(buf + decoded_size); decoded_size++;
int i = 0;uint8_t Length=_length;
while (Length != 0) {
_value[i] = *(buf + decoded_size); decoded_size++;
Length--; i++;
}
for(int j=0;j<_length;j++){
Logger::nas_mm().debug("decoded ABBA value(0x%4x),length(0x%4x)", _value[j],_length);}
Logger::nas_mm().debug("decoded ABBA len(%d)", decoded_size);
return decoded_size;
}
#ifndef __ABBA_H_
#define __ABBA_H_
#include <stdint.h>
namespace nas {
class ABBA {
public:
ABBA();
ABBA(uint8_t iei);
ABBA(const uint8_t iei, uint8_t length, uint8_t *value);
~ABBA();
//void setValue(uint8_t iei, uint8_t value);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
uint8_t getValue();
private:
uint8_t _iei;
uint8_t _length;
uint8_t _value[255];
};
}
#endif
#include "Additional_5G_Security_Information.hpp"
#include "logger.hpp"
using namespace nas;
Additional_5G_Security_Information::Additional_5G_Security_Information(uint8_t iei) {
_iei = iei;
}
Additional_5G_Security_Information::Additional_5G_Security_Information(const uint8_t iei, bool rinmr, bool hdp) {
_iei = iei;
RINMR = rinmr;
HDP = hdp;
}
Additional_5G_Security_Information::Additional_5G_Security_Information() {}
Additional_5G_Security_Information::~Additional_5G_Security_Information() {}
void Additional_5G_Security_Information::setRINMR(bool value) {
RINMR = value;
}
void Additional_5G_Security_Information::setHDP(bool value) {
HDP = value;
}
bool Additional_5G_Security_Information::getRINMR() {
return RINMR;
}
bool Additional_5G_Security_Information::getHDP() {
return HDP;
}
int Additional_5G_Security_Information::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding Additional_5G_Security_Information iei(0x%x)", _iei);
if (len < 3) {
Logger::nas_mm().error("len is less than 3");
return 0;
}
uint8_t octet = 0;
int encoded_size=0;
if(RINMR)
octet |= 0x02;
if(HDP)
octet |= 0x01;
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = 1; encoded_size++;
*(buf + encoded_size) = octet; encoded_size++;
Logger::nas_mm().debug("encoded Additional_5G_Security_Information IE(len(1 octet))");
return encoded_size;
}
int Additional_5G_Security_Information::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
if (len < 3) {
Logger::nas_mm().error("len is less than 3");
return 0;
}
else {
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
// length = *(buf + decoded_size);
decoded_size++;
uint8_t octet = *(buf + decoded_size); decoded_size++;
RINMR = octet&0x02;
HDP =octet& 0x01;
Logger::nas_mm().debug("decoded Additional_5G_Security_Information RINMR(0x%x) HDP(0x%x)", RINMR, HDP);
return decoded_size;
}
}
#ifndef __Additional_5G_Security_Information_H_
#define __Additional_5G_Security_Information_H_
#include <stdint.h>
namespace nas {
class Additional_5G_Security_Information {
public:
Additional_5G_Security_Information();
Additional_5G_Security_Information(uint8_t iei);
Additional_5G_Security_Information(const uint8_t iei, bool RINMR, bool HDP);
~Additional_5G_Security_Information();
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
void setRINMR(bool value);
void setHDP(bool value);
bool getRINMR();
bool getHDP();
private:
uint8_t _iei;
bool RINMR;
bool HDP;
};
}
#endif
#include "Additional_Information.hpp"
#include "logger.hpp"
using namespace nas;
Additional_Information::Additional_Information(uint8_t iei) {
_iei = iei;
}
Additional_Information::Additional_Information(const uint8_t iei, uint8_t _length, uint8_t value) {
_iei = iei;
_value = value;
length = _length;
}
Additional_Information::Additional_Information() {}
Additional_Information::~Additional_Information() {}
void Additional_Information::setValue(uint8_t iei, uint8_t value) {
_iei = iei;
_value = value;
}
uint8_t Additional_Information::getValue() {
return _value;
}
int Additional_Information::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding Additional_Information iei(0x%x)", _iei);
if (len < length) {
Logger::nas_mm().error("len is less than %d", length);
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = (length - 2); encoded_size++;
*(buf + encoded_size) = _value; encoded_size++;
}
else {
*(buf + encoded_size) = (length - 1); encoded_size++;
*(buf + encoded_size) = _value; encoded_size++;
}
Logger::nas_mm().debug("encoded Additional_Information len(%d)", encoded_size);
return encoded_size;
}
int Additional_Information::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding Additional_Information iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
_value = 0x00;
length = *(buf + decoded_size); decoded_size++;
_value = *(buf + decoded_size); decoded_size++;
Logger::nas_mm().debug("decoded Additional_Information value(0x%x)", _value);
Logger::nas_mm().debug("decoded Additional_Information len(%d)", decoded_size);
return decoded_size;
}
#ifndef __Additional_Information_H_
#define __Additional_Information_H_
#include <stdint.h>
namespace nas {
class Additional_Information {
public:
Additional_Information();
Additional_Information(uint8_t iei);
Additional_Information(const uint8_t iei, uint8_t _length, uint8_t value);
~Additional_Information();
void setValue(uint8_t iei, uint8_t value);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
uint8_t getValue();
private:
uint8_t _iei;
uint8_t length;
uint8_t _value;
};
}
#endif
#include "Allowed_PDU_Session_Status.hpp"
#include "logger.hpp"
using namespace nas;
Allowed_PDU_Session_Status::Allowed_PDU_Session_Status(uint8_t iei) {
_iei = iei;
}
Allowed_PDU_Session_Status::Allowed_PDU_Session_Status(const uint8_t iei, uint16_t value) {
_iei = iei;
_value = value;
length = 4;
}
Allowed_PDU_Session_Status::Allowed_PDU_Session_Status() {}
Allowed_PDU_Session_Status::~Allowed_PDU_Session_Status() {}
void Allowed_PDU_Session_Status::setValue(uint8_t iei, uint16_t value) {
_iei = iei;
_value = value;
}
uint16_t Allowed_PDU_Session_Status::getValue() {
return _value;
}
int Allowed_PDU_Session_Status::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding Allowed_PDU_Session_Status iei(0x%x)", _iei);
if (len < length) {
Logger::nas_mm().error("len is less than %d", length);
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = length - 2; encoded_size++;
*(buf + encoded_size) = (_value&0x00ff); encoded_size++;
*(buf + encoded_size) = (_value&0xff00)>>8; encoded_size++;
}
else {
// *(buf + encoded_size) = length - 1; encoded_size++;
// *(buf + encoded_size) = _value; encoded_size++; encoded_size++;
}
Logger::nas_mm().debug("encoded Allowed_PDU_Session_Status len(%d)", encoded_size);
return encoded_size;
}
int Allowed_PDU_Session_Status::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding Allowed_PDU_Session_Status iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
_value = 0x0000;
length = *(buf + decoded_size); decoded_size++;
_value |= *(buf + decoded_size); decoded_size++;
_value |= (*(buf + decoded_size))<<8; decoded_size++;
Logger::nas_mm().debug("decoded Allowed_PDU_Session_Status value(0x%4x)", _value);
Logger::nas_mm().debug("decoded Allowed_PDU_Session_Status len(%d)", decoded_size);
return decoded_size;
}
#ifndef __Allowed_PDU_Session_Status_H_
#define __Allowed_PDU_Session_Status_H_
#include <stdint.h>
namespace nas {
class Allowed_PDU_Session_Status {
public:
Allowed_PDU_Session_Status();
Allowed_PDU_Session_Status(uint8_t iei);
Allowed_PDU_Session_Status(const uint8_t iei, uint16_t value);
~Allowed_PDU_Session_Status();
void setValue(uint8_t iei, uint16_t value);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
uint16_t getValue();
private:
uint8_t _iei;
uint8_t length;
uint16_t _value;
};
}
#endif
#include "Authentication_Failure_Parameter.hpp"
#include "logger.hpp"
using namespace nas;
Authentication_Failure_Parameter::Authentication_Failure_Parameter(uint8_t iei) {
_iei = iei;
}
Authentication_Failure_Parameter::Authentication_Failure_Parameter(const uint8_t iei, bstring auts) {
_iei = iei;
value = bstrcpy(auts);
length = blength(auts) + 2;
}
Authentication_Failure_Parameter::Authentication_Failure_Parameter() {}
Authentication_Failure_Parameter::~Authentication_Failure_Parameter() {}
void Authentication_Failure_Parameter::getValue(bstring &auts) {
auts = bstrcpy(value);
}
int Authentication_Failure_Parameter::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding Authentication_Failure_Parameter iei(0x%x)", _iei);
if (len < length) {
Logger::nas_mm().error("len is less than %x",length);
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = length-2; encoded_size++;
int size = encode_bstring(value, (buf + encoded_size), len - encoded_size);
encoded_size += size;
return encoded_size;
}
else {
// *(buf + encoded_size) = length - 1; encoded_size++;
// *(buf + encoded_size) = _value; encoded_size++; encoded_size++;
}
Logger::nas_mm().debug("encoded Authentication_Failure_Parameter len(%d)", encoded_size);
return encoded_size;
}
int Authentication_Failure_Parameter::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding Authentication_Failure_Parameter iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
length = *(buf + decoded_size); decoded_size++;
Logger::nas_mm().debug("decoded IE Authentication_Failure_Parameter length(%d)", length);
decode_bstring(&value, length, (buf + decoded_size), len - decoded_size);
decoded_size += length;
for (int i = 0; i < length; i++) {
Logger::nas_mm().debug("decoded Authentication_Failure_Parameter value(0x%x)", (uint8_t*)value->data[i]);
}
Logger::nas_mm().debug("decoded Authentication_Failure_Parameter len(%d)", decoded_size);
return decoded_size;
}
#ifndef __Authentication_Failure_Parameter_H_
#define __Authentication_Failure_Parameter_H_
#include <iostream>
#include <stdint.h>
extern "C" {
#include "bstrlib.h"
#include "TLVEncoder.h"
#include "TLVDecoder.h"
}
namespace nas {
class Authentication_Failure_Parameter {
public:
Authentication_Failure_Parameter();
Authentication_Failure_Parameter(uint8_t iei);
Authentication_Failure_Parameter(const uint8_t iei, bstring auts);
~Authentication_Failure_Parameter();
//void setValue(uint8_t iei, uint8_t value);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
void getValue(bstring &auts);
private:
uint8_t _iei;
uint8_t length;
bstring value;
};
}
#endif
#include "Authentication_Parameter_AUTN.hpp"
#include "logger.hpp"
using namespace nas;
Authentication_Parameter_AUTN::Authentication_Parameter_AUTN(uint8_t iei) {
_iei = iei;
}
Authentication_Parameter_AUTN::Authentication_Parameter_AUTN(const uint8_t iei,uint8_t *value) {
_iei = iei;
for(int i=0;i<16;i++){
this->_value[i] =value[i];}
}
Authentication_Parameter_AUTN::Authentication_Parameter_AUTN() {}
Authentication_Parameter_AUTN::~Authentication_Parameter_AUTN() {}
uint8_t *Authentication_Parameter_AUTN::getValue() {
//for (int j = 0; j < 16; j++) {
// Logger::nas_mm().debug("decoded Authentication_Response_Parameter value(0x%2x)", _value[j]);
//}
return _value;}
int Authentication_Parameter_AUTN::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding Authentication_Parameter_AUTN iei(0x%x)", _iei);
if (len < 18) {
Logger::nas_mm().error("len is less than 18");
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = 16; encoded_size++;
for (int i = 0; i < 16;i++) {
*(buf + encoded_size) = _value[i]; encoded_size++;
}
return encoded_size;
}
else {
// *(buf + encoded_size) = length - 1; encoded_size++;
// *(buf + encoded_size) = _value; encoded_size++; encoded_size++;
}
Logger::nas_mm().debug("encoded Authentication_Parameter_AUTN len(%d)", encoded_size);
return encoded_size;
}
int Authentication_Parameter_AUTN::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding Authentication_Parameter_AUTN iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
decoded_size++;
for(int i=0;i<16;i++) {
_value[i] = *(buf + decoded_size); decoded_size++;
}
for(int j=0;j<16;j++){
Logger::nas_mm().debug("decoded Authentication_Parameter_AUTN value(0x%2x)", _value[j]);}
Logger::nas_mm().debug("decoded Authentication_Parameter_AUTN len(%d)", decoded_size);
return decoded_size;
}
#ifndef __Authentication_Parameter_AUTN_H_
#define __Authentication_Parameter_AUTN_H_
#include <stdint.h>
namespace nas {
class Authentication_Parameter_AUTN {
public:
Authentication_Parameter_AUTN();
Authentication_Parameter_AUTN(uint8_t iei);
Authentication_Parameter_AUTN(const uint8_t iei, uint8_t *value);
~Authentication_Parameter_AUTN();
//void setValue(uint8_t iei, uint8_t value);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
uint8_t *getValue();
private:
uint8_t _iei;
uint8_t _value[16];
};
}
#endif
#include "Authentication_Parameter_RAND.hpp"
#include "logger.hpp"
using namespace nas;
Authentication_Parameter_RAND::Authentication_Parameter_RAND(uint8_t iei) {
_iei = iei;
}
Authentication_Parameter_RAND::Authentication_Parameter_RAND(const uint8_t iei, uint8_t *value) {
_iei = iei;
for(int i=0;i<16;i++){this->_value[i] = value[i];}
}
Authentication_Parameter_RAND::Authentication_Parameter_RAND() {}
Authentication_Parameter_RAND::~Authentication_Parameter_RAND() {}
uint8_t *Authentication_Parameter_RAND::getValue() {
return _value;
}
int Authentication_Parameter_RAND::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding Authentication_Parameter_RAND iei(0x%x)", _iei);
if (len < 17) {
Logger::nas_mm().error("len is less than 17");
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
memcpy((void*)(buf+encoded_size), (void*)_value, 16); encoded_size += 16;
//int i = 0;
//for (int i = 0; i < 16; i++) {
// *(buf + encoded_size) = _value[i]; encoded_size++;
//}
return encoded_size;
}
else {
// *(buf + encoded_size) = length - 1; encoded_size++;
// *(buf + encoded_size) = _value; encoded_size++; encoded_size++;
}
Logger::nas_mm().debug("encoded Authentication_Parameter_RAND len(%d)", encoded_size);
return encoded_size;
}
int Authentication_Parameter_RAND::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding Authentication_Parameter_RAND iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
for(int i=0;i<16;i++){
_value[i] = *(buf + decoded_size); decoded_size++;
}
for (int j = 0; j < 16; j++) {
Logger::nas_mm().debug("decoded Authentication_Parameter_RAND value(0x%2x)", _value[j]);
}
Logger::nas_mm().debug("decoded Authentication_Parameter_RAND len(%d)", decoded_size);
return decoded_size;
}
#ifndef __Authentication_Parameter_RAND_H_
#define __Authentication_Parameter_RAND_H_
#include <stdint.h>
namespace nas {
class Authentication_Parameter_RAND {
public:
Authentication_Parameter_RAND();
Authentication_Parameter_RAND(uint8_t iei);
Authentication_Parameter_RAND(const uint8_t iei, uint8_t *value);
~Authentication_Parameter_RAND();
//void setValue(uint8_t iei, uint8_t value);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
uint8_t *getValue();
private:
uint8_t _iei;
uint8_t _value[16];
};
}
#endif
#include "Authentication_Response_Parameter.hpp"
#include "logger.hpp"
using namespace nas;
Authentication_Response_Parameter::Authentication_Response_Parameter(uint8_t iei) {
_iei = iei;
}
Authentication_Response_Parameter::Authentication_Response_Parameter(const uint8_t iei,bstring para) {
_iei = iei;
PARA = bstrcpy(para);
}
Authentication_Response_Parameter::Authentication_Response_Parameter() {}
Authentication_Response_Parameter::~Authentication_Response_Parameter() {}
void Authentication_Response_Parameter::getValue(bstring &para) {
para = bstrcpy(PARA);
}
int Authentication_Response_Parameter::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding Authentication_Response_Parameter iei(0x%x)", _iei);
if (len < 18) {
Logger::nas_mm().error("len is less than 18");
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = 16; encoded_size++;
int size = encode_bstring(PARA, (buf + encoded_size), len - encoded_size);
encoded_size += size;
return encoded_size;
}
else {
// *(buf + encoded_size) = length - 1; encoded_size++;
// *(buf + encoded_size) = _value; encoded_size++; encoded_size++;
}
Logger::nas_mm().debug("encoded Authentication_Response_Parameter len(%d)", encoded_size);
return encoded_size;
}
int Authentication_Response_Parameter::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding Authentication_Response_Parameter iei(0x%x)", *buf);
int decoded_size = 0;
uint8_t length = 0;
if (is_option) {
decoded_size++;
}
length = *(buf + decoded_size); decoded_size++;
decode_bstring(&PARA, length, (buf + decoded_size), len - decoded_size);
decoded_size += length;
for (int i = 0; i < length; i++) {
Logger::nas_mm().debug("decoded NAS_Message_Container value(0x%x)", (uint8_t*)PARA->data[i]);
}
Logger::nas_mm().debug("decoded Authentication_Response_Parameter len(%d)", decoded_size);
return decoded_size;
}
#ifndef __Authentication_Response_Parameter_H_
#define __Authentication_Response_Parameter_H_
#include <iostream>
#include <stdint.h>
extern "C"{
#include "bstrlib.h"
#include "TLVEncoder.h"
#include "TLVDecoder.h"
}
namespace nas {
class Authentication_Response_Parameter {
public:
Authentication_Response_Parameter();
Authentication_Response_Parameter(uint8_t iei);
Authentication_Response_Parameter(const uint8_t iei, bstring para);
~Authentication_Response_Parameter();
//void setValue(uint8_t iei, uint8_t value);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
void getValue(bstring &para);
private:
uint8_t _iei;
bstring PARA;
};
}
#endif
#include "DNN.hpp"
#include "logger.hpp"
using namespace nas;
DNN::DNN(uint8_t iei) {
_iei = iei;
}
DNN::DNN(const uint8_t iei, bstring dnn) {
_iei = iei;
_DNN = bstrcpy(dnn);
length = blength(dnn) + 2;
}
DNN::DNN() {}
DNN::~DNN() {}
/*void DNN::setValue(uint8_t iei, uint8_t value) {
_iei = iei;
_value = value;
}*/
void DNN::getValue(bstring &dnn) {
//dnn = _DNN;
//dnn = bstrcpy(_DNN);
dnn = blk2bstr((uint8_t*)bdata(_DNN)+1, blength(_DNN)-1);
}
int DNN::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding DNN iei(0x%x)", _iei);
if (len < length) {
Logger::nas_mm().error("len is less than %d", length);
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = (length - 2); encoded_size++;
int size = encode_bstring(_DNN, (buf + encoded_size), len - encoded_size);
encoded_size += size;
}
else {
*(buf + encoded_size) = (length - 1); encoded_size++;
int size = encode_bstring(_DNN, (buf + encoded_size), len - encoded_size);
encoded_size += size;
}
Logger::nas_mm().debug("encoded DNN len(%d)", encoded_size);
return encoded_size;
}
int DNN::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding DNN iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
length = *(buf + decoded_size); decoded_size++;
decode_bstring(&_DNN, length, (buf + decoded_size), len - decoded_size);
decoded_size += length;
for (int i = 0; i < blength(_DNN); i++) {
Logger::nas_mm().debug("decoded DNN value(0x%x)", (uint8_t*)bdata(_DNN)[i]);
//print_buffer("amf_n1", "decoded dnn bitstring", (uint8_t*)bdata(_DNN), blength(_DNN));
}
Logger::nas_mm().debug("decoded DNN len(%d)", decoded_size);
return decoded_size;
}
#ifndef __DNN_H_
#define __DNN_H_
#include <iostream>
#include <stdint.h>
extern "C" {
#include "bstrlib.h"
#include "TLVEncoder.h"
#include "TLVDecoder.h"
}
namespace nas {
class DNN {
public:
DNN();
DNN(uint8_t iei);
DNN(const uint8_t iei, bstring dnn);
~DNN();
//void setValue(uint8_t iei, uint8_t value);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
void getValue(bstring &dnn);
private:
uint8_t _iei;
uint8_t length;
bstring _DNN;
};
}
#endif
#include "EAP_Message.hpp"
#include "logger.hpp"
using namespace nas;
EAP_Message::EAP_Message(uint8_t iei) {
_iei = iei;
}
EAP_Message::EAP_Message(const uint8_t iei, bstring eap) {
_iei = iei;
EAP = bstrcpy(eap);
length = blength(eap) + 3;
}
EAP_Message::EAP_Message() {}
EAP_Message::~EAP_Message() {}
void EAP_Message::getValue(bstring &eap) {
eap = bstrcpy(EAP);
}
int EAP_Message::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding EAP_Message iei(0x%x)", _iei);
if (len < length) {
Logger::nas_mm().error("len is less than %d", length);
return 0;
}
int encoded_size = 0;
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = (length - 3)&0x00ff; encoded_size++;
*(buf + encoded_size) = ((length - 3) & 0xff00)>>8; encoded_size++;
int size = encode_bstring(EAP, (buf + encoded_size), len - encoded_size);
encoded_size += size;
Logger::nas_mm().debug("encoded EAP_Message len(%d)", encoded_size);
return encoded_size;
}
int EAP_Message::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding EAP_Message iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
length = 0;
length |= *(buf + decoded_size); decoded_size++;
length |= (*(buf + decoded_size)) << 8; decoded_size++;
decode_bstring(&EAP, length, (buf + decoded_size), len - decoded_size);
decoded_size += length;
for (int i = 0; i < length; i++) {
Logger::nas_mm().debug("decoded EAP_Message value(0x%x)", (uint8_t*)EAP->data[i]);
}
Logger::nas_mm().debug("decoded EAP_Message len(%d)", decoded_size);
return decoded_size;
}
#ifndef __EAP_Message_H_
#define __EAP_Message_H_
#include <iostream>
#include <stdint.h>
extern "C"{
#include "bstrlib.h"
#include "TLVEncoder.h"
#include "TLVDecoder.h"
}
namespace nas {
class EAP_Message {
public:
EAP_Message();
EAP_Message(uint8_t iei);
EAP_Message(const uint8_t iei, bstring eap);
~EAP_Message();
//void setValue(uint8_t iei, uint8_t value);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
void getValue(bstring &eap);
private:
uint8_t _iei;
uint16_t length;
bstring EAP;
};
}
#endif
#include "EPS_Bearer_Context_Status.hpp"
#include "logger.hpp"
using namespace nas;
EPS_Bearer_Context_Status::EPS_Bearer_Context_Status(uint8_t iei) {
_iei = iei;
}
EPS_Bearer_Context_Status::EPS_Bearer_Context_Status(const uint8_t iei, uint16_t value) {
_iei = iei;
_value = value;
length = 4;
}
EPS_Bearer_Context_Status::EPS_Bearer_Context_Status() {}
EPS_Bearer_Context_Status::~EPS_Bearer_Context_Status() {}
void EPS_Bearer_Context_Status::setValue(uint8_t iei, uint16_t value) {
_iei = iei;
_value = value;
}
uint16_t EPS_Bearer_Context_Status::getValue() {
return _value;
}
int EPS_Bearer_Context_Status::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding EPS_Bearer_Context_Status iei(0x%x)", _iei);
if (len < length) {
Logger::nas_mm().error("len is less than %d", length);
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = length - 2; encoded_size++;
*(buf + encoded_size) = (_value&0x00ff); encoded_size++;
*(buf + encoded_size) = (_value&0xff00)>>8; encoded_size++;
}
else {
//*(buf + encoded_size) = length - 1; encoded_size++;
//*(buf + encoded_size) = _value; encoded_size++; encoded_size++;
}
Logger::nas_mm().debug("encoded EPS_Bearer_Context_Status len(%d)", encoded_size);
return encoded_size;
}
int EPS_Bearer_Context_Status::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding EPS_Bearer_Context_Status iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
_value = 0x0000;
length = *(buf + decoded_size); decoded_size++;
_value |= *(buf + decoded_size); decoded_size++;
_value |= (*(buf + decoded_size))<<8; decoded_size++;
Logger::nas_mm().debug("decoded EPS_Bearer_Context_Status value(0x%4x)", _value);
Logger::nas_mm().debug("decoded EPS_Bearer_Context_Status len(%d)", decoded_size);
return decoded_size;
}
#ifndef __EPS_Bearer_Context_Status_H_
#define __EPS_Bearer_Context_Status_H_
#include <stdint.h>
namespace nas {
class EPS_Bearer_Context_Status {
public:
EPS_Bearer_Context_Status();
EPS_Bearer_Context_Status(uint8_t iei);
EPS_Bearer_Context_Status(const uint8_t iei, uint16_t value);
~EPS_Bearer_Context_Status();
void setValue(uint8_t iei, uint16_t value);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
uint16_t getValue();
private:
uint8_t _iei;
uint8_t length;
uint16_t _value;
};
}
#endif
#include "EPS_NAS_Message_Container.hpp"
#include "logger.hpp"
using namespace nas;
EPS_NAS_Message_Container::EPS_NAS_Message_Container(uint8_t iei) {
_iei = iei;
}
EPS_NAS_Message_Container::EPS_NAS_Message_Container(const uint8_t iei, bstring value) {
_iei = iei;
_value = bstrcpy(value);
length = blength(value) + 3;
}
EPS_NAS_Message_Container::EPS_NAS_Message_Container() {}
EPS_NAS_Message_Container::~EPS_NAS_Message_Container() {}
void EPS_NAS_Message_Container::setValue(uint8_t iei, uint8_t value) {
_iei = iei;
//_value = value;
}
void EPS_NAS_Message_Container::getValue(bstring &value) {
value = bstrcpy(_value);
}
int EPS_NAS_Message_Container::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding EPS_NAS_Message_Container iei(0x%x)", _iei);
if (len < length) {
Logger::nas_mm().error("len is less than %d", length);
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
* (buf + encoded_size) = (length - 3) & 0x00ff; encoded_size++;
* (buf + encoded_size) = ((length - 3) & 0xff000) >> 8; encoded_size++;
int size = encode_bstring(_value, (buf + encoded_size), len - encoded_size);
encoded_size += size;
}
else {
// *(buf + encoded_size) = length - 1; encoded_size++;
// *(buf + encoded_size) = _value; encoded_size++; encoded_size++;
}
Logger::nas_mm().debug("encoded EPS_NAS_Message_Container len(%d)", encoded_size);
return encoded_size;
}
int EPS_NAS_Message_Container::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding EPS_NAS_Message_Container iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
length = 0;
length |= *(buf + decoded_size); decoded_size++;
length |= (*(buf + decoded_size)) << 8; decoded_size++;
decode_bstring(&_value, length, (buf + decoded_size), len - decoded_size);
decoded_size += length;
for (int i = 0; i < length; i++) {
Logger::nas_mm().debug("decoded EPS_NAS_Message_Container value(0x%x)", (uint8_t*)_value->data[i]);
}
Logger::nas_mm().debug("decoded EPS_NAS_Message_Container len(%d)", decoded_size);
return decoded_size;
}
#ifndef __EPS_NAS_Message_Container_H_
#define __EPS_NAS_Message_Container_H_
#include <iostream>
#include <stdint.h>
extern "C" {
#include "bstrlib.h"
#include "TLVEncoder.h"
#include "TLVDecoder.h"
}
namespace nas {
class EPS_NAS_Message_Container {
public:
EPS_NAS_Message_Container();
EPS_NAS_Message_Container(uint8_t iei);
EPS_NAS_Message_Container(const uint8_t iei, bstring value);
~EPS_NAS_Message_Container();
void setValue(uint8_t iei, uint8_t value);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
void getValue(bstring &value);
private:
uint8_t _iei;
uint16_t length;
bstring _value;
};
}
#endif
#include "EPS_NAS_Security_Algorithms.hpp"
#include "logger.hpp"
#include <iostream>
using namespace nas;
using namespace std;
EPS_NAS_Security_Algorithms::EPS_NAS_Security_Algorithms() {}
EPS_NAS_Security_Algorithms::~EPS_NAS_Security_Algorithms() {}
EPS_NAS_Security_Algorithms::EPS_NAS_Security_Algorithms(uint8_t iei, uint8_t ciphering, uint8_t integrity_protection)
{
_iei = iei;
CIPHERING = ciphering;
INTEGRITY_PROTECTION = integrity_protection;
}
void EPS_NAS_Security_Algorithms::setCIPHERING(uint8_t value) { CIPHERING = value; }
void EPS_NAS_Security_Algorithms::setINTEGRITY_PROTECTION(uint8_t value) { INTEGRITY_PROTECTION = value; }
uint8_t EPS_NAS_Security_Algorithms::getCIPHERING() { return CIPHERING; }
uint8_t EPS_NAS_Security_Algorithms::getINTEGRITY_PROTECTION() { return INTEGRITY_PROTECTION; }
int EPS_NAS_Security_Algorithms::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding EPS_NAS_Security_Algorithms iei(0x%x)", _iei);
int encoded_size = 0;
if (len < 2) {
Logger::nas_mm().error("len is less than 2");
return -1;
}
else {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = ((CIPHERING&0x07)<<4)|(INTEGRITY_PROTECTION&0x07); encoded_size++;
Logger::nas_mm().debug("encoded EPS_NAS_Security_Algorithms IE 0x%x", *buf);
}
return encoded_size;
}
int EPS_NAS_Security_Algorithms::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding EPS_NAS_Security_Algorithms IE");
if (len < 2) {
Logger::nas_mm().error("len is less than 2");
return 0;
}
else {
int decoded_size = 0;
decoded_size++;
CIPHERING = (*(buf+decoded_size)&0x70)>>4;
INTEGRITY_PROTECTION = *(buf+decoded_size) & 0x07;
decoded_size++;
Logger::nas_mm().debug("decoded NAS_Security_Algorithms len 1 octet,CIPHERING=0x%x,INTEGRITY_PROTECTION=0x%x", CIPHERING, INTEGRITY_PROTECTION);
return decoded_size;
}
}
#ifndef __EPS_NAS_Security_Algorithms_H
#define __EPS_NAS_Security_Algorithms_H
#include <stdint.h>
namespace nas {
class EPS_NAS_Security_Algorithms {
public:
EPS_NAS_Security_Algorithms();
~EPS_NAS_Security_Algorithms();
EPS_NAS_Security_Algorithms(uint8_t iei, uint8_t ciphering, uint8_t integrity_protection);
void setCIPHERING(uint8_t value);
void setINTEGRITY_PROTECTION(uint8_t value);
uint8_t getCIPHERING();
uint8_t getINTEGRITY_PROTECTION();
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
private:
uint8_t _iei;
uint8_t CIPHERING;
uint8_t INTEGRITY_PROTECTION;
};
}
#endif
#include "ExtendedProtocolDiscriminator.hpp"
using namespace nas;
void ExtendedProtocolDiscriminator::setValue(const uint8_t epd){
m_epd = epd;
}
uint8_t ExtendedProtocolDiscriminator::getValue(){
return m_epd;
}
void ExtendedProtocolDiscriminator::encode2buffer(uint8_t *buf, int len){
}
#ifndef _EPD_H_
#define _EPD_H_
#include<stdint.h>
namespace nas{
class ExtendedProtocolDiscriminator{
public:
void encode2buffer(uint8_t *buf, int len);
void setValue(const uint8_t epd);
uint8_t getValue();
private:
uint8_t m_epd;
};
}
#endif
#include "Extended_DRX_Parameters.hpp"
#include "logger.hpp"
using namespace nas;
Extended_DRX_Parameters::Extended_DRX_Parameters(uint8_t iei) {
_iei = iei;
}
Extended_DRX_Parameters::Extended_DRX_Parameters(const uint8_t iei, uint8_t paging_time, uint8_t value) {
_iei = iei;
_paging_time = paging_time & 0x0F;
_value = value&0x0F;
}
Extended_DRX_Parameters::Extended_DRX_Parameters() {}
Extended_DRX_Parameters::~Extended_DRX_Parameters() {}
void Extended_DRX_Parameters::setValue(uint8_t value) {
_value = value&0x0F;
}
void Extended_DRX_Parameters::setPaging_time(uint8_t value) {
_paging_time = value & 0x0F;
}
uint8_t Extended_DRX_Parameters::getValue() {
return _value;
}
uint8_t Extended_DRX_Parameters::getPaging_time() {
return _paging_time;
}
int Extended_DRX_Parameters::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding Extended_DRX_Parameters iei(0x%x)", _iei);
if (len < 3) {
Logger::nas_mm().error("len is less than 3");
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = 1; encoded_size++;
*(buf + encoded_size) = (0x0F& _value)| ((_paging_time&0x0f)<<4); encoded_size++;
}
else {
// *(buf + encoded_size) = length - 1; encoded_size++;
// *(buf + encoded_size) = _value; encoded_size++; encoded_size++;
}
Logger::nas_mm().debug("encoded Extended_DRX_Parameters len(%d)", encoded_size);
return encoded_size;
}
int Extended_DRX_Parameters::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding Extended_DRX_Parameters iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
_value=0x00;
// length = *(buf + decoded_size);
decoded_size++;
_value = *(buf + decoded_size) & 0x0f;
_paging_time = *(buf + decoded_size) & 0xf0; decoded_size++;
Logger::nas_mm().debug("decoded Extended_DRX_Parameters paging_time(0x%x) value(0x%x) ", _paging_time, _value);
Logger::nas_mm().debug("decoded Extended_DRX_Parameters len(%d)", decoded_size);
return decoded_size;
}
#ifndef __Extended_DRX_Parameters_H_
#define __Extended_DRX_Parameters_H_
#include <stdint.h>
namespace nas {
class Extended_DRX_Parameters {
public:
Extended_DRX_Parameters();
Extended_DRX_Parameters(uint8_t iei);
Extended_DRX_Parameters(const uint8_t iei, uint8_t paging_time, uint8_t value);
~Extended_DRX_Parameters();
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
void setValue(uint8_t value);
uint8_t getValue();
void setPaging_time(uint8_t value);
uint8_t getPaging_time();
private:
uint8_t _iei;
uint8_t _paging_time;
uint8_t _value;
};
}
#endif
#include "GPRS_Timer_2.hpp"
#include "logger.hpp"
using namespace nas;
GPRS_Timer_2::GPRS_Timer_2(uint8_t iei) {
_iei = iei;
}
GPRS_Timer_2::GPRS_Timer_2(const uint8_t iei, uint8_t value) {
_iei = iei;
_value = value;
}
GPRS_Timer_2::GPRS_Timer_2() {}
GPRS_Timer_2::~GPRS_Timer_2() {}
void GPRS_Timer_2::setIEI(uint8_t iei) {
_iei = iei;
}
void GPRS_Timer_2::setValue(uint8_t value) {
_value = value;
}
uint8_t GPRS_Timer_2::getValue() {
return _value;
}
int GPRS_Timer_2::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding GPRS_Timer_2 iei(0x%x)", _iei);
if (len < 3) {
Logger::nas_mm().error("len is less than 3");
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = 1; encoded_size++;
*(buf + encoded_size) = _value; encoded_size++;
Logger::nas_mm().debug("encoded GPRS_Timer_2 _value(0x%x),iei(0x%x)", *(buf+encoded_size-1),_iei);
}
else {
// *(buf + encoded_size) = length - 1; encoded_size++;
// *(buf + encoded_size) = _value; encoded_size++; encoded_size++;
}
Logger::nas_mm().debug("encoded GPRS_Timer_2 len(%d)", encoded_size);
return encoded_size;
}
int GPRS_Timer_2::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding GPRS_Timer_2 iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
_iei=*buf;
decoded_size++;
}
_value=0x00;
// length = *(buf + decoded_size);
decoded_size++;
_value = *(buf + decoded_size); decoded_size++;
Logger::nas_mm().debug("decoded GPRS_Timer_2 _value(0x%x),iei(0x%x)", _value,_iei);
Logger::nas_mm().debug("decoded GPRS_Timer_2 len(%d)", decoded_size);
return decoded_size;
}
#ifndef __GPRS_Timer_2_H_
#define __GPRS_Timer_2_H_
#include <stdint.h>
namespace nas {
class GPRS_Timer_2 {
public:
GPRS_Timer_2();
GPRS_Timer_2(uint8_t iei);
GPRS_Timer_2(const uint8_t iei, uint8_t value);
~GPRS_Timer_2();
void setIEI(uint8_t iei);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
void setValue(uint8_t value);
uint8_t getValue();
private:
uint8_t _iei;
uint8_t _value;
};
}
#endif
#include "GPRS_Timer_3.hpp"
#include "logger.hpp"
using namespace nas;
GPRS_Timer_3::GPRS_Timer_3(uint8_t iei) {
_iei = iei;
}
GPRS_Timer_3::GPRS_Timer_3(const uint8_t iei,uint8_t unit, uint8_t value) {
_iei = iei;
UNIT = unit;
_value = value;
}
GPRS_Timer_3::GPRS_Timer_3() {}
GPRS_Timer_3::~GPRS_Timer_3() {}
void GPRS_Timer_3::setValue(uint8_t unit,uint8_t value) {
UNIT = unit;
_value = value;
}
uint8_t GPRS_Timer_3::getUnit() {
return UNIT;
}
uint8_t GPRS_Timer_3::getValue() {
return _value;
}
int GPRS_Timer_3::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding GPRS_Timer_3 iei(0x%x)", _iei);
if (len < 3) {
Logger::nas_mm().error("len is less than 3");
return 0;
}
uint8_t octet=0;
int encoded_size = 0;
octet = (UNIT<<5)| (_value & 0x1f);
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = 1; encoded_size++;
*(buf + encoded_size) = octet; encoded_size++;
Logger::nas_mm().debug("encoded GPRS_Timer_3 conent(0x%x)", octet);
}
else {
*(buf + encoded_size) = 1; encoded_size++;
*(buf + encoded_size) = octet; encoded_size++;
}
Logger::nas_mm().debug("encoded GPRS_Timer_3 len(%d)", encoded_size);
return encoded_size;
}
int GPRS_Timer_3::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding GPRS_Timer_3 iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
_iei=*buf;
decoded_size++;
}
uint8_t octet=0;
// length = *(buf + decoded_size);
decoded_size++;
octet = *(buf + decoded_size); decoded_size++;
UNIT = (octet & 0xe0) >> 5;
_value = octet & 0x1f;
Logger::nas_mm().debug("decoded GPRS_Timer_3 conent(0x%x)", octet);
Logger::nas_mm().debug("decoded GPRS_Timer_3 len(%d)", decoded_size);
return decoded_size;
}
#ifndef __GPRS_Timer_3_H_
#define __GPRS_Timer_3_H_
#include <stdint.h>
namespace nas {
class GPRS_Timer_3 {
public:
GPRS_Timer_3();
GPRS_Timer_3(uint8_t iei);
GPRS_Timer_3(const uint8_t iei,uint8_t unit, uint8_t value);
~GPRS_Timer_3();
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
void setValue(uint8_t unit,uint8_t value);
uint8_t getValue();
uint8_t getUnit();
private:
uint8_t _iei;
uint8_t UNIT;
uint8_t _value;
};
}
#endif
#include "IMEISV_Request.hpp"
#include "logger.hpp"
using namespace nas;
IMEISV_Request::IMEISV_Request(uint8_t iei) {
_iei = iei;
}
IMEISV_Request::IMEISV_Request(const uint8_t iei,uint8_t value) {
_iei = iei;
_value = value;
}
IMEISV_Request::IMEISV_Request() {}
IMEISV_Request::~IMEISV_Request() {}
void IMEISV_Request::setValue(uint8_t value) {
_value = value;
}
uint8_t IMEISV_Request::getValue() {
return _value;
}
int IMEISV_Request::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding IMEISV_Request iei(0x%x)", _iei);
if (len < 1) {
Logger::nas_mm().error("len is less than 1");
return 0;
}
uint8_t octet = 0;
if (!(_iei & 0x0f)) {
//octet = (0x0f) & ((tsc << 3) | key_id);
//*buf = octet;
//Logger::nas_mm().debug("encoded Payload_Container_Type IE(len(1/2 octet))");
//return 0;
}
else {
octet = (_iei << 4) | (_value&0x07);
*buf = octet;
Logger::nas_mm().debug("encoded IMEISV_Request IE(len(1 octet))");
return 1;
}
}
int IMEISV_Request::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
if (len < 1) {
Logger::nas_mm().error("len is less than one");
return 0;
}
else {
uint8_t octet = (*buf);
if (is_option) {
_iei = (octet & 0xf0) >> 4;
}
else {
_iei = 0;
}
_value =octet& 0x07;
Logger::nas_mm().debug("decoded IMEISV_Request value(0x%x)", _value);
return 1;
}
}
#ifndef __IMEISV_Request_H_
#define __IMEISV_Request_H_
#include <stdint.h>
namespace nas {
class IMEISV_Request {
public:
IMEISV_Request();
IMEISV_Request(uint8_t iei);
IMEISV_Request(const uint8_t iei, uint8_t value);
~IMEISV_Request();
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
void setValue(uint8_t value);
uint8_t getValue();
private:
uint8_t _iei;
uint8_t _value;
};
}
#endif
#include "LADN_Indication.hpp"
#include "logger.hpp"
using namespace nas;
LADN_Indication::LADN_Indication(uint8_t iei) {
_iei = iei;
}
LADN_Indication::LADN_Indication(const uint8_t iei, std::vector<bstring> ladn) {
_iei = iei;
length = 3;
LADN.assign(ladn.begin(), ladn.end());
for (int i = 0; i < ladn.size(); i++) {
length = length + 1+blength(ladn.at(i));
}
}
LADN_Indication::LADN_Indication() {}
LADN_Indication::~LADN_Indication() {}
void LADN_Indication::setValue(uint8_t iei, uint8_t value) {
_iei = iei;
//_value = value;
}
bool LADN_Indication::getValue(std::vector<bstring> &ladn){
ladn.assign(LADN.begin(), LADN.end());
return 0;
}
int LADN_Indication::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding LADN_Indication iei(0x%x)", _iei);
if (len < length) {
Logger::nas_mm().error("len is less than %d", length);
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = (length - 3)&0x00ff; encoded_size++;
*(buf + encoded_size) = ((length - 3) & 0xff00)>>8; encoded_size++;
for (int i = 0; i < LADN.size(); i++) {
*(buf + encoded_size) = blength(LADN.at(i));encoded_size++;
encoded_size+=encode_bstring(LADN.at(i), (buf + encoded_size), len - encoded_size);
}
}
else {
// *(buf + encoded_size) = length - 1; encoded_size++;
// *(buf + encoded_size) = _value; encoded_size++; encoded_size++;
}
Logger::nas_mm().debug("encoded LADN_Indication len(%d)", encoded_size);
return encoded_size;
}
int LADN_Indication::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding LADN_Indication iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
length = 0;
length |= *(buf + decoded_size); decoded_size++;
length |= (*(buf + decoded_size))<<8; decoded_size++;
Logger::nas_mm().debug("decoded LADN_Indication len(%d)", length);
int LEAGTH = length;
uint8_t len_dnn;
bstring dnn;
while (LEAGTH) {
len_dnn= *(buf + decoded_size); decoded_size++; LEAGTH--;
decode_bstring(&dnn, len_dnn, (buf + decoded_size), len - decoded_size);
decoded_size += len_dnn;
LEAGTH-= len_dnn;
LADN.insert(LADN.end(), dnn);
}
for (int i = 0; i < LADN.size(); i++) {
for (int j = 0; j < blength(LADN.at(i)); j++) {
Logger::nas_mm().debug("decoded LADN_Indication value(0x%x)", (uint8_t*)LADN.at(i)->data[j]);
}
}
Logger::nas_mm().debug("decoded LADN_Indication len(%d)", decoded_size);
return decoded_size;
}
#ifndef __LADN_Indication_H_
#define __LADN_Indication_H_
#include <iostream>
#include <vector>
#include <stdint.h>
extern "C" {
#include "bstrlib.h"
#include "TLVEncoder.h"
#include "TLVDecoder.h"
}
using namespace std;
namespace nas {
class LADN_Indication {
public:
LADN_Indication();
LADN_Indication(uint8_t iei);
LADN_Indication(const uint8_t iei, std::vector<bstring> ladn);
~LADN_Indication();
void setValue(uint8_t iei, uint8_t value);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
bool getValue(std::vector<bstring> &ladn);
private:
uint8_t _iei;
uint16_t length;
std::vector<bstring> LADN;
};
}
#endif
#include "MA_PDU_Session_Information.hpp"
#include "logger.hpp"
using namespace nas;
MA_PDU_Session_Information::MA_PDU_Session_Information(uint8_t iei) {
_iei = iei;
}
MA_PDU_Session_Information::MA_PDU_Session_Information(const uint8_t iei, uint8_t value) {
_iei = iei;
_value = value;
}
MA_PDU_Session_Information::MA_PDU_Session_Information() {}
MA_PDU_Session_Information::~MA_PDU_Session_Information() {}
void MA_PDU_Session_Information::setValue(uint8_t value) {
_value = value;
}
uint8_t MA_PDU_Session_Information::getValue() {
return _value;
}
int MA_PDU_Session_Information::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding MA_PDU_Session_Information iei(0x%x)", _iei);
if (len < 1) {
Logger::nas_mm().error("len is less than 1");
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = ((_iei&0x0f)<<4)|(_value&0x0f); encoded_size++;
}
else {
*(buf + encoded_size) = _value & 0x0f; encoded_size++;
}
Logger::nas_mm().debug("encoded MA_PDU_Session_Information len(%d)", encoded_size);
return encoded_size;
}
int MA_PDU_Session_Information::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding MA_PDU_Session_Information iei(0x%x)", *buf);
int decoded_size = 0;
uint8_t octet = 0;
if (is_option) {
octet =*buf;
decoded_size++;
}
_value=0x00;
_value = octet &0x0f;
Logger::nas_mm().debug("decoded MA_PDU_Session_Information _value(0x%x)", _value);
Logger::nas_mm().debug("decoded MA_PDU_Session_Information len(%d)", decoded_size);
return decoded_size;
}
#ifndef __MA_PDU_Session_Information_H_
#define __MA_PDU_Session_Information_H_
#include <stdint.h>
namespace nas {
class MA_PDU_Session_Information {
public:
MA_PDU_Session_Information();
MA_PDU_Session_Information(uint8_t iei);
MA_PDU_Session_Information(const uint8_t iei, uint8_t value);
~MA_PDU_Session_Information();
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
void setValue(uint8_t value);
uint8_t getValue();
private:
uint8_t _iei;
uint8_t _value;
};
}
#endif
#include "MICO_Indication.hpp"
#include "logger.hpp"
using namespace nas;
MICO_Indication::MICO_Indication(const uint8_t _iei, bool sprti, bool raai) {
iei = _iei;
RAAI = raai;
SPRTI = sprti;
}
MICO_Indication::MICO_Indication(bool sprti, bool raai) {
this->iei = 0;
this->RAAI = raai;
this->SPRTI = sprti;
}
MICO_Indication::MICO_Indication() {
}
MICO_Indication::~MICO_Indication() {};
int MICO_Indication::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding MICO_Indication IE iei(0x%x)", iei);
if (len < 1) {
Logger::nas_mm().error("len is less than one");
return -1;
}
else {
uint8_t octet = 0;
if (!(iei & 0x0f)) {
//octet = (0x0f) & ((tsc << 3) | key_id);
//*buf = octet;
//Logger::nas_mm().debug("encoded NasKeySetIdentifier IE(len(1/2 octet))");
//return 0;
}
else {
octet = (iei << 4) | (SPRTI << 1) | RAAI;
*buf = octet;
Logger::nas_mm().debug("encoded MICO_Indication IE(len(1 octet))");
return 1;
}
}
}
int MICO_Indication::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding MICO_Indication IE");
if (len < 1) {
Logger::nas_mm().error("len is less than one");
return 0;
}
else {
uint8_t octet = (*buf);
if (is_option) {
iei = (octet & 0xf0) >> 4;
}
else {
iei = 0;
}
SPRTI = octet & 0x02;
RAAI = octet & 0x01;
Logger::nas_mm().debug("decoded MICO_Indication iei(0x%x) sprti(0x%x) raai(0x%x)", iei,SPRTI,RAAI);
return 1;
}
}
void MICO_Indication::setSPRTI(bool value) {
SPRTI = value;
}
void MICO_Indication::setRAAI(bool value) {
RAAI = value;
}
bool MICO_Indication::getSPRTI() {
return SPRTI;
}
bool MICO_Indication::getRAAI() {
return RAAI;
}
#ifndef _MICO_Indication_H
#define _MICO_Indication_H
#include <stdint.h>
namespace nas {
class MICO_Indication {
public:
MICO_Indication();
MICO_Indication(const uint8_t _iei, bool sprti, bool raai);
MICO_Indication(bool sprti, bool raai);
~MICO_Indication();
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
void setSPRTI(bool value);
void setRAAI(bool value);
bool getRAAI();
bool getSPRTI();
private:
uint8_t iei;
bool SPRTI;
bool RAAI;
};
}
#endif
#include "NAS_Message_Container.hpp"
#include "logger.hpp"
using namespace nas;
NAS_Message_Container::NAS_Message_Container(uint8_t iei) {
_iei = iei;
}
NAS_Message_Container::NAS_Message_Container(const uint8_t iei, bstring value) {
_iei = iei;
_value = bstrcpy(value);
length = blength(value) + 3;
}
NAS_Message_Container::NAS_Message_Container() {}
NAS_Message_Container::~NAS_Message_Container() {}
void NAS_Message_Container::setValue(uint8_t iei, uint8_t value) {
_iei = iei;
//_value = value;
}
void NAS_Message_Container::getValue(bstring &value) {
value = bstrcpy(_value);
}
int NAS_Message_Container::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding NAS_Message_Container iei(0x%x)", _iei);
if (len < length) {
Logger::nas_mm().error("len is less than %d", length);
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
* (buf + encoded_size) = (length - 3) & 0x00ff; encoded_size++;
* (buf + encoded_size) = ((length - 3) & 0xff000) >> 8; encoded_size++;
int size = encode_bstring(_value, (buf + encoded_size), len - encoded_size);
encoded_size += size;
}
else {
// *(buf + encoded_size) = length - 1; encoded_size++;
// *(buf + encoded_size) = _value; encoded_size++; encoded_size++;
}
Logger::nas_mm().debug("encoded NAS_Message_Container len(%d)", encoded_size);
return encoded_size;
}
int NAS_Message_Container::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding NAS_Message_Container iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
length = 0;
length |= (*(buf + decoded_size))<<8; decoded_size++;
length |= *(buf + decoded_size); decoded_size++;
decode_bstring(&_value, length, (buf + decoded_size), len - decoded_size);
decoded_size += length;
for (int i = 0; i < length; i++) {
Logger::nas_mm().debug("decoded NAS_Message_Container value(0x%x)", (uint8_t*)_value->data[i]);
}
Logger::nas_mm().debug("decoded NAS_Message_Container len(%d)", decoded_size);
return decoded_size;
}
#ifndef __NAS_Message_Container_H_
#define __NAS_Message_Container_H_
#include <iostream>
#include <stdint.h>
extern "C"{
#include "bstrlib.h"
#include "TLVEncoder.h"
#include "TLVDecoder.h"
}
namespace nas {
class NAS_Message_Container {
public:
NAS_Message_Container();
NAS_Message_Container(uint8_t iei);
NAS_Message_Container(const uint8_t iei, bstring value);
~NAS_Message_Container();
void setValue(uint8_t iei, uint8_t value);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
void getValue(bstring &value);
private:
uint8_t _iei;
uint16_t length;
bstring _value;
};
}
#endif
#include "NAS_Security_Algorithms.hpp"
#include "logger.hpp"
#include <iostream>
using namespace nas;
using namespace std;
NAS_Security_Algorithms::NAS_Security_Algorithms() {}
NAS_Security_Algorithms::~NAS_Security_Algorithms() {}
NAS_Security_Algorithms::NAS_Security_Algorithms(uint8_t ciphering, uint8_t integrity_protection)
{
CIPHERING = ciphering;
INTEGRITY_PROTECTION = integrity_protection;
}
void NAS_Security_Algorithms::setCIPHERING(uint8_t value) { CIPHERING = value; }
void NAS_Security_Algorithms::setINTEGRITY_PROTECTION(uint8_t value) { INTEGRITY_PROTECTION = value; }
uint8_t NAS_Security_Algorithms::getCIPHERING() { return CIPHERING; }
uint8_t NAS_Security_Algorithms::getINTEGRITY_PROTECTION() { return INTEGRITY_PROTECTION; }
int NAS_Security_Algorithms::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding NAS_Security_Algorithms ");
if (len < 1) {
Logger::nas_mm().error("len is less than one");
return -1;
}
else {
*buf = ((CIPHERING&0x0f)<<4)|(INTEGRITY_PROTECTION&0x0f);
Logger::nas_mm().debug("encoded NAS_Security_Algorithms IE 0x%x", *buf);
}
return 1;
}
int NAS_Security_Algorithms::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding NAS_Security_Algorithms IE");
if (len < 1) {
Logger::nas_mm().error("len is less than one");
return 0;
}
else {
CIPHERING = (*buf&0xf0)>>4;
INTEGRITY_PROTECTION = *buf & 0x0f;
Logger::nas_mm().debug("decoded NAS_Security_Algorithms len 1 octet,CIPHERING=0x%x,INTEGRITY_PROTECTION=0x%x", CIPHERING, INTEGRITY_PROTECTION);
return 1;
}
}
#ifndef __NAS_Security_Algorithms_H
#define __NAS_Security_Algorithms_H
#include <stdint.h>
namespace nas {
class NAS_Security_Algorithms {
public:
NAS_Security_Algorithms();
~NAS_Security_Algorithms();
NAS_Security_Algorithms(uint8_t ciphering, uint8_t integrity_protection);
void setCIPHERING(uint8_t value);
void setINTEGRITY_PROTECTION(uint8_t value);
uint8_t getCIPHERING();
uint8_t getINTEGRITY_PROTECTION();
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
private:
uint8_t CIPHERING;
uint8_t INTEGRITY_PROTECTION;
};
}
#endif
#include "NSSAI.hpp"
#include <vector>
#include "logger.hpp"
using namespace nas;
using namespace std;
NSSAI::NSSAI(uint8_t iei) {
_iei = iei;
}
NSSAI::NSSAI(const uint8_t iei, std::vector<struct SNSSAI_s> nssai) {
_iei = iei;
length = 0;
S_NSSAI.assign(nssai.begin(), nssai.end());
for(int i=0; i<nssai.size(); i++){
length += 2;//for sst
if(nssai[i].sd != -1) length += 3;
if(nssai[i].mHplmnSst != -1) length += 1;
if(nssai[i].mHplmnSd != -1) length += 3;
}
}
NSSAI::NSSAI() {}
NSSAI::~NSSAI() {}
void NSSAI::setS_NAASI(uint8_t SST) {
}
bool NSSAI::getValue(std::vector<struct SNSSAI_s> &nssai)
{
nssai.assign(S_NSSAI.begin(), S_NSSAI.end());
}
int NSSAI::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding NSSAI iei(0x%x)", _iei);
if (len < length) {
Logger::nas_mm().error("len is less than %d", length);
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = length; encoded_size++;
for(int i =0;i< S_NSSAI.size(); i++){
int len_s_nssai = 1; encoded_size ++;
*(buf + encoded_size) = S_NSSAI.at(i).sst; encoded_size++;
if (S_NSSAI.at(i).sd != -1)
{
len_s_nssai += 3;
*(buf + encoded_size) = (S_NSSAI.at(i).sd & 0x00ff0000)>> 16; encoded_size++;
Logger::nas_mm().debug("decoded NSSAI len(%x)", *(buf + encoded_size-1));
*(buf + encoded_size) = (S_NSSAI.at(i).sd & 0x0000ff00)>>8; encoded_size++;
Logger::nas_mm().debug("decoded NSSAI len(%x)", *(buf + encoded_size-1));
*(buf + encoded_size) = S_NSSAI.at(i).sd & 0x000000ff; encoded_size++;
Logger::nas_mm().debug("decoded NSSAI len(%x)", *(buf + encoded_size-1));
}
if (S_NSSAI.at(i).mHplmnSst != -1)
{
len_s_nssai += 1;
*(buf + encoded_size) = S_NSSAI.at(i).mHplmnSst; encoded_size++;
}
if (S_NSSAI.at(i).mHplmnSd != -1)
{
len_s_nssai += 3;
*(buf + encoded_size) = (S_NSSAI.at(i).mHplmnSd & 0x00ff0000) >> 16; encoded_size++;
*(buf + encoded_size) = (S_NSSAI.at(i).mHplmnSd & 0x0000ff00) >> 8; encoded_size++;
*(buf + encoded_size) = S_NSSAI.at(i).mHplmnSd & 0x000000ff; encoded_size++;
}
*(buf + encoded_size - len_s_nssai - 1) = len_s_nssai;
}
}
else {
// *(buf + encoded_size) = length - 1; encoded_size++;
// *(buf + encoded_size) = _value; encoded_size++; encoded_size++;
}
Logger::nas_mm().debug("encoded NSSAI len(%d)", encoded_size);
return encoded_size;
}
int NSSAI::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding NSSAI iei(0x%x)", *buf);
int decoded_size = 0;
SNSSAI_s a = {0,0,0,0};
if (is_option) {
decoded_size++;
}
length = *(buf + decoded_size); decoded_size++;
int LEAGTH = length;
while (LEAGTH) {
switch (*(buf + decoded_size))
{
case 1: {
decoded_size++;//snssai—leagth
LEAGTH--;
a.sst = *(buf + decoded_size); decoded_size++;//无 sd
LEAGTH--;
a.sd = -1;
a.mHplmnSst = -1;
a.mHplmnSd = -1;
}break;
case 4: {
decoded_size++; LEAGTH--;
a.sst = *(buf + decoded_size); decoded_size++; LEAGTH--;
a.sd |= *(buf + decoded_size); decoded_size++; LEAGTH--;//有 sd
a.sd << 8;
a.sd |= *(buf + decoded_size); decoded_size++; LEAGTH--;//有 sd
a.sd << 8;
a.sd |= *(buf + decoded_size); decoded_size++; LEAGTH--;//有 sd
a.mHplmnSst = -1;
a.mHplmnSd = -1;
}break;
case 5: {
decoded_size++; LEAGTH--;
a.sst = *(buf + decoded_size); decoded_size++; LEAGTH--;
a.sd |= *(buf + decoded_size); decoded_size++; LEAGTH--;//有 sd
a.sd << 8;
a.sd |= *(buf + decoded_size); decoded_size++; LEAGTH--;//有 sd
a.sd << 8;
a.sd |= *(buf + decoded_size); decoded_size++; LEAGTH--;//有 sd
a.mHplmnSst = *(buf + decoded_size); decoded_size++; LEAGTH--;
a.mHplmnSd = -1;
}break;
case 8: {
decoded_size++; LEAGTH--;
a.sst = *(buf + decoded_size); decoded_size++; LEAGTH--;
a.sd |= *(buf + decoded_size); decoded_size++; LEAGTH--;//有 sd
a.sd << 8;
a.sd |= *(buf + decoded_size); decoded_size++; LEAGTH--;//有 sd
a.sd << 8;
a.sd |= *(buf + decoded_size); decoded_size++; LEAGTH--;//有 sd
a.mHplmnSst = *(buf + decoded_size); decoded_size++; LEAGTH--;
a.mHplmnSd |= *(buf + decoded_size); decoded_size++; LEAGTH--;//有 sd
a.mHplmnSd << 16;
a.mHplmnSd |= *(buf + decoded_size); decoded_size++; LEAGTH--;//有 sd
a.mHplmnSd << 8;
a.mHplmnSd |= *(buf + decoded_size); decoded_size++; LEAGTH--;//有 sd
}break;
}
S_NSSAI.insert(S_NSSAI.end(),a);
a={0,0,0,0};
}
for(int i =0;i< S_NSSAI.size(); i++){
Logger::nas_mm().debug("decoded NSSAI SST(0x%x) SD(0x%x) hplmnSST(0x%x) hplmnSD(%d)",S_NSSAI.at(i).sst,S_NSSAI.at(i).sd, S_NSSAI.at(i).mHplmnSst, S_NSSAI.at(i).mHplmnSd); }
Logger::nas_mm().debug("decoded NSSAI len(%d)", decoded_size);
return decoded_size;
}
#ifndef __NSSAI_H_
#define __NSSAI_H_
#include <vector>
#include "nas_ie_header.hpp"
#include <stdint.h>
namespace nas {
class NSSAI{
public:
NSSAI();
NSSAI(uint8_t iei);
NSSAI(const uint8_t iei, std::vector<struct SNSSAI_s> nssai);
~NSSAI();
void setS_NAASI(uint8_t SST);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
bool getValue(std::vector<struct SNSSAI_s> &nssai);
private:
uint8_t _iei;
uint8_t length;
std::vector<struct SNSSAI_s> S_NSSAI;
};
}
#endif
#include "NSSAI_Inclusion_Mode.hpp"
#include "logger.hpp"
using namespace nas;
NSSAI_Inclusion_Mode::NSSAI_Inclusion_Mode(const uint8_t iei, uint8_t value) {
_iei = iei;
_value = value;
}
NSSAI_Inclusion_Mode::NSSAI_Inclusion_Mode() {}
NSSAI_Inclusion_Mode::~NSSAI_Inclusion_Mode() {};
void NSSAI_Inclusion_Mode::setValue(const uint8_t value) {
_value = value;
}
uint8_t NSSAI_Inclusion_Mode::getValue() {
return _value;
}
int NSSAI_Inclusion_Mode::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding NSSAI_Inclusion_Mode IE iei(0x%x)", _iei);
if (len < 1) {
Logger::nas_mm().error("len is less than one");
return -1;
}
else {
uint8_t octet = 0;
if (!(_iei & 0x0f)) {
//octet = (0x0f) & ((tsc << 3) | key_id);
//*buf = octet;
//Logger::nas_mm().debug("encoded Payload_Container_Type IE(len(1/2 octet))");
//return 0;
}
else {
octet = (_iei << 4) | (_value&0x0f);
*buf = octet;
Logger::nas_mm().debug("encoded NSSAI_Inclusion_Mode IE(len(1 octet))");
return 1;
}
}
}
int NSSAI_Inclusion_Mode::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding NSSAI_Inclusion_Mode IE");
if (len < 1) {
Logger::nas_mm().error("len is less than one");
return 0;
}
else {
uint8_t octet = (*buf);
if (is_option) {
_iei = (octet & 0xf0) >> 4;
}
else {
_iei = 0;
}
_value= octet & 0x0f;
Logger::nas_mm().debug("decoded NSSAI_Inclusion_Mode iei(0x%x) value(0x%x)", _iei,_value);
return 1;
}
}
#ifndef _NSSAI_Inclusion_Mode_H
#define _NSSAI_Inclusion_Mode_H
#include <stdint.h>
namespace nas {
class NSSAI_Inclusion_Mode {
public:
NSSAI_Inclusion_Mode();
NSSAI_Inclusion_Mode(const uint8_t iei, uint8_t value);
~NSSAI_Inclusion_Mode();
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
void setValue(const uint8_t value);
uint8_t getValue();
private:
uint8_t _iei;
uint8_t _value;
};
}
#endif
#include "NasKeySetIdentifier.hpp"
#include "logger.hpp"
using namespace nas;
NasKeySetIdentifier::NasKeySetIdentifier(const uint8_t m_iei, uint8_t m_tsc, uint8_t m_key_id){
iei = m_iei;
tsc = 0x01 & m_tsc;
key_id = 0x07 & m_key_id;
Logger::nas_mm().debug("encoding NasKeySetIdentifier ...");
}
NasKeySetIdentifier::NasKeySetIdentifier(uint8_t tsc, uint8_t key_id){
this->iei = 0;
this->tsc = 0x01 & tsc;
this->key_id = 0x07 & key_id;
Logger::nas_mm().debug("encoding NasKeySetIdentifier???");
}
NasKeySetIdentifier::NasKeySetIdentifier(){
}
NasKeySetIdentifier::~NasKeySetIdentifier(){};
int NasKeySetIdentifier::encode2buffer(uint8_t *buf, int len){
Logger::nas_mm().debug("encoding NasKeySetIdentifier IE iei(0x%x)",iei);
if(len < 1){
Logger::nas_mm().error("len is less than one");
return -1;
}else{
uint8_t octet = 0;
if(!(iei&0x0f)){
octet = (0x0f) & ((tsc<<3) | key_id);
*buf = octet;
Logger::nas_mm().debug("encoded NasKeySetIdentifier IE tsc(0x%x),key_id(0x%x)", tsc, key_id);
return 1;
}else{
octet = (iei<<4) | (tsc<<3) | key_id;
*buf = octet;
Logger::nas_mm().debug("encoded NasKeySetIdentifier IE(len(1 octet))");
Logger::nas_mm().debug("encoded NasKeySetIdentifier IE tsc(0x%x),key_id(0x%x)", tsc, key_id);
return 1;
}
}
}
int NasKeySetIdentifier::decodefrombuffer(uint8_t *buf, int len, bool is_option, bool is_high){
Logger::nas_mm().debug("decoding NasKeySetIdentifier IE");
if(len < 1){
Logger::nas_mm().error("len is less than one");
return -1;
}else{
uint8_t octet = (*buf);
if(is_option){
iei = (octet&0xf0)>>4;
}else{
iei = 0;
}
if(!is_high){
tsc = octet&0x08;
key_id = octet&0x07;
}else{
tsc = (octet&0x80)>>4;
key_id = (octet&0x70)>>4;
}
Logger::nas_mm().debug("decoded NasKeySetIdentifier IE tsc(0x%x),key_id(0x%x)", tsc, key_id);
if(iei) return 1;
else return 0;
}
}
void NasKeySetIdentifier::setTypeOfSecurityContext(uint8_t type){
tsc = 0x01 & type;
}
void NasKeySetIdentifier::setNasKeyIdentifier(uint8_t id){
key_id = 0x07 & id;
}
uint8_t NasKeySetIdentifier::getTypeOfSecurityContext(){
return tsc;
}
uint8_t NasKeySetIdentifier::getasKeyIdentifier(){
return key_id;
}
#ifndef _NasKeySetIdentifier_H
#define _NasKeySetIdentifier_H
#include <stdint.h>
namespace nas{
class NasKeySetIdentifier{
public:
NasKeySetIdentifier();
NasKeySetIdentifier(const uint8_t iei, uint8_t tsc, uint8_t key_id);
NasKeySetIdentifier(uint8_t tsc, uint8_t key_id);
~NasKeySetIdentifier();
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option, bool is_high);
void setTypeOfSecurityContext(uint8_t type);
void setNasKeyIdentifier(uint8_t id);
uint8_t getTypeOfSecurityContext();
uint8_t getasKeyIdentifier();
private:
uint8_t iei;
uint8_t tsc;
uint8_t key_id;
};
}
#endif
#include "NasMessageType.hpp"
using namespace nas;
void NasMessageType::setValue(const uint8_t type){
m_type = type;
}
uint8_t NasMessageType::getValue(){
return m_type;
}
#ifndef _MESSAGE_TYPE_H_
#define _MESSAGE_TYPE_H_
#include<stdint.h>
namespace nas{
class NasMessageType{
public:
void setValue(const uint8_t type);
uint8_t getValue();
private:
uint8_t m_type;
};
}
#endif
#include "Network_Slicing_Indication.hpp"
#include "logger.hpp"
using namespace nas;
Network_Slicing_Indication::Network_Slicing_Indication(uint8_t iei) {
_iei = iei;
}
Network_Slicing_Indication::Network_Slicing_Indication(const uint8_t iei, bool dcni, bool nssci) {
_iei = iei;
DCNI= dcni;
NSSCI = nssci;
}
Network_Slicing_Indication::Network_Slicing_Indication() {}
Network_Slicing_Indication::~Network_Slicing_Indication() {}
void Network_Slicing_Indication::setDCNI(bool value) {
DCNI = value;
}
void Network_Slicing_Indication::setNSSCI(bool value) {
NSSCI = value;
}
bool Network_Slicing_Indication::getDCNI() {
return DCNI;
}
bool Network_Slicing_Indication::getNSSCI() {
return NSSCI;
}
int Network_Slicing_Indication::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding Network_Slicing_Indication iei(0x%x)", _iei);
if (len < 1) {
// Logger::nas_mm().error("len is less than %d", length);
return 0;
}
uint8_t octet = 0;
if (!(_iei & 0x0f)) {
//octet = (0x0f) & ((tsc << 3) | key_id);
//*buf = octet;
//Logger::nas_mm().debug("encoded Payload_Container_Type IE(len(1/2 octet))");
//return 0;
}
else {
octet = (_iei << 4) | (DCNI<<1)|NSSCI;
Logger::nas_mm().debug("decoded Network_Slicing_Indication DCNI(0x%x) NSSCI(0x%x)", octet,NSSCI);
*buf = octet;
Logger::nas_mm().debug("encoded Network_Slicing_Indication IE(len(1 octet))");
return 1;
}
}
int Network_Slicing_Indication::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
if (len < 1) {
Logger::nas_mm().error("len is less than one");
return 0;
}
else {
uint8_t octet = (*buf);
if (is_option) {
_iei = (octet & 0xf0) >> 4;
}
else {
_iei = 0;
}
DCNI = 0; NSSCI = 0;
DCNI = octet&0x02;
NSSCI =octet& 0x01;
Logger::nas_mm().debug("decoded Network_Slicing_Indication DCNI(0x%x) NSSCI(0x%x)", DCNI,NSSCI);
return 1;
}
}
#ifndef __Network_Slicing_Indication_H_
#define __Network_Slicing_Indication_H_
#include <stdint.h>
namespace nas {
class Network_Slicing_Indication {
public:
Network_Slicing_Indication();
Network_Slicing_Indication(uint8_t iei);
Network_Slicing_Indication(const uint8_t iei, bool dcni, bool nssci);
~Network_Slicing_Indication();
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
void setDCNI(bool value);
void setNSSCI(bool value);
bool getDCNI();
bool getNSSCI();
private:
uint8_t _iei;
bool NSSCI;
bool DCNI;
};
}
#endif
#include "Non_3GPP_NW_Provided_Policies.hpp"
#include "logger.hpp"
using namespace nas;
Non_3GPP_NW_Provided_Policies::Non_3GPP_NW_Provided_Policies(const uint8_t iei, uint8_t value) {
_iei = iei;
_value = value;
}
Non_3GPP_NW_Provided_Policies::Non_3GPP_NW_Provided_Policies() {}
Non_3GPP_NW_Provided_Policies::~Non_3GPP_NW_Provided_Policies() {};
void Non_3GPP_NW_Provided_Policies::setValue(const uint8_t value) {
_value = value;
}
uint8_t Non_3GPP_NW_Provided_Policies::getValue() {
return _value;
}
int Non_3GPP_NW_Provided_Policies::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding Non_3GPP_NW_Provided_Policies IE iei(0x%x)", _iei);
if (len < 1) {
Logger::nas_mm().error("len is less than one");
return -1;
}
else {
uint8_t octet = 0;
if (!(_iei & 0x0f)) {
//octet = (0x0f) & ((tsc << 3) | key_id);
//*buf = octet;
//Logger::nas_mm().debug("encoded Payload_Container_Type IE(len(1/2 octet))");
//return 0;
}
else {
octet = (_iei << 4) | (_value&0x0f);
*buf = octet;
Logger::nas_mm().debug("encoded Non_3GPP_NW_Provided_Policies IE(len(1 octet))");
return 1;
}
}
}
int Non_3GPP_NW_Provided_Policies::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding Non_3GPP_NW_Provided_Policies IE");
if (len < 1) {
Logger::nas_mm().error("len is less than one");
return 0;
}
else {
uint8_t octet = (*buf);
if (is_option) {
_iei = (octet & 0xf0) >> 4;
}
else {
_iei = 0;
}
_value= octet & 0x0f;
Logger::nas_mm().debug("decoded Non_3GPP_NW_Provided_Policies iei(0x%x) value(0x%x)", _iei,_value);
return 1;
}
}
#ifndef _Non_3GPP_NW_Provided_Policies_H
#define _Non_3GPP_NW_Provided_Policies_H
#include <stdint.h>
namespace nas {
class Non_3GPP_NW_Provided_Policies {
public:
Non_3GPP_NW_Provided_Policies();
Non_3GPP_NW_Provided_Policies(const uint8_t iei, uint8_t value);
~Non_3GPP_NW_Provided_Policies();
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
void setValue(const uint8_t value);
uint8_t getValue();
private:
uint8_t _iei;
uint8_t _value;
};
}
#endif
#include "PDU_Session_Identity_2.hpp"
#include "logger.hpp"
using namespace nas;
PDU_Session_Identity_2::PDU_Session_Identity_2(uint8_t iei) {
_iei = iei;
}
PDU_Session_Identity_2::PDU_Session_Identity_2(const uint8_t iei, uint8_t value) {
_iei = iei;
_value = value;
}
PDU_Session_Identity_2::PDU_Session_Identity_2() {}
PDU_Session_Identity_2::~PDU_Session_Identity_2() {}
void PDU_Session_Identity_2::setValue(uint8_t value) {
_value = value;
}
uint8_t PDU_Session_Identity_2::getValue() {
return _value;
}
int PDU_Session_Identity_2::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding PDU_Session_Identity_2 iei(0x%x)", _iei);
if (len < 2) {
Logger::nas_mm().error("len is less than 2");
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = _value; encoded_size++;
}
else {
// *(buf + encoded_size) = length - 1; encoded_size++;
// *(buf + encoded_size) = _value; encoded_size++; encoded_size++;
}
Logger::nas_mm().debug("encoded PDU_Session_Identity_2 len(%d)", encoded_size);
return encoded_size;
}
int PDU_Session_Identity_2::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding PDU_Session_Identity_2 iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
_value=0x00;
_value = *(buf + decoded_size); decoded_size++;
Logger::nas_mm().debug("decoded PDU_Session_Identity_2 value(0x%x)", _value);
Logger::nas_mm().debug("decoded PDU_Session_Identity_2 len(%d)", decoded_size);
return decoded_size;
}
#ifndef ___PDU_Session_Identity_2_H_
#define ___PDU_Session_Identity_2_H_
#include <stdint.h>
namespace nas {
class PDU_Session_Identity_2 {
public:
PDU_Session_Identity_2();
PDU_Session_Identity_2(uint8_t iei);
PDU_Session_Identity_2(const uint8_t iei, uint8_t value);
~PDU_Session_Identity_2();
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
void setValue(uint8_t value);
uint8_t getValue();
private:
uint8_t _iei;
uint8_t _value;
};
}
#endif
#include "PDU_Session_Reactivation_Result.hpp"
#include "logger.hpp"
using namespace nas;
PDU_Session_Reactivation_Result::PDU_Session_Reactivation_Result(uint8_t iei) {
_iei = iei;
}
PDU_Session_Reactivation_Result::PDU_Session_Reactivation_Result(const uint8_t iei, uint16_t value) {
_iei = iei;
_value = value;
length = 4;
}
PDU_Session_Reactivation_Result::PDU_Session_Reactivation_Result() {}
PDU_Session_Reactivation_Result::~PDU_Session_Reactivation_Result() {}
void PDU_Session_Reactivation_Result::setValue(uint8_t iei, uint16_t value) {
_iei = iei;
_value = value;
}
uint16_t PDU_Session_Reactivation_Result::getValue() {
return _value;
}
int PDU_Session_Reactivation_Result::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding PDU_Session_Reactivation_Result iei(0x%x)", _iei);
if (len < length) {
Logger::nas_mm().error("len is less than %d", length);
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = length - 2; encoded_size++;
*(buf + encoded_size) = (_value&0x00ff); encoded_size++;
*(buf + encoded_size) = (_value&0xff00)>>8; encoded_size++;
}
else {
//*(buf + encoded_size) = length - 1; encoded_size++;
//*(buf + encoded_size) = _value; encoded_size++; encoded_size++;
}
Logger::nas_mm().debug("encoded PDU_Session_Reactivation_Result len(%d)", encoded_size);
return encoded_size;
}
int PDU_Session_Reactivation_Result::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding PDU_Session_Reactivation_Result iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
_value = 0x0000;
length = *(buf + decoded_size); decoded_size++;
_value |= *(buf + decoded_size); decoded_size++;
_value |= (*(buf + decoded_size))<<8; decoded_size++;
Logger::nas_mm().debug("decoded PDU_Session_Reactivation_Result value(0x%4x)", _value);
Logger::nas_mm().debug("decoded PDU_Session_Reactivation_Result len(%d)", decoded_size);
return decoded_size;
}
#ifndef __PDU_Session_Reactivation_Result_H_
#define __PDU_Session_Reactivation_Result_H_
#include <stdint.h>
namespace nas {
class PDU_Session_Reactivation_Result {
public:
PDU_Session_Reactivation_Result();
PDU_Session_Reactivation_Result(uint8_t iei);
PDU_Session_Reactivation_Result(const uint8_t iei, uint16_t value);
~PDU_Session_Reactivation_Result();
void setValue(uint8_t iei, uint16_t value);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
uint16_t getValue();
private:
uint8_t _iei;
uint8_t length;
uint16_t _value;
};
}
#endif
#include "PDU_Session_Reactivation_Result_Error_Cause.hpp"
#include "logger.hpp"
using namespace nas;
PDU_Session_Reactivation_Result_Error_Cause::PDU_Session_Reactivation_Result_Error_Cause(uint8_t iei) {
_iei = iei;
}
PDU_Session_Reactivation_Result_Error_Cause::PDU_Session_Reactivation_Result_Error_Cause(const uint8_t iei,uint8_t session_id, uint8_t value) {
_iei = iei;
_value = value;
SESSION_ID = session_id;
length = 5;
}
PDU_Session_Reactivation_Result_Error_Cause::PDU_Session_Reactivation_Result_Error_Cause() {}
PDU_Session_Reactivation_Result_Error_Cause::~PDU_Session_Reactivation_Result_Error_Cause() {}
void PDU_Session_Reactivation_Result_Error_Cause::setValue(uint8_t session_id, uint8_t value) {
SESSION_ID = session_id;
_value = value;
}
uint8_t PDU_Session_Reactivation_Result_Error_Cause::getValue() {
return _value;
}
int PDU_Session_Reactivation_Result_Error_Cause::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding PDU_Session_Reactivation_Result_Error_Cause iei(0x%x)", _iei);
if (len < length) {
Logger::nas_mm().error("len is less than %d", length);
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = (length - 3)&0x00ff; encoded_size++;
*(buf + encoded_size) = ((length - 3) & 0xff00)>>8; encoded_size++;
*(buf + encoded_size) = SESSION_ID; encoded_size++;
*(buf + encoded_size) = _value; encoded_size++;
}
else {
// *(buf + encoded_size) = length - 1; encoded_size++;
// *(buf + encoded_size) = _value; encoded_size++; encoded_size++;
}
Logger::nas_mm().debug("encoded PDU_Session_Reactivation_Result_Error_Cause len(%d)", encoded_size);
return encoded_size;
}
int PDU_Session_Reactivation_Result_Error_Cause::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding PDU_Session_Reactivation_Result_Error_Cause iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
_value = 0x00;
length |= *(buf + decoded_size); decoded_size++;
length |= (*(buf + decoded_size))<<8; decoded_size++;
SESSION_ID = *(buf + decoded_size); decoded_size++;
_value = *(buf + decoded_size); decoded_size++;
Logger::nas_mm().debug("decoded PDU_Session_Reactivation_Result_Error_Cause value(0x%x)", _value);
Logger::nas_mm().debug("decoded PDU_Session_Reactivation_Result_Error_Cause len(%d)", decoded_size);
return decoded_size;
}
#ifndef __PDU_Session_Reactivation_Result_Error_Cause_H_
#define __PDU_Session_Reactivation_Result_Error_Cause_H_
#include <stdint.h>
namespace nas {
class PDU_Session_Reactivation_Result_Error_Cause {
public:
PDU_Session_Reactivation_Result_Error_Cause();
PDU_Session_Reactivation_Result_Error_Cause(uint8_t iei);
PDU_Session_Reactivation_Result_Error_Cause(const uint8_t iei,uint8_t session_id, uint8_t value);
~PDU_Session_Reactivation_Result_Error_Cause();
void setValue(uint8_t session_id, uint8_t value);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
uint8_t getValue();
private:
uint8_t _iei;
uint16_t length;
uint8_t SESSION_ID;
uint8_t _value;
};
}
#endif
#include "PDU_Session_Status.hpp"
#include "logger.hpp"
using namespace nas;
PDU_Session_Status::PDU_Session_Status(uint8_t iei) {
_iei = iei;
}
PDU_Session_Status::PDU_Session_Status(const uint8_t iei, uint16_t value) {
_iei = iei;
_value = value;
length = 4;
}
PDU_Session_Status::PDU_Session_Status() {}
PDU_Session_Status::~PDU_Session_Status() {}
void PDU_Session_Status::setValue(uint8_t iei, uint16_t value) {
_iei = iei;
_value = value;
}
uint16_t PDU_Session_Status::getValue() {
return _value;
}
int PDU_Session_Status::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding PDU_Session_Status iei(0x%x)", _iei);
if (len < length) {
Logger::nas_mm().error("len is less than %d", length);
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = length - 2; encoded_size++;
*(buf + encoded_size) = (_value&0xff00)>>8; encoded_size++;
*(buf + encoded_size) = (_value&0x00ff); encoded_size++;
}
else {
//*(buf + encoded_size) = length - 1; encoded_size++;
//*(buf + encoded_size) = _value; encoded_size++; encoded_size++;
}
Logger::nas_mm().debug("encoded PDU_Session_Status len(%d)", encoded_size);
return encoded_size;
}
int PDU_Session_Status::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding PDU_Session_Status iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
_value = 0x0000;
length = *(buf + decoded_size); decoded_size++;
_value |= *(buf + decoded_size); decoded_size++;
_value |= (*(buf + decoded_size))<<8; decoded_size++;
Logger::nas_mm().debug("decoded PDU_Session_Status value(0x%4x)", _value);
Logger::nas_mm().debug("decoded PDU_Session_Status len(%d)", decoded_size);
return decoded_size;
}
#ifndef __PDU_Session_Status_H_
#define __PDU_Session_Status_H_
#include <stdint.h>
namespace nas {
class PDU_Session_Status {
public:
PDU_Session_Status();
PDU_Session_Status(uint8_t iei);
PDU_Session_Status(const uint8_t iei, uint16_t value);
~PDU_Session_Status();
void setValue(uint8_t iei, uint16_t value);
int encode2buffer(uint8_t *buf, int len);
int decodefrombuffer(uint8_t *buf, int len, bool is_option);
uint16_t getValue();
private:
uint8_t _iei;
uint8_t length;
uint16_t _value;
};
}
#endif
#include "PLMN_List.hpp"
#include "logger.hpp"
using namespace nas;
PLMN_List::PLMN_List(uint8_t iei) {
_iei = iei;
}
PLMN_List::PLMN_List(const uint8_t iei, uint8_t MNC_MCC1, uint8_t MNC_MCC2, uint8_t MNC_MCC3) {
_iei = iei;
_MNC_MCC1 = MNC_MCC1;
_MNC_MCC2 = MNC_MCC2;
_MNC_MCC3 = MNC_MCC3;
}
PLMN_List::PLMN_List() {}
PLMN_List::~PLMN_List() {}
void PLMN_List::setMNC_MCC1(uint8_t iei, uint8_t value) {
_iei = iei;
_MNC_MCC1 = value;
}
void PLMN_List::setMNC_MCC2(uint8_t iei, uint8_t value) {
_iei = iei;
_MNC_MCC2 = value;
}
void PLMN_List::setMNC_MCC3(uint8_t iei, uint8_t value) {
_iei = iei;
_MNC_MCC3 = value;
}
uint8_t PLMN_List::getMNC_MCC1() {
return _MNC_MCC1;
}
uint8_t PLMN_List::getMNC_MCC2() {
return _MNC_MCC2;
}
uint8_t PLMN_List::getMNC_MCC3() {
return _MNC_MCC3;
}
int PLMN_List::encode2buffer(uint8_t *buf, int len) {
Logger::nas_mm().debug("encoding PLMN_List iei(0x%x)", _iei);
if (len < 5) {
Logger::nas_mm().error("len is less than 5");
return 0;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei; encoded_size++;
*(buf + encoded_size) = 3; encoded_size++;
*(buf + encoded_size) = (_MNC_MCC1 & 0x0F)|((_MNC_MCC2 & 0x0F)<<4); encoded_size++;
*(buf + encoded_size) = _MNC_MCC3; encoded_size++;
*(buf + encoded_size) = ((_MNC_MCC1 & 0xF0)>>4) | (_MNC_MCC2 & 0xF0); encoded_size++;
}
else {
// *(buf + encoded_size) = length - 1; encoded_size++;
// *(buf + encoded_size) = _value; encoded_size++; encoded_size++;
}
Logger::nas_mm().debug("encoded PLMN_List len(%d)", encoded_size);
return encoded_size;
}
int PLMN_List::decodefrombuffer(uint8_t *buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding PLMN_List iei(0x%x)", *buf);
int decoded_size = 0;
if (is_option) {
decoded_size++;
}
decoded_size++;
_MNC_MCC1 = 0x00;
_MNC_MCC2 = 0x00;
_MNC_MCC3 = 0x00;
_MNC_MCC1 |= *(buf + decoded_size) & 0x0F;
_MNC_MCC2 |=( *(buf + decoded_size) & 0xF0)>>4; decoded_size++;
_MNC_MCC3 = *(buf + decoded_size); decoded_size++;
_MNC_MCC1 |= (*(buf + decoded_size) & 0x0F)<<4;
_MNC_MCC2 |= *(buf + decoded_size) & 0xF0; decoded_size++;
Logger::nas_mm().debug("decoded PLMN_List MNC_MCC1(0x%x),MNC_MCC2(0x%x),MNC_MCC3(0x%x)", _MNC_MCC1,_MNC_MCC2,_MNC_MCC3);
Logger::nas_mm().debug("decoded PLMN_List len(%d)", decoded_size);
return decoded_size;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment