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

Update NasMmPlainHeader IEs

parent 3c0bd496
......@@ -29,11 +29,22 @@ using namespace nas;
//------------------------------------------------------------------------------
ExtendedProtocolDiscriminator::ExtendedProtocolDiscriminator(const uint8_t& epd)
: epd_(epd) {}
: NasIe(), epd_(epd) {}
//------------------------------------------------------------------------------
ExtendedProtocolDiscriminator::~ExtendedProtocolDiscriminator() {}
//------------------------------------------------------------------------------
bool ExtendedProtocolDiscriminator::Validate(const int& len) const {
if (len < kExtendedProtocolDiscriminatorLength) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kExtendedProtocolDiscriminatorLength);
return false;
}
return true;
}
//------------------------------------------------------------------------------
void ExtendedProtocolDiscriminator::Set(const uint8_t& epd) {
epd_ = epd;
......@@ -50,13 +61,8 @@ uint8_t ExtendedProtocolDiscriminator::Get() const {
}
//------------------------------------------------------------------------------
int ExtendedProtocolDiscriminator::Encode(uint8_t* buf, const uint32_t& len) {
if (len < kType1IeSize) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kType1IeSize);
return KEncodeDecodeError;
}
int ExtendedProtocolDiscriminator::Encode(uint8_t* buf, const int& len) {
if (!Validate(len)) return KEncodeDecodeError;
uint32_t encoded_size = 0;
ENCODE_U8(buf, epd_, encoded_size);
return encoded_size;
......@@ -64,13 +70,8 @@ int ExtendedProtocolDiscriminator::Encode(uint8_t* buf, const uint32_t& len) {
//------------------------------------------------------------------------------
int ExtendedProtocolDiscriminator::Decode(
const uint8_t* const buf, const uint32_t& len) {
if (len < kType1IeSize) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kType1IeSize);
return KEncodeDecodeError;
}
const uint8_t* const buf, const int& len, bool is_iei) {
if (!Validate(len)) return KEncodeDecodeError;
uint32_t decoded_size = 0;
DECODE_U8(buf, epd_, decoded_size);
return decoded_size;
......
......@@ -22,22 +22,27 @@
#ifndef EXTENDED_PROTOCOL_DISCRIMINATOR_H_
#define EXTENDED_PROTOCOL_DISCRIMINATOR_H_
#include "NasIe.hpp"
#include <stdint.h>
constexpr uint8_t kExtendedProtocolDiscriminatorLength = 1;
namespace nas {
class ExtendedProtocolDiscriminator {
class ExtendedProtocolDiscriminator : public NasIe {
public:
ExtendedProtocolDiscriminator(){}; // TODO: = delete;
ExtendedProtocolDiscriminator(const uint8_t& epd);
virtual ~ExtendedProtocolDiscriminator();
bool Validate(const int& len) const override;
void Set(const uint8_t& epd);
void Get(uint8_t& epd) const;
uint8_t Get() const;
int Encode(uint8_t* buf, const uint32_t& len);
int Decode(const uint8_t* const buf, const uint32_t& len);
int Encode(uint8_t* buf, const int& len) override;
int Decode(
const uint8_t* const buf, const int& len, bool is_iei = true) override;
private:
uint8_t epd_;
......
......@@ -29,11 +29,22 @@ using namespace nas;
//------------------------------------------------------------------------------
NasMessageType::NasMessageType(const uint8_t& message_type)
: message_type_(message_type) {}
: NasIe(), message_type_(message_type) {}
//------------------------------------------------------------------------------
NasMessageType::~NasMessageType() {}
//------------------------------------------------------------------------------
bool NasMessageType::Validate(const int& len) const {
if (len < kNasMessageTypeIeSize) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kNasMessageTypeIeSize);
return false;
}
return true;
}
//------------------------------------------------------------------------------
void NasMessageType::Set(const uint8_t& message_type) {
message_type_ = message_type;
......@@ -50,26 +61,18 @@ uint8_t NasMessageType::Get() const {
}
//------------------------------------------------------------------------------
int NasMessageType::Encode(uint8_t* buf, const uint32_t& len) {
if (len < kType1IeSize) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kType1IeSize);
return KEncodeDecodeError;
}
int NasMessageType::Encode(uint8_t* buf, const int& len) {
if (!Validate(len)) return KEncodeDecodeError;
uint32_t encoded_size = 0;
ENCODE_U8(buf, message_type_, encoded_size);
return encoded_size;
}
//------------------------------------------------------------------------------
int NasMessageType::Decode(const uint8_t* const buf, const uint32_t& len) {
if (len < kType1IeSize) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kType1IeSize);
return KEncodeDecodeError;
}
int NasMessageType::Decode(
const uint8_t* const buf, const int& len, bool is_iei) {
if (!Validate(len)) return KEncodeDecodeError;
uint32_t decoded_size = 0;
DECODE_U8(buf, message_type_, decoded_size);
return decoded_size;
......
......@@ -22,24 +22,28 @@
#ifndef _MESSAGE_TYPE_H_
#define _MESSAGE_TYPE_H_
#include "NasIe.hpp"
#include <stdint.h>
constexpr uint8_t kNasMessageTypeIeSize = 1;
namespace nas {
class NasMessageType {
class NasMessageType : public NasIe {
public:
NasMessageType(){}; // TODO: = delete;
NasMessageType(const uint8_t& message_type);
virtual ~NasMessageType();
bool Validate(const int& len) const override;
void Set(const uint8_t& message_type);
void Get(uint8_t& message_type) const;
uint8_t Get() const;
int Encode(uint8_t* buf, const uint32_t& len);
int Decode(const uint8_t* const buf, const uint32_t& len);
int Encode(uint8_t* buf, const int& len) override;
int Decode(
const uint8_t* const buf, const int& len, bool is_iei = false) override;
private:
uint8_t message_type_;
......
......@@ -28,11 +28,22 @@
using namespace nas;
//------------------------------------------------------------------------------
SecurityHeaderType::SecurityHeaderType() {}
SecurityHeaderType::SecurityHeaderType() : NasIe() {}
//------------------------------------------------------------------------------
SecurityHeaderType::~SecurityHeaderType() {}
//------------------------------------------------------------------------------
bool SecurityHeaderType::Validate(const int& len) const {
if (len < kSecurityHeaderTypeLength) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kSecurityHeaderTypeLength);
return false;
}
return true;
}
//------------------------------------------------------------------------------
void SecurityHeaderType::Set(
const uint8_t& secu_header_type, const uint8_t& spare) {
......@@ -51,32 +62,21 @@ uint8_t SecurityHeaderType::Get() const {
}
//------------------------------------------------------------------------------
int SecurityHeaderType::Encode(uint8_t* buf, const uint32_t& len) {
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 value = (secu_header_type_ & 0x0f) | (spare_ & 0xf0);
int SecurityHeaderType::Encode(uint8_t* buf, const int& len) {
if (!Validate(len)) return KEncodeDecodeError;
uint8_t value = (secu_header_type_ & 0x0f) | (spare_ & 0xf0);
uint32_t encoded_size = 0;
ENCODE_U8(buf, value, encoded_size);
return encoded_size;
}
//------------------------------------------------------------------------------
int SecurityHeaderType::Decode(const uint8_t* const buf, const uint32_t& len) {
if (len < kType1IeSize) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kType1IeSize);
return KEncodeDecodeError;
}
int SecurityHeaderType::Decode(
const uint8_t* const buf, const int& len, bool is_iei) {
if (!Validate(len)) return KEncodeDecodeError;
uint8_t value = 0;
uint32_t decoded_size = 0;
DECODE_U8(buf, value, decoded_size);
secu_header_type_ = 0x0f & value;
spare_ = value & 0xf0;
......
......@@ -22,21 +22,27 @@
#ifndef _SECURITY_HEADER_TYPE_H_
#define _SECURITY_HEADER_TYPE_H_
#include "NasIe.hpp"
#include <stdint.h>
constexpr uint8_t kSecurityHeaderTypeLength = 1;
namespace nas {
class SecurityHeaderType {
class SecurityHeaderType : public NasIe {
public:
SecurityHeaderType();
virtual ~SecurityHeaderType();
bool Validate(const int& len) const override;
void Set(const uint8_t& secu_header_type, const uint8_t& spare = 0);
void Get(uint8_t& secu_header_type) const;
uint8_t Get() const;
int Encode(uint8_t* buf, const uint32_t& len);
int Decode(const uint8_t* const buf, const uint32_t& len);
int Encode(uint8_t* buf, const int& len) override;
int Decode(
const uint8_t* const buf, const int& len, bool is_iei = false) override;
private:
uint8_t spare_ : 4;
......
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