Commit 2542778d authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Code cleanup

parent e925211a
......@@ -47,7 +47,7 @@
#include "LADN_Indication.hpp"
#include "MA_PDU_Session_Information.hpp"
#include "NasMessageContainer.hpp"
#include "NAS_Security_Algorithms.hpp"
#include "NasSecurityAlgorithms.hpp"
#include "NSSAI.hpp"
#include "NssaiInclusionMode.hpp"
#include "NasKeySetIdentifier.hpp"
......
......@@ -129,23 +129,23 @@ int NasKeySetIdentifier::Decode(
*/
//------------------------------------------------------------------------------
void NasKeySetIdentifier::setTypeOfSecurityContext(const bool& type) {
void NasKeySetIdentifier::SetTypeOfSecurityContext(const bool& type) {
tsc_ = type;
SetValue(); // Update value
}
//------------------------------------------------------------------------------
void NasKeySetIdentifier::setNasKeyIdentifier(const uint8_t& id) {
void NasKeySetIdentifier::SetNasKeyIdentifier(const uint8_t& id) {
key_id_ = 0x07 & id;
SetValue(); // Update value
}
//------------------------------------------------------------------------------
bool NasKeySetIdentifier::getTypeOfSecurityContext() const {
bool NasKeySetIdentifier::GetTypeOfSecurityContext() const {
return tsc_;
}
//------------------------------------------------------------------------------
uint8_t NasKeySetIdentifier::getNasKeyIdentifier() const {
uint8_t NasKeySetIdentifier::GetNasKeyIdentifier() const {
return key_id_;
}
......@@ -23,7 +23,6 @@
#define _NAS_KEY_SET_IDENTIFIER_H
#include "Type1NasIe.hpp"
#include <stdint.h>
constexpr auto kNasKeySetIdentifierName = "NAS Key Set Identifier";
namespace nas {
......@@ -43,17 +42,16 @@ class NasKeySetIdentifier : public Type1NasIe {
// void Set(const bool& tsc, const uint8_t& key_id, const uint8_t& iei);
void Get(bool& tsc, uint8_t& key_id);
void setTypeOfSecurityContext(const bool& type);
bool getTypeOfSecurityContext() const;
void SetTypeOfSecurityContext(const bool& type);
bool GetTypeOfSecurityContext() const;
void setNasKeyIdentifier(const uint8_t& id);
uint8_t getNasKeyIdentifier() const;
void SetNasKeyIdentifier(const uint8_t& id);
uint8_t GetNasKeyIdentifier() const;
private:
void SetValue() override;
void GetValue() override;
// uint8_t iei_;
bool tsc_;
uint8_t key_id_;
};
......
......@@ -19,23 +19,14 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#include "NAS_Security_Algorithms.hpp"
#include <iostream>
#include "NasSecurityAlgorithms.hpp"
#include "logger.hpp"
using namespace nas;
using namespace std;
//------------------------------------------------------------------------------
NAS_Security_Algorithms::NAS_Security_Algorithms()
NasSecurityAlgorithms::NasSecurityAlgorithms()
: Type3NasIe(),
type_of_ciphering_algorithm_(),
type_of_integrity_protection_algorithm_() {
......@@ -43,7 +34,7 @@ NAS_Security_Algorithms::NAS_Security_Algorithms()
}
//------------------------------------------------------------------------------
NAS_Security_Algorithms::NAS_Security_Algorithms(uint8_t iei)
NasSecurityAlgorithms::NasSecurityAlgorithms(uint8_t iei)
: Type3NasIe(iei),
type_of_ciphering_algorithm_(),
type_of_integrity_protection_algorithm_() {
......@@ -51,10 +42,10 @@ NAS_Security_Algorithms::NAS_Security_Algorithms(uint8_t iei)
}
//------------------------------------------------------------------------------
NAS_Security_Algorithms::~NAS_Security_Algorithms() {}
NasSecurityAlgorithms::~NasSecurityAlgorithms() {}
//------------------------------------------------------------------------------
NAS_Security_Algorithms::NAS_Security_Algorithms(
NasSecurityAlgorithms::NasSecurityAlgorithms(
uint8_t ciphering, uint8_t integrity_protection)
: Type3NasIe() {
type_of_ciphering_algorithm_ = ciphering & 0x0f;
......@@ -63,41 +54,41 @@ NAS_Security_Algorithms::NAS_Security_Algorithms(
}
//------------------------------------------------------------------------------
void NAS_Security_Algorithms::SetTypeOfCipheringAlgorithm(uint8_t value) {
void NasSecurityAlgorithms::SetTypeOfCipheringAlgorithm(uint8_t value) {
type_of_ciphering_algorithm_ = value & 0x0f;
}
//------------------------------------------------------------------------------
void NAS_Security_Algorithms::SetTypeOfIntegrityProtectionAlgorithm(
void NasSecurityAlgorithms::SetTypeOfIntegrityProtectionAlgorithm(
uint8_t value) {
type_of_integrity_protection_algorithm_ = value & 0x0f;
}
//------------------------------------------------------------------------------
uint8_t NAS_Security_Algorithms::GetTypeOfCipheringAlgorithm() const {
uint8_t NasSecurityAlgorithms::GetTypeOfCipheringAlgorithm() const {
return type_of_ciphering_algorithm_;
}
//------------------------------------------------------------------------------
uint8_t NAS_Security_Algorithms::GetTypeOfIntegrityProtectionAlgorithm() const {
uint8_t NasSecurityAlgorithms::GetTypeOfIntegrityProtectionAlgorithm() const {
return type_of_integrity_protection_algorithm_;
}
//------------------------------------------------------------------------------
void NAS_Security_Algorithms::Set(
void NasSecurityAlgorithms::Set(
uint8_t ciphering, uint8_t integrity_protection) {
type_of_ciphering_algorithm_ = ciphering & 0x0f;
type_of_integrity_protection_algorithm_ = integrity_protection & 0x0f;
}
//------------------------------------------------------------------------------
void NAS_Security_Algorithms::Get(
void NasSecurityAlgorithms::Get(
uint8_t& ciphering, uint8_t& integrity_protection) const {
ciphering = type_of_ciphering_algorithm_;
integrity_protection = type_of_integrity_protection_algorithm_;
}
//------------------------------------------------------------------------------
int NAS_Security_Algorithms::Encode(uint8_t* buf, int len) {
int NasSecurityAlgorithms::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
if (len < kNasSecurityAlgorithmsLength) {
......@@ -123,7 +114,7 @@ int NAS_Security_Algorithms::Encode(uint8_t* buf, int len) {
}
//------------------------------------------------------------------------------
int NAS_Security_Algorithms::Decode(uint8_t* buf, int len, bool is_iei) {
int NasSecurityAlgorithms::Decode(uint8_t* buf, int len, bool is_iei) {
Logger::nas_mm().debug("Decoding %s", GetIeName().c_str());
if (len < kNasSecurityAlgorithmsLength) {
......
......@@ -23,21 +23,20 @@
#define _NAS_SECURITY_ALGORITHS_H
#include "Type3NasIe.hpp"
#include <stdint.h>
constexpr uint8_t kNasSecurityAlgorithmsLength = 2;
constexpr auto kNasSecurityAlgorithmsIeName = "NAS Security Algorithms";
namespace nas {
class NAS_Security_Algorithms : public Type3NasIe {
class NasSecurityAlgorithms : public Type3NasIe {
public:
NAS_Security_Algorithms();
NAS_Security_Algorithms(uint8_t iei);
NAS_Security_Algorithms(uint8_t ciphering, uint8_t integrity_protection);
NAS_Security_Algorithms(
NasSecurityAlgorithms();
NasSecurityAlgorithms(uint8_t iei);
NasSecurityAlgorithms(uint8_t ciphering, uint8_t integrity_protection);
NasSecurityAlgorithms(
uint8_t iei, uint8_t ciphering, uint8_t integrity_protection);
~NAS_Security_Algorithms();
~NasSecurityAlgorithms();
void SetTypeOfCipheringAlgorithm(uint8_t value);
uint8_t GetTypeOfCipheringAlgorithm() const;
......
......@@ -21,6 +21,7 @@
#ifndef _TYPE1_NAS_IE_H_
#define _TYPE1_NAS_IE_H_
#include "NasIe.hpp"
constexpr uint8_t kType1NasIeLength = 1;
......
......@@ -21,10 +21,6 @@
#include "Type4NasIe.hpp"
#include "3gpp_24.501.hpp"
#include "common_defs.h"
#include "logger.hpp"
using namespace nas;
//------------------------------------------------------------------------------
Type4NasIe::Type4NasIe() : NasIe() {
......
......@@ -21,6 +21,7 @@
#ifndef _TYPE4_NAS_IE_H_
#define _TYPE4_NAS_IE_H_
#include "NasIe.hpp"
namespace nas {
......
......@@ -21,10 +21,6 @@
#include "UESecurityCapability.hpp"
#include "logger.hpp"
#include "3gpp_24.501.hpp"
#include "common_defs.h"
using namespace nas;
//------------------------------------------------------------------------------
......
......@@ -24,8 +24,6 @@
#include "Type4NasIe.hpp"
#include <stdint.h>
constexpr uint8_t kUeSecurityCapabilityMinimumLength = 4;
constexpr uint8_t kUeSecurityCapabilityMaximumLength = 10;
constexpr auto kUeSecurityCapabilityIeName = "UE Security Capability";
......
......@@ -45,8 +45,8 @@ void AuthenticationRequest::setHeader(uint8_t security_header_type) {
//------------------------------------------------------------------------------
void AuthenticationRequest::setngKSI(uint8_t tsc, uint8_t key_set_id) {
ie_ngKSI.Set(false); // 4 lower bits
ie_ngKSI.setNasKeyIdentifier(key_set_id);
ie_ngKSI.setTypeOfSecurityContext(tsc);
ie_ngKSI.SetNasKeyIdentifier(key_set_id);
ie_ngKSI.SetTypeOfSecurityContext(tsc);
}
//------------------------------------------------------------------------------
......
......@@ -87,8 +87,8 @@ void DeregistrationRequest::getDeregistrationType(
//------------------------------------------------------------------------------
bool DeregistrationRequest::getngKSI(uint8_t& ng_ksi) {
if (ie_ngKSI) {
ng_ksi = (ie_ngKSI->getTypeOfSecurityContext()) |
ie_ngKSI->getNasKeyIdentifier();
ng_ksi = (ie_ngKSI->GetTypeOfSecurityContext()) |
ie_ngKSI->GetNasKeyIdentifier();
return true;
} else {
// ng_ksi = 0;
......
......@@ -78,14 +78,14 @@ bool RegistrationRequest::get5gsRegistrationType(
//------------------------------------------------------------------------------
void RegistrationRequest::setngKSI(uint8_t tsc, uint8_t key_set_id) {
ie_ngKSI.Set(true); // high pos
ie_ngKSI.setNasKeyIdentifier(key_set_id);
ie_ngKSI.setTypeOfSecurityContext(tsc);
ie_ngKSI.SetNasKeyIdentifier(key_set_id);
ie_ngKSI.SetTypeOfSecurityContext(tsc);
}
//------------------------------------------------------------------------------
bool RegistrationRequest::getngKSI(uint8_t& ng_ksi) {
ng_ksi =
(ie_ngKSI.getTypeOfSecurityContext()) | ie_ngKSI.getNasKeyIdentifier();
(ie_ngKSI.GetTypeOfSecurityContext()) | ie_ngKSI.GetNasKeyIdentifier();
return true;
}
......@@ -181,8 +181,8 @@ void RegistrationRequest::setNonCurrentNativeNasKSI(
bool RegistrationRequest::getNonCurrentNativeNasKSI(uint8_t& value) const {
if (ie_non_current_native_nas_ksi.has_value()) {
value |=
(ie_non_current_native_nas_ksi.value().getTypeOfSecurityContext()) |
(ie_non_current_native_nas_ksi.value().getNasKeyIdentifier());
(ie_non_current_native_nas_ksi.value().GetTypeOfSecurityContext()) |
(ie_non_current_native_nas_ksi.value().GetNasKeyIdentifier());
return true;
} else {
return false;
......
......@@ -19,13 +19,6 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#include "SecurityModeCommand.hpp"
#include "3gpp_24.501.hpp"
......@@ -60,8 +53,8 @@ void SecurityModeCommand::setNAS_Security_Algorithms(
//------------------------------------------------------------------------------
void SecurityModeCommand::setngKSI(uint8_t tsc, uint8_t key_set_id) {
ie_ngKSI.setTypeOfSecurityContext(tsc);
ie_ngKSI.setNasKeyIdentifier(key_set_id);
ie_ngKSI.SetTypeOfSecurityContext(tsc);
ie_ngKSI.SetNasKeyIdentifier(key_set_id);
}
//------------------------------------------------------------------------------
......@@ -238,8 +231,7 @@ int SecurityModeCommand::Encode(uint8_t* buf, int len) {
}
//------------------------------------------------------------------------------
int SecurityModeCommand::Decode(
NasMmPlainHeader* header, uint8_t* buf, int len) {
int SecurityModeCommand::Decode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Decoding SecurityModeCommand message");
int decoded_size = 0;
int decoded_result = 0;
......@@ -360,5 +352,5 @@ int SecurityModeCommand::Decode(
}
Logger::nas_mm().debug(
"Decoded SecurityModeCommand message len (%d)", decoded_size);
return 1;
return decoded_size;
}
......@@ -34,33 +34,42 @@ class SecurityModeCommand : public NasMmPlainHeader {
void setHeader(uint8_t security_header_type);
int Encode(uint8_t* buf, int len);
int Decode(NasMmPlainHeader* header, uint8_t* buf, int len);
int Decode(uint8_t* buf, int len);
void setNAS_Security_Algorithms(uint8_t ciphering, uint8_t integrity);
// TODO: Get
void setngKSI(uint8_t tsc, uint8_t key_set_id);
// TODO: Get
void setUE_Security_Capability(uint8_t g_EASel, uint8_t g_IASel);
// TODO: Get
void setUE_Security_Capability(
uint8_t g_EASel, uint8_t g_IASel, uint8_t eea, uint8_t eia);
// TODO: Get
void setIMEISV_Request(uint8_t value);
// TODO: Get
void setEPS_NAS_Security_Algorithms(uint8_t ciphering, uint8_t integrity);
// TODO: Get
void setAdditional_5G_Security_Information(bool rinmr, bool hdp);
// TODO: Get
void SetEapMessage(bstring eap);
// TODO: Get
void setABBA(uint8_t length, uint8_t* value);
// TODO: Get
void setS1_UE_Security_Capability(uint8_t g_EEASel, uint8_t g_EIASel);
// TODO: Get
public:
NAS_Security_Algorithms ie_selected_nas_security_algorithms; // Mandatory
NasKeySetIdentifier ie_ngKSI; // Mandatory
UESecurityCapability ie_ue_security_capability; // Mandatory
NasSecurityAlgorithms ie_selected_nas_security_algorithms; // Mandatory
NasKeySetIdentifier ie_ngKSI; // Mandatory
UESecurityCapability ie_ue_security_capability; // Mandatory
std::optional<IMEISV_Request> ie_imeisv_request; // Optional
std::optional<EPS_NAS_Security_Algorithms>
......
......@@ -249,8 +249,8 @@ int ServiceRequest::Decode(NasMmPlainHeader* header, uint8_t* buf, int len) {
//------------------------------------------------------------------------------
bool ServiceRequest::getngKSI(uint8_t& ng_ksi) {
if (ie_ngKSI) {
ng_ksi = (ie_ngKSI->getTypeOfSecurityContext()) |
ie_ngKSI->getNasKeyIdentifier();
ng_ksi = (ie_ngKSI->GetTypeOfSecurityContext()) |
ie_ngKSI->GetNasKeyIdentifier();
return true;
} else {
return false;
......
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