Commit 9f43c107 authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Code refactor for 5GMMCapability

parent 884d221f
...@@ -1285,8 +1285,8 @@ void amf_n1::registration_request_handle( ...@@ -1285,8 +1285,8 @@ void amf_n1::registration_request_handle(
// Get non-current native NAS key set identity (Optional IE), used for // Get non-current native NAS key set identity (Optional IE), used for
// inter-system change from S1 to N1 Get 5GMM Capability IE (optional), not // inter-system change from S1 to N1 Get 5GMM Capability IE (optional), not
// included for periodic registration updating procedure // included for periodic registration updating procedure
uint8_t _5g_mm_cap = registration_request->get5GMMCapability(); uint8_t _5g_mm_cap = 0;
if (_5g_mm_cap == -1) { if (!registration_request->get5GMMCapability(_5g_mm_cap)) {
Logger::amf_n1().warn("No Optional IE 5GMMCapability available"); Logger::amf_n1().warn("No Optional IE 5GMMCapability available");
} }
nc->mmCapability = _5g_mm_cap; nc->mmCapability = _5g_mm_cap;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "5GMMCapability.hpp" #include "5GMMCapability.hpp"
#include "3gpp_24.501.hpp"
#include "common_defs.h" #include "common_defs.h"
#include "logger.hpp" #include "logger.hpp"
...@@ -79,6 +80,15 @@ int _5GMMCapability::encode2Buffer(uint8_t* buf, int len) { ...@@ -79,6 +80,15 @@ int _5GMMCapability::encode2Buffer(uint8_t* buf, int len) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int _5GMMCapability::decodeFromBuffer(uint8_t* buf, int len, bool is_option) { int _5GMMCapability::decodeFromBuffer(uint8_t* buf, int len, bool is_option) {
if ((len < k5gmmCapabilityMinimumLength) or
(len > k5gmmCapabilityMaximumLength)) {
Logger::nas_mm().error(
"Buffer length is less than the minimum/or greater than the maximum "
"length of this IE (Min %d octet, Max %d octet)",
k5gmmCapabilityMinimumLength, k5gmmCapabilityMaximumLength);
return KEncodeDecodeError;
}
uint8_t decoded_size = 0; uint8_t decoded_size = 0;
Logger::nas_mm().debug("Decoding _5GMMCapability IEI (0x%x)", *buf); Logger::nas_mm().debug("Decoding _5GMMCapability IEI (0x%x)", *buf);
......
...@@ -31,7 +31,7 @@ using namespace nas; ...@@ -31,7 +31,7 @@ using namespace nas;
RegistrationRequest::RegistrationRequest() RegistrationRequest::RegistrationRequest()
: NasMmPlainHeader(EPD_5GS_MM_MSG, REGISTRATION_REQUEST) { : NasMmPlainHeader(EPD_5GS_MM_MSG, REGISTRATION_REQUEST) {
ie_non_current_native_nas_ksi = std::nullopt; ie_non_current_native_nas_ksi = std::nullopt;
ie_5g_mm_capability = nullptr; ie_5g_mm_capability = std::nullopt;
ie_ue_security_capability = nullptr; ie_ue_security_capability = nullptr;
ie_requested_NSSAI = nullptr; ie_requested_NSSAI = nullptr;
ie_s1_ue_network_capability = nullptr; ie_s1_ue_network_capability = nullptr;
...@@ -176,7 +176,7 @@ void RegistrationRequest::setIMEI_IMEISV() {} ...@@ -176,7 +176,7 @@ void RegistrationRequest::setIMEI_IMEISV() {}
void RegistrationRequest::set5G_S_TMSI() {} void RegistrationRequest::set5G_S_TMSI() {}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void RegistrationRequest::setNon_current_native_nas_ksi( void RegistrationRequest::setNonCurrentNativeNasKSI(
uint8_t tsc, uint8_t key_set_id) { uint8_t tsc, uint8_t key_set_id) {
ie_non_current_native_nas_ksi = ie_non_current_native_nas_ksi =
std::make_optional<NasKeySetIdentifier>(0xC, tsc, key_set_id); std::make_optional<NasKeySetIdentifier>(0xC, tsc, key_set_id);
...@@ -196,15 +196,16 @@ bool RegistrationRequest::getNonCurrentNativeNasKSI(uint8_t& value) const { ...@@ -196,15 +196,16 @@ bool RegistrationRequest::getNonCurrentNativeNasKSI(uint8_t& value) const {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void RegistrationRequest::set5G_MM_capability(uint8_t value) { void RegistrationRequest::set5G_MM_capability(uint8_t value) {
ie_5g_mm_capability = new _5GMMCapability(0x10, value); ie_5g_mm_capability = std::make_optional<_5GMMCapability>(0x10, value);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
uint8_t RegistrationRequest::get5GMMCapability() { bool RegistrationRequest::get5GMMCapability(uint8_t& value) {
if (ie_5g_mm_capability) if (ie_5g_mm_capability.has_value()) {
return ie_5g_mm_capability->getValue(); value = ie_5g_mm_capability.value().getValue();
else return true;
return 0; } else
return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -562,10 +563,10 @@ int RegistrationRequest::encode2Buffer(uint8_t* buf, int len) { ...@@ -562,10 +563,10 @@ int RegistrationRequest::encode2Buffer(uint8_t* buf, int len) {
Logger::nas_mm().error("Encoding IE_non_current_native_nas_ksi error"); Logger::nas_mm().error("Encoding IE_non_current_native_nas_ksi error");
} }
} }
if (!ie_5g_mm_capability) { if (!ie_5g_mm_capability.has_value()) {
Logger::nas_mm().warn("IE ie_5g_mm_capability is not available"); Logger::nas_mm().warn("IE ie_5g_mm_capability is not available");
} else { } else {
if (int size = ie_5g_mm_capability->encode2Buffer( if (int size = ie_5g_mm_capability.value().encode2Buffer(
buf + encoded_size, len - encoded_size)) { buf + encoded_size, len - encoded_size)) {
encoded_size += size; encoded_size += size;
} else { } else {
...@@ -803,6 +804,7 @@ int RegistrationRequest::encode2Buffer(uint8_t* buf, int len) { ...@@ -803,6 +804,7 @@ int RegistrationRequest::encode2Buffer(uint8_t* buf, int len) {
int RegistrationRequest::decodeFromBuffer(uint8_t* buf, int len) { int RegistrationRequest::decodeFromBuffer(uint8_t* buf, int len) {
Logger::nas_mm().debug("Decoding RegistrationRequest message"); Logger::nas_mm().debug("Decoding RegistrationRequest message");
int decoded_size = 0; int decoded_size = 0;
int decoded_size_ie = 0;
int decoded_result = 0; int decoded_result = 0;
// plain_header = header; // plain_header = header;
decoded_size = NasMmPlainHeader::decodeFromBuffer(buf, len); decoded_size = NasMmPlainHeader::decodeFromBuffer(buf, len);
...@@ -859,10 +861,16 @@ int RegistrationRequest::decodeFromBuffer(uint8_t* buf, int len) { ...@@ -859,10 +861,16 @@ int RegistrationRequest::decodeFromBuffer(uint8_t* buf, int len) {
} }
switch (octet) { switch (octet) {
case 0x10: { case 0x10: {
Logger::nas_mm().debug("Decoding IEI (0x10)"); Logger::nas_mm().debug("Decoding 5GMMCapability (IEI 0x10)");
ie_5g_mm_capability = new _5GMMCapability(); _5GMMCapability ie_5g_mm_capability_tmp = {};
decoded_size += ie_5g_mm_capability->decodeFromBuffer( if ((decoded_size_ie = ie_5g_mm_capability_tmp.decodeFromBuffer(
buf + decoded_size, len - decoded_size, true); buf + decoded_size, len - decoded_size, true)) ==
KEncodeDecodeError) {
return KEncodeDecodeError;
}
decoded_size += decoded_size_ie;
ie_5g_mm_capability =
std::optional<_5GMMCapability>(ie_5g_mm_capability_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;
......
...@@ -71,11 +71,11 @@ class RegistrationRequest : public NasMmPlainHeader { ...@@ -71,11 +71,11 @@ class RegistrationRequest : public NasMmPlainHeader {
uint8_t amf_set_id, uint8_t amf_pointer, const string _5g_tmsi); uint8_t amf_set_id, uint8_t amf_pointer, const string _5g_tmsi);
bool getAdditionalGuti(nas::_5G_GUTI_t& guti); bool getAdditionalGuti(nas::_5G_GUTI_t& guti);
void setNon_current_native_nas_ksi(uint8_t tsc, uint8_t key_set_id); void setNonCurrentNativeNasKSI(uint8_t tsc, uint8_t key_set_id);
bool getNonCurrentNativeNasKSI(uint8_t& value) const; bool getNonCurrentNativeNasKSI(uint8_t& value) const;
void set5G_MM_capability(uint8_t value); void set5G_MM_capability(uint8_t value);
uint8_t get5GMMCapability(); bool get5GMMCapability(uint8_t& value);
void setUE_Security_Capability(uint8_t g_EASel, uint8_t g_IASel); void setUE_Security_Capability(uint8_t g_EASel, uint8_t g_IASel);
void setUE_Security_Capability( void setUE_Security_Capability(
...@@ -152,7 +152,7 @@ class RegistrationRequest : public NasMmPlainHeader { ...@@ -152,7 +152,7 @@ class RegistrationRequest : public NasMmPlainHeader {
_5GSMobileIdentity ie_5gs_mobility_id; // Mandatory _5GSMobileIdentity ie_5gs_mobility_id; // Mandatory
std::optional<NasKeySetIdentifier> ie_non_current_native_nas_ksi; // Optional std::optional<NasKeySetIdentifier> ie_non_current_native_nas_ksi; // Optional
_5GMMCapability* ie_5g_mm_capability; // Optional std::optional<_5GMMCapability> ie_5g_mm_capability; // Optional
UESecurityCapability* ie_ue_security_capability; // Optional UESecurityCapability* ie_ue_security_capability; // Optional
NSSAI* ie_requested_NSSAI; // Optional NSSAI* ie_requested_NSSAI; // Optional
// TODO: Last visited registered TAI // TODO: Last visited registered TAI
......
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