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