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

First refactoring version of PduSessionResourceModifyRequest

parent 9d560c5f
......@@ -379,3 +379,17 @@ bool conv::octet_string_2_int8(const OCTET_STRING_t& o_str, uint8_t& value) {
value = o_str.buf[0];
return true;
}
//------------------------------------------------------------------------------
bool conv::octet_string_2_octet_string(
OCTET_STRING_t& destination, const OCTET_STRING_t& source) {
if (!source.buf) return false;
destination.buf = (uint8_t*) calloc(source.size + 1, sizeof(uint8_t));
if (!destination.buf) return false;
memcpy(destination.buf, source.buf, source.size);
((uint8_t*) destination.buf)[source.size] = '\0';
destination.size = source.size;
return true;
}
......@@ -81,5 +81,8 @@ class conv {
static bool int8_2_octet_string(const uint8_t& value, OCTET_STRING_t& o_str);
static bool octet_string_2_int8(const OCTET_STRING_t& o_str, uint8_t& value);
// TODO: bitstring_2_int32
static bool octet_string_2_octet_string(
OCTET_STRING_t& destination, const OCTET_STRING_t& source);
};
#endif /* FILE_CONVERSIONS_HPP_SEEN */
......@@ -20,13 +20,16 @@
*/
#include "NAS-PDU.hpp"
#include "conversions.hpp"
namespace ngap {
//------------------------------------------------------------------------------
NAS_PDU::NAS_PDU() {
buffer_ = nullptr;
size_ = -1;
// buffer_ = nullptr;
// size_ = -1;
pdu_.buf = nullptr;
pdu_.size = -1;
}
//------------------------------------------------------------------------------
......@@ -34,32 +37,60 @@ NAS_PDU::~NAS_PDU() {}
//------------------------------------------------------------------------------
bool NAS_PDU::encode(Ngap_NAS_PDU_t& nas_pdu) {
int ret;
ret = OCTET_STRING_fromBuf(&nas_pdu, buffer_, size_);
if (ret != 0) return false;
return true;
if (!pdu_.buf) return false;
return conv::octet_string_2_octet_string(nas_pdu, pdu_);
// int ret = OCTET_STRING_fromBuf(&nas_pdu, buffer_, size_);
// if (ret != 0) return false;
// return true;
}
//------------------------------------------------------------------------------
bool NAS_PDU::decode(Ngap_NAS_PDU_t& nas_pdu) {
buffer_ = (char*) nas_pdu.buf;
size_ = nas_pdu.size;
return true;
if (!nas_pdu.buf) return false;
return conv::octet_string_2_octet_string(pdu_, nas_pdu);
// buffer_ = (char*) calloc(nas_pdu.size, sizeof(char));
// memcpy(buffer_, nas_pdu.buf, nas_pdu.size);
// size_ = nas_pdu.size;
// return true;
}
//------------------------------------------------------------------------------
bool NAS_PDU::get(uint8_t*& buffer, size_t& size) const {
buffer = (uint8_t*) buffer_;
size = size_;
if (!buffer_) return false;
if (size_ < 0) return false;
if (!pdu_.buf) return false;
if (pdu_.size < 0) return false;
memcpy(buffer, pdu_.buf, pdu_.size);
size = pdu_.size;
return true;
}
//------------------------------------------------------------------------------
void NAS_PDU::set(uint8_t* buffer, size_t size) {
buffer_ = (char*) buffer;
size_ = size;
if (!buffer) return;
pdu_.buf = (uint8_t*) calloc(size, sizeof(uint8_t));
memcpy(pdu_.buf, buffer, size);
pdu_.size = size;
return;
}
//------------------------------------------------------------------------------
bool NAS_PDU::get(OCTET_STRING_t& pdu) const {
return conv::octet_string_2_octet_string(pdu, pdu_);
}
//------------------------------------------------------------------------------
bool NAS_PDU::set(const OCTET_STRING_t& pdu) {
return conv::octet_string_2_octet_string(pdu_, pdu);
}
//------------------------------------------------------------------------------
bool NAS_PDU::get(NAS_PDU& nas_pdu) const {
return nas_pdu.set(pdu_);
}
//------------------------------------------------------------------------------
bool NAS_PDU::set(const NAS_PDU& nas_pdu) {
OCTET_STRING_t pdu = {};
nas_pdu.get(pdu);
return conv::octet_string_2_octet_string(pdu_, pdu);
}
} // namespace ngap
......@@ -38,9 +38,15 @@ class NAS_PDU {
bool get(uint8_t*& buffer, size_t& size) const;
void set(uint8_t* buffer, size_t size);
bool get(OCTET_STRING_t& pdu) const;
bool get(NAS_PDU& nas_pdu) const;
bool set(const OCTET_STRING_t& pdu);
bool set(const NAS_PDU& nas_pdu);
private:
char* buffer_;
size_t size_;
// char* buffer_;
// size_t size_;
OCTET_STRING_t pdu_;
};
} // namespace ngap
......
......@@ -31,9 +31,9 @@ UEPagingIdentity::~UEPagingIdentity() {}
//------------------------------------------------------------------------------
void UEPagingIdentity::setUEPagingIdentity(
const std::string& setid, const std::string& pointer,
const std::string& set_id, const std::string& pointer,
const std::string& tmsi) {
fiveGSTmsi.set(setid, pointer, tmsi);
fiveGSTmsi.set(set_id, pointer, tmsi);
}
//------------------------------------------------------------------------------
......@@ -43,8 +43,8 @@ void UEPagingIdentity::getUEPagingIdentity(std::string& _5g_s_tmsi) {
//------------------------------------------------------------------------------
void UEPagingIdentity::getUEPagingIdentity(
std::string& setid, std::string& pointer, std::string& tmsi) {
fiveGSTmsi.get(setid, pointer, tmsi);
std::string& set_id, std::string& pointer, std::string& tmsi) {
fiveGSTmsi.get(set_id, pointer, tmsi);
}
//------------------------------------------------------------------------------
......
......@@ -36,11 +36,11 @@ class UEPagingIdentity {
virtual ~UEPagingIdentity();
void setUEPagingIdentity(
const std::string& setid, const std::string& pointer,
const std::string& set_id, const std::string& pointer,
const std::string& tmsi);
void getUEPagingIdentity(std::string& _5g_s_tmsi);
void getUEPagingIdentity(
std::string& setid, std::string& pointer, std::string& tmsi);
std::string& set_id, std::string& pointer, std::string& tmsi);
bool encode2pdu(Ngap_UEPagingIdentity_t* pdu);
bool decodeFromPdu(Ngap_UEPagingIdentity_t pdu);
......
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