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

Code cleanup of Payload container

parent 1a8eb820
...@@ -164,6 +164,7 @@ static const std::vector<std::string> nas_ciphering_algorithm_list_e2str = { ...@@ -164,6 +164,7 @@ static const std::vector<std::string> nas_ciphering_algorithm_list_e2str = {
/********************* UL NAS TRANSPORT payload container type /********************* UL NAS TRANSPORT payload container type
* **************************/ * **************************/
// TODO: define enum class
#define N1_SM_INFORMATION 0x01 #define N1_SM_INFORMATION 0x01
#define SMS_CONTAINER 0x02 #define SMS_CONTAINER 0x02
#define LTE_POSITIONING_PROTOCOL 0x03 #define LTE_POSITIONING_PROTOCOL 0x03
......
...@@ -83,4 +83,5 @@ constexpr uint8_t kIeiSscMode = 0x0a; ...@@ -83,4 +83,5 @@ constexpr uint8_t kIeiSscMode = 0x0a;
constexpr uint8_t kIeiSuggestedInterfaceIdentifier = 0x29; constexpr uint8_t kIeiSuggestedInterfaceIdentifier = 0x29;
constexpr uint8_t kIeiUeDsTtResidenceTime = 0x6f; constexpr uint8_t kIeiUeDsTtResidenceTime = 0x6f;
constexpr uint8_t kIeiEpsNasMessageContainer = 0x70; constexpr uint8_t kIeiEpsNasMessageContainer = 0x70; // OK
constexpr uint8_t kIeiPayloadContainerType = 0x08; // Should be verified
This diff is collapsed.
...@@ -19,13 +19,6 @@ ...@@ -19,13 +19,6 @@
* contact@openairinterface.org * contact@openairinterface.org
*/ */
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef __Payload_Container_H_ #ifndef __Payload_Container_H_
#define __Payload_Container_H_ #define __Payload_Container_H_
#include <stdint.h> #include <stdint.h>
...@@ -39,6 +32,10 @@ extern "C" { ...@@ -39,6 +32,10 @@ extern "C" {
#include "TLVEncoder.h" #include "TLVEncoder.h"
#include "bstrlib.h" #include "bstrlib.h"
} }
constexpr uint8_t kPayloadContainerMinimumLength = 4;
constexpr uint32_t kPayloadContainerMaximumLength = 65538;
namespace nas { namespace nas {
class Payload_Container { class Payload_Container {
public: public:
...@@ -49,17 +46,16 @@ class Payload_Container { ...@@ -49,17 +46,16 @@ class Payload_Container {
const uint8_t iei, std::vector<PayloadContainerEntry> content); const uint8_t iei, std::vector<PayloadContainerEntry> content);
~Payload_Container(); ~Payload_Container();
void setValue(uint8_t iei, uint8_t value); void setValue(uint8_t iei, uint8_t value);
int encode2Buffer(uint8_t* buf, int len); int encode2Buffer(uint8_t* buf, int len, uint8_t type);
int decodeFromBuffer(uint8_t* buf, int len, bool is_option, uint8_t type); int decodeFromBuffer(uint8_t* buf, int len, bool is_option, uint8_t type);
int decodeFromBuffer(uint8_t* buf, int len, bool is_option);
void getValue(std::vector<PayloadContainerEntry>& content); void getValue(std::vector<PayloadContainerEntry>& content);
void getValue(bstring& cnt); void getValue(bstring& cnt);
private: private:
uint8_t _iei; uint8_t _iei;
uint16_t length; uint16_t length;
bstring content; std::optional<bstring> content;
std::vector<PayloadContainerEntry> CONTENT; std::optional<std::vector<PayloadContainerEntry>> CONTENT;
}; };
} // namespace nas } // namespace nas
......
...@@ -19,15 +19,10 @@ ...@@ -19,15 +19,10 @@
* contact@openairinterface.org * contact@openairinterface.org
*/ */
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#include "Payload_Container_Type.hpp" #include "Payload_Container_Type.hpp"
#include "3gpp_24.501.hpp"
#include "common_defs.h"
#include "logger.hpp" #include "logger.hpp"
using namespace nas; using namespace nas;
...@@ -35,7 +30,7 @@ using namespace nas; ...@@ -35,7 +30,7 @@ using namespace nas;
Payload_Container_Type::Payload_Container_Type( Payload_Container_Type::Payload_Container_Type(
const uint8_t iei, uint8_t value) { const uint8_t iei, uint8_t value) {
_iei = iei; _iei = iei;
_value = value; _value = value & 0x0f;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -46,7 +41,7 @@ Payload_Container_Type::~Payload_Container_Type(){}; ...@@ -46,7 +41,7 @@ Payload_Container_Type::~Payload_Container_Type(){};
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void Payload_Container_Type::setValue(const uint8_t value) { void Payload_Container_Type::setValue(const uint8_t value) {
_value = value; _value = value & 0x0f;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -56,44 +51,50 @@ uint8_t Payload_Container_Type::getValue() { ...@@ -56,44 +51,50 @@ uint8_t Payload_Container_Type::getValue() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int Payload_Container_Type::encode2Buffer(uint8_t* buf, int len) { int Payload_Container_Type::encode2Buffer(uint8_t* buf, int len) {
Logger::nas_mm().debug("encoding Payload_Container_Type IE iei(0x%x)", _iei); Logger::nas_mm().debug("Encoding Payload_Container_Type IE");
if (len < 1) {
Logger::nas_mm().error("len is less than one"); if (len < kPayloadContainerTypeLength) {
return -1; Logger::nas_mm().error(
} else { "Buffer length is less than the minimum length of this IE (%d octet)",
kPayloadContainerTypeLength);
return KEncodeDecodeError;
}
int encoded_size = 0;
uint8_t octet = 0; uint8_t octet = 0;
if (!(_iei & 0x0f)) { if (_iei) {
octet = (_value & 0x0f);
*buf = octet;
Logger::nas_mm().debug(
"encoded Payload_Container_Type IE(len(1/2 octet))");
return 1;
} else {
octet = (_iei << 4) | (_value & 0x0f); octet = (_iei << 4) | (_value & 0x0f);
*buf = octet; } else {
Logger::nas_mm().debug("encoded Payload_Container_Type IE(len(1 octet))"); octet = (_value & 0x0f);
return 1;
}
} }
ENCODE_U8(buf + encoded_size, octet, encoded_size);
Logger::nas_mm().debug("Encoded Payload_Container_Type IE");
return encoded_size;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int Payload_Container_Type::decodeFromBuffer( int Payload_Container_Type::decodeFromBuffer(
uint8_t* buf, int len, bool is_option) { uint8_t* buf, int len, bool is_option) {
Logger::nas_mm().debug("decoding Payload_Container_Type IE"); Logger::nas_mm().debug("decoding Payload_Container_Type IE");
if (len < 1) {
Logger::nas_mm().error("len is less than one"); if (len < kPayloadContainerTypeLength) {
return 0; Logger::nas_mm().error(
} else { "Buffer length is less than the minimum length of this IE (%d octet)",
uint8_t octet = (*buf); kPayloadContainerTypeLength);
return KEncodeDecodeError;
}
int decoded_size = 0;
uint8_t octet = 0;
DECODE_U8(buf + decoded_size, octet, decoded_size);
if (is_option) { if (is_option) {
_iei = (octet & 0xf0) >> 4; _iei = (octet & 0xf0) >> 4;
} else {
_iei = 0;
} }
_value = octet & 0x0f; _value = octet & 0x0f;
Logger::nas_mm().debug( Logger::nas_mm().debug(
"decoded Payload_Container_Type iei(0x%x) value(0x%x)", _iei, _value); "Decoded Payload_Container_Type (IEI 0x%x, value 0x%x)", _iei, _value);
return 1; return decoded_size;
}
} }
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include <stdint.h> #include <stdint.h>
constexpr uint8_t kPayloadContainerTypeLength = 1;
namespace nas { namespace nas {
class Payload_Container_Type { class Payload_Container_Type {
......
...@@ -94,6 +94,7 @@ typedef struct { ...@@ -94,6 +94,7 @@ typedef struct {
} IE_t_E; } IE_t_E;
typedef struct { typedef struct {
uint8_t length;
uint8_t payloadContainerType : 4; uint8_t payloadContainerType : 4;
std::vector<IE_t> optionalIE; std::vector<IE_t> optionalIE;
} PayloadContainerEntry; } PayloadContainerEntry;
......
...@@ -113,11 +113,12 @@ int DLNASTransport::encode2Buffer(uint8_t* buf, int len) { ...@@ -113,11 +113,12 @@ int DLNASTransport::encode2Buffer(uint8_t* buf, int len) {
return 0; return 0;
} }
} }
if (!ie_payload_container) { if (!ie_payload_container or !ie_payload_container_type) {
Logger::nas_mm().warn("IE ie_payload_container is not available"); Logger::nas_mm().warn("IE ie_payload_container is not available");
} else { } else {
if (int size = ie_payload_container->encode2Buffer( if (int size = ie_payload_container->encode2Buffer(
buf + encoded_size, len - encoded_size)) { buf + encoded_size, len - encoded_size,
ie_payload_container_type->getValue())) {
encoded_size += size; encoded_size += size;
} else { } else {
Logger::nas_mm().error("Encoding ie_payload_container error"); Logger::nas_mm().error("Encoding ie_payload_container error");
...@@ -183,7 +184,8 @@ int DLNASTransport::decodeFromBuffer( ...@@ -183,7 +184,8 @@ int DLNASTransport::decodeFromBuffer(
buf + decoded_size, len - decoded_size, false); buf + decoded_size, len - decoded_size, false);
ie_payload_container = new Payload_Container(); ie_payload_container = new Payload_Container();
decoded_size += ie_payload_container->decodeFromBuffer( decoded_size += ie_payload_container->decodeFromBuffer(
buf + decoded_size, len - decoded_size, false); buf + decoded_size, len - decoded_size, false,
N1_SM_INFORMATION); // TODO: verified Typeb of Payload Container
Logger::nas_mm().debug("Decoded_size (%d)", decoded_size); Logger::nas_mm().debug("Decoded_size (%d)", decoded_size);
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);
......
...@@ -46,7 +46,7 @@ RegistrationRequest::RegistrationRequest() ...@@ -46,7 +46,7 @@ RegistrationRequest::RegistrationRequest()
ie_5gs_drx_parameters = std::nullopt; ie_5gs_drx_parameters = std::nullopt;
ie_eps_nas_message_container = std::nullopt; ie_eps_nas_message_container = std::nullopt;
ie_ladn_indication = std::nullopt; ie_ladn_indication = std::nullopt;
ie_payload_container_type = nullptr; ie_payload_container_type = std::nullopt;
ie_payload_container = nullptr; ie_payload_container = nullptr;
ie_network_slicing_indication = nullptr; ie_network_slicing_indication = nullptr;
ie_5gs_update_type = nullptr; ie_5gs_update_type = nullptr;
...@@ -428,13 +428,14 @@ bool RegistrationRequest::getLadnIndication(std::vector<bstring>& ladnValue) { ...@@ -428,13 +428,14 @@ bool RegistrationRequest::getLadnIndication(std::vector<bstring>& ladnValue) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void RegistrationRequest::setPayload_Container_Type(uint8_t value) { void RegistrationRequest::setPayload_Container_Type(uint8_t value) {
ie_payload_container_type = new Payload_Container_Type(0x08, value); ie_payload_container_type = std::make_optional<Payload_Container_Type>(
kIeiPayloadContainerType, value);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
uint8_t RegistrationRequest::getPayloadContainerType() { uint8_t RegistrationRequest::getPayloadContainerType() {
if (ie_payload_container_type) { if (ie_payload_container_type.has_value()) {
return ie_payload_container_type->getValue(); return ie_payload_container_type.value().getValue();
} else { } else {
return 0; return 0;
} }
...@@ -758,10 +759,10 @@ int RegistrationRequest::encode2Buffer(uint8_t* buf, int len) { ...@@ -758,10 +759,10 @@ int RegistrationRequest::encode2Buffer(uint8_t* buf, int len) {
return 0; return 0;
} }
} }
if (!ie_payload_container_type) { if (!ie_payload_container_type.has_value()) {
Logger::nas_mm().warn("IE ie_payload_container_type is not available"); Logger::nas_mm().warn("IE ie_payload_container_type is not available");
} else { } else {
if (int size = ie_payload_container_type->encode2Buffer( if (int size = ie_payload_container_type.value().encode2Buffer(
buf + encoded_size, len - encoded_size)) { buf + encoded_size, len - encoded_size)) {
encoded_size += size; encoded_size += size;
} else { } else {
...@@ -769,11 +770,12 @@ int RegistrationRequest::encode2Buffer(uint8_t* buf, int len) { ...@@ -769,11 +770,12 @@ int RegistrationRequest::encode2Buffer(uint8_t* buf, int len) {
return 0; return 0;
} }
} }
if (!ie_payload_container) { if (!ie_payload_container or !ie_payload_container_type) {
Logger::nas_mm().warn("IE ie_payload_container is not available"); Logger::nas_mm().warn("IE ie_payload_container is not available");
} else { } else {
if (int size = ie_payload_container->encode2Buffer( if (int size = ie_payload_container->encode2Buffer(
buf + encoded_size, len - encoded_size)) { buf + encoded_size, len - encoded_size,
ie_payload_container_type.value().getValue())) {
encoded_size += size; encoded_size += size;
} else { } else {
Logger::nas_mm().error("encoding ie_payload_container error"); Logger::nas_mm().error("encoding ie_payload_container error");
...@@ -873,11 +875,13 @@ int RegistrationRequest::decodeFromBuffer(uint8_t* buf, int len) { ...@@ -873,11 +875,13 @@ int RegistrationRequest::decodeFromBuffer(uint8_t* buf, int len) {
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 0x08: { case kIeiPayloadContainerType: {
Logger::nas_mm().debug("Decoding IEI (0x8)"); Logger::nas_mm().debug("Decoding IEI 0x8: Payload Container Type");
ie_payload_container_type = new Payload_Container_Type(); Payload_Container_Type ie_payload_container_type_tmp = {};
decoded_size += ie_payload_container_type->decodeFromBuffer( decoded_size += ie_payload_container_type_tmp.decodeFromBuffer(
buf + decoded_size, len - decoded_size, true); buf + decoded_size, len - decoded_size, true);
ie_payload_container_type = std::optional<Payload_Container_Type>(
ie_payload_container_type_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;
...@@ -1046,7 +1050,8 @@ int RegistrationRequest::decodeFromBuffer(uint8_t* buf, int len) { ...@@ -1046,7 +1050,8 @@ int RegistrationRequest::decodeFromBuffer(uint8_t* buf, int len) {
Logger::nas_mm().debug("Decoding IEI(0x7B)"); Logger::nas_mm().debug("Decoding IEI(0x7B)");
ie_payload_container = new Payload_Container(); ie_payload_container = new Payload_Container();
decoded_size += ie_payload_container->decodeFromBuffer( decoded_size += ie_payload_container->decodeFromBuffer(
buf + decoded_size, len - decoded_size, true); buf + decoded_size, len - decoded_size, true,
N1_SM_INFORMATION); // TODO: verified type of Payload container
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;
......
...@@ -172,8 +172,8 @@ class RegistrationRequest : public NasMmPlainHeader { ...@@ -172,8 +172,8 @@ class RegistrationRequest : public NasMmPlainHeader {
std::optional<EPS_NAS_Message_Container> std::optional<EPS_NAS_Message_Container>
ie_eps_nas_message_container; // Optional ie_eps_nas_message_container; // Optional
std::optional<LADN_Indication> ie_ladn_indication; // Optional std::optional<LADN_Indication> ie_ladn_indication; // Optional
std::optional<Payload_Container_Type> ie_payload_container_type; // Optional
Payload_Container_Type* ie_payload_container_type; // Optional
Payload_Container* ie_payload_container; // Optional Payload_Container* ie_payload_container; // Optional
Network_Slicing_Indication* ie_network_slicing_indication; // Optional Network_Slicing_Indication* ie_network_slicing_indication; // Optional
_5GS_Update_Type* ie_5gs_update_type; // Optional _5GS_Update_Type* ie_5gs_update_type; // Optional
......
...@@ -195,11 +195,12 @@ int ULNASTransport::encode2Buffer(uint8_t* buf, int len) { ...@@ -195,11 +195,12 @@ int ULNASTransport::encode2Buffer(uint8_t* buf, int len) {
return 0; return 0;
} }
} }
if (!ie_payload_container) { if (!ie_payload_container or !ie_payload_container_type) {
Logger::nas_mm().warn("IE ie_payload_container is not available"); Logger::nas_mm().warn("IE ie_payload_container is not available");
} else { } else {
if (int size = ie_payload_container->encode2Buffer( if (int size = ie_payload_container->encode2Buffer(
buf + encoded_size, len - encoded_size)) { buf + encoded_size, len - encoded_size,
ie_payload_container_type->getValue())) {
encoded_size += size; encoded_size += size;
} else { } else {
Logger::nas_mm().error("encoding ie_payload_container error"); Logger::nas_mm().error("encoding ie_payload_container error");
......
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