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