Commit 0344ddc8 authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Code refactoring for NAS PDU

parent 49a301cf
...@@ -664,7 +664,6 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) { ...@@ -664,7 +664,6 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) {
uint8_t* nas_buf = nullptr; uint8_t* nas_buf = nullptr;
size_t nas_len = 0; size_t nas_len = 0;
if (init_ue_msg.initUeMsg->getNasPdu(nas_buf, nas_len)) { if (init_ue_msg.initUeMsg->getNasPdu(nas_buf, nas_len)) {
// bstring nas = blk2bstr(nas_buf, nas_len);
itti_msg->nas_buf = blk2bstr(nas_buf, nas_len); itti_msg->nas_buf = blk2bstr(nas_buf, nas_len);
} else { } else {
Logger::amf_n2().error("Missing IE NAS-PDU"); Logger::amf_n2().error("Missing IE NAS-PDU");
......
...@@ -25,41 +25,41 @@ namespace ngap { ...@@ -25,41 +25,41 @@ namespace ngap {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
NAS_PDU::NAS_PDU() { NAS_PDU::NAS_PDU() {
naspdubuffer = NULL; buffer_ = nullptr;
buffersize = -1; size_ = -1;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
NAS_PDU::~NAS_PDU() {} NAS_PDU::~NAS_PDU() {}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool NAS_PDU::encode2octetstring(Ngap_NAS_PDU_t& m_naspdu) { bool NAS_PDU::encode(Ngap_NAS_PDU_t& nas_pdu) {
int ret; int ret;
ret = OCTET_STRING_fromBuf(&m_naspdu, naspdubuffer, buffersize); ret = OCTET_STRING_fromBuf(&nas_pdu, buffer_, size_);
if (ret != 0) return false; if (ret != 0) return false;
return true; return true;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool NAS_PDU::decodefromoctetstring(Ngap_NAS_PDU_t& m_naspdu) { bool NAS_PDU::decode(Ngap_NAS_PDU_t& nas_pdu) {
naspdubuffer = (char*) m_naspdu.buf; buffer_ = (char*) nas_pdu.buf;
buffersize = m_naspdu.size; size_ = nas_pdu.size;
return true; return true;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool NAS_PDU::getNasPdu(uint8_t*& buffer, size_t& size) const { bool NAS_PDU::getNasPdu(uint8_t*& buffer, size_t& size) const {
buffer = (uint8_t*) naspdubuffer; buffer = (uint8_t*) buffer_;
size = buffersize; size = size_;
if (!naspdubuffer) return false; if (!buffer_) return false;
if (buffersize < 0) return false; if (size_ < 0) return false;
return true; return true;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void NAS_PDU::setNasPdu(uint8_t* buffer, size_t size) { void NAS_PDU::setNasPdu(uint8_t* buffer, size_t size) {
naspdubuffer = (char*) buffer; buffer_ = (char*) buffer;
buffersize = size; size_ = size;
} }
} // namespace ngap } // namespace ngap
...@@ -33,14 +33,14 @@ class NAS_PDU { ...@@ -33,14 +33,14 @@ class NAS_PDU {
NAS_PDU(); NAS_PDU();
virtual ~NAS_PDU(); virtual ~NAS_PDU();
bool encode2octetstring(Ngap_NAS_PDU_t&); bool encode(Ngap_NAS_PDU_t&);
bool decodefromoctetstring(Ngap_NAS_PDU_t&); bool decode(Ngap_NAS_PDU_t&);
bool getNasPdu(uint8_t*& buffer, size_t& size) const; bool getNasPdu(uint8_t*& buffer, size_t& size) const;
void setNasPdu(uint8_t* buffer, size_t size); void setNasPdu(uint8_t* buffer, size_t size);
private: private:
char* naspdubuffer; char* buffer_;
size_t buffersize; size_t size_;
}; };
} // namespace ngap } // namespace ngap
......
...@@ -61,8 +61,7 @@ bool PDUSessionResourceModifyItemModReq:: ...@@ -61,8 +61,7 @@ bool PDUSessionResourceModifyItemModReq::
pduSessionResourceModifyItemModReq.nAS_PDU = pduSessionResourceModifyItemModReq.nAS_PDU =
(Ngap_NAS_PDU_t*) calloc(1, sizeof(Ngap_NAS_PDU_t)); (Ngap_NAS_PDU_t*) calloc(1, sizeof(Ngap_NAS_PDU_t));
if (!pduSessionResourceModifyItemModReq.nAS_PDU) return false; if (!pduSessionResourceModifyItemModReq.nAS_PDU) return false;
if (!nAS_PDU->encode2octetstring( if (!nAS_PDU->encode(*pduSessionResourceModifyItemModReq.nAS_PDU)) {
*pduSessionResourceModifyItemModReq.nAS_PDU)) {
if (pduSessionResourceModifyItemModReq.nAS_PDU != nullptr) if (pduSessionResourceModifyItemModReq.nAS_PDU != nullptr)
free(pduSessionResourceModifyItemModReq.nAS_PDU); free(pduSessionResourceModifyItemModReq.nAS_PDU);
return false; return false;
...@@ -86,8 +85,7 @@ bool PDUSessionResourceModifyItemModReq:: ...@@ -86,8 +85,7 @@ bool PDUSessionResourceModifyItemModReq::
if (pduSessionResourceModifyItemModReq.nAS_PDU) { if (pduSessionResourceModifyItemModReq.nAS_PDU) {
nAS_PDU = new NAS_PDU(); nAS_PDU = new NAS_PDU();
if (!nAS_PDU->decodefromoctetstring( if (!nAS_PDU->decode(*pduSessionResourceModifyItemModReq.nAS_PDU))
*pduSessionResourceModifyItemModReq.nAS_PDU))
return false; return false;
} }
......
...@@ -72,7 +72,7 @@ bool PDUSessionResourceSetupItemCxtReq:: ...@@ -72,7 +72,7 @@ bool PDUSessionResourceSetupItemCxtReq::
Ngap_NAS_PDU_t* naspdu = Ngap_NAS_PDU_t* naspdu =
(Ngap_NAS_PDU_t*) calloc(1, sizeof(Ngap_NAS_PDU_t)); (Ngap_NAS_PDU_t*) calloc(1, sizeof(Ngap_NAS_PDU_t));
if (!naspdu) return false; if (!naspdu) return false;
if (!nAS_PDU->encode2octetstring(*naspdu)) { if (!nAS_PDU->encode(*naspdu)) {
free_wrapper((void**) &naspdu); free_wrapper((void**) &naspdu);
return false; return false;
} }
...@@ -100,8 +100,7 @@ bool PDUSessionResourceSetupItemCxtReq:: ...@@ -100,8 +100,7 @@ bool PDUSessionResourceSetupItemCxtReq::
if (pduSessionResourceSetupItemCxtReq->nAS_PDU) { if (pduSessionResourceSetupItemCxtReq->nAS_PDU) {
if (nAS_PDU == nullptr) nAS_PDU = new NAS_PDU(); if (nAS_PDU == nullptr) nAS_PDU = new NAS_PDU();
if (!nAS_PDU->decodefromoctetstring( if (!nAS_PDU->decode(*pduSessionResourceSetupItemCxtReq->nAS_PDU))
*pduSessionResourceSetupItemCxtReq->nAS_PDU))
return false; return false;
} }
......
...@@ -68,7 +68,7 @@ bool PDUSessionResourceSetupItemSUReq::encode2PDUSessionResourceSetupItemSUReq( ...@@ -68,7 +68,7 @@ bool PDUSessionResourceSetupItemSUReq::encode2PDUSessionResourceSetupItemSUReq(
Ngap_NAS_PDU_t* naspdu = Ngap_NAS_PDU_t* naspdu =
(Ngap_NAS_PDU_t*) calloc(1, sizeof(Ngap_NAS_PDU_t)); (Ngap_NAS_PDU_t*) calloc(1, sizeof(Ngap_NAS_PDU_t));
if (!naspdu) return false; if (!naspdu) return false;
if (!nAS_PDU->encode2octetstring(*naspdu)) { if (!nAS_PDU->encode(*naspdu)) {
free_wrapper((void**) &naspdu); free_wrapper((void**) &naspdu);
return false; return false;
} }
...@@ -93,8 +93,7 @@ bool PDUSessionResourceSetupItemSUReq:: ...@@ -93,8 +93,7 @@ bool PDUSessionResourceSetupItemSUReq::
if (pduSessionResourceSetupItemSUReq->pDUSessionNAS_PDU) { if (pduSessionResourceSetupItemSUReq->pDUSessionNAS_PDU) {
nAS_PDU = new NAS_PDU(); nAS_PDU = new NAS_PDU();
if (!nAS_PDU->decodefromoctetstring( if (!nAS_PDU->decode(*pduSessionResourceSetupItemSUReq->pDUSessionNAS_PDU))
*pduSessionResourceSetupItemSUReq->pDUSessionNAS_PDU))
return false; return false;
} }
......
...@@ -154,7 +154,7 @@ void DownLinkNasTransportMsg::setNasPdu(uint8_t* nas, size_t sizeofnas) { ...@@ -154,7 +154,7 @@ void DownLinkNasTransportMsg::setNasPdu(uint8_t* nas, size_t sizeofnas) {
ie->criticality = Ngap_Criticality_reject; ie->criticality = Ngap_Criticality_reject;
ie->value.present = Ngap_DownlinkNASTransport_IEs__value_PR_NAS_PDU; ie->value.present = Ngap_DownlinkNASTransport_IEs__value_PR_NAS_PDU;
int ret = nasPdu.encode2octetstring(ie->value.choice.NAS_PDU); int ret = nasPdu.encode(ie->value.choice.NAS_PDU);
if (!ret) { if (!ret) {
Logger::ngap().error("Encode NAS_PDU IE error"); Logger::ngap().error("Encode NAS_PDU IE error");
free_wrapper((void**) &ie); free_wrapper((void**) &ie);
...@@ -284,9 +284,8 @@ bool DownLinkNasTransportMsg::decodeFromPdu(Ngap_NGAP_PDU_t* ngapMsgPdu) { ...@@ -284,9 +284,8 @@ bool DownLinkNasTransportMsg::decodeFromPdu(Ngap_NGAP_PDU_t* ngapMsgPdu) {
Ngap_Criticality_reject && Ngap_Criticality_reject &&
downLinkNasTransportIEs->protocolIEs.list.array[i]->value.present == downLinkNasTransportIEs->protocolIEs.list.array[i]->value.present ==
Ngap_DownlinkNASTransport_IEs__value_PR_NAS_PDU) { Ngap_DownlinkNASTransport_IEs__value_PR_NAS_PDU) {
if (!nasPdu.decodefromoctetstring( if (!nasPdu.decode(downLinkNasTransportIEs->protocolIEs.list.array[i]
downLinkNasTransportIEs->protocolIEs.list.array[i] ->value.choice.NAS_PDU)) {
->value.choice.NAS_PDU)) {
Logger::ngap().error("Decode NGAP NAS_PDU IE error"); Logger::ngap().error("Decode NGAP NAS_PDU IE error");
return false; return false;
} }
......
...@@ -383,7 +383,7 @@ void InitialContextSetupRequestMsg::setNasPdu(uint8_t* nas, size_t size) { ...@@ -383,7 +383,7 @@ void InitialContextSetupRequestMsg::setNasPdu(uint8_t* nas, size_t size) {
ie->criticality = Ngap_Criticality_ignore; ie->criticality = Ngap_Criticality_ignore;
ie->value.present = Ngap_InitialContextSetupRequestIEs__value_PR_NAS_PDU; ie->value.present = Ngap_InitialContextSetupRequestIEs__value_PR_NAS_PDU;
int ret = nasPdu->encode2octetstring(ie->value.choice.NAS_PDU); int ret = nasPdu->encode(ie->value.choice.NAS_PDU);
if (!ret) { if (!ret) {
Logger::ngap().error("Encode NAS PDU error!"); Logger::ngap().error("Encode NAS PDU error!");
free_wrapper((void**) &ie); free_wrapper((void**) &ie);
...@@ -638,7 +638,7 @@ bool InitialContextSetupRequestMsg::decodeFromPdu(Ngap_NGAP_PDU_t* ngapMsgPdu) { ...@@ -638,7 +638,7 @@ bool InitialContextSetupRequestMsg::decodeFromPdu(Ngap_NGAP_PDU_t* ngapMsgPdu) {
->value.present == ->value.present ==
Ngap_InitialContextSetupRequestIEs__value_PR_NAS_PDU) { Ngap_InitialContextSetupRequestIEs__value_PR_NAS_PDU) {
nasPdu = new NAS_PDU(); nasPdu = new NAS_PDU();
if (!nasPdu->decodefromoctetstring( if (!nasPdu->decode(
initialContextSetupRequestIEs->protocolIEs.list.array[i] initialContextSetupRequestIEs->protocolIEs.list.array[i]
->value.choice.NAS_PDU)) { ->value.choice.NAS_PDU)) {
Logger::ngap().error("Decoded NGAP NAS_PDU IE error"); Logger::ngap().error("Decoded NGAP NAS_PDU IE error");
......
...@@ -81,7 +81,7 @@ void InitialUEMessageMsg::setNasPdu(uint8_t* nas, size_t size) { ...@@ -81,7 +81,7 @@ void InitialUEMessageMsg::setNasPdu(uint8_t* nas, size_t size) {
ie->criticality = Ngap_Criticality_reject; ie->criticality = Ngap_Criticality_reject;
ie->value.present = Ngap_InitialUEMessage_IEs__value_PR_NAS_PDU; ie->value.present = Ngap_InitialUEMessage_IEs__value_PR_NAS_PDU;
int ret = nasPdu.encode2octetstring(ie->value.choice.NAS_PDU); int ret = nasPdu.encode(ie->value.choice.NAS_PDU);
if (!ret) { if (!ret) {
Logger::ngap().error("Encode NAS PDU IE error"); Logger::ngap().error("Encode NAS PDU IE error");
free_wrapper((void**) &ie); free_wrapper((void**) &ie);
...@@ -218,9 +218,8 @@ bool InitialUEMessageMsg::decodeFromPdu(Ngap_NGAP_PDU_t* ngapMsgPdu) { ...@@ -218,9 +218,8 @@ bool InitialUEMessageMsg::decodeFromPdu(Ngap_NGAP_PDU_t* ngapMsgPdu) {
Ngap_Criticality_reject && Ngap_Criticality_reject &&
initialUEMessageIEs->protocolIEs.list.array[i]->value.present == initialUEMessageIEs->protocolIEs.list.array[i]->value.present ==
Ngap_InitialUEMessage_IEs__value_PR_NAS_PDU) { Ngap_InitialUEMessage_IEs__value_PR_NAS_PDU) {
if (!nasPdu.decodefromoctetstring( if (!nasPdu.decode(initialUEMessageIEs->protocolIEs.list.array[i]
initialUEMessageIEs->protocolIEs.list.array[i] ->value.choice.NAS_PDU)) {
->value.choice.NAS_PDU)) {
Logger::ngap().error("Decoded NGAP NAS_PDU IE error"); Logger::ngap().error("Decoded NGAP NAS_PDU IE error");
return false; return false;
} }
......
...@@ -149,7 +149,7 @@ void PduSessionResourceReleaseCommandMsg::setNasPdu(uint8_t* nas, size_t size) { ...@@ -149,7 +149,7 @@ void PduSessionResourceReleaseCommandMsg::setNasPdu(uint8_t* nas, size_t size) {
ie->value.present = ie->value.present =
Ngap_PDUSessionResourceReleaseCommandIEs__value_PR_NAS_PDU; Ngap_PDUSessionResourceReleaseCommandIEs__value_PR_NAS_PDU;
int ret = nasPdu->encode2octetstring(ie->value.choice.NAS_PDU); int ret = nasPdu->encode(ie->value.choice.NAS_PDU);
if (!ret) { if (!ret) {
Logger::nas_mm().warn("encode NAS_PDU IE error"); Logger::nas_mm().warn("encode NAS_PDU IE error");
free_wrapper((void**) &ie); free_wrapper((void**) &ie);
...@@ -328,7 +328,7 @@ bool PduSessionResourceReleaseCommandMsg::decodeFromPdu( ...@@ -328,7 +328,7 @@ bool PduSessionResourceReleaseCommandMsg::decodeFromPdu(
->value.present == ->value.present ==
Ngap_PDUSessionResourceReleaseCommandIEs__value_PR_NAS_PDU) { Ngap_PDUSessionResourceReleaseCommandIEs__value_PR_NAS_PDU) {
nasPdu = new NAS_PDU(); nasPdu = new NAS_PDU();
if (!nasPdu->decodefromoctetstring( if (!nasPdu->decode(
pduSessionResourceReleaseCommandIEs->protocolIEs.list pduSessionResourceReleaseCommandIEs->protocolIEs.list
.array[i] .array[i]
->value.choice.NAS_PDU)) { ->value.choice.NAS_PDU)) {
......
...@@ -178,7 +178,7 @@ void PduSessionResourceSetupRequestMsg::setNasPdu(uint8_t* nas, size_t size) { ...@@ -178,7 +178,7 @@ void PduSessionResourceSetupRequestMsg::setNasPdu(uint8_t* nas, size_t size) {
ie->criticality = Ngap_Criticality_reject; ie->criticality = Ngap_Criticality_reject;
ie->value.present = Ngap_PDUSessionResourceSetupRequestIEs__value_PR_NAS_PDU; ie->value.present = Ngap_PDUSessionResourceSetupRequestIEs__value_PR_NAS_PDU;
int ret = nasPdu->encode2octetstring(ie->value.choice.NAS_PDU); int ret = nasPdu->encode(ie->value.choice.NAS_PDU);
if (!ret) { if (!ret) {
Logger::ngap().error("Encode NGAP NAS_PDU IE error"); Logger::ngap().error("Encode NGAP NAS_PDU IE error");
free_wrapper((void**) &ie); free_wrapper((void**) &ie);
...@@ -372,7 +372,7 @@ bool PduSessionResourceSetupRequestMsg::decodeFromPdu( ...@@ -372,7 +372,7 @@ bool PduSessionResourceSetupRequestMsg::decodeFromPdu(
->value.present == ->value.present ==
Ngap_PDUSessionResourceSetupRequestIEs__value_PR_NAS_PDU) { Ngap_PDUSessionResourceSetupRequestIEs__value_PR_NAS_PDU) {
nasPdu = new NAS_PDU(); nasPdu = new NAS_PDU();
if (!nasPdu->decodefromoctetstring( if (!nasPdu->decode(
pduSessionResourceSetupRequestIEs->protocolIEs.list.array[i] pduSessionResourceSetupRequestIEs->protocolIEs.list.array[i]
->value.choice.NAS_PDU)) { ->value.choice.NAS_PDU)) {
Logger::ngap().error("Decoded NGAP NAS_PDU IE error"); Logger::ngap().error("Decoded NGAP NAS_PDU IE error");
......
...@@ -97,7 +97,7 @@ void UplinkNASTransportMsg::setNasPdu(uint8_t* nas, size_t sizeofnas) { ...@@ -97,7 +97,7 @@ void UplinkNASTransportMsg::setNasPdu(uint8_t* nas, size_t sizeofnas) {
ie->criticality = Ngap_Criticality_reject; ie->criticality = Ngap_Criticality_reject;
ie->value.present = Ngap_UplinkNASTransport_IEs__value_PR_NAS_PDU; ie->value.present = Ngap_UplinkNASTransport_IEs__value_PR_NAS_PDU;
int ret = nasPdu.encode2octetstring(ie->value.choice.NAS_PDU); int ret = nasPdu.encode(ie->value.choice.NAS_PDU);
if (!ret) { if (!ret) {
Logger::ngap().error("Encode NGAP NAS_PDU IE error"); Logger::ngap().error("Encode NGAP NAS_PDU IE error");
free_wrapper((void**) &ie); free_wrapper((void**) &ie);
...@@ -224,9 +224,8 @@ bool UplinkNASTransportMsg::decodeFromPdu(Ngap_NGAP_PDU_t* ngapMsgPdu) { ...@@ -224,9 +224,8 @@ bool UplinkNASTransportMsg::decodeFromPdu(Ngap_NGAP_PDU_t* ngapMsgPdu) {
Ngap_Criticality_reject && Ngap_Criticality_reject &&
uplinkNASTransportIEs->protocolIEs.list.array[i]->value.present == uplinkNASTransportIEs->protocolIEs.list.array[i]->value.present ==
Ngap_UplinkNASTransport_IEs__value_PR_NAS_PDU) { Ngap_UplinkNASTransport_IEs__value_PR_NAS_PDU) {
if (!nasPdu.decodefromoctetstring( if (!nasPdu.decode(uplinkNASTransportIEs->protocolIEs.list.array[i]
uplinkNASTransportIEs->protocolIEs.list.array[i] ->value.choice.NAS_PDU)) {
->value.choice.NAS_PDU)) {
Logger::ngap().error("Decoded NGAP NAS_PDU IE error"); Logger::ngap().error("Decoded NGAP NAS_PDU IE error");
return false; return false;
} }
......
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