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

Update Authentication Request with NKSI

parent 2d7a889a
......@@ -131,11 +131,13 @@ int NasKeySetIdentifier::Decode(
//------------------------------------------------------------------------------
void NasKeySetIdentifier::setTypeOfSecurityContext(const bool& type) {
tsc_ = type;
SetValue(); // Update value
}
//------------------------------------------------------------------------------
void NasKeySetIdentifier::setNasKeyIdentifier(const uint8_t& id) {
key_id_ = 0x07 & id;
SetValue(); // Update value
}
//------------------------------------------------------------------------------
......
......@@ -19,13 +19,6 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#include "AuthenticationRequest.hpp"
#include "3gpp_24.501.hpp"
......@@ -34,9 +27,8 @@
using namespace nas;
//------------------------------------------------------------------------------
AuthenticationRequest::AuthenticationRequest() {
plain_header = NULL;
ie_ngKSI = NULL;
AuthenticationRequest::AuthenticationRequest()
: NasMmPlainHeader(EPD_5GS_MM_MSG, AUTHENTICATION_REQUEST) {
ie_abba = NULL;
ie_authentication_parameter_rand = NULL;
ie_authentication_parameter_autn = NULL;
......@@ -48,14 +40,14 @@ AuthenticationRequest::~AuthenticationRequest() {}
//------------------------------------------------------------------------------
void AuthenticationRequest::setHeader(uint8_t security_header_type) {
plain_header = new NasMmPlainHeader();
plain_header->setHeader(
EPD_5GS_MM_MSG, security_header_type, AUTHENTICATION_REQUEST);
NasMmPlainHeader::SetSecurityHeaderType(security_header_type);
}
//------------------------------------------------------------------------------
void AuthenticationRequest::setngKSI(uint8_t tsc, uint8_t key_set_id) {
ie_ngKSI = new NasKeySetIdentifier(tsc, key_set_id);
ie_ngKSI.Set(false); // 4 lower bits
ie_ngKSI.setNasKeyIdentifier(key_set_id);
ie_ngKSI.setTypeOfSecurityContext(tsc);
}
//------------------------------------------------------------------------------
......@@ -83,26 +75,27 @@ void AuthenticationRequest::setEAP_Message(bstring eap) {
//------------------------------------------------------------------------------
int AuthenticationRequest::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding AuthenticationRequest 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_ngKSI) {
Logger::nas_mm().warn("IE ie_ngKSI is not available");
encoded_size += encoded_ie_size;
int size = ie_ngKSI.Encode(buf + encoded_size, len - encoded_size);
if (size != KEncodeDecodeError) {
encoded_size += size;
} else {
int size = ie_ngKSI->Encode(buf + encoded_size, len - encoded_size);
if (size != KEncodeDecodeError) {
encoded_size += size;
} else {
Logger::nas_mm().error("Encoding ie_ngKSI error");
return 0;
}
// Spare half octet
encoded_size++; // 1/2 octet + 1/2 octet from ie_ngKSI
Logger::nas_mm().error("Encoding ie_ngKSI error");
return 0;
}
// Spare half octet
encoded_size++; // 1/2 octet + 1/2 octet from ie_ngKSI
if (!ie_abba) {
Logger::nas_mm().warn("IE ie_abba is not available");
} else {
......@@ -161,13 +154,12 @@ int AuthenticationRequest::Encode(uint8_t* buf, int len) {
}
//------------------------------------------------------------------------------
int AuthenticationRequest::Decode(
NasMmPlainHeader* header, uint8_t* buf, int len) {
int AuthenticationRequest::Decode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Decoding RegistrationReject message");
int decoded_size = 3;
plain_header = header;
ie_ngKSI = new NasKeySetIdentifier();
decoded_size += ie_ngKSI->Decode(
int decoded_size = 0;
decoded_size = NasMmPlainHeader::Decode(buf, len);
decoded_size += ie_ngKSI.Decode(
buf + decoded_size, len - decoded_size, false,
false); // length 1/2, low position
decoded_size++; // 1/2 octet from ie_ngKSI, 1/2 from Spare half octet
......
......@@ -19,27 +19,23 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef _AuthenticationRequest_H_
#define _AuthenticationRequest_H_
#ifndef _AUTHENTICATION_REQUEST_H_
#define _AUTHENTICATION_REQUEST_H_
#include "NasIeHeader.hpp"
namespace nas {
class AuthenticationRequest {
class AuthenticationRequest : public NasMmPlainHeader {
public:
AuthenticationRequest();
~AuthenticationRequest();
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 setngKSI(uint8_t tsc, uint8_t key_set_id);
void setEAP_Message(bstring eap);
void setABBA(uint8_t length, uint8_t* value);
......@@ -47,8 +43,7 @@ class AuthenticationRequest {
void setAuthentication_Parameter_AUTN(uint8_t* value);
public:
NasMmPlainHeader* plain_header;
NasKeySetIdentifier* ie_ngKSI;
NasKeySetIdentifier ie_ngKSI;
ABBA* ie_abba;
Authentication_Parameter_RAND* ie_authentication_parameter_rand;
Authentication_Parameter_AUTN* ie_authentication_parameter_autn;
......
......@@ -72,6 +72,21 @@ void NasMmPlainHeader::setHeader(
msg_type_.Set(msg_type);
}
//------------------------------------------------------------------------------
void NasMmPlainHeader::SetMessageName(const std::string& name) {
msg_name_ = name;
}
//------------------------------------------------------------------------------
std::string NasMmPlainHeader::GetMessageName() const {
return msg_name_;
}
//------------------------------------------------------------------------------
void NasMmPlainHeader::GetMessageName(std::string& name) const {
name = msg_name_;
}
//------------------------------------------------------------------------------
int NasMmPlainHeader::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding NasMmPlainHeader");
......
......@@ -35,9 +35,13 @@ class NasMmPlainHeader {
NasMmPlainHeader(){};
NasMmPlainHeader(const uint8_t& epd, const uint8_t& msg_type);
virtual ~NasMmPlainHeader();
void setHeader(
const uint8_t& epd, const uint8_t& security_header_type,
const uint8_t& msg_type);
void SetMessageName(const std::string& name);
std::string GetMessageName() const;
void GetMessageName(std::string& name) const;
int Encode(uint8_t* buf, int len);
int Decode(const uint8_t* const buf, int len);
......@@ -52,10 +56,12 @@ class NasMmPlainHeader {
uint8_t GetMessageType();
private:
ExtendedProtocolDiscriminator epd_; // Mandatory
// TODO: Spare half octet (1/2 octet)
ExtendedProtocolDiscriminator epd_; // Mandatory
SecurityHeaderType secu_header_type_; // Mandatory (1/2 octet)
NasMessageType msg_type_; // Mandatory
// TODO: Spare half octet (1/2 octet)
NasMessageType msg_type_; // Mandatory
std::string msg_name_; // non 3GPP IE
};
} // namespace nas
......
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