Commit 4f9b867a authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Update Authentication Request/Response

parent 87fc2c3c
......@@ -2190,12 +2190,11 @@ void amf_n1::authentication_response_handle(
// Decode AUTHENTICATION RESPONSE message
auto auth_response = std::make_unique<AuthenticationResponse>();
auth_response->Decode(
nullptr, (uint8_t*) bdata(plain_msg), blength(plain_msg));
auth_response->Decode((uint8_t*) bdata(plain_msg), blength(plain_msg));
bstring resStar = nullptr;
bool isAuthOk = true;
// Get response RES*
if (!auth_response->getAuthenticationResponseParameter(resStar)) {
if (!auth_response->GetAuthenticationResponseParameter(resStar)) {
Logger::amf_n1().warn(
"Cannot receive AuthenticationResponseParameter (RES*)");
} else {
......
......@@ -100,9 +100,10 @@ constexpr uint8_t kIeiAuthenticationParameterAutn = 0x20;
constexpr uint8_t kIeiAuthenticationParameterRand = 0x21;
constexpr uint8_t kIei5gsNetworkFeatureSupport = 0x21;
constexpr uint8_t kIeiAllowedPduSessionStatus = 0x25;
constexpr uint8_t kIeiPduSessionReactivationResult = 0x26;
constexpr uint8_t kIeiUeStatus = 0x2b;
constexpr uint8_t kIeiAllowedPduSessionStatus = 0x25;
constexpr uint8_t kIeiPduSessionReactivationResult = 0x26;
constexpr uint8_t kIeiUeStatus = 0x2b;
constexpr uint8_t kIeiAuthenticationResponseParameter = 0x2D;
constexpr uint8_t kIeiUeSecurityCapability = 0x2e;
constexpr uint8_t kIeiUeNetworkCapability = 0x17;
......
......@@ -34,7 +34,7 @@
#include "Authentication_Failure_Parameter.hpp"
#include "Authentication_Parameter_AUTN.hpp"
#include "Authentication_Parameter_RAND.hpp"
#include "Authentication_Response_Parameter.hpp"
#include "AuthenticationResponseParameter.hpp"
#include "DNN.hpp"
#include "EapMessage.hpp"
#include "EpsBearerContextStatus.hpp"
......
......@@ -19,87 +19,96 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#include "Authentication_Response_Parameter.hpp"
#include "AuthenticationResponseParameter.hpp"
#include "logger.hpp"
using namespace nas;
//------------------------------------------------------------------------------
Authentication_Response_Parameter::Authentication_Response_Parameter(
uint8_t iei) {
_iei = iei;
AuthenticationResponseParameter::AuthenticationResponseParameter()
: Type4NasIe(kIeiAuthenticationResponseParameter), res_or_res_star_() {
SetLengthIndicator(4); // Minimum length for the content (RES or RES*)
SetIeName(kAuthenticationResponseParameterIeName);
}
//------------------------------------------------------------------------------
Authentication_Response_Parameter::Authentication_Response_Parameter(
const uint8_t iei, bstring para) {
_iei = iei;
PARA = bstrcpy(para);
AuthenticationResponseParameter::AuthenticationResponseParameter(bstring para)
: Type4NasIe(kIeiAuthenticationResponseParameter) {
res_or_res_star_ = bstrcpy(para);
SetLengthIndicator(blength(res_or_res_star_));
SetIeName(kAuthenticationResponseParameterIeName);
}
//------------------------------------------------------------------------------
Authentication_Response_Parameter::Authentication_Response_Parameter() {}
AuthenticationResponseParameter::~AuthenticationResponseParameter() {}
//------------------------------------------------------------------------------
Authentication_Response_Parameter::~Authentication_Response_Parameter() {}
void AuthenticationResponseParameter::SetValue(const bstring& para) {
res_or_res_star_ = bstrcpy(para);
}
//------------------------------------------------------------------------------
void Authentication_Response_Parameter::getValue(bstring& para) {
para = bstrcpy(PARA);
void AuthenticationResponseParameter::GetValue(bstring& para) const {
para = bstrcpy(res_or_res_star_);
}
//------------------------------------------------------------------------------
int Authentication_Response_Parameter::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug(
"Encoding Authentication_Response_Parameter IEI 0x%x", _iei);
if (len < 18) {
Logger::nas_mm().error("len is less than 18");
return 0;
int AuthenticationResponseParameter::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
int ie_len = GetIeLength();
if (len < ie_len) {
Logger::nas_mm().error("Len is less than %d", ie_len);
return KEncodeDecodeError;
}
int encoded_size = 0;
if (_iei) {
*(buf + encoded_size) = _iei;
encoded_size++;
*(buf + encoded_size) = 16;
encoded_size++;
int size = encode_bstring(PARA, (buf + encoded_size), len - encoded_size);
encoded_size += size;
return encoded_size;
} else {
// *(buf + encoded_size) = length - 1; encoded_size++;
// *(buf + encoded_size) = _value; encoded_size++; 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;
// Value
int size = encode_bstring(
res_or_res_star_, (buf + encoded_size), len - encoded_size);
encoded_size += size;
Logger::nas_mm().debug(
"Encoded Authentication_Response_Parameter (len %d)", encoded_size);
"Encoded %s, len (%d)", GetIeName().c_str(), encoded_size);
return encoded_size;
}
//------------------------------------------------------------------------------
int Authentication_Response_Parameter::Decode(
uint8_t* buf, int len, bool is_option) {
Logger::nas_mm().debug(
"Decoding Authentication_Response_Parameter IEI 0x%x", *buf);
int decoded_size = 0;
uint8_t length = 0;
if (is_option) {
decoded_size++;
int AuthenticationResponseParameter::Decode(
uint8_t* buf, int len, bool is_iei) {
if (len < kAuthenticationResponseParameterMinimumLength) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kAuthenticationResponseParameterMinimumLength);
return KEncodeDecodeError;
}
length = *(buf + decoded_size);
decoded_size++;
decode_bstring(&PARA, length, (buf + decoded_size), len - decoded_size);
decoded_size += length;
for (int i = 0; i < length; i++) {
uint8_t decoded_size = 0;
uint8_t octet = 0;
Logger::nas_mm().debug("Decoding %s", GetIeName().c_str());
// 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;
// RES or RES*
uint16_t ie_len = GetLengthIndicator();
decode_bstring(
&res_or_res_star_, ie_len, (buf + decoded_size), len - decoded_size);
decoded_size += ie_len;
for (int i = 0; i < ie_len; i++) {
Logger::nas_mm().debug(
"Decoded NAS_Message_Container value 0x%x", (uint8_t) PARA->data[i]);
"Decoded value 0x%x", (uint8_t) res_or_res_star_->data[i]);
}
Logger::nas_mm().debug(
"Decoded Authentication_Response_Parameter (len %d)", decoded_size);
"Decoded %s, len (%d)", GetIeName().c_str(), decoded_size);
return decoded_size;
}
......@@ -19,40 +19,32 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef _AUTHENTICATION_RESPONSE_PARAMETER_H_
#define _AUTHENTICATION_RESPONSE_PARAMETER_H_
#ifndef __Authentication_Response_Parameter_H_
#define __Authentication_Response_Parameter_H_
#include <stdint.h>
#include "Type4NasIe.hpp"
#include <iostream>
extern "C" {
#include "TLVDecoder.h"
#include "TLVEncoder.h"
#include "bstrlib.h"
}
constexpr uint8_t kAuthenticationResponseParameterMinimumLength = 6;
constexpr uint8_t kAuthenticationResponseParameterMaximumLength = 18;
constexpr auto kAuthenticationResponseParameterIeName =
"Authentication Response Parameter";
namespace nas {
class Authentication_Response_Parameter {
class AuthenticationResponseParameter : public Type4NasIe {
public:
Authentication_Response_Parameter();
Authentication_Response_Parameter(uint8_t iei);
Authentication_Response_Parameter(const uint8_t iei, bstring para);
~Authentication_Response_Parameter();
// void setValue(uint8_t iei, uint8_t value);
AuthenticationResponseParameter();
AuthenticationResponseParameter(bstring para);
~AuthenticationResponseParameter();
int Encode(uint8_t* buf, int len);
int Decode(uint8_t* buf, int len, bool is_option);
void getValue(bstring& para);
int Decode(uint8_t* buf, int len, bool is_iei);
void SetValue(const bstring& para);
void GetValue(bstring& para) const;
private:
uint8_t _iei;
bstring PARA;
bstring res_or_res_star_;
};
} // namespace nas
......
......@@ -19,13 +19,6 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#include "AuthenticationReject.hpp"
#include "3gpp_24.501.hpp"
......@@ -34,9 +27,9 @@
using namespace nas;
//------------------------------------------------------------------------------
AuthenticationReject::AuthenticationReject() {
plain_header = NULL;
ie_eap_message = NULL;
AuthenticationReject::AuthenticationReject()
: NasMmPlainHeader(EPD_5GS_MM_MSG, AUTHENTICATION_REJECT) {
ie_eap_message = std::nullopt;
}
//------------------------------------------------------------------------------
......@@ -44,31 +37,33 @@ AuthenticationReject::~AuthenticationReject() {}
//------------------------------------------------------------------------------
void AuthenticationReject::setHeader(uint8_t security_header_type) {
plain_header = new NasMmPlainHeader();
plain_header->setHeader(
EPD_5GS_MM_MSG, security_header_type, AUTHENTICATION_REJECT);
NasMmPlainHeader::SetSecurityHeaderType(security_header_type);
}
//------------------------------------------------------------------------------
void AuthenticationReject::setEAP_Message(bstring eap) {
ie_eap_message = new EapMessage(0x78, eap);
void AuthenticationReject::SetEapMessage(const bstring& eap) {
ie_eap_message = std::make_optional<EapMessage>(kIeiEapMessage, eap);
}
//------------------------------------------------------------------------------
int AuthenticationReject::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding AuthenticationReject 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_eap_message) {
encoded_size += encoded_ie_size;
if (!ie_eap_message.has_value()) {
Logger::nas_mm().warn("IE ie_eap_message is not available");
} else {
if (int size =
ie_eap_message->Encode(buf + encoded_size, len - encoded_size)) {
if (int size = ie_eap_message.value().Encode(
buf + encoded_size, len - encoded_size)) {
encoded_size += size;
} else {
Logger::nas_mm().error("Encoding ie_eap_message error");
......@@ -81,27 +76,39 @@ int AuthenticationReject::Encode(uint8_t* buf, int len) {
}
//------------------------------------------------------------------------------
int AuthenticationReject::Decode(
NasMmPlainHeader* header, uint8_t* buf, int len) {
int AuthenticationReject::Decode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Decoding AuthenticationReject message");
int decoded_size = 3;
plain_header = header;
Logger::nas_mm().debug("Decoded_size (%d)", decoded_size);
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;
// IEIs
uint8_t octet = *(buf + decoded_size);
Logger::nas_mm().debug("First option IEI (0x%x)", octet);
while ((octet != 0x0)) {
switch (octet) {
case 0x78: {
Logger::nas_mm().debug("Decoding IEI (0x78)");
ie_eap_message = new EapMessage();
decoded_size += ie_eap_message->Decode(
buf + decoded_size, len - decoded_size, true);
octet = *(buf + decoded_size);
case kIeiEapMessage: {
Logger::nas_mm().debug("Decoding IEI 0x%x", kIeiEapMessage);
EapMessage ie_eap_message_tmp = {};
if ((decoded_result = ie_eap_message_tmp.Decode(
buf + decoded_size, len - decoded_size, true)) ==
KEncodeDecodeError)
return decoded_result;
decoded_size += decoded_result;
ie_eap_message = std::optional<EapMessage>(ie_eap_message_tmp);
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet);
} break;
}
}
Logger::nas_mm().debug(
"Decoded AuthenticationReject message len (%d)", decoded_size);
return 1;
return decoded_size;
}
......@@ -19,32 +19,27 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef _AuthenticationReject_H_
#define _AuthenticationReject_H_
#ifndef _AUTHENTICATION_REJECT_H_
#define _AUTHENTICATION_REJECT_H_
#include "NasIeHeader.hpp"
namespace nas {
class AuthenticationReject {
class AuthenticationReject : public NasMmPlainHeader {
public:
AuthenticationReject();
~AuthenticationReject();
int Encode(uint8_t* buf, int len);
int Decode(NasMmPlainHeader* header, uint8_t* buf, int len);
void setHeader(uint8_t security_header_type);
void setEAP_Message(bstring eap);
int Encode(uint8_t* buf, int len);
int Decode(uint8_t* buf, int len);
void SetEapMessage(const bstring& eap);
public:
NasMmPlainHeader* plain_header;
EapMessage* ie_eap_message;
std::optional<EapMessage> ie_eap_message;
};
} // namespace nas
......
......@@ -71,7 +71,7 @@ void AuthenticationRequest::setAuthentication_Parameter_AUTN(
}
//------------------------------------------------------------------------------
void AuthenticationRequest::setEAP_Message(bstring eap) {
void AuthenticationRequest::SetEapMessage(bstring eap) {
ie_eap_message = std::make_optional<EapMessage>(kIeiEapMessage, eap);
}
......@@ -160,8 +160,16 @@ int AuthenticationRequest::Decode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Decoding RegistrationReject message");
int decoded_size = 0;
int decoded_result = 0;
decoded_size = NasMmPlainHeader::Decode(buf, len);
// 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;
// NgKSI
decoded_size += ie_ngKSI.Decode(
buf + decoded_size, len - decoded_size, false,
false); // length 1/2, low position
......
......@@ -37,7 +37,7 @@ class AuthenticationRequest : public NasMmPlainHeader {
void setHeader(uint8_t security_header_type);
void setngKSI(uint8_t tsc, uint8_t key_set_id);
void setEAP_Message(bstring eap);
void SetEapMessage(bstring eap);
void setABBA(uint8_t length, uint8_t* value);
void setAuthentication_Parameter_RAND(
uint8_t value[kAuthenticationParameterRandValueLength]);
......@@ -46,7 +46,9 @@ class AuthenticationRequest : public NasMmPlainHeader {
public:
NasKeySetIdentifier ie_ngKSI; // Mandatory
ABBA ie_abba; // Mandatory
// Spare half octet (will be processed together with NgKSI)
ABBA ie_abba; // Mandatory
std::optional<Authentication_Parameter_RAND>
ie_authentication_parameter_rand; // Optional
std::optional<Authentication_Parameter_AUTN>
......
......@@ -19,13 +19,6 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#include "AuthenticationResponse.hpp"
#include "3gpp_24.501.hpp"
......@@ -34,10 +27,10 @@
using namespace nas;
//------------------------------------------------------------------------------
AuthenticationResponse::AuthenticationResponse() {
plain_header = NULL;
ie_authentication_response_parameter = NULL;
ie_eap_message = NULL;
AuthenticationResponse::AuthenticationResponse()
: NasMmPlainHeader(EPD_5GS_MM_MSG, AUTHENTICATION_RESPONSE) {
ie_authentication_response_parameter = std::nullopt;
ie_eap_message = std::nullopt;
}
//------------------------------------------------------------------------------
......@@ -45,22 +38,20 @@ AuthenticationResponse::~AuthenticationResponse() {}
//------------------------------------------------------------------------------
void AuthenticationResponse::setHeader(uint8_t security_header_type) {
plain_header = new NasMmPlainHeader();
plain_header->setHeader(
EPD_5GS_MM_MSG, security_header_type, AUTHENTICATION_RESPONSE);
NasMmPlainHeader::SetSecurityHeaderType(security_header_type);
}
//------------------------------------------------------------------------------
void AuthenticationResponse::setAuthentication_Response_Parameter(
bstring para) {
void AuthenticationResponse::SetAuthenticationResponseParameter(
const bstring& para) {
ie_authentication_response_parameter =
new Authentication_Response_Parameter(0x2D, para);
std::make_optional<AuthenticationResponseParameter>(para);
}
//------------------------------------------------------------------------------
bool AuthenticationResponse::getAuthenticationResponseParameter(bstring& para) {
if (ie_authentication_response_parameter) {
ie_authentication_response_parameter->getValue(para);
bool AuthenticationResponse::GetAuthenticationResponseParameter(bstring& para) {
if (ie_authentication_response_parameter.has_value()) {
ie_authentication_response_parameter.value().GetValue(para);
return true;
} else {
return false;
......@@ -68,35 +59,40 @@ bool AuthenticationResponse::getAuthenticationResponseParameter(bstring& para) {
}
//------------------------------------------------------------------------------
void AuthenticationResponse::setEAP_Message(bstring eap) {
ie_eap_message = new EapMessage(0x78, eap);
void AuthenticationResponse::SetEapMessage(const bstring& eap) {
ie_eap_message = std::make_optional<EapMessage>(kIeiEapMessage, eap);
}
//------------------------------------------------------------------------------
bool AuthenticationResponse::getEapMessage(bstring& eap) {
if (ie_eap_message) {
ie_eap_message->getValue(eap);
return 0;
bool AuthenticationResponse::GetEapMessage(bstring& eap) {
if (ie_eap_message.has_value()) {
ie_eap_message.value().getValue(eap);
return true;
} else {
return -1;
return false;
}
}
//------------------------------------------------------------------------------
int AuthenticationResponse::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding AuthenticationResponse 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_authentication_response_parameter) {
encoded_size += encoded_ie_size;
if (!ie_authentication_response_parameter.has_value()) {
Logger::nas_mm().warn(
"IE ie_authentication_response_parameter is not available");
} else {
if (int size = ie_authentication_response_parameter->Encode(
if (int size = ie_authentication_response_parameter.value().Encode(
buf + encoded_size, len - encoded_size)) {
encoded_size += size;
} else {
......@@ -105,11 +101,11 @@ int AuthenticationResponse::Encode(uint8_t* buf, int len) {
return 0;
}
}
if (!ie_eap_message) {
if (!ie_eap_message.has_value()) {
Logger::nas_mm().warn("IE ie_eap_message is not available");
} else {
if (int size =
ie_eap_message->Encode(buf + encoded_size, len - encoded_size)) {
if (int size = ie_eap_message.value().Encode(
buf + encoded_size, len - encoded_size)) {
encoded_size += size;
} else {
Logger::nas_mm().error("Encoding ie_eap_message error");
......@@ -118,40 +114,52 @@ int AuthenticationResponse::Encode(uint8_t* buf, int len) {
}
Logger::nas_mm().debug(
"Encoded AuthenticationResponse message len (%d)", encoded_size);
return 1;
return encoded_size;
}
//------------------------------------------------------------------------------
int AuthenticationResponse::Decode(
NasMmPlainHeader* header, uint8_t* buf, int len) {
int AuthenticationResponse::Decode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Decoding AuthenticationResponse message");
int decoded_size = 3;
plain_header = header;
Logger::nas_mm().debug("Decoded_size (%d)", decoded_size);
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;
// IEIs
uint8_t octet = *(buf + decoded_size);
Logger::nas_mm().debug("First option IEI (0x%x)", octet);
while ((octet != 0x0)) {
switch (octet) {
case 0x2D: {
Logger::nas_mm().debug("Decoding IEI (0x2D)");
ie_authentication_response_parameter =
new Authentication_Response_Parameter();
decoded_size += ie_authentication_response_parameter->Decode(
case kIeiAuthenticationResponseParameter: {
Logger::nas_mm().debug(
"Decoding IEI 0x%x", kIeiAuthenticationResponseParameter);
AuthenticationResponseParameter
ie_authentication_response_parameter_tmp = {};
decoded_size += ie_authentication_response_parameter_tmp.Decode(
buf + decoded_size, len - decoded_size, true);
ie_authentication_response_parameter =
std::optional<AuthenticationResponseParameter>(
ie_authentication_response_parameter_tmp);
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet);
} break;
case 0x78: {
Logger::nas_mm().debug("Decoding IEI (0x78)");
ie_eap_message = new EapMessage();
decoded_size += ie_eap_message->Decode(
case kIeiEapMessage: {
Logger::nas_mm().debug("Decoding IEI 0x%x", kIeiEapMessage);
EapMessage ie_eap_message_tmp = {};
decoded_size += ie_eap_message_tmp.Decode(
buf + decoded_size, len - decoded_size, true);
octet = *(buf + decoded_size);
ie_eap_message = std::optional<EapMessage>(ie_eap_message_tmp);
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet);
} break;
}
}
Logger::nas_mm().debug(
"Decoded AuthenticationResponse message len (%d)", decoded_size);
return 1;
return decoded_size;
}
......@@ -19,36 +19,33 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef _AuthenticationResponse_H_
#define _AuthenticationResponse_H_
#ifndef _AUTHENTICATION_RESPONSE_H_
#define _AUTHENTICATION_RESPONSE_H_
#include "NasIeHeader.hpp"
namespace nas {
class AuthenticationResponse {
class AuthenticationResponse : public NasMmPlainHeader {
public:
AuthenticationResponse();
~AuthenticationResponse();
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 setAuthentication_Response_Parameter(bstring para);
void setEAP_Message(bstring eap);
bool getAuthenticationResponseParameter(bstring& para);
bool getEapMessage(bstring& eap);
void SetAuthenticationResponseParameter(const bstring& para);
bool GetAuthenticationResponseParameter(bstring& para);
void SetEapMessage(const bstring& eap);
bool GetEapMessage(bstring& eap);
public:
NasMmPlainHeader* plain_header;
Authentication_Response_Parameter* ie_authentication_response_parameter;
EapMessage* ie_eap_message;
std::optional<AuthenticationResponseParameter>
ie_authentication_response_parameter; // Optional
std::optional<EapMessage> ie_eap_message; // Optional
};
} // namespace nas
......
......@@ -62,7 +62,7 @@ void AuthenticationResult::setABBA(uint8_t length, uint8_t* value) {
}
//------------------------------------------------------------------------------
void AuthenticationResult::setEAP_Message(bstring eap) {
void AuthenticationResult::SetEapMessage(bstring eap) {
ie_eap_message = new EapMessage(0x00, eap);
}
......
......@@ -41,7 +41,7 @@ class AuthenticationResult {
int Decode(NasMmPlainHeader* header, uint8_t* buf, int len);
void setHeader(uint8_t security_header_type);
void setngKSI(uint8_t tsc, uint8_t key_set_id);
void setEAP_Message(bstring eap);
void SetEapMessage(bstring eap);
void setABBA(uint8_t length, uint8_t* value);
public:
......
......@@ -125,34 +125,36 @@ int NasMmPlainHeader::Encode(uint8_t* buf, int len) {
//------------------------------------------------------------------------------
int NasMmPlainHeader::Decode(const uint8_t* const buf, int len) {
Logger::nas_mm().debug("Decoding NasMmPlainHeader");
uint32_t decoded_size = 0;
int decoded_size = 0;
if (len < kNasMmPlainHeaderLength) {
Logger::nas_mm().error("Buffer length is less than 3 octets");
return KEncodeDecodeError;
} else {
uint32_t size = 0;
if ((size = epd_.Decode(buf + decoded_size, len - decoded_size)) ==
KEncodeDecodeError) {
Logger::nas_mm().error("Decode NAS MM Header IE error");
return KEncodeDecodeError;
}
decoded_size += size;
}
if ((size = secu_header_type_.Decode(
buf + decoded_size, len - decoded_size)) == KEncodeDecodeError) {
Logger::nas_mm().error("Decode NAS MM Header IE error");
return KEncodeDecodeError;
}
decoded_size += size;
int size = 0;
if ((size = epd_.Decode(buf + decoded_size, len - decoded_size)) ==
KEncodeDecodeError) {
Logger::nas_mm().error("Decode NAS MM Header IE error");
return KEncodeDecodeError;
}
decoded_size += size;
if ((size = msg_type_.Decode(buf + decoded_size, len - decoded_size)) ==
KEncodeDecodeError) {
Logger::nas_mm().error("Decode NAS MM Header IE error");
return KEncodeDecodeError;
}
decoded_size += size;
if ((size = secu_header_type_.Decode(
buf + decoded_size, len - decoded_size)) == KEncodeDecodeError) {
Logger::nas_mm().error("Decode NAS MM Header IE error");
return KEncodeDecodeError;
}
decoded_size += size;
if ((size = msg_type_.Decode(buf + decoded_size, len - decoded_size)) ==
KEncodeDecodeError) {
Logger::nas_mm().error("Decode NAS MM Header IE error");
return KEncodeDecodeError;
}
decoded_size += size;
Logger::nas_mm().debug(
"decoded NasMmPlainHeader len (%d octets)", decoded_size);
"Decoded NasMmPlainHeader len (%d octets)", decoded_size);
return decoded_size;
}
......@@ -232,7 +232,7 @@ void RegistrationAccept::setSOR_Transparent_Container(
}
//------------------------------------------------------------------------------
void RegistrationAccept::setEAP_Message(bstring eap) {
void RegistrationAccept::SetEapMessage(bstring eap) {
ie_eap_message = std::make_optional<EapMessage>(0x78, eap);
}
......
......@@ -110,7 +110,7 @@ class RegistrationAccept : public NasMmPlainHeader {
void setSOR_Transparent_Container(uint8_t header, const uint8_t (&value)[16]);
// TODO: Get
void setEAP_Message(bstring eap);
void SetEapMessage(bstring eap);
// TODO: Get
void setNSSAI_Inclusion_Mode(uint8_t value);
......
......@@ -60,7 +60,7 @@ void RegistrationReject::setGPRS_Timer_2_3502(uint8_t value) {
}
//------------------------------------------------------------------------------
void RegistrationReject::setEAP_Message(bstring eap) {
void RegistrationReject::SetEapMessage(bstring eap) {
ie_eap_message = std::make_optional<EapMessage>(kIeiEapMessage, eap);
}
......@@ -143,8 +143,18 @@ int RegistrationReject::Encode(uint8_t* buf, int len) {
int RegistrationReject::Decode(
NasMmPlainHeader* header, uint8_t* buf, int len) {
Logger::nas_mm().debug("Decoding RegistrationReject message");
int decoded_size = 0;
decoded_size = NasMmPlainHeader::Decode(buf, len);
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
decoded_size +=
ie_5gmm_cause.Decode(buf + decoded_size, len - decoded_size, false);
Logger::nas_mm().debug("Decoded_size (%d)", decoded_size);
......
......@@ -47,7 +47,7 @@ class RegistrationReject : public NasMmPlainHeader {
void setGPRS_Timer_2_3502(uint8_t value);
// TOGO: Get
void setEAP_Message(bstring eap);
void SetEapMessage(bstring eap);
void setRejected_NSSAI(const std::vector<Rejected_SNSSAI>& nssai);
// TODO: Get
......
......@@ -832,9 +832,16 @@ int RegistrationRequest::Decode(uint8_t* buf, int len) {
int decoded_size = 0;
int decoded_size_ie = 0;
int decoded_result = 0;
// plain_header = header;
decoded_size = NasMmPlainHeader::Decode(buf, len);
// ie_5gs_registration_type = new _5GSRegistrationType();
// 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;
// Registration Type
decoded_size += ie_5gs_registration_type.Decode(
buf + decoded_size, len - decoded_size, false);
decoded_size += ie_ngKSI.Decode(
......
......@@ -102,7 +102,7 @@ void SecurityModeCommand::setAdditional_5G_Security_Information(
}
//------------------------------------------------------------------------------
void SecurityModeCommand::setEAP_Message(bstring eap) {
void SecurityModeCommand::SetEapMessage(bstring eap) {
ie_eap_message = new EapMessage(0x78, eap);
}
......
......@@ -48,7 +48,7 @@ class SecurityModeCommand {
void setIMEISV_Request(uint8_t value);
void setEPS_NAS_Security_Algorithms(uint8_t ciphering, uint8_t integrity);
void setAdditional_5G_Security_Information(bool rinmr, bool hdp);
void setEAP_Message(bstring eap);
void SetEapMessage(bstring eap);
void setABBA(uint8_t length, uint8_t* value);
void setS1_UE_Security_Capability(uint8_t g_EEASel, uint8_t g_EIASel);
......
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