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

Update 5GMM Cause

parent 22afd280
......@@ -2279,7 +2279,7 @@ void amf_n1::authentication_failure_handle(
// 1. decode AUTHENTICATION FAILURE message
auto auth_failure = std::make_unique<AuthenticationFailure>();
auth_failure->Decode(NULL, (uint8_t*) bdata(plain_msg), blength(plain_msg));
auth_failure->Decode((uint8_t*) bdata(plain_msg), blength(plain_msg));
uint8_t mm_cause = auth_failure->get5GMmCause();
if (mm_cause == -1) {
Logger::amf_n1().error("Missing mandatory IE 5G_MM_CAUSE");
......
......@@ -26,81 +26,83 @@
using namespace nas;
//------------------------------------------------------------------------------
_5GMM_Cause::_5GMM_Cause(uint8_t iei, uint8_t value) {
_iei = iei;
_value = value;
_5GMM_Cause::_5GMM_Cause(uint8_t iei) : Type3NasIe(iei) {
value_ = 0;
SetIeName(k5gmmCauseIeName);
}
//------------------------------------------------------------------------------
void _5GMM_Cause::setValue(uint8_t value) {
_value = value;
_5GMM_Cause::_5GMM_Cause() : Type3NasIe() {
value_ = 0;
SetIeName(k5gmmCauseIeName);
}
//------------------------------------------------------------------------------
uint8_t _5GMM_Cause::getValue() {
return _value;
_5GMM_Cause::_5GMM_Cause(uint8_t iei, uint8_t value) : Type3NasIe(iei) {
value_ = value;
SetIeName(k5gmmCauseIeName);
}
//------------------------------------------------------------------------------
_5GMM_Cause::_5GMM_Cause() {
_iei = 0;
_value = 0;
_5GMM_Cause::~_5GMM_Cause(){};
//------------------------------------------------------------------------------
void _5GMM_Cause::SetValue(uint8_t value) {
value_ = value;
}
//------------------------------------------------------------------------------
_5GMM_Cause::~_5GMM_Cause(){};
uint8_t _5GMM_Cause::GetValue() const {
return value_;
}
//------------------------------------------------------------------------------
void _5GMM_Cause::set(uint8_t iei, uint8_t value) {
_iei = iei;
_value = value;
void _5GMM_Cause::Set(uint8_t iei, uint8_t value) {
SetIei(iei);
value_ = value;
}
//------------------------------------------------------------------------------
int _5GMM_Cause::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding _5GMM_Cause IE ");
Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
if (len < k5gmmCauseMaximumLength) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
k5gmmCauseMaximumLength);
return KEncodeDecodeError;
}
int encoded_size = 0;
if (_iei) {
if (len < k5gmmCauseMaximumLength) {
Logger::nas_mm().error(
"Buffer length is less than the length of this IE (%d octet)",
k5gmmCauseMaximumLength);
return KEncodeDecodeError;
}
ENCODE_U8(buf + encoded_size, _iei, encoded_size);
}
ENCODE_U8(buf + encoded_size, _value, encoded_size);
// IEI
encoded_size += Type3NasIe::Encode(buf + encoded_size, len);
// Value
ENCODE_U8(buf + encoded_size, value_, encoded_size);
Logger::nas_mm().debug("Encoded _5GMM_Cause IE (len %d)", encoded_size);
Logger::nas_mm().debug(
"Encoded %s, len (%d)", GetIeName().c_str(), encoded_size);
return encoded_size;
}
//------------------------------------------------------------------------------
int _5GMM_Cause::Decode(uint8_t* buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding _5GMM_Cause IE");
int decoded_size = 0;
if (is_option) {
DECODE_U8(buf + decoded_size, _iei, decoded_size); // for IE
if (len < k5gmmCauseMaximumLength) {
Logger::nas_mm().error(
"Buffer length is less than the length of this IE (%d octet)",
k5gmmCauseMaximumLength);
return KEncodeDecodeError;
}
} else {
if (len < k5gmmCauseMinimumLength) {
Logger::nas_mm().error(
"Buffer length is less than the length of this IE (%d octet)",
k5gmmCauseMinimumLength);
return KEncodeDecodeError;
}
int _5GMM_Cause::Decode(uint8_t* buf, int len, bool is_iei) {
Logger::nas_mm().debug("Decoding %s", GetIeName().c_str());
if (len < k5gmmCauseMinimumLength) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
k5gmmCauseMinimumLength);
return KEncodeDecodeError;
}
DECODE_U8(buf + decoded_size, _value, decoded_size);
int decoded_size = 0;
// IEI and Length
decoded_size += Type3NasIe::Decode(buf + decoded_size, len, true);
DECODE_U8(buf + decoded_size, value_, decoded_size);
Logger::nas_mm().debug("Decoded value 0x%x", value_);
Logger::nas_mm().debug(
"Decoded _5GMM_Cause (len %d octet), 5G Cause 0x%x", decoded_size,
_value);
"Decoded %s, len (%d)", GetIeName().c_str(), decoded_size);
return decoded_size;
}
......@@ -22,6 +22,7 @@
#ifndef __5GMM_Cause_H
#define __5GMM_Cause_H
#include "Type3NasIe.hpp"
#include <stdint.h>
enum class _5gmmCauseEnum {
......@@ -69,22 +70,26 @@ enum class _5gmmCauseEnum {
constexpr uint8_t k5gmmCauseMinimumLength = 1;
constexpr uint8_t k5gmmCauseMaximumLength = 2;
constexpr auto k5gmmCauseIeName = "5GMM Cause";
namespace nas {
class _5GMM_Cause {
class _5GMM_Cause : public Type3NasIe {
public:
_5GMM_Cause();
_5GMM_Cause(uint8_t iei);
_5GMM_Cause(uint8_t _iei, uint8_t value);
~_5GMM_Cause();
int Encode(uint8_t* buf, int len);
int Decode(uint8_t* buf, int len, bool is_option);
void set(uint8_t _iei, uint8_t value);
void setValue(uint8_t value);
uint8_t getValue();
int Decode(uint8_t* buf, int len, bool is_iei);
void Set(uint8_t _iei, uint8_t value);
void SetValue(uint8_t value);
uint8_t GetValue() const;
private:
uint8_t _iei;
uint8_t _value;
uint8_t value_;
};
} // namespace nas
......
......@@ -19,13 +19,6 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#include "AuthenticationFailure.hpp"
#include "3gpp_24.501.hpp"
......@@ -34,10 +27,9 @@
using namespace nas;
//------------------------------------------------------------------------------
AuthenticationFailure::AuthenticationFailure() {
plain_header = NULL;
ie_5gmm_cause = NULL;
ie_authentication_failure_parameter = NULL;
AuthenticationFailure::AuthenticationFailure()
: NasMmPlainHeader(EPD_5GS_MM_MSG, AUTHENTICATION_FAILURE) {
ie_authentication_failure_parameter = std::nullopt;
}
//------------------------------------------------------------------------------
......@@ -45,33 +37,28 @@ AuthenticationFailure::~AuthenticationFailure() {}
//------------------------------------------------------------------------------
void AuthenticationFailure::SetHeader(uint8_t security_header_type) {
plain_header = new NasMmPlainHeader();
plain_header->SetHeader(
EPD_5GS_MM_MSG, security_header_type, AUTHENTICATION_FAILURE);
NasMmPlainHeader::SetSecurityHeaderType(security_header_type);
}
//------------------------------------------------------------------------------
void AuthenticationFailure::Set5gmmCause(uint8_t value) {
ie_5gmm_cause = new _5GMM_Cause(0x00, value);
ie_5gmm_cause.SetValue(value);
}
//------------------------------------------------------------------------------
uint8_t AuthenticationFailure::get5GMmCause() {
if (ie_5gmm_cause) {
return ie_5gmm_cause->getValue();
} else {
return -1;
}
return ie_5gmm_cause.GetValue();
}
//------------------------------------------------------------------------------
void AuthenticationFailure::setAuthentication_Failure_Parameter(bstring auts) {
void AuthenticationFailure::setAuthentication_Failure_Parameter(
const bstring& auts) {
ie_authentication_failure_parameter =
new Authentication_Failure_Parameter(0x30, auts);
std::make_optional<Authentication_Failure_Parameter>(0x30, auts);
}
bool AuthenticationFailure::getAutsInAuthFailPara(bstring& auts) {
if (ie_authentication_failure_parameter) {
ie_authentication_failure_parameter->getValue(auts);
if (ie_authentication_failure_parameter.has_value()) {
ie_authentication_failure_parameter.value().getValue(auts);
return true;
} else {
return false;
......@@ -81,51 +68,68 @@ bool AuthenticationFailure::getAutsInAuthFailPara(bstring& auts) {
//------------------------------------------------------------------------------
int AuthenticationFailure::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding AuthenticationFailure message");
int encoded_size = 0;
if (!plain_header) {
Logger::nas_mm().error("Mandatory IE missing Header");
return 0;
int encoded_size = 0;
int encoded_ie_size = 0;
// Header
if ((encoded_ie_size = NasMmPlainHeader::Encode(buf, len)) ==
KEncodeDecodeError) {
Logger::nas_mm().error("Encoding NAS Header error");
return KEncodeDecodeError;
}
if (!(plain_header->Encode(buf, len))) return 0;
encoded_size += 3;
if (!ie_5gmm_cause) {
Logger::nas_mm().warn("IE ie_5gmm_cause is not available");
encoded_size += encoded_ie_size;
int size = ie_5gmm_cause.Encode(buf + encoded_size, len - encoded_size);
if (size != KEncodeDecodeError) {
encoded_size += size;
} else {
if (int size =
ie_5gmm_cause->Encode(buf + encoded_size, len - encoded_size)) {
encoded_size += size;
} else {
Logger::nas_mm().error("Encoding ie_5gmm_cause error");
}
Logger::nas_mm().error("Encoding ie_5gmm_cause error");
return KEncodeDecodeError;
}
if (!ie_authentication_failure_parameter) {
if (!ie_authentication_failure_parameter.has_value()) {
Logger::nas_mm().warn(
"IE ie_authentication_failure_parameter is not available");
} else {
if (int size = ie_authentication_failure_parameter->Encode(
buf + encoded_size, len - encoded_size)) {
size = ie_authentication_failure_parameter.value().Encode(
buf + encoded_size, len - encoded_size);
if (size != KEncodeDecodeError) {
encoded_size += size;
} else {
Logger::nas_mm().error(
"Encoding ie_authentication_failure_parameter error");
return 0;
return KEncodeDecodeError;
}
}
Logger::nas_mm().debug(
"Encoded AuthenticationFailure message len (%d)", encoded_size);
return 1;
return encoded_size;
}
//------------------------------------------------------------------------------
int AuthenticationFailure::Decode(
NasMmPlainHeader* header, uint8_t* buf, int len) {
int AuthenticationFailure::Decode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Decoding AuthenticationFailure message");
int decoded_size = 3;
plain_header = header;
ie_5gmm_cause = new _5GMM_Cause();
decoded_size +=
ie_5gmm_cause->Decode(buf + decoded_size, len - decoded_size, false);
int decoded_size = 0;
int decoded_result = 0;
// Header
decoded_result = NasMmPlainHeader::Decode(buf, len);
if (decoded_result == KEncodeDecodeError) {
Logger::nas_mm().error("Decoding NAS Header error");
return KEncodeDecodeError;
}
decoded_size += decoded_result;
// 5GMM Cause
if ((decoded_result = ie_5gmm_cause.Decode(
buf + decoded_size, len - decoded_size, false)) ==
KEncodeDecodeError)
return decoded_result;
decoded_size += decoded_result;
Logger::nas_mm().debug("Decoded_size (%d)", decoded_size);
uint8_t octet = *(buf + decoded_size);
Logger::nas_mm().debug("First option IEI (0x%x)", octet);
......@@ -133,10 +137,16 @@ int AuthenticationFailure::Decode(
switch (octet) {
case 0x30: {
Logger::nas_mm().debug("Decoding IEI (0x30)");
Authentication_Failure_Parameter
ie_authentication_failure_parameter_tmp = {};
if ((decoded_result = ie_authentication_failure_parameter_tmp.Decode(
buf + decoded_size, len - decoded_size, true)) ==
KEncodeDecodeError)
return decoded_result;
decoded_size += decoded_result;
ie_authentication_failure_parameter =
new Authentication_Failure_Parameter();
decoded_size += ie_authentication_failure_parameter->Decode(
buf + decoded_size, len - decoded_size, true);
std::optional<Authentication_Failure_Parameter>(
ie_authentication_failure_parameter_tmp);
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet);
} break;
......@@ -144,5 +154,5 @@ int AuthenticationFailure::Decode(
}
Logger::nas_mm().debug(
"Decoded AuthenticationFailure message len (%d)", decoded_size);
return 1;
return decoded_size;
}
......@@ -19,37 +19,33 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef _AuthenticationFailure_H_
#define _AuthenticationFailure_H_
#ifndef _AUTHENTICATION_FAILURE_H_
#define _AUTHENTICATION_FAILURE_H_
#include "NasIeHeader.hpp"
namespace nas {
class AuthenticationFailure {
class AuthenticationFailure : public NasMmPlainHeader {
public:
AuthenticationFailure();
~AuthenticationFailure();
int Encode(uint8_t* buf, int len);
int Decode(NasMmPlainHeader* header, uint8_t* buf, int len);
int Decode(uint8_t* buf, int len);
void SetHeader(uint8_t security_header_type);
void Set5gmmCause(uint8_t value);
void setAuthentication_Failure_Parameter(bstring auts);
void Set5gmmCause(uint8_t value);
uint8_t get5GMmCause();
void setAuthentication_Failure_Parameter(const bstring& auts);
bool getAutsInAuthFailPara(bstring& auts);
public:
NasMmPlainHeader* plain_header;
_5GMM_Cause* ie_5gmm_cause;
Authentication_Failure_Parameter* ie_authentication_failure_parameter;
_5GMM_Cause ie_5gmm_cause; // Mandatory
std::optional<Authentication_Failure_Parameter>
ie_authentication_failure_parameter; // Optional
};
} // namespace nas
......
......@@ -199,7 +199,6 @@ int AuthenticationRequest::Decode(uint8_t* buf, int len) {
} break;
case kIeiAuthenticationParameterAutn: {
Authentication_Parameter_AUTN ie_authentication_parameter_autn_tmp = {};
if ((decoded_result = ie_authentication_parameter_autn_tmp.Decode(
buf + decoded_size, len - decoded_size, true)) ==
KEncodeDecodeError)
......
......@@ -80,6 +80,6 @@ int DeregistrationAccept::Decode(uint8_t* buf, int len) {
decoded_size += decoded_result;
Logger::nas_mm().debug(
"decoded De-registrationReject message len (%d)", decoded_size);
"Decoded De-registrationReject message len (%d)", decoded_size);
return decoded_size;
}
......@@ -19,13 +19,6 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author
\date 2020
\email: contact@openairinterface.org
*/
#ifndef _DEREGISTRATION_REQUEST_H_
#define _DEREGISTRATION_REQUEST_H_
......
......@@ -46,7 +46,7 @@ void RegistrationReject::SetHeader(uint8_t security_header_type) {
//------------------------------------------------------------------------------
void RegistrationReject::Set5gmmCause(uint8_t value) {
ie_5gmm_cause.setValue(value);
ie_5gmm_cause.SetValue(value);
}
//------------------------------------------------------------------------------
......
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