Commit 2581c2eb authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Update Configuration Update Command

parent 4fa0f372
...@@ -3220,7 +3220,7 @@ void amf_n1::ul_nas_transport_handle( ...@@ -3220,7 +3220,7 @@ void amf_n1::ul_nas_transport_handle(
// Decode UL_NAS_TRANSPORT message // Decode UL_NAS_TRANSPORT message
Logger::amf_n1().debug("Handling UL NAS Transport"); Logger::amf_n1().debug("Handling UL NAS Transport");
auto ul_nas = std::make_unique<ULNASTransport>(); auto ul_nas = std::make_unique<ULNASTransport>();
ul_nas->Decode(NULL, (uint8_t*) bdata(nas), blength(nas)); ul_nas->Decode((uint8_t*) bdata(nas), blength(nas));
uint8_t payload_type = ul_nas->GetPayloadContainerType(); uint8_t payload_type = ul_nas->GetPayloadContainerType();
uint8_t pdu_session_id = ul_nas->GetPduSessionId(); uint8_t pdu_session_id = ul_nas->GetPduSessionId();
......
...@@ -111,7 +111,7 @@ void NetworkName::setTextString(const bstring& str) { ...@@ -111,7 +111,7 @@ void NetworkName::setTextString(const bstring& str) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int NetworkName::encode2buffer(uint8_t* buf, int len) { int NetworkName::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding NetworkName"); Logger::nas_mm().debug("Encoding NetworkName");
if (len < kNetworkNameMinimumLength) { if (len < kNetworkNameMinimumLength) {
......
...@@ -47,7 +47,7 @@ class NetworkName { ...@@ -47,7 +47,7 @@ class NetworkName {
void setTextString(const std::string& str); void setTextString(const std::string& str);
void setTextString(const bstring& str); void setTextString(const bstring& str);
int encode2buffer(uint8_t* buf, int len); int Encode(uint8_t* buf, int len);
int decodefrombuffer(uint8_t* buf, int len, bool is_option = true); int decodefrombuffer(uint8_t* buf, int len, bool is_option = true);
private: private:
......
...@@ -80,7 +80,7 @@ int Rejected_NSSAI::Encode(uint8_t* buf, int len) { ...@@ -80,7 +80,7 @@ int Rejected_NSSAI::Encode(uint8_t* buf, int len) {
uint8_t payload_len = 0; uint8_t payload_len = 0;
for (auto n : rejected_nssais) { for (auto n : rejected_nssais) {
int size = n.encode2buffer(buf + encoded_size, len - encoded_size); int size = n.Encode(buf + encoded_size, len - encoded_size);
if (size != KEncodeDecodeError) { if (size != KEncodeDecodeError) {
encoded_size += size; encoded_size += size;
payload_len += size; payload_len += size;
......
...@@ -107,7 +107,7 @@ void Rejected_SNSSAI::getCause(uint8_t& cause) { ...@@ -107,7 +107,7 @@ void Rejected_SNSSAI::getCause(uint8_t& cause) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int Rejected_SNSSAI::encode2buffer(uint8_t* buf, int len) { int Rejected_SNSSAI::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding Rejected_SNSSAI"); Logger::nas_mm().debug("Encoding Rejected_SNSSAI");
if (len < length_ + 1) { if (len < length_ + 1) {
Logger::nas_mm().error("len is less than %d", length_); Logger::nas_mm().error("len is less than %d", length_);
......
...@@ -47,7 +47,7 @@ class Rejected_SNSSAI { ...@@ -47,7 +47,7 @@ class Rejected_SNSSAI {
uint8_t getCause(); uint8_t getCause();
void getCause(uint8_t& cause); void getCause(uint8_t& cause);
int encode2buffer(uint8_t* buf, int len); int Encode(uint8_t* buf, int len);
int decodefrombuffer(uint8_t* buf, int len); int decodefrombuffer(uint8_t* buf, int len);
private: private:
......
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
using namespace nas; using namespace nas;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
ConfigurationUpdateCommand::ConfigurationUpdateCommand() { ConfigurationUpdateCommand::ConfigurationUpdateCommand()
plain_header = nullptr; : NasMmPlainHeader(EPD_5GS_MM_MSG, CONFIGURATION_UPDATE_COMMAND) {
full_name_for_network = nullopt; full_name_for_network = nullopt;
short_name_for_network = nullopt; short_name_for_network = nullopt;
} }
...@@ -39,9 +39,7 @@ ConfigurationUpdateCommand::~ConfigurationUpdateCommand() {} ...@@ -39,9 +39,7 @@ ConfigurationUpdateCommand::~ConfigurationUpdateCommand() {}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void ConfigurationUpdateCommand::SetHeader(uint8_t security_header_type) { void ConfigurationUpdateCommand::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, CONFIGURATION_UPDATE_COMMAND);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -94,36 +92,41 @@ void ConfigurationUpdateCommand::getShortNameForNetwork( ...@@ -94,36 +92,41 @@ void ConfigurationUpdateCommand::getShortNameForNetwork(
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int ConfigurationUpdateCommand::Encode(uint8_t* buf, int len) { int ConfigurationUpdateCommand::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding ConfigurationUpdateCommand message"); Logger::nas_mm().debug("Encoding ConfigurationUpdateCommand 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 -1;
// Header
if ((encoded_ie_size = NasMmPlainHeader::Encode(buf, len)) ==
KEncodeDecodeError) {
Logger::nas_mm().error("Encoding NAS Header error");
return KEncodeDecodeError;
} }
uint8_t encoded_size_ie = 0; encoded_size += encoded_ie_size;
if (!(encoded_size_ie = plain_header->Encode(buf, len))) return 0;
encoded_size += encoded_size_ie;
if (!full_name_for_network.has_value()) { if (!full_name_for_network.has_value()) {
Logger::nas_mm().debug("IE Full Name For Network is not available"); Logger::nas_mm().debug("IE Full Name For Network is not available");
} else { } else {
if (int size = full_name_for_network.value().encode2buffer( encoded_ie_size = full_name_for_network.value().Encode(
buf + encoded_size, len - encoded_size)) { buf + encoded_size, len - encoded_size);
encoded_size += size; if (encoded_ie_size != KEncodeDecodeError) {
encoded_size += encoded_ie_size;
} else { } else {
Logger::nas_mm().error("Encoding Full Name For Network error"); Logger::nas_mm().error("Encoding Full Name For Network error");
return 0; return KEncodeDecodeError;
} }
} }
if (!short_name_for_network.has_value()) { if (!short_name_for_network.has_value()) {
Logger::nas_mm().debug("IE Short Name For Network is not available"); Logger::nas_mm().debug("IE Short Name For Network is not available");
} else { } else {
if (int size = short_name_for_network.value().encode2buffer( encoded_ie_size = short_name_for_network.value().Encode(
buf + encoded_size, len - encoded_size)) { buf + encoded_size, len - encoded_size);
encoded_size += size; if (encoded_ie_size != KEncodeDecodeError) {
encoded_size += encoded_ie_size;
} else { } else {
Logger::nas_mm().error("Encoding Short Name For Network error"); Logger::nas_mm().error("Encoding Short Name For Network error");
return 0; return KEncodeDecodeError;
} }
} }
...@@ -135,10 +138,17 @@ int ConfigurationUpdateCommand::Encode(uint8_t* buf, int len) { ...@@ -135,10 +138,17 @@ int ConfigurationUpdateCommand::Encode(uint8_t* buf, int len) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int ConfigurationUpdateCommand::Decode(uint8_t* buf, int len) { int ConfigurationUpdateCommand::Decode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Decoding ConfigurationUpdateCommand message"); Logger::nas_mm().debug("Decoding ConfigurationUpdateCommand message");
int decoded_size = 0;
uint8_t decoded_size_ie = 0; int decoded_size = 0;
if (!(decoded_size_ie = plain_header->Decode(buf, len))) return 0; int decoded_result = 0;
decoded_size += decoded_size_ie;
// 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;
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);
...@@ -146,9 +156,12 @@ int ConfigurationUpdateCommand::Decode(uint8_t* buf, int len) { ...@@ -146,9 +156,12 @@ int ConfigurationUpdateCommand::Decode(uint8_t* buf, int len) {
switch (octet) { switch (octet) {
case kIeiFullNameForNetwork: { case kIeiFullNameForNetwork: {
Logger::nas_mm().debug("Decoding IEI 0x43: Full Name for Network"); Logger::nas_mm().debug("Decoding IEI 0x43: Full Name for Network");
NetworkName full_name_for_network_tmp; NetworkName full_name_for_network_tmp = {};
decoded_size += full_name_for_network_tmp.decodefrombuffer( if ((decoded_result = full_name_for_network_tmp.decodefrombuffer(
buf + decoded_size, len - decoded_size, true); buf + decoded_size, len - decoded_size, true)) ==
KEncodeDecodeError)
return decoded_result;
decoded_size += decoded_result;
full_name_for_network = full_name_for_network =
std::optional<NetworkName>(full_name_for_network_tmp); std::optional<NetworkName>(full_name_for_network_tmp);
octet = *(buf + decoded_size); octet = *(buf + decoded_size);
...@@ -156,9 +169,12 @@ int ConfigurationUpdateCommand::Decode(uint8_t* buf, int len) { ...@@ -156,9 +169,12 @@ int ConfigurationUpdateCommand::Decode(uint8_t* buf, int len) {
} break; } break;
case kIeiShortNameForNetwork: { case kIeiShortNameForNetwork: {
Logger::nas_mm().debug("Decoding IEI 0x45: Short Name for Network"); Logger::nas_mm().debug("Decoding IEI 0x45: Short Name for Network");
NetworkName short_name_for_network_tmp; NetworkName short_name_for_network_tmp = {};
decoded_size += short_name_for_network_tmp.decodefrombuffer( if ((decoded_result = short_name_for_network_tmp.decodefrombuffer(
buf + decoded_size, len - decoded_size, true); buf + decoded_size, len - decoded_size, true)) ==
KEncodeDecodeError)
return decoded_result;
decoded_size += decoded_result;
short_name_for_network = short_name_for_network =
std::optional<NetworkName>(short_name_for_network_tmp); std::optional<NetworkName>(short_name_for_network_tmp);
octet = *(buf + decoded_size); octet = *(buf + decoded_size);
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "NasIeHeader.hpp" #include "NasIeHeader.hpp"
namespace nas { namespace nas {
class ConfigurationUpdateCommand { class ConfigurationUpdateCommand : public NasMmPlainHeader {
public: public:
ConfigurationUpdateCommand(); ConfigurationUpdateCommand();
~ConfigurationUpdateCommand(); ~ConfigurationUpdateCommand();
...@@ -50,8 +50,6 @@ class ConfigurationUpdateCommand { ...@@ -50,8 +50,6 @@ class ConfigurationUpdateCommand {
int Decode(uint8_t* buf, int len); int Decode(uint8_t* buf, int len);
public: public:
NasMmPlainHeader*
plain_header; // TODO: Should be removed in the new NAS version
// Optional // Optional
// TODO: Configuration update indication // TODO: Configuration update indication
// TODO: 5G-GUTI // TODO: 5G-GUTI
......
...@@ -233,13 +233,11 @@ int DLNASTransport::Decode(uint8_t* buf, int len) { ...@@ -233,13 +233,11 @@ int DLNASTransport::Decode(uint8_t* buf, int len) {
decoded_size += decoded_result; decoded_size += decoded_result;
ie_additional_information = ie_additional_information =
std::optional<AdditionalInformation>(ie_additional_information_tmp); std::optional<AdditionalInformation>(ie_additional_information_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 kIei5gmmCause: { case kIei5gmmCause: {
Logger::nas_mm().debug("Decoding IEI (0x58)"); Logger::nas_mm().debug("Decoding IEI (0x58)");
_5GMM_Cause ie_5gmm_cause_tmp = {}; _5GMM_Cause ie_5gmm_cause_tmp = {};
if ((decoded_result = ie_5gmm_cause_tmp.Decode( if ((decoded_result = ie_5gmm_cause_tmp.Decode(
buf + decoded_size, len - decoded_size, true)) == buf + decoded_size, len - decoded_size, true)) ==
...@@ -247,13 +245,11 @@ int DLNASTransport::Decode(uint8_t* buf, int len) { ...@@ -247,13 +245,11 @@ int DLNASTransport::Decode(uint8_t* buf, int len) {
return decoded_result; return decoded_result;
decoded_size += decoded_result; decoded_size += decoded_result;
ie_5gmm_cause = std::optional<_5GMM_Cause>(ie_5gmm_cause_tmp); ie_5gmm_cause = std::optional<_5GMM_Cause>(ie_5gmm_cause_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 kIeiGprsTimer3BackOffTimer: { case kIeiGprsTimer3BackOffTimer: {
Logger::nas_mm().debug("Decoding IEI (0x37)"); Logger::nas_mm().debug("Decoding IEI (0x37)");
GprsTimer3 ie_back_off_timer_value_tmp(kIeiGprsTimer3BackOffTimer); GprsTimer3 ie_back_off_timer_value_tmp(kIeiGprsTimer3BackOffTimer);
if ((decoded_result = ie_back_off_timer_value_tmp.Decode( if ((decoded_result = ie_back_off_timer_value_tmp.Decode(
buf + decoded_size, len - decoded_size, true)) == buf + decoded_size, len - decoded_size, true)) ==
...@@ -262,7 +258,6 @@ int DLNASTransport::Decode(uint8_t* buf, int len) { ...@@ -262,7 +258,6 @@ int DLNASTransport::Decode(uint8_t* buf, int len) {
decoded_size += decoded_result; decoded_size += decoded_result;
ie_back_off_timer_value = ie_back_off_timer_value =
std::optional<GprsTimer3>(ie_back_off_timer_value_tmp); std::optional<GprsTimer3>(ie_back_off_timer_value_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;
...@@ -270,5 +265,5 @@ int DLNASTransport::Decode(uint8_t* buf, int len) { ...@@ -270,5 +265,5 @@ int DLNASTransport::Decode(uint8_t* buf, int len) {
} }
Logger::nas_mm().debug( Logger::nas_mm().debug(
"Decoded DLNASTransport message len (%d)", decoded_size); "Decoded DLNASTransport message len (%d)", decoded_size);
return 1; return decoded_size;
} }
...@@ -317,7 +317,7 @@ int ULNASTransport::Encode(uint8_t* buf, int len) { ...@@ -317,7 +317,7 @@ int ULNASTransport::Encode(uint8_t* buf, int len) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int ULNASTransport::Decode(NasMmPlainHeader* header, uint8_t* buf, int len) { int ULNASTransport::Decode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Decoding ULNASTransport message"); Logger::nas_mm().debug("Decoding ULNASTransport message");
int decoded_size = 0; int decoded_size = 0;
int decoded_result = 0; int decoded_result = 0;
......
...@@ -34,7 +34,7 @@ class ULNASTransport : public NasMmPlainHeader { ...@@ -34,7 +34,7 @@ class ULNASTransport : public NasMmPlainHeader {
void SetHeader(uint8_t security_header_type); void SetHeader(uint8_t security_header_type);
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 SetPayloadContainerType(uint8_t value); void SetPayloadContainerType(uint8_t value);
uint8_t GetPayloadContainerType(); uint8_t GetPayloadContainerType();
......
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