Commit 3c0bd496 authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Add base classes for NAS IEs

parent 9d8b594d
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#define FILE_3GPP_29_500_SEEN #define FILE_3GPP_29_500_SEEN
// SMF + AMF + 3GPP TS 29.571 (Common data) // SMF + AMF + 3GPP TS 29.571 (Common data)
enum class http_response_codes_e { enum class http_response_codes_e : uint16_t {
HTTP_RESPONSE_CODE_0 = 0, HTTP_RESPONSE_CODE_0 = 0,
HTTP_RESPONSE_CODE_200_OK = 200, HTTP_RESPONSE_CODE_200_OK = 200,
HTTP_RESPONSE_CODE_201_CREATED = 201, HTTP_RESPONSE_CODE_201_CREATED = 201,
......
...@@ -27,7 +27,15 @@ ...@@ -27,7 +27,15 @@
constexpr uint8_t kType1IeSize = 1; constexpr uint8_t kType1IeSize = 1;
// Extended Protocol Discriminator (EPD) // Extended Protocol Discriminator (EPD)
// TODO: replaced by emum
#define EPD_5GS_MM_MSG 0b01111110 #define EPD_5GS_MM_MSG 0b01111110
#define EPD_5GS_SM_MSG 0b00101110 #define EPD_5GS_SM_MSG 0b00101110
// Extended Protocol Discriminator (EPD)
enum class EPDEnum {
EPD_RESERVED = 0b00001110,
_5GS_SESSION_MANAGEMENT_MESSAGE = 0b00101110,
_5GS_MOBILITY_MANAGEMENT_MESSAGE = 0b01111110
};
#endif #endif
...@@ -99,16 +99,18 @@ enum class RegistrationTypeEnum { ...@@ -99,16 +99,18 @@ enum class RegistrationTypeEnum {
/********* 5GSMobilityIdentity **********/ /********* 5GSMobilityIdentity **********/
enum class _5GSMobilityIdentityEnum { enum class _5GSMobilityIdentityEnum : uint8_t {
NO_IDENTITY = 0b000, NO_IDENTITY = 0b000,
SUCI = 0b001, SUCI = 0b001,
_5G_GUTI = 0b010, _5G_GUTI = 0b010,
IMEI = 0b011, IMEI = 0b011,
_5G_S_TMSI = 0b100, _5G_S_TMSI = 0b100,
IMEISV = 0b101, IMEISV = 0b101,
MAC_ADDRESS = 0b110 MAC_ADDRESS = 0b110,
MAX_VALUE = MAC_ADDRESS
}; };
// Type of Identity
#define NO_IDENTITY 0b000 #define NO_IDENTITY 0b000
#define SUCI 0b001 #define SUCI 0b001
#define _5G_GUTI 0b010 #define _5G_GUTI 0b010
...@@ -120,6 +122,7 @@ enum class _5GSMobilityIdentityEnum { ...@@ -120,6 +122,7 @@ enum class _5GSMobilityIdentityEnum {
#define EVEN_IENTITY 0 #define EVEN_IENTITY 0
#define ODD_IDENTITY 1 #define ODD_IDENTITY 1
// SUPI format
#define SUPI_FORMAT_IMSI 0b000 #define SUPI_FORMAT_IMSI 0b000
#define SUPI_FORMAT_NETWORK_SPECIFIC_IDENTIFIER 0b001 #define SUPI_FORMAT_NETWORK_SPECIFIC_IDENTIFIER 0b001
......
/*
* 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
*/
#include "NasIe.hpp"
#include "3gpp_24.501.hpp"
#include "common_defs.h"
#include "logger.hpp"
using namespace nas;
//------------------------------------------------------------------------------
NasIe::NasIe() {
ie_name_ = {};
}
//------------------------------------------------------------------------------
NasIe::~NasIe() {}
//------------------------------------------------------------------------------
void NasIe::SetIeName(const std::string& name) {
ie_name_ = name;
}
//------------------------------------------------------------------------------
std::string NasIe::GetIeName() const {
return ie_name_;
}
//------------------------------------------------------------------------------
void NasIe::GetIeName(std::string& name) const {
name = ie_name_;
}
/*
* 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
*/
#ifndef _NAS_IE_H_
#define _NAS_IE_H_
#include <optional>
namespace nas {
class NasIe {
public:
NasIe();
virtual ~NasIe();
virtual bool Validate(const int& len) const = 0;
void SetIeName(const std::string& name);
std::string GetIeName() const;
void GetIeName(std::string& name) const;
virtual int Encode(uint8_t* buf, const int& len) = 0;
virtual int Decode(
const uint8_t* const buf, const int& len, bool is_option = false) = 0;
protected:
std::string ie_name_;
};
} // namespace nas
#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
*/
#include "Type1NasIe.hpp"
#include "3gpp_24.501.hpp"
#include "common_defs.h"
#include "logger.hpp"
using namespace nas;
//------------------------------------------------------------------------------
Type1NasIe::Type1NasIe() : NasIe(), high_pos_(false), value_(0) {
iei_ = std::nullopt;
}
//------------------------------------------------------------------------------
Type1NasIe::Type1NasIe(const bool& high_pos, const uint8_t& value) {
iei_ = std::nullopt;
high_pos_ = high_pos;
value_ = value & 0x0f;
}
//------------------------------------------------------------------------------
Type1NasIe::Type1NasIe(const bool& high_pos) : value_() {
iei_ = std::nullopt;
high_pos_ = high_pos;
}
//------------------------------------------------------------------------------
Type1NasIe::Type1NasIe(const uint8_t& iei, const uint8_t& value) : NasIe() {
iei_ = std::optional<uint8_t>(iei & 0x0f);
high_pos_ = false;
value_ = value & 0x0f;
}
//------------------------------------------------------------------------------
Type1NasIe::Type1NasIe(const uint8_t& iei) : NasIe(), value_() {
iei_ = std::optional<uint8_t>(iei & 0x0f);
high_pos_ = false;
}
//------------------------------------------------------------------------------
Type1NasIe::~Type1NasIe() {}
/*
//------------------------------------------------------------------------------
void Type1NasIe::SetIei(const uint8_t& iei) {
iei_ = std::optional<uint8_t>(iei & 0x0f);
high_pos_ = false;
}
*/
//------------------------------------------------------------------------------
void Type1NasIe::Set(const bool& high_pos, const uint8_t& value) {
high_pos_ = high_pos;
value_ = value & 0x0f;
}
//------------------------------------------------------------------------------
void Type1NasIe::Set(const bool& high_pos) {
high_pos_ = high_pos;
}
//------------------------------------------------------------------------------
bool Type1NasIe::Validate(const int& len) const {
if (len < kType1NasIeLength) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kType1NasIeLength);
return false;
}
return true;
}
//------------------------------------------------------------------------------
void Type1NasIe::SetValue(const uint8_t& value) {
value_ = value & 0x0f; // 4 lower bits
}
//------------------------------------------------------------------------------
int Type1NasIe::Encode(uint8_t* buf, const int& len) {
Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
if (!Validate(len)) return KEncodeDecodeError;
int encoded_size = 0;
uint8_t octet = 0;
if (iei_.has_value()) {
octet = (iei_.value() << 4) | value_;
} else {
int decoded_size = 0;
// First get value of this octet
DECODE_U8(buf + encoded_size, octet, decoded_size);
if (high_pos_) {
octet =
(octet & 0x0f) | (value_ << 4); // Keep 4 less significant bits and
// update 4 most significant bits
} else {
octet = (octet & 0xf0) | (value_); // Keep 4 most significant bits and
// update 4 less significant bits
}
}
ENCODE_U8(buf + encoded_size, octet, encoded_size);
Logger::nas_mm().debug(
"Encoded %s (len %d)", GetIeName().c_str(), encoded_size);
if (iei_.has_value()) {
return encoded_size; // 1 octet
} else {
return 0; // 1/2 octet
}
}
//------------------------------------------------------------------------------
int Type1NasIe::Decode(const uint8_t* const buf, const int& len, bool is_iei) {
return Decode(buf, len, false, is_iei);
}
//------------------------------------------------------------------------------
int Type1NasIe::Decode(
const uint8_t* const buf, const int& len, const bool& high_pos,
bool is_iei) {
Logger::nas_mm().debug("Decoding %s", GetIeName().c_str());
if (!Validate(len)) return KEncodeDecodeError;
high_pos_ = high_pos;
int decoded_size = 0;
uint8_t octet = 0;
DECODE_U8(buf + decoded_size, octet, decoded_size);
if (is_iei) {
iei_ = std::optional<uint8_t>((octet & 0xf0) >> 4);
value_ = octet & 0x0f;
} else {
if (high_pos_) {
value_ = (octet & 0xf0) >> 4;
} else {
value_ = (octet & 0x0f);
}
}
Logger::nas_mm().debug(
"Decoded %s (len %d)", GetIeName().c_str(), decoded_size);
if (is_iei) {
return decoded_size; // 1 octet
} else {
return 0; // 1/2 octet
}
}
/*
* 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
*/
#ifndef _TYPE1_NAS_IE_H_
#define _TYPE1_NAS_IE_H_
#include "NasIe.hpp"
constexpr uint8_t kType1NasIeLength = 1;
namespace nas {
class Type1NasIe : public NasIe {
public:
Type1NasIe();
Type1NasIe(const bool& high_pos, const uint8_t& value);
Type1NasIe(const bool& high_pos);
Type1NasIe(const uint8_t& iei, const uint8_t& value);
Type1NasIe(const uint8_t& iei);
virtual ~Type1NasIe();
bool Validate(const int& len) const override;
// void SetIei(const uint8_t& iei);
void Set(const bool& high_pos, const uint8_t& value);
void Set(const bool& high_pos);
void SetValue(const uint8_t& value);
int Encode(uint8_t* buf, const int& len) override;
int Decode(
const uint8_t* const buf, const int& len, bool is_iei = true) override;
int Decode(
const uint8_t* const buf, const int& len, const bool& high_pos,
bool is_iei = false);
protected:
virtual void SetValue() = 0;
virtual void GetValue() = 0;
std::optional<uint8_t>
iei_; // IEI present in Format TV (in bit position 8,7,6,5)
bool high_pos_; // choose bit position for Format V
uint8_t value_; // value (in bit positions 4,3,2,1 or 8,7,6,5)
};
} // namespace nas
#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
*/
#include "Type1NasIeFormatTv.hpp"
#include "3gpp_24.501.hpp"
#include "common_defs.h"
#include "logger.hpp"
using namespace nas;
//------------------------------------------------------------------------------
Type1NasIeFormatTv::Type1NasIeFormatTv() : NasIe(), value_(0) {
iei_ = std::nullopt;
}
//------------------------------------------------------------------------------
Type1NasIeFormatTv::Type1NasIeFormatTv(const uint8_t& iei)
: NasIe(), value_(0) {
iei_ = std::optional<uint8_t>(iei & 0x0f);
}
//------------------------------------------------------------------------------
Type1NasIeFormatTv::~Type1NasIeFormatTv() {}
//------------------------------------------------------------------------------
void Type1NasIeFormatTv::SetIei(const uint8_t& iei) {
iei_ = std::optional<uint8_t>(iei & 0x0f);
}
//------------------------------------------------------------------------------
bool Type1NasIeFormatTv::Validate(const int& len) const {
if (len < kType1NasIeFormatTvLength) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kType1NasIeFormatTvLength);
return false;
}
return true;
}
//------------------------------------------------------------------------------
void Type1NasIeFormatTv::SetValue(const uint8_t& value) {
value_ = value & 0x0f; // 4 lower bits
}
//------------------------------------------------------------------------------
int Type1NasIeFormatTv::Encode(uint8_t* buf, const int& len) {
Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
if (!Validate(len)) return KEncodeDecodeError;
int encoded_size = 0;
uint8_t octet = 0;
if (iei_.has_value()) {
octet = (iei_.value() << 4) | value_;
} else {
octet = value_ & 0x0f;
}
ENCODE_U8(buf + encoded_size, octet, encoded_size);
Logger::nas_mm().debug(
"Encoded %s (len %d)", GetIeName().c_str(), encoded_size);
if (iei_.has_value()) {
return encoded_size; // 1 octet
} else {
return 0; // 1/2 octet
}
}
//------------------------------------------------------------------------------
int Type1NasIeFormatTv::Decode(
const uint8_t* const buf, const int& len, bool is_iei) {
Logger::nas_mm().debug("Decoding %s", GetIeName().c_str());
if (!Validate(len)) return KEncodeDecodeError;
int decoded_size = 0;
uint8_t octet = 0;
DECODE_U8(buf + decoded_size, octet, decoded_size);
if (is_iei) {
iei_ = std::optional<uint8_t>((octet & 0xf0) >> 4);
}
value_ = octet & 0x0f;
Logger::nas_mm().debug(
"Decoded %s (len %d)", GetIeName().c_str(), decoded_size);
if (is_iei) {
return decoded_size; // 1 octet
} else {
return 0; // 1/2 octet
}
}
/*
* 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
*/
#ifndef _TYPE1_NAS_IE_FORMAT_TV_H_
#define _TYPE1_NAS_IE_FORMAT_TV_H_
#include "NasIe.hpp"
constexpr uint8_t kType1NasIeFormatTvLength = 1;
namespace nas {
class Type1NasIeFormatTv : public NasIe {
public:
Type1NasIeFormatTv();
Type1NasIeFormatTv(const uint8_t& iei);
virtual ~Type1NasIeFormatTv();
bool Validate(const int& len) const override;
void SetIei(const uint8_t& iei);
void SetValue(const uint8_t& value);
void SetValue();
void GetValue();
int Encode(uint8_t* buf, const int& len) override;
int Decode(
const uint8_t* const buf, const int& len, bool is_iei = true) override;
protected:
std::optional<uint8_t> iei_; // in bit position 5,6,7,8 of an octet
uint8_t value_; // value in bit positions 4, 3, 2, 1 of an octet
};
} // namespace nas
#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
*/
#include "Type1NasIeFormatV.hpp"
#include "3gpp_24.501.hpp"
#include "common_defs.h"
#include "logger.hpp"
using namespace nas;
//------------------------------------------------------------------------------
Type1NasIeFormatV::Type1NasIeFormatV() : NasIe(), high_pos_(false), value_(0) {}
//------------------------------------------------------------------------------
Type1NasIeFormatV::Type1NasIeFormatV(const bool& high_pos)
: NasIe(), value_(0) {
high_pos_ = high_pos;
}
//------------------------------------------------------------------------------
Type1NasIeFormatV::Type1NasIeFormatV(const bool& high_pos, const uint8_t& value)
: NasIe() {
high_pos_ = high_pos;
value_ = value & 0x0f;
}
//------------------------------------------------------------------------------
Type1NasIeFormatV::~Type1NasIeFormatV() {}
//------------------------------------------------------------------------------
bool Type1NasIeFormatV::Validate(const int& len) const {
if (len < kType1NasIeFormatVLength) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kType1NasIeFormatVLength);
return false;
}
return true;
}
//------------------------------------------------------------------------------
void Type1NasIeFormatV::Set(const bool& high_pos, const uint8_t& value) {
high_pos_ = high_pos;
value_ = value & 0x0f; // 4 bits
}
//------------------------------------------------------------------------------
void Type1NasIeFormatV::Set(const uint8_t& value) {
value_ = value & 0x0f; // 4 bits
}
//------------------------------------------------------------------------------
int Type1NasIeFormatV::Encode(uint8_t* buf, const int& len) {
Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
if (!Validate(len)) return KEncodeDecodeError;
int encoded_size = 0;
int decoded_size = 0;
uint8_t octet = 0;
// First get value of this octet
DECODE_U8(buf + encoded_size, octet, decoded_size);
if (high_pos_) {
octet = (octet & 0x0f) | (value_ << 4); // Keep 4 less significant bits and
// update 4 most significant bits
} else {
octet = (octet & 0xf0) | (value_); // Keep 4 most significant bits and
// update 4 less significant bits
}
ENCODE_U8(buf + encoded_size, octet, encoded_size);
Logger::nas_mm().debug(
"Encoded %s (len %d)", GetIeName().c_str(), encoded_size);
return 0; // 1/2 octet
}
//------------------------------------------------------------------------------
int Type1NasIeFormatV::Decode(
const uint8_t* const buf, const int& len, bool high_pos) {
Logger::nas_mm().debug("Decoding %s", GetIeName().c_str());
if (!Validate(len)) return KEncodeDecodeError;
high_pos_ = high_pos;
int decoded_size = 0;
uint8_t octet = 0;
DECODE_U8(buf + decoded_size, octet, decoded_size);
if (high_pos_) {
value_ = (octet & 0xf0) >> 4;
} else {
value_ = (octet & 0x0f);
}
Logger::nas_mm().debug(
"Decoded %s (len %d)", GetIeName().c_str(), decoded_size);
return 0; // 1/2 octet
}
/*
* 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
*/
#ifndef _TYPE1_NAS_IE_FORMAT_V_H_
#define _TYPE1_NAS_IE_FORMAT_V_H_
#include "NasIe.hpp"
constexpr uint8_t kType1NasIeFormatVLength = 1;
namespace nas {
class Type1NasIeFormatV : public NasIe {
public:
Type1NasIeFormatV();
Type1NasIeFormatV(const bool& high_pos);
Type1NasIeFormatV(const bool& high_pos, const uint8_t& value);
virtual ~Type1NasIeFormatV();
bool Validate(const int& len) const override;
void Set(const bool& high_pos, const uint8_t& value);
void Set(const uint8_t& value);
int Encode(uint8_t* buf, const int& len) override;
int Decode(
const uint8_t* const buf, const int& len, bool high_pos = false) override;
protected:
bool high_pos_;
uint8_t value_; // only for value in bit positions 8, 7, 6, 5 of an octet
// in case of value in bit positions 4, 3, 2, 1 of an octet,
// use Type1NasIeFormatTV instead)
};
} // namespace nas
#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
*/
#include "Type2NasIeFormatT.hpp"
#include "3gpp_24.501.hpp"
#include "common_defs.h"
#include "logger.hpp"
using namespace nas;
//------------------------------------------------------------------------------
Type2NasIeFormatT::Type2NasIeFormatT() : NasIe() {
iei_ = 0;
}
//------------------------------------------------------------------------------
Type2NasIeFormatT::Type2NasIeFormatT(const uint8_t& iei) : NasIe() {
iei_ = iei;
}
//------------------------------------------------------------------------------
Type2NasIeFormatT::~Type2NasIeFormatT() {}
//------------------------------------------------------------------------------
bool Type2NasIeFormatT::Validate(const int& len) const {
if (len < kType2NasIeFormatTLength) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kType2NasIeFormatTLength);
return false;
}
return true;
}
//------------------------------------------------------------------------------
int Type2NasIeFormatT::Encode(uint8_t* buf, const int& len) {
Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
if (!Validate(len)) return KEncodeDecodeError;
int encoded_size = 0;
ENCODE_U8(buf + encoded_size, iei_, encoded_size);
Logger::nas_mm().debug(
"Encoded %s (len %d)", GetIeName().c_str(), encoded_size);
return encoded_size; // 1 octet
}
//------------------------------------------------------------------------------
int Type2NasIeFormatT::Decode(
const uint8_t* const buf, const int& len, bool is_iei) {
Logger::nas_mm().debug("Decoding %s", GetIeName().c_str());
if (!Validate(len)) return KEncodeDecodeError;
int decoded_size = 0;
DECODE_U8(buf + decoded_size, iei_, decoded_size);
Logger::nas_mm().debug(
"Decoded %s (len %d)", GetIeName().c_str(), decoded_size);
return decoded_size; // 1 octet
}
/*
* 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
*/
#ifndef _TYPE2_NAS_IE_FORMAT_T_H_
#define _TYPE2_NAS_IE_FORMAT_T_H_
#include "NasIe.hpp"
constexpr uint8_t kType2NasIeFormatTLength = 1;
namespace nas {
class Type2NasIeFormatT : public NasIe {
public:
Type2NasIeFormatT();
Type2NasIeFormatT(const uint8_t& iei);
virtual ~Type2NasIeFormatT();
bool Validate(const int& len) const override;
int Encode(uint8_t* buf, const int& len) override;
int Decode(
const uint8_t* const buf, const int& len, bool is_iei = true) override;
protected:
uint8_t iei_; // 1 byte
};
} // namespace nas
#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
*/
#include "Type3NasIe.hpp"
#include "3gpp_24.501.hpp"
#include "common_defs.h"
#include "logger.hpp"
using namespace nas;
//------------------------------------------------------------------------------
Type3NasIe::Type3NasIe() : NasIe() {
iei_ = std::nullopt;
}
//------------------------------------------------------------------------------
Type3NasIe::Type3NasIe(const uint8_t& iei) : NasIe() {
iei_ = std::optional<uint8_t>(iei);
}
//------------------------------------------------------------------------------
Type3NasIe::~Type3NasIe() {}
//------------------------------------------------------------------------------
void Type3NasIe::SetIei(const uint8_t& iei) {
iei_ = std::optional<uint8_t>(iei);
}
//------------------------------------------------------------------------------
bool Type3NasIe::Validate(const int& len) const {
if (iei_.has_value() and (len < kType3NasIeFormatTvLength)) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kType3NasIeFormatTvLength);
return false;
}
return true;
}
/*
* 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
*/
#ifndef _TYPE3_NAS_IE_H_
#define _TYPE3_NAS_IE_H_
#include "NasIe.hpp"
constexpr uint8_t kType3NasIeFormatTvLength = 1;
namespace nas {
class Type3NasIe : public NasIe {
public:
Type3NasIe();
Type3NasIe(const uint8_t& iei);
virtual ~Type3NasIe();
bool Validate(const int& len) const override;
void SetIei(const uint8_t& iei);
int Encode(uint8_t* buf, const int& len) override;
int Decode(
const uint8_t* const buf, const int& len, bool is_iei = false) override;
protected:
std::optional<uint8_t> iei_; // IEI present format TV
};
} // namespace nas
#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
*/
#include "Type4NasIe.hpp"
#include "3gpp_24.501.hpp"
#include "common_defs.h"
#include "logger.hpp"
using namespace nas;
//------------------------------------------------------------------------------
Type4NasIe::Type4NasIe() : NasIe() {
iei_ = std::nullopt;
li_ = 0;
}
//------------------------------------------------------------------------------
Type4NasIe::Type4NasIe(const uint8_t& iei) : NasIe() {
iei_ = std::optional<uint8_t>(iei);
}
//------------------------------------------------------------------------------
Type4NasIe::~Type4NasIe() {}
//------------------------------------------------------------------------------
void Type4NasIe::SetIei(const uint8_t& iei) {
iei_ = std::optional<uint8_t>(iei);
}
//------------------------------------------------------------------------------
bool Type4NasIe::Validate(const int& len) const {
uint8_t actual_lengh = iei_.has_value() ? li_ + 1 : li_;
if (len < actual_lengh) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
actual_lengh);
return false;
}
return true;
}
/*
* 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
*/
#ifndef _TYPE4_NAS_IE_H_
#define _TYPE4_NAS_IE_H_
#include "NasIe.hpp"
namespace nas {
class Type4NasIe : public NasIe {
public:
Type4NasIe();
Type4NasIe(const uint8_t& iei);
virtual ~Type4NasIe();
bool Validate(const int& len) const override;
void SetIei(const uint8_t& iei);
int Encode(uint8_t* buf, const int& len) override;
int Decode(
const uint8_t* const buf, const int& len, bool is_iei = false) override;
protected:
std::optional<uint8_t> iei_; // IEI present in format TLV
uint8_t li_; // length indicator, 1 byte
};
} // namespace nas
#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
*/
#include "Type6NasIe.hpp"
#include "3gpp_24.501.hpp"
#include "common_defs.h"
#include "logger.hpp"
using namespace nas;
//------------------------------------------------------------------------------
Type6NasIe::Type6NasIe() : NasIe() {
iei_ = std::nullopt;
li_ = 0;
}
//------------------------------------------------------------------------------
Type6NasIe::Type6NasIe(const uint8_t& iei) : NasIe() {
iei_ = std::optional<uint8_t>(iei);
}
//------------------------------------------------------------------------------
Type6NasIe::~Type6NasIe() {}
//------------------------------------------------------------------------------
void Type6NasIe::SetIei(const uint8_t& iei) {
iei_ = std::optional<uint8_t>(iei);
}
//------------------------------------------------------------------------------
bool Type6NasIe::Validate(const int& len) const {
uint16_t actual_lengh = iei_.has_value() ? li_ + 1 : li_;
if (len < actual_lengh) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
actual_lengh);
return false;
}
return true;
}
/*
* 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
*/
#ifndef _TYPE6_NAS_IE_H_
#define _TYPE6_NAS_IE_H_
#include "NasIe.hpp"
namespace nas {
class Type6NasIe : public NasIe {
public:
Type6NasIe();
Type6NasIe(const uint8_t& iei);
virtual ~Type6NasIe();
bool Validate(const int& len) const override;
void SetIei(const uint8_t& iei);
int Encode(uint8_t* buf, const int& len) override;
int Decode(
const uint8_t* const buf, const int& len, bool is_iei = false) override;
protected:
std::optional<uint8_t> iei_; // IEI present in format TLV-E
uint16_t li_; // length indicator, 2 bytes
};
} // namespace nas
#endif
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