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

Update Security Mode Command

parent 4f9b867a
......@@ -2405,11 +2405,8 @@ bool amf_n1::start_security_mode_control_procedure(
smc->setUE_Security_Capability(nc->ueSecurityCapEnc, nc->ueSecurityCapInt);
}
if (smc->ie_ue_security_capability != NULL) {
smc->ie_ue_security_capability->SetLengthIndicator(nc->ueSecurityCaplen);
} else {
Logger::amf_n1().error("UE Security Capability is missing");
}
// TODO: remove
// smc->ie_ue_security_capability->SetLengthIndicator(nc->ueSecurityCaplen);
smc->setIMEISV_Request(0xe1); // TODO: remove hardcoded value
smc->setAdditional_5G_Security_Information(true, false);
......
......@@ -48,22 +48,23 @@ EPS_NAS_Security_Algorithms::EPS_NAS_Security_Algorithms(
}
//------------------------------------------------------------------------------
void EPS_NAS_Security_Algorithms::setCIPHERING(uint8_t value) {
void EPS_NAS_Security_Algorithms::SetTypeOfCipheringAlgorithm(uint8_t value) {
CIPHERING = value;
}
//------------------------------------------------------------------------------
void EPS_NAS_Security_Algorithms::setINTEGRITY_PROTECTION(uint8_t value) {
void EPS_NAS_Security_Algorithms::SetTypeOfIntegrityProtectionAlgorithm(
uint8_t value) {
INTEGRITY_PROTECTION = value;
}
//------------------------------------------------------------------------------
uint8_t EPS_NAS_Security_Algorithms::getCIPHERING() {
uint8_t EPS_NAS_Security_Algorithms::GetTypeOfCipheringAlgorithm() {
return CIPHERING;
}
//------------------------------------------------------------------------------
uint8_t EPS_NAS_Security_Algorithms::getINTEGRITY_PROTECTION() {
uint8_t EPS_NAS_Security_Algorithms::GetTypeOfIntegrityProtectionAlgorithm() {
return INTEGRITY_PROTECTION;
}
......
......@@ -39,10 +39,10 @@ class EPS_NAS_Security_Algorithms {
~EPS_NAS_Security_Algorithms();
EPS_NAS_Security_Algorithms(
uint8_t iei, uint8_t ciphering, uint8_t integrity_protection);
void setCIPHERING(uint8_t value);
void setINTEGRITY_PROTECTION(uint8_t value);
uint8_t getCIPHERING();
uint8_t getINTEGRITY_PROTECTION();
void SetTypeOfCipheringAlgorithm(uint8_t value);
void SetTypeOfIntegrityProtectionAlgorithm(uint8_t value);
uint8_t GetTypeOfCipheringAlgorithm();
uint8_t GetTypeOfIntegrityProtectionAlgorithm();
int Encode(uint8_t* buf, int len);
int Decode(uint8_t* buf, int len, bool is_option);
......
......@@ -35,64 +35,116 @@ using namespace nas;
using namespace std;
//------------------------------------------------------------------------------
NAS_Security_Algorithms::NAS_Security_Algorithms() {}
NAS_Security_Algorithms::NAS_Security_Algorithms()
: Type3NasIe(),
type_of_ciphering_algorithm_(),
type_of_integrity_protection_algorithm_() {
SetIeName(kNasSecurityAlgorithmsIeName);
}
//------------------------------------------------------------------------------
NAS_Security_Algorithms::NAS_Security_Algorithms(uint8_t iei)
: Type3NasIe(iei),
type_of_ciphering_algorithm_(),
type_of_integrity_protection_algorithm_() {
SetIeName(kNasSecurityAlgorithmsIeName);
}
//------------------------------------------------------------------------------
NAS_Security_Algorithms::~NAS_Security_Algorithms() {}
//------------------------------------------------------------------------------
NAS_Security_Algorithms::NAS_Security_Algorithms(
uint8_t ciphering, uint8_t integrity_protection) {
CIPHERING = ciphering;
INTEGRITY_PROTECTION = integrity_protection;
uint8_t ciphering, uint8_t integrity_protection)
: Type3NasIe() {
type_of_ciphering_algorithm_ = ciphering & 0x0f;
type_of_integrity_protection_algorithm_ = integrity_protection & 0x0f;
SetIeName(kNasSecurityAlgorithmsIeName);
}
//------------------------------------------------------------------------------
void NAS_Security_Algorithms::setCIPHERING(uint8_t value) {
CIPHERING = value;
void NAS_Security_Algorithms::SetTypeOfCipheringAlgorithm(uint8_t value) {
type_of_ciphering_algorithm_ = value & 0x0f;
}
//------------------------------------------------------------------------------
void NAS_Security_Algorithms::setINTEGRITY_PROTECTION(uint8_t value) {
INTEGRITY_PROTECTION = value;
void NAS_Security_Algorithms::SetTypeOfIntegrityProtectionAlgorithm(
uint8_t value) {
type_of_integrity_protection_algorithm_ = value & 0x0f;
}
//------------------------------------------------------------------------------
uint8_t NAS_Security_Algorithms::getCIPHERING() {
return CIPHERING;
uint8_t NAS_Security_Algorithms::GetTypeOfCipheringAlgorithm() const {
return type_of_ciphering_algorithm_;
}
//------------------------------------------------------------------------------
uint8_t NAS_Security_Algorithms::getINTEGRITY_PROTECTION() {
return INTEGRITY_PROTECTION;
uint8_t NAS_Security_Algorithms::GetTypeOfIntegrityProtectionAlgorithm() const {
return type_of_integrity_protection_algorithm_;
}
//------------------------------------------------------------------------------
void NAS_Security_Algorithms::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(
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) {
Logger::nas_mm().debug("encoding NAS_Security_Algorithms ");
if (len < 1) {
Logger::nas_mm().error("len is less than one");
return -1;
} else {
*buf = ((CIPHERING & 0x0f) << 4) | (INTEGRITY_PROTECTION & 0x0f);
Logger::nas_mm().debug("encoded NAS_Security_Algorithms IE 0x%x", *buf);
Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
if (len < kNasSecurityAlgorithmsLength) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kNasSecurityAlgorithmsLength);
return KEncodeDecodeError;
}
return 1;
int encoded_size = 0;
// IEI
encoded_size += Type3NasIe::Encode(buf + encoded_size, len);
uint8_t octet = 0;
octet = ((type_of_ciphering_algorithm_ & 0x0f) << 4) |
(type_of_integrity_protection_algorithm_ & 0x0f);
ENCODE_U8(buf + encoded_size, octet, encoded_size);
Logger::nas_mm().debug(
"Encoded %s, len (%d)", GetIeName().c_str(), encoded_size);
return encoded_size;
}
//------------------------------------------------------------------------------
int NAS_Security_Algorithms::Decode(uint8_t* buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding NAS_Security_Algorithms IE");
if (len < 1) {
Logger::nas_mm().error("len is less than one");
return 0;
} else {
CIPHERING = (*buf & 0xf0) >> 4;
INTEGRITY_PROTECTION = *buf & 0x0f;
Logger::nas_mm().debug(
"decoded NAS_Security_Algorithms len 1 "
"octet,CIPHERING=0x%x,INTEGRITY_PROTECTION=0x%x",
CIPHERING, INTEGRITY_PROTECTION);
return 1;
int NAS_Security_Algorithms::Decode(uint8_t* buf, int len, bool is_iei) {
Logger::nas_mm().debug("Decoding %s", GetIeName().c_str());
if (len < kNasSecurityAlgorithmsLength) {
Logger::nas_mm().error(
"Buffer length is less than the minimum length of this IE (%d octet)",
kNasSecurityAlgorithmsLength);
return KEncodeDecodeError;
}
int decoded_size = 0;
// IEI and Length
decoded_size += Type3NasIe::Decode(buf + decoded_size, len, is_iei);
uint8_t octet = 0;
DECODE_U8(buf + decoded_size, octet, decoded_size);
type_of_ciphering_algorithm_ = (octet & 0xf0) >> 4;
type_of_integrity_protection_algorithm_ = octet & 0x0f;
Logger::nas_mm().debug(
"Decoded %s, len (%d)", GetIeName().c_str(), decoded_size);
return decoded_size;
}
......@@ -19,35 +19,41 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef __NAS_Security_Algorithms_H
#define __NAS_Security_Algorithms_H
#ifndef _NAS_SECURITY_ALGORITHS_H
#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 {
class NAS_Security_Algorithms : public Type3NasIe {
public:
NAS_Security_Algorithms();
~NAS_Security_Algorithms();
NAS_Security_Algorithms(uint8_t iei);
NAS_Security_Algorithms(uint8_t ciphering, uint8_t integrity_protection);
void setCIPHERING(uint8_t value);
void setINTEGRITY_PROTECTION(uint8_t value);
uint8_t getCIPHERING();
uint8_t getINTEGRITY_PROTECTION();
NAS_Security_Algorithms(
uint8_t iei, uint8_t ciphering, uint8_t integrity_protection);
~NAS_Security_Algorithms();
void SetTypeOfCipheringAlgorithm(uint8_t value);
uint8_t GetTypeOfCipheringAlgorithm() const;
void SetTypeOfIntegrityProtectionAlgorithm(uint8_t value);
uint8_t GetTypeOfIntegrityProtectionAlgorithm() const;
void Set(uint8_t ciphering, uint8_t integrity_protection);
void Get(uint8_t& ciphering, uint8_t& integrity_protection) const;
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);
private:
uint8_t CIPHERING;
uint8_t INTEGRITY_PROTECTION;
uint8_t type_of_ciphering_algorithm_;
uint8_t type_of_integrity_protection_algorithm_;
};
} // namespace nas
......
......@@ -145,6 +145,22 @@ bool UESecurityCapability::GetEia(uint8_t& value) const {
return false;
}
//------------------------------------------------------------------------------
void UESecurityCapability::Set(uint8_t _5g_ea, uint8_t _5g_ia) {
_5g_ea_ = _5g_ea;
_5g_ia_ = _5g_ia;
}
//------------------------------------------------------------------------------
void UESecurityCapability::Set(
uint8_t _5g_ea, uint8_t _5g_ia, uint8_t eea, uint8_t eia) {
_5g_ea_ = _5g_ea;
_5g_ia_ = _5g_ia;
eea_ = std::optional<uint8_t>(eea);
eia_ = std::optional<uint8_t>(eia);
SetLengthIndicator(4);
}
//------------------------------------------------------------------------------
int UESecurityCapability::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
......
......@@ -56,6 +56,9 @@ class UESecurityCapability : public Type4NasIe {
void SetEia(uint8_t value);
bool GetEia(uint8_t& value) const;
void Set(uint8_t _5g_ea, uint8_t _5g_ia);
void Set(uint8_t _5g_ea, uint8_t _5g_ia, uint8_t eea, uint8_t eia);
int Encode(uint8_t* buf, int len);
int Decode(uint8_t* buf, int len, bool is_iei);
......
......@@ -34,17 +34,14 @@
using namespace nas;
//------------------------------------------------------------------------------
SecurityModeCommand::SecurityModeCommand() {
plain_header = NULL;
ie_eap_message = NULL;
ie_selected_nas_security_algorithms = NULL;
ie_ngKSI = NULL;
ie_ue_security_capability = NULL;
ie_imeisv_request = NULL;
ie_eps_nas_security_algorithms = NULL;
ie_additional_5G_security_information = NULL;
ie_abba = NULL;
ie_s1_ue_security_capability = NULL;
SecurityModeCommand::SecurityModeCommand()
: NasMmPlainHeader(EPD_5GS_MM_MSG, SECURITY_MODE_COMMAND) {
ie_imeisv_request = std::nullopt;
ie_eps_nas_security_algorithms = std::nullopt;
ie_additional_5G_security_information = std::nullopt;
ie_eap_message = std::nullopt;
ie_abba = std::nullopt;
ie_s1_ue_security_capability = std::nullopt;
}
//------------------------------------------------------------------------------
......@@ -52,131 +49,132 @@ SecurityModeCommand::~SecurityModeCommand() {}
//------------------------------------------------------------------------------
void SecurityModeCommand::setHeader(uint8_t security_header_type) {
plain_header = new NasMmPlainHeader();
plain_header->setHeader(
EPD_5GS_MM_MSG, security_header_type, SECURITY_MODE_COMMAND);
NasMmPlainHeader::SetSecurityHeaderType(security_header_type);
}
//------------------------------------------------------------------------------
void SecurityModeCommand::setNAS_Security_Algorithms(
uint8_t ciphering, uint8_t integrity) {
ie_selected_nas_security_algorithms =
new NAS_Security_Algorithms(ciphering, integrity);
ie_selected_nas_security_algorithms.Set(ciphering, integrity);
}
//------------------------------------------------------------------------------
void SecurityModeCommand::setngKSI(uint8_t tsc, uint8_t key_set_id) {
ie_ngKSI = new NasKeySetIdentifier(tsc, key_set_id);
ie_ngKSI.setTypeOfSecurityContext(tsc);
ie_ngKSI.setNasKeyIdentifier(key_set_id);
}
//------------------------------------------------------------------------------
void SecurityModeCommand::setUE_Security_Capability(
uint8_t g_EASel, uint8_t g_IASel) {
ie_ue_security_capability = new UESecurityCapability(g_EASel, g_IASel);
ie_ue_security_capability.Set(g_EASel, g_IASel);
}
//------------------------------------------------------------------------------
void SecurityModeCommand::setUE_Security_Capability(
uint8_t g_EASel, uint8_t g_IASel, uint8_t eea, uint8_t eia) {
ie_ue_security_capability =
new UESecurityCapability(g_EASel, g_IASel, eea, eia);
ie_ue_security_capability.Set(g_EASel, g_IASel, eea, eia);
}
//------------------------------------------------------------------------------
void SecurityModeCommand::setIMEISV_Request(uint8_t value) {
ie_imeisv_request = new IMEISV_Request(0x0E, value);
ie_imeisv_request = std::make_optional<IMEISV_Request>(0x0E, value);
}
//------------------------------------------------------------------------------
void SecurityModeCommand::setEPS_NAS_Security_Algorithms(
uint8_t ciphering, uint8_t integrity) {
ie_eps_nas_security_algorithms =
new EPS_NAS_Security_Algorithms(0x57, ciphering, integrity);
std::make_optional<EPS_NAS_Security_Algorithms>(
0x57, ciphering, integrity);
}
//------------------------------------------------------------------------------
void SecurityModeCommand::setAdditional_5G_Security_Information(
bool rinmr, bool hdp) {
ie_additional_5G_security_information =
new Additional_5G_Security_Information(0x36, rinmr, hdp);
std::make_optional<Additional_5G_Security_Information>(0x36, rinmr, hdp);
}
//------------------------------------------------------------------------------
void SecurityModeCommand::SetEapMessage(bstring eap) {
ie_eap_message = new EapMessage(0x78, eap);
ie_eap_message = std::make_optional<EapMessage>(0x78, eap);
}
//------------------------------------------------------------------------------
void SecurityModeCommand::setABBA(uint8_t length, uint8_t* value) {
ie_abba = new ABBA(0x38, length, value);
ie_abba = std::make_optional<ABBA>(0x38, length, value);
}
//------------------------------------------------------------------------------
void SecurityModeCommand::setS1_UE_Security_Capability(
uint8_t g_EEASel, uint8_t g_EIASel) {
ie_s1_ue_security_capability =
new S1_UE_Security_Capability(0x19, g_EEASel, g_EIASel);
std::make_optional<S1_UE_Security_Capability>(0x19, g_EEASel, g_EIASel);
}
//------------------------------------------------------------------------------
int SecurityModeCommand::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding SecurityModeCommand 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_selected_nas_security_algorithms) {
Logger::nas_mm().warn(
"IE ie_selected_nas_security_algorithms is not available");
encoded_size += encoded_ie_size;
// NAS security algorithms
int size = ie_selected_nas_security_algorithms.Encode(
buf + encoded_size, len - encoded_size);
if (size != KEncodeDecodeError) {
encoded_size += size;
} else {
if (int size = ie_selected_nas_security_algorithms->Encode(
buf + encoded_size, len - encoded_size)) {
encoded_size += size;
} else {
Logger::nas_mm().error(
"Encoding ie_selected_nas_security_algorithms error");
return 0;
}
Logger::nas_mm().error(
"Encoding ie_selected_nas_security_algorithms error");
return KEncodeDecodeError;
}
if (!ie_ngKSI) {
Logger::nas_mm().warn("IE ie_ngKSI is not available");
} else {
if (int size = ie_ngKSI->Encode(buf + encoded_size, len - encoded_size) ==
KEncodeDecodeError) {
Logger::nas_mm().error("Encoding ie_ngKSI error");
return 0;
}
// NAS key set identifier
size = ie_ngKSI.Encode(buf + encoded_size, len - encoded_size);
if (size != KEncodeDecodeError) {
encoded_size++; // 1/2 octet for ngKSI, 1/2 for Spare half octet
} else {
Logger::nas_mm().error("Encoding ie_ngKSI error");
return KEncodeDecodeError;
}
if (!ie_ue_security_capability) {
Logger::nas_mm().warn("IE ie_ue_security_capability is not available");
// UE security capability
size =
ie_ue_security_capability.Encode(buf + encoded_size, len - encoded_size);
if (size != KEncodeDecodeError) {
encoded_size += size;
} else {
if (int size = ie_ue_security_capability->Encode(
buf + encoded_size, len - encoded_size)) {
encoded_size += size;
} else {
Logger::nas_mm().error("Encoding ie_ue_security_capability error");
return 0;
}
Logger::nas_mm().error("Encoding ie_ue_security_capability error");
return KEncodeDecodeError;
}
if (!ie_imeisv_request) {
// Optional IEs
if (!ie_imeisv_request.has_value()) {
Logger::nas_mm().warn("IE ie_imeisv_request is not available");
} else {
if (int size =
ie_imeisv_request->Encode(buf + encoded_size, len - encoded_size)) {
if (int size = ie_imeisv_request.value().Encode(
buf + encoded_size, len - encoded_size)) {
encoded_size += size;
} else {
Logger::nas_mm().error("Encoding ie_imeisv_request error");
return 0;
}
}
if (!ie_eps_nas_security_algorithms) {
if (!ie_eps_nas_security_algorithms.has_value()) {
Logger::nas_mm().warn("IE ie_eps_nas_security_algorithms is not available");
} else {
if (int size = ie_eps_nas_security_algorithms->Encode(
if (int size = ie_eps_nas_security_algorithms.value().Encode(
buf + encoded_size, len - encoded_size)) {
encoded_size += size;
} else {
......@@ -184,11 +182,12 @@ int SecurityModeCommand::Encode(uint8_t* buf, int len) {
return 0;
}
}
if (!ie_additional_5G_security_information) {
if (!ie_additional_5G_security_information.has_value()) {
Logger::nas_mm().warn(
"IE ie_additional_5G_security_information is not available");
} else {
if (int size = ie_additional_5G_security_information->Encode(
if (int size = ie_additional_5G_security_information.value().Encode(
buf + encoded_size, len - encoded_size)) {
encoded_size += size;
} else {
......@@ -197,31 +196,35 @@ int SecurityModeCommand::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");
return 0;
}
}
if (!ie_abba) {
if (!ie_abba.has_value()) {
Logger::nas_mm().warn("IE ie_abba is not available");
} else {
if (int size = ie_abba->Encode(buf + encoded_size, len - encoded_size)) {
if (int size =
ie_abba.value().Encode(buf + encoded_size, len - encoded_size)) {
encoded_size += size;
} else {
Logger::nas_mm().error("Encoding ie_abba error");
return 0;
}
}
if (!ie_s1_ue_security_capability) {
if (!ie_s1_ue_security_capability.has_value()) {
Logger::nas_mm().warn("IE ie_s1_ue_security_capability is not available");
} else {
if (int size = ie_s1_ue_security_capability->Encode(
if (int size = ie_s1_ue_security_capability.value().Encode(
buf + encoded_size, len - encoded_size)) {
encoded_size += size;
} else {
......@@ -238,18 +241,35 @@ int SecurityModeCommand::Encode(uint8_t* buf, int len) {
int SecurityModeCommand::Decode(
NasMmPlainHeader* header, uint8_t* buf, int len) {
Logger::nas_mm().debug("Decoding SecurityModeCommand message");
int decoded_size = 3;
plain_header = header;
ie_selected_nas_security_algorithms = new NAS_Security_Algorithms();
decoded_size += ie_selected_nas_security_algorithms->Decode(
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;
// NAS security algorithms
decoded_result = ie_selected_nas_security_algorithms.Decode(
buf + decoded_size, len - decoded_size, false);
ie_ngKSI = new NasKeySetIdentifier();
decoded_size +=
ie_ngKSI->Decode(buf + decoded_size, len - decoded_size, false, false);
if (decoded_result == KEncodeDecodeError) return KEncodeDecodeError;
decoded_size += decoded_result;
// NAS key set identifier
decoded_result =
ie_ngKSI.Decode(buf + decoded_size, len - decoded_size, false, false);
if (decoded_result == KEncodeDecodeError) return KEncodeDecodeError;
decoded_size++; // 1/2 octet for ngKSI, 1/2 for Spare half octet
ie_ue_security_capability = new UESecurityCapability();
decoded_size += ie_ue_security_capability->Decode(
// UE security capability
decoded_result = ie_ue_security_capability.Decode(
buf + decoded_size, len - decoded_size, false);
if (decoded_result == KEncodeDecodeError) return KEncodeDecodeError;
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);
......@@ -257,9 +277,14 @@ int SecurityModeCommand::Decode(
switch ((octet & 0xf0) >> 4) {
case 0xE: {
Logger::nas_mm().debug("Decoding IEI (0xE)");
ie_imeisv_request = new IMEISV_Request();
decoded_size += ie_imeisv_request->Decode(
buf + decoded_size, len - decoded_size, true);
IMEISV_Request ie_imeisv_request_tmp = {};
if ((decoded_result = ie_imeisv_request_tmp.Decode(
buf + decoded_size, len - decoded_size, true)) ==
KEncodeDecodeError)
return decoded_result;
decoded_size += decoded_result;
ie_imeisv_request =
std::optional<IMEISV_Request>(ie_imeisv_request_tmp);
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet);
} break;
......@@ -267,42 +292,67 @@ int SecurityModeCommand::Decode(
switch (octet) {
case 0x57: {
Logger::nas_mm().debug("decoding IEI (0x57)");
ie_eps_nas_security_algorithms = new EPS_NAS_Security_Algorithms();
decoded_size += ie_eps_nas_security_algorithms->Decode(
buf + decoded_size, len - decoded_size, true);
EPS_NAS_Security_Algorithms ie_eps_nas_security_algorithms_tmp = {};
if ((decoded_result = ie_eps_nas_security_algorithms_tmp.Decode(
buf + decoded_size, len - decoded_size, true)) ==
KEncodeDecodeError)
return decoded_result;
decoded_size += decoded_result;
ie_eps_nas_security_algorithms =
std::optional<EPS_NAS_Security_Algorithms>(
ie_eps_nas_security_algorithms_tmp);
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet);
} break;
case 0x36: {
Logger::nas_mm().debug("decoding IEI (0x36)");
Additional_5G_Security_Information
ie_additional_5G_security_information_tmp = {};
if ((decoded_result = ie_additional_5G_security_information_tmp.Decode(
buf + decoded_size, len - decoded_size, true)) ==
KEncodeDecodeError)
return decoded_result;
decoded_size += decoded_result;
ie_additional_5G_security_information =
new Additional_5G_Security_Information();
decoded_size += ie_additional_5G_security_information->Decode(
buf + decoded_size, len - decoded_size, true);
std::optional<Additional_5G_Security_Information>(
ie_additional_5G_security_information_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(
buf + decoded_size, len - decoded_size, true);
octet = *(buf + decoded_size);
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;
case 0x38: {
Logger::nas_mm().debug("decoding IEI (0x38)");
ie_abba = new ABBA();
decoded_size +=
ie_abba->Decode(buf + decoded_size, len - decoded_size, true);
octet = *(buf + decoded_size);
ABBA ie_abba_tmp = {};
if ((decoded_result = ie_abba_tmp.Decode(
buf + decoded_size, len - decoded_size, true)) ==
KEncodeDecodeError)
return decoded_result;
decoded_size += decoded_result;
ie_abba = std::optional<ABBA>(ie_abba_tmp);
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet);
} break;
case 0x19: {
Logger::nas_mm().debug("decoding IEI (0x19)");
ie_s1_ue_security_capability = new S1_UE_Security_Capability();
decoded_size += ie_s1_ue_security_capability->Decode(
buf + decoded_size, len - decoded_size, true);
S1_UE_Security_Capability ie_s1_ue_security_capability_tmp = {};
if ((decoded_result = ie_s1_ue_security_capability_tmp.Decode(
buf + decoded_size, len - decoded_size, true)) ==
KEncodeDecodeError)
return decoded_result;
decoded_size += decoded_result;
ie_s1_ue_security_capability = std::optional<S1_UE_Security_Capability>(
ie_s1_ue_security_capability_tmp);
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet);
} break;
......
......@@ -19,50 +19,58 @@
* contact@openairinterface.org
*/
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef _SecurityModeCommand_H_
#define _SecurityModeCommand_H_
#ifndef _SECURITY_MODE_COMMAND_H_
#define _SECURITY_MODE_COMMAND_H_
#include "NasIeHeader.hpp"
namespace nas {
class SecurityModeCommand {
class SecurityModeCommand : public NasMmPlainHeader {
public:
SecurityModeCommand();
~SecurityModeCommand();
void setHeader(uint8_t security_header_type);
int Encode(uint8_t* buf, int len);
int Decode(NasMmPlainHeader* header, uint8_t* buf, int len);
void setHeader(uint8_t security_header_type);
void setNAS_Security_Algorithms(uint8_t ciphering, uint8_t integrity);
void setngKSI(uint8_t tsc, uint8_t key_set_id);
void setUE_Security_Capability(uint8_t g_EASel, uint8_t g_IASel);
void setUE_Security_Capability(
uint8_t g_EASel, uint8_t g_IASel, uint8_t eea, uint8_t eia);
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 SetEapMessage(bstring eap);
void setABBA(uint8_t length, uint8_t* value);
void setS1_UE_Security_Capability(uint8_t g_EEASel, uint8_t g_EIASel);
public:
NasMmPlainHeader* plain_header;
NAS_Security_Algorithms* ie_selected_nas_security_algorithms;
NasKeySetIdentifier* ie_ngKSI;
UESecurityCapability* ie_ue_security_capability;
IMEISV_Request* ie_imeisv_request;
EPS_NAS_Security_Algorithms* ie_eps_nas_security_algorithms;
Additional_5G_Security_Information* ie_additional_5G_security_information;
EapMessage* ie_eap_message;
ABBA* ie_abba;
S1_UE_Security_Capability* ie_s1_ue_security_capability;
NAS_Security_Algorithms 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>
ie_eps_nas_security_algorithms; // Optional
std::optional<Additional_5G_Security_Information>
ie_additional_5G_security_information; // Optional
std::optional<EapMessage> ie_eap_message; // Optional
std::optional<ABBA> ie_abba; // Optional
std::optional<S1_UE_Security_Capability>
ie_s1_ue_security_capability; // Optional
};
} // 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