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