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