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

Update RegistrationType

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