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