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

Code cleanup

parent f5b19b56
......@@ -92,6 +92,8 @@ constexpr uint8_t kIei5gmmCapability = 0x10;
constexpr uint8_t kIeiUeSecurityCapability = 0x2e;
constexpr uint8_t kIeiUeNetworkCapability = 0x17;
constexpr uint8_t kIeiUplinkDataStatus = 0x40;
constexpr uint8_t kT3502Value = 0x16;
constexpr uint8_t kEquivalentPlmns = 0x4A;
......
......@@ -73,7 +73,10 @@ int _5GMMCapability::Encode(uint8_t* buf, int len) {
int encoded_size = 0;
// IEI and Length
encoded_size += Type4NasIe::Encode(buf + encoded_size, len);
int encoded_header_size = Type4NasIe::Encode(buf + encoded_size, len);
if (encoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
encoded_size += encoded_header_size;
// Octet 3
ENCODE_U8(buf + encoded_size, octet3_, encoded_size);
// TODO: Encode spare for the rest
......@@ -89,7 +92,7 @@ int _5GMMCapability::Encode(uint8_t* buf, int len) {
}
//------------------------------------------------------------------------------
int _5GMMCapability::Decode(uint8_t* buf, int len, bool is_option) {
int _5GMMCapability::Decode(uint8_t* buf, int len, bool is_iei) {
if (len < k5gmmCapabilityMinimumLength) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
......@@ -102,7 +105,10 @@ int _5GMMCapability::Decode(uint8_t* buf, int len, bool is_option) {
Logger::nas_mm().debug("Decoding %s", GetIeName().c_str());
// IEI and Length
decoded_size += Type4NasIe::Decode(buf + decoded_size, len, is_option);
int decoded_header_size = Type4NasIe::Decode(buf + decoded_size, len, is_iei);
// decoded_size += Type4NasIe::Decode(buf + decoded_size, len, is_iei);
if (decoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
decoded_size += decoded_header_size;
DECODE_U8(buf + decoded_size, octet3_, decoded_size);
// TODO: decode the rest as spare for now
......
......@@ -43,7 +43,7 @@ class _5GMMCapability : public Type4NasIe {
uint8_t GetOctet3() const;
int Encode(uint8_t* buf, int len);
int Decode(uint8_t* buf, int len, bool is_option = true);
int Decode(uint8_t* buf, int len, bool is_iei = true);
private:
uint8_t octet3_; // minimum length of 3 octets
......
......@@ -73,7 +73,9 @@ int NSSAI::Encode(uint8_t* buf, int len) {
int encoded_size = 0;
// IEI and Length
encoded_size += Type4NasIe::Encode(buf + encoded_size, len);
int encoded_header_size = Type4NasIe::Encode(buf + encoded_size, len);
if (encoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
encoded_size += encoded_header_size;
for (int i = 0; i < S_NSSAIs.size(); i++) {
// TODO: Define encode for SNSSAI_s
......@@ -122,7 +124,10 @@ int NSSAI::Decode(uint8_t* buf, int len, bool is_iei) {
SNSSAI_s a = {0, 0, 0, 0};
// IEI and Length
decoded_size += Type4NasIe::Decode(buf + decoded_size, len, is_iei);
int decoded_header_size = Type4NasIe::Decode(buf + decoded_size, len, is_iei);
// decoded_size += Type4NasIe::Decode(buf + decoded_size, len, is_iei);
if (decoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
decoded_size += decoded_header_size;
int length_tmp = GetLengthIndicator();
......
......@@ -59,24 +59,41 @@ void Type4NasIe::GetLengthIndicator(uint8_t& li) const {
uint8_t Type4NasIe::GetLengthIndicator() const {
return li_;
}
//------------------------------------------------------------------------------
uint8_t Type4NasIe::GetIeLength() const {
return (iei_.has_value() ? (li_ + 2) : (li_ + 1)); // 1 for IEI, 1 for Length
}
//------------------------------------------------------------------------------
uint8_t Type4NasIe::GetHeaderLength() const {
return (iei_.has_value() ? 2 : 1); // 1 for IEI, 1 for Length
}
//------------------------------------------------------------------------------
bool Type4NasIe::Validate(const int& len) const {
uint8_t actual_lengh =
iei_.has_value() ? (li_ + 2) : (li_ + 1); // 1 for IEI and 1 for LI
if (len < actual_lengh) {
int ie_len = GetIeLength(); // Length of the content + IEI/Len
if (len < ie_len) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
actual_lengh);
"Buffer length is less than the length of this IE (%d octet(s))",
ie_len);
return false;
}
return true;
}
//------------------------------------------------------------------------------
bool Type4NasIe::ValidateHeader(const int& len) const {
int header_len = GetHeaderLength(); // Length of IEI/Len
if (len < header_len) {
Logger::nas_mm().error(
"Buffer length is less than the length of the header (IEI/Length) of "
"this IE (%d octet(s))",
header_len);
return false;
}
return true;
}
//------------------------------------------------------------------------------
int Type4NasIe::Encode(uint8_t* buf, const int& len) {
if (!Validate(len)) return KEncodeDecodeError;
......@@ -93,7 +110,7 @@ int Type4NasIe::Encode(uint8_t* buf, const int& len) {
//------------------------------------------------------------------------------
int Type4NasIe::Decode(const uint8_t* const buf, const int& len, bool is_iei) {
if (!Validate(len)) return KEncodeDecodeError;
if (!ValidateHeader(len)) return KEncodeDecodeError;
int decoded_size = 0;
uint8_t octet = 0;
......@@ -105,7 +122,8 @@ int Type4NasIe::Decode(const uint8_t* const buf, const int& len, bool is_iei) {
DECODE_U8(buf + decoded_size, li_, decoded_size);
// Logger::nas_mm().debug(
// "Decoded %s (len %d)", GetIeName().c_str(), decoded_size);
// after obtaining information for IEI/Length, validate the buffer size
if (!Validate(len)) return KEncodeDecodeError;
return decoded_size;
}
......@@ -32,12 +32,14 @@ class Type4NasIe : public NasIe {
virtual ~Type4NasIe();
bool Validate(const int& len) const override;
bool ValidateHeader(const int& len) const;
void SetIei(const uint8_t& iei);
void SetLengthIndicator(const uint8_t& li);
void GetLengthIndicator(uint8_t& li) const;
uint8_t GetLengthIndicator() const;
uint8_t GetIeLength() const;
uint8_t GetHeaderLength() const;
int Encode(uint8_t* buf, const int& len) override;
int Decode(
......
......@@ -93,7 +93,10 @@ int UENetworkCapability::Encode(uint8_t* buf, int len) {
int encoded_size = 0;
// IEI and Length
encoded_size += Type4NasIe::Encode(buf + encoded_size, len);
int encoded_header_size = Type4NasIe::Encode(buf + encoded_size, len);
if (encoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
encoded_size += encoded_header_size;
// EEA
ENCODE_U8(buf + encoded_size, eea_, encoded_size);
// EIA
......@@ -124,7 +127,10 @@ int UENetworkCapability::Decode(uint8_t* buf, int len, bool is_iei) {
int decoded_size = 0;
// IEI and Length
decoded_size += Type4NasIe::Decode(buf + decoded_size, len, is_iei);
int decoded_header_size = Type4NasIe::Decode(buf + decoded_size, len, is_iei);
// decoded_size += Type4NasIe::Decode(buf + decoded_size, len, is_iei);
if (decoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
decoded_size += decoded_header_size;
DECODE_U8(buf + decoded_size, eea_, decoded_size);
DECODE_U8(buf + decoded_size, eia_, decoded_size);
......
......@@ -159,7 +159,9 @@ int UESecurityCapability::Encode(uint8_t* buf, int len) {
int encoded_size = 0;
// IEI and Length
encoded_size += Type4NasIe::Encode(buf + encoded_size, len);
int encoded_header_size = Type4NasIe::Encode(buf + encoded_size, len);
if (encoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
encoded_size += encoded_header_size;
// EA
ENCODE_U8(buf + encoded_size, _5g_ea_, encoded_size);
......@@ -195,7 +197,10 @@ int UESecurityCapability::Decode(uint8_t* buf, int len, bool is_iei) {
uint8_t octet = 0;
// IEI and Length
decoded_size += Type4NasIe::Decode(buf + decoded_size, len, is_iei);
int decoded_header_size = Type4NasIe::Decode(buf + decoded_size, len, is_iei);
// decoded_size += Type4NasIe::Decode(buf + decoded_size, len, is_iei);
if (decoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
decoded_size += decoded_header_size;
// EA
DECODE_U8(buf + decoded_size, _5g_ea_, decoded_size);
// IA
......
......@@ -23,77 +23,71 @@
#include "3gpp_24.501.hpp"
#include "common_defs.h"
#include "Ie_Const.hpp"
#include "logger.hpp"
using namespace nas;
//------------------------------------------------------------------------------
UplinkDataStatus::UplinkDataStatus(uint8_t iei) {
_iei = iei;
UplinkDataStatus::UplinkDataStatus() : Type4NasIe(kIeiUplinkDataStatus) {
_value = 0;
length = 0;
SetLengthIndicator(2);
SetIeName(kUplinkDataStatusIeName);
}
//------------------------------------------------------------------------------
UplinkDataStatus::UplinkDataStatus(const uint8_t& iei, const uint16_t& value) {
_iei = iei;
UplinkDataStatus::UplinkDataStatus(const uint16_t& value)
: Type4NasIe(kIeiUplinkDataStatus) {
_value = value;
length = 2;
}
//------------------------------------------------------------------------------
UplinkDataStatus::UplinkDataStatus() {
_iei = 0;
_value = 0;
length = 0;
SetLengthIndicator(2);
SetIeName(kUplinkDataStatusIeName);
}
//-----------------------------------------------------------------------------
UplinkDataStatus::~UplinkDataStatus() {}
//------------------------------------------------------------------------------
void UplinkDataStatus::setValue(uint8_t iei, uint16_t value) {
_iei = iei;
void UplinkDataStatus::SetValue(uint16_t value) {
_value = value;
}
//------------------------------------------------------------------------------
uint16_t UplinkDataStatus::getValue() {
uint16_t UplinkDataStatus::GetValue() const {
return _value;
}
//------------------------------------------------------------------------------
int UplinkDataStatus::encode2Buffer(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding UplinkDataStatus IEI (0x%x)", _iei);
if (len < kUplinkDataStatusMinimumLength) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kUplinkDataStatusMinimumLength);
return KEncodeDecodeError;
}
Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
int encoded_size = 0;
if (_iei) {
ENCODE_U8(buf + encoded_size, _iei, encoded_size);
}
// IEI and Length
int encoded_header_size = Type4NasIe::Encode(buf + encoded_size, len);
if (encoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
encoded_size += encoded_header_size;
ENCODE_U8(buf + encoded_size, length, encoded_size);
// Value
ENCODE_U16(buf + encoded_size, _value, encoded_size);
Logger::nas_mm().debug("Encoded UplinkDataStatus, size (%d)", encoded_size);
Logger::nas_mm().debug(
"Encoded %s, len (%d)", GetIeName().c_str(), encoded_size);
return encoded_size;
}
//------------------------------------------------------------------------------
int UplinkDataStatus::decodeFromBuffer(uint8_t* buf, int len, bool is_option) {
Logger::nas_mm().debug("Decoding UplinkDataStatus");
int UplinkDataStatus::decodeFromBuffer(uint8_t* buf, int len, bool is_iei) {
Logger::nas_mm().debug("Decoding %s", GetIeName().c_str());
int decoded_size = 0;
if (is_option) {
DECODE_U8(buf + decoded_size, _iei, decoded_size);
}
DECODE_U8(buf + decoded_size, length, decoded_size);
// IEI and Length
int decoded_header_size = Type4NasIe::Decode(buf + decoded_size, len, is_iei);
if (decoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
decoded_size += decoded_header_size;
DECODE_U16(buf + decoded_size, _value, decoded_size);
Logger::nas_mm().debug(
"Decoded UplinkDataStatus value 0x%x, len %d", _value, decoded_size);
"Decoded %s, value 0x%x len %d", GetIeName().c_str(), _value,
decoded_size);
return decoded_size;
}
......@@ -19,30 +19,32 @@
* contact@openairinterface.org
*/
#ifndef __UplinkDataStatus_H_
#define __UplinkDataStatus_H_
#ifndef _UPLINK_DATA_STATUS_H_
#define _UPLINK_DATA_STATUS_H_
#include "Type4NasIe.hpp"
#include <stdint.h>
constexpr uint8_t kUplinkDataStatusMinimumLength = 4;
constexpr uint8_t kUplinkDataStatusMaximumLength = 34;
constexpr auto kUplinkDataStatusIeName = "Uplink Data Status";
namespace nas {
class UplinkDataStatus {
class UplinkDataStatus : public Type4NasIe {
public:
UplinkDataStatus();
UplinkDataStatus(uint8_t);
UplinkDataStatus(const uint8_t& iei, const uint16_t& value);
UplinkDataStatus(const uint16_t& value);
~UplinkDataStatus();
void setValue(uint8_t iei, uint16_t value);
void SetValue(uint16_t value);
uint16_t GetValue() const;
int encode2Buffer(uint8_t* buf, int len);
int decodeFromBuffer(uint8_t* buf, int len, bool is_option);
uint16_t getValue();
int decodeFromBuffer(uint8_t* buf, int len, bool is_iei);
private:
uint8_t _iei;
uint8_t length;
uint16_t _value;
// TODO: spare
};
......
......@@ -291,13 +291,13 @@ bool RegistrationRequest::getS1UeNetworkCapability(uint8_t& eea, uint8_t& eia) {
//------------------------------------------------------------------------------
void RegistrationRequest::setUplinkDataStatus(const uint16_t& value) {
ie_uplink_data_status = std::make_optional<UplinkDataStatus>(0x40, value);
ie_uplink_data_status = std::make_optional<UplinkDataStatus>(value);
}
//------------------------------------------------------------------------------
bool RegistrationRequest::getUplinkDataStatus(uint16_t& value) {
if (ie_uplink_data_status.has_value()) {
value = ie_uplink_data_status.value().getValue();
value = ie_uplink_data_status.value().GetValue();
return true;
} else {
return false;
......@@ -954,7 +954,7 @@ int RegistrationRequest::decodeFromBuffer(uint8_t* buf, int len) {
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI 0x%x", octet);
} break;
case 0x40: {
case kIeiUplinkDataStatus: {
Logger::nas_mm().debug("Decoding IEI(0x40)");
UplinkDataStatus ie_uplink_data_status_tmp = {};
decoded_size += ie_uplink_data_status_tmp.decodeFromBuffer(
......
......@@ -155,14 +155,14 @@ class RegistrationRequest : public NasMmPlainHeader {
std::optional<UESecurityCapability> ie_ue_security_capability; // Optional
std::optional<NSSAI> ie_requested_NSSAI; // Optional
std::optional<_5GSTrackingAreaIdentity>
ie_last_visited_registered_TAI; // Optional
ie_last_visited_registered_TAI; // Optional
std::optional<UENetworkCapability> ie_s1_ue_network_capability; // Optional
std::optional<UplinkDataStatus> ie_uplink_data_status; // Optional
std::optional<PDUSessionStatus> ie_PDU_session_status; // Optional
std::optional<MICOIndication> ie_MICO_indication; // Optional
std::optional<UEStatus> ie_ue_status; // Optional
std::optional<_5GSMobileIdentity> ie_additional_guti; // Optional
std::optional<UplinkDataStatus> ie_uplink_data_status; // Optional
std::optional<PDUSessionStatus> ie_PDU_session_status; // Optional
std::optional<MICOIndication> ie_MICO_indication; // Optional
std::optional<UEStatus> ie_ue_status; // Optional
std::optional<_5GSMobileIdentity> ie_additional_guti; // Optional
std::optional<AllowedPDUSessionStatus>
ie_allowed_PDU_session_status; // Optional
std::optional<UEUsageSetting> ie_ues_usage_setting; // Optional
......
......@@ -74,7 +74,7 @@ void ServiceRequest::set5G_S_TMSI(
//------------------------------------------------------------------------------
void ServiceRequest::setUplink_data_status(uint16_t value) {
ie_uplink_data_status = new UplinkDataStatus(0x40, value);
ie_uplink_data_status = new UplinkDataStatus(value);
}
//------------------------------------------------------------------------------
......@@ -207,7 +207,7 @@ int ServiceRequest::decodeFromBuffer(
Logger::nas_mm().debug("First optional IE (0x%x)", octet);
while ((octet != 0x0)) {
switch (octet) {
case 0x40: {
case kIeiUplinkDataStatus: {
Logger::nas_mm().debug("Decoding ie_uplink_data_status (IEI: 0x40)");
ie_uplink_data_status = new UplinkDataStatus();
decoded_size += ie_uplink_data_status->decodeFromBuffer(
......@@ -261,7 +261,7 @@ bool ServiceRequest::getngKSI(uint8_t& ng_ksi) {
//------------------------------------------------------------------------------
uint16_t ServiceRequest::getUplinkDataStatus() {
if (ie_uplink_data_status) {
return ie_uplink_data_status->getValue();
return ie_uplink_data_status->GetValue();
} else {
return -1;
}
......
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