Commit e046c042 authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Update RegistrationType

parent a70b4397
......@@ -20,116 +20,86 @@
*/
#include "5GSRegistrationType.hpp"
#include "3gpp_24.501.hpp"
#include "common_defs.h"
#include "logger.hpp"
using namespace nas;
//------------------------------------------------------------------------------
_5GSRegistrationType::_5GSRegistrationType()
: iei_(0), follow_on_req_(false), reg_type_(0) {}
: Type1NasIeFormatTv(), follow_on_req_(false), reg_type_(0) {
SetIeName("5GS Registration Type");
}
//------------------------------------------------------------------------------
_5GSRegistrationType::_5GSRegistrationType(bool follow_on_req, uint8_t type)
: iei_(0) {
follow_on_req_ = follow_on_req;
reg_type_ = 0x07 & type;
_5GSRegistrationType::_5GSRegistrationType(
const bool& follow_on_req, const uint8_t& type)
: Type1NasIeFormatTv(), follow_on_req_(follow_on_req) {
if (validateValue(follow_on_req, type)) reg_type_ = type;
setValue();
SetIeName(k5gsRegistrationTypeName);
}
//------------------------------------------------------------------------------
_5GSRegistrationType::_5GSRegistrationType(
uint8_t iei, bool follow_on_req, uint8_t type) {
iei_ = 0x0f & iei;
const uint8_t& iei, const bool& follow_on_req, const uint8_t& type)
: Type1NasIeFormatTv(iei) {
follow_on_req_ = follow_on_req;
reg_type_ = 0x07 & type;
if (validateValue(follow_on_req, type)) reg_type_ = type;
setValue();
SetIeName("5GS Registration Type");
}
//------------------------------------------------------------------------------
_5GSRegistrationType::~_5GSRegistrationType() {}
//------------------------------------------------------------------------------
int _5GSRegistrationType::encode2Buffer(uint8_t* buf, int len) {
Logger::nas_mm().error("Encoding 5gsregistrationtype IE");
if (len < kType1IeSize) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kType1IeSize);
return KEncodeDecodeError;
}
uint8_t octet = 0;
uint8_t encoded_size = 0;
if (follow_on_req_) octet = 0b1000;
octet |= reg_type_;
if (!(iei_ & 0x0f)) {
ENCODE_U8(buf, 0x0f & octet, encoded_size);
} else {
ENCODE_U8(buf, (iei_ << 4) | octet, encoded_size);
}
Logger::nas_mm().debug(
"Encoded 5GSRegistrationType IE (%d octet))", encoded_size);
return encoded_size;
void _5GSRegistrationType::setValue() {
if (follow_on_req_)
value_ = 0b1000 | (0x07 & reg_type_);
else
value_ = 0x07 & reg_type_;
}
//------------------------------------------------------------------------------
int _5GSRegistrationType::decodeFromBuffer(
uint8_t* buf, int len, bool is_option) {
if (len < kType1IeSize) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kType1IeSize);
return KEncodeDecodeError;
}
if (is_option) {
return KEncodeDecodeError;
}
Logger::nas_mm().debug("Decoding 5GSRegistrationType");
uint8_t decoded_size = 0;
uint8_t octet = 0;
DECODE_U8(buf, octet, decoded_size);
if (octet & 0x08)
follow_on_req_ = FOLLOW_ON_REQ_PENDING;
else
follow_on_req_ = NO_FOLLOW_ON_REQ_PENDING;
reg_type_ = 0x07 & octet;
void _5GSRegistrationType::getValue() {
follow_on_req_ = (0b1000 & value_) >> 3;
reg_type_ = value_ & 0b00000111;
}
Logger::nas_mm().debug(
"Decoded 5GSRegistrationType IE (%d octet)", decoded_size);
return 0; // to read NAS Key Set Identifier (1/2 octet)
//------------------------------------------------------------------------------
bool _5GSRegistrationType::validateValue(
const bool& follow_on_req, const uint8_t& type) {
if (type > static_cast<uint8_t>(_5GSMobilityIdentityEnum::MAX_VALUE))
return false;
return true;
}
//------------------------------------------------------------------------------
void _5GSRegistrationType::set(
const bool& follow_on_req, const uint8_t& type, const uint8_t& iei) {
follow_on_req_ = follow_on_req;
reg_type_ = 0x07 & type;
iei_ = 0x0f & iei;
if (validateValue(follow_on_req, type)) reg_type_ = type;
setValue();
SetIei(iei);
}
//------------------------------------------------------------------------------
void _5GSRegistrationType::setFollowOnReq(const bool follow_on_req) {
void _5GSRegistrationType::set(const bool& follow_on_req, const uint8_t& type) {
follow_on_req_ = follow_on_req;
if (validateValue(follow_on_req, type)) reg_type_ = type;
setValue();
}
//------------------------------------------------------------------------------
bool _5GSRegistrationType::isFollowOnReq() {
getValue();
return follow_on_req_;
}
//------------------------------------------------------------------------------
void _5GSRegistrationType::setRegType(const uint8_t type) {
reg_type_ = 0x07 & type;
}
//------------------------------------------------------------------------------
uint8_t _5GSRegistrationType::getRegType() {
getValue();
return reg_type_;
}
......@@ -22,22 +22,28 @@
#ifndef _5GS_REGISTRATION_TYPE_H_
#define _5GS_REGISTRATION_TYPE_H_
#include "Type1NasIeFormatTv.hpp"
#include <stdint.h>
constexpr auto k5gsRegistrationTypeName = "5GS Registration Type";
namespace nas {
class _5GSRegistrationType {
class _5GSRegistrationType : public Type1NasIeFormatTv {
public:
_5GSRegistrationType();
_5GSRegistrationType(bool follow_on_req, uint8_t type);
_5GSRegistrationType(uint8_t iei, bool follow_on_req, uint8_t type);
~_5GSRegistrationType();
_5GSRegistrationType(const bool& follow_on_req, const uint8_t& type);
_5GSRegistrationType(
const uint8_t& iei, const bool& follow_on_req, const uint8_t& type);
virtual ~_5GSRegistrationType();
void setValue();
void getValue();
int decodeFromBuffer(uint8_t* buf, int len, bool is_option = false);
int encode2Buffer(uint8_t* buf, int len);
bool validateValue(const bool& follow_on_req, const uint8_t& type);
void set(
const bool& follow_on_req, const uint8_t& type, const uint8_t& iei = 0);
void set(const bool& follow_on_req, const uint8_t& type, const uint8_t& iei);
void set(const bool& follow_on_req, const uint8_t& type);
void setFollowOnReq(const bool is);
bool isFollowOnReq();
......@@ -46,7 +52,6 @@ class _5GSRegistrationType {
uint8_t getRegType();
private:
uint8_t iei_ : 4;
bool follow_on_req_;
uint8_t reg_type_ : 3;
};
......
......@@ -64,8 +64,7 @@ void RegistrationRequest::setHeader(uint8_t security_header_type) {
//------------------------------------------------------------------------------
void RegistrationRequest::set5gsRegistrationType(bool is_for, uint8_t type) {
ie_5gsregistrationtype.setFollowOnReq(is_for);
ie_5gsregistrationtype.setRegType(type);
ie_5gsregistrationtype.set(is_for, type);
}
//------------------------------------------------------------------------------
......@@ -550,7 +549,7 @@ int RegistrationRequest::encode2Buffer(uint8_t* buf, int len) {
encoded_size += encoded_ie_size;
// 5GS Registration Type
if ((encoded_ie_size = ie_5gsregistrationtype.encode2Buffer(
if ((encoded_ie_size = ie_5gsregistrationtype.Encode(
buf + encoded_size, len - encoded_size)) == KEncodeDecodeError) {
Logger::nas_mm().error("Encoding IE 5GS Registration Type error");
return KEncodeDecodeError;
......@@ -843,7 +842,7 @@ int RegistrationRequest::decodeFromBuffer(uint8_t* buf, int len) {
// plain_header = header;
decoded_size = NasMmPlainHeader::decodeFromBuffer(buf, len);
// ie_5gsregistrationtype = new _5GSRegistrationType();
decoded_size += ie_5gsregistrationtype.decodeFromBuffer(
decoded_size += ie_5gsregistrationtype.Decode(
buf + decoded_size, len - decoded_size, false);
decoded_size += ie_ngKSI.decodeFromBuffer(
buf + decoded_size, len - decoded_size, false, true);
......
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