Commit 7d03ee3f authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Use unique_ptr instead of naked ptr

parent 45b9c888
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
/*! \file amf_app.cpp /*! \file amf_app.cpp
\brief \brief
\author Keliang DU, BUPT, Tien-Thinh NGUYEN, EURECOM \author Keliang DU (BUPT), Tien-Thinh NGUYEN (EURECOM)
\date 2020 \date 2020
\email: contact@openairinterface.org \email: contact@openairinterface.org
*/ */
......
...@@ -603,10 +603,13 @@ void amf_n1::service_request_handle( ...@@ -603,10 +603,13 @@ void amf_n1::service_request_handle(
set_amf_ue_ngap_id_2_nas_context(amf_ue_ngap_id, nc); set_amf_ue_ngap_id_2_nas_context(amf_ue_ngap_id, nc);
nas_secu_ctx* secu = nc.get()->security_ctx; nas_secu_ctx* secu = nc.get()->security_ctx;
ServiceRequest* serReq = new ServiceRequest();
std::unique_ptr<ServiceRequest> serReq = std::make_unique<ServiceRequest>();
//ServiceRequest* serReq = new ServiceRequest();
serReq->decodefrombuffer(nullptr, (uint8_t*) bdata(nas), blength(nas)); serReq->decodefrombuffer(nullptr, (uint8_t*) bdata(nas), blength(nas));
bdestroy(nas); bdestroy(nas);
ServiceAccept* serApt = new ServiceAccept(); //ServiceAccept* serApt = new ServiceAccept();
std::unique_ptr<ServiceAccept> serApt = std::make_unique<ServiceAccept>();
serApt->setHeader(PLAIN_5GS_MSG); serApt->setHeader(PLAIN_5GS_MSG);
string supi = "imsi-" + nc.get()->imsi; string supi = "imsi-" + nc.get()->imsi;
supi2amfId[supi] = amf_ue_ngap_id; supi2amfId[supi] = amf_ue_ngap_id;
...@@ -634,8 +637,8 @@ void amf_n1::service_request_handle( ...@@ -634,8 +637,8 @@ void amf_n1::service_request_handle(
psc = amf_n11_inst->supi_to_pdu_ctx(supi); psc = amf_n11_inst->supi_to_pdu_ctx(supi);
if (!psc) { if (!psc) {
Logger::amf_n1().error("Cannot get pdu_session_context"); Logger::amf_n1().error("Cannot get pdu_session_context");
delete serReq; //delete serReq;
delete serApt; //delete serApt;
return; return;
} }
} else { } else {
...@@ -680,8 +683,8 @@ void amf_n1::service_request_handle( ...@@ -680,8 +683,8 @@ void amf_n1::service_request_handle(
"Could not send ITTI message %s to task TASK_AMF_N2", "Could not send ITTI message %s to task TASK_AMF_N2",
i->get_msg_name()); i->get_msg_name());
} }
delete serApt; //delete serApt;
delete serReq; //delete serReq;
return; return;
} }
serApt->setPDU_session_status(0x2000); serApt->setPDU_session_status(0x2000);
...@@ -723,8 +726,8 @@ void amf_n1::service_request_handle( ...@@ -723,8 +726,8 @@ void amf_n1::service_request_handle(
"Could not send ITTI message %s to task TASK_AMF_N2", "Could not send ITTI message %s to task TASK_AMF_N2",
i->get_msg_name()); i->get_msg_name());
} }
delete serApt; //delete serApt;
delete serReq; //delete serReq;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -732,7 +735,9 @@ void amf_n1::registration_request_handle( ...@@ -732,7 +735,9 @@ void amf_n1::registration_request_handle(
bool isNasSig, std::shared_ptr<nas_context> nc, uint32_t ran_ue_ngap_id, bool isNasSig, std::shared_ptr<nas_context> nc, uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id, std::string snn, bstring reg) { long amf_ue_ngap_id, std::string snn, bstring reg) {
// Decode registration request message // Decode registration request message
RegistrationRequest* regReq = new RegistrationRequest(); //RegistrationRequest* regReq = new RegistrationRequest();
std::unique_ptr<RegistrationRequest> regReq = std::make_unique<RegistrationRequest>();
regReq->decodefrombuffer(nullptr, (uint8_t*) bdata(reg), blength(reg)); regReq->decodefrombuffer(nullptr, (uint8_t*) bdata(reg), blength(reg));
bdestroy(reg); // free buffer bdestroy(reg); // free buffer
...@@ -877,7 +882,7 @@ void amf_n1::registration_request_handle( ...@@ -877,7 +882,7 @@ void amf_n1::registration_request_handle(
std::shared_ptr<ue_ngap_context> unc = std::shared_ptr<ue_ngap_context> unc =
amf_n2_inst->ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id); amf_n2_inst->ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id);
if (unc.get()) unc.reset(); if (unc.get()) unc.reset();
delete regReq; //delete regReq;
return; return;
} }
} else { } else {
...@@ -903,8 +908,7 @@ void amf_n1::registration_request_handle( ...@@ -903,8 +908,7 @@ void amf_n1::registration_request_handle(
Logger::amf_n1().error("Missing Mandatory IE 5GS Registration type..."); Logger::amf_n1().error("Missing Mandatory IE 5GS Registration type...");
response_registration_reject_msg( response_registration_reject_msg(
_5GMM_CAUSE_INVALID_MANDATORY_INFO, ran_ue_ngap_id, amf_ue_ngap_id); _5GMM_CAUSE_INVALID_MANDATORY_INFO, ran_ue_ngap_id, amf_ue_ngap_id);
delete regReq; //delete regReq;
return; return;
} }
nc.get()->registration_type = reg_type; nc.get()->registration_type = reg_type;
...@@ -916,7 +920,7 @@ void amf_n1::registration_request_handle( ...@@ -916,7 +920,7 @@ void amf_n1::registration_request_handle(
Logger::amf_n1().error("Missing Mandatory IE ngKSI..."); Logger::amf_n1().error("Missing Mandatory IE ngKSI...");
response_registration_reject_msg( response_registration_reject_msg(
_5GMM_CAUSE_INVALID_MANDATORY_INFO, ran_ue_ngap_id, amf_ue_ngap_id); _5GMM_CAUSE_INVALID_MANDATORY_INFO, ran_ue_ngap_id, amf_ue_ngap_id);
delete regReq; free_wrapper((void**) &regReq);
return; return;
} }
nc.get()->ngKsi = ngKSI; nc.get()->ngKsi = ngKSI;
...@@ -945,7 +949,7 @@ void amf_n1::registration_request_handle( ...@@ -945,7 +949,7 @@ void amf_n1::registration_request_handle(
if (!regReq->getRequestedNssai(requestedNssai)) { if (!regReq->getRequestedNssai(requestedNssai)) {
Logger::amf_n1().warn("No Optional IE RequestedNssai available"); Logger::amf_n1().warn("No Optional IE RequestedNssai available");
} }
delete regReq; // free after getting values from message // delete regReq; // free after getting values from message
nc.get()->requestedNssai = requestedNssai; nc.get()->requestedNssai = requestedNssai;
nc.get()->ctx_avaliability_ind = true; nc.get()->ctx_avaliability_ind = true;
...@@ -1059,7 +1063,8 @@ void amf_n1::itti_send_dl_nas_buffer_to_task_n2( ...@@ -1059,7 +1063,8 @@ void amf_n1::itti_send_dl_nas_buffer_to_task_n2(
// response messages // response messages
void amf_n1::response_registration_reject_msg( void amf_n1::response_registration_reject_msg(
uint8_t cause_value, uint32_t ran_ue_ngap_id, long amf_ue_ngap_id) { uint8_t cause_value, uint32_t ran_ue_ngap_id, long amf_ue_ngap_id) {
RegistrationReject* registrationRej = new RegistrationReject(); // RegistrationReject* registrationRej = new RegistrationReject();
std::unique_ptr<RegistrationReject> registrationRej = std::make_unique<RegistrationReject>();
registrationRej->setHeader(PLAIN_5GS_MSG); registrationRej->setHeader(PLAIN_5GS_MSG);
registrationRej->set_5GMM_Cause(cause_value); registrationRej->set_5GMM_Cause(cause_value);
uint8_t buffer[BUFFER_SIZE_1024] = {0}; uint8_t buffer[BUFFER_SIZE_1024] = {0};
...@@ -1071,27 +1076,28 @@ void amf_n1::response_registration_reject_msg( ...@@ -1071,27 +1076,28 @@ void amf_n1::response_registration_reject_msg(
Logger::nas_mm().error("Encode Registration-Reject message error"); Logger::nas_mm().error("Encode Registration-Reject message error");
return; return;
} else { } else {
delete registrationRej; //delete registrationRej;
} }
bstring b = blk2bstr(buffer, encoded_size); bstring b = blk2bstr(buffer, encoded_size);
itti_send_dl_nas_buffer_to_task_n2(b, ran_ue_ngap_id, amf_ue_ngap_id); itti_send_dl_nas_buffer_to_task_n2(b, ran_ue_ngap_id, amf_ue_ngap_id);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// specific procedures running logic
void amf_n1::run_registration_procedure(std::shared_ptr<nas_context>& nc) { void amf_n1::run_registration_procedure(std::shared_ptr<nas_context>& nc) {
Logger::amf_n1().debug("Start to run registration procedure"); Logger::amf_n1().debug("Start to run registration procedure");
if (!nc.get()->ctx_avaliability_ind) { if (!nc.get()->ctx_avaliability_ind) {
Logger::amf_n1().error("NAS context is not available"); Logger::amf_n1().error("NAS context is not available");
return; return;
} }
nc.get()->is_specific_procedure_for_registration_running = true; nc.get()->is_specific_procedure_for_registration_running = true;
if (nc.get()->is_imsi_present) { if (nc.get()->is_imsi_present) {
Logger::amf_n1().debug("SUCI SUPI format IMSI is available"); Logger::amf_n1().debug("SUCI SUPI format IMSI is available");
if (!nc.get()->is_auth_vectors_present) { if (!nc.get()->is_auth_vectors_present) {
Logger::amf_n1().debug( Logger::amf_n1().debug(
"Authentication vector in nas_context is not available"); "Authentication vector in nas_context is not available");
if (auth_vectors_generator(nc)) { // all authentication in one(AMF) if (auth_vectors_generator(nc)) { // all authentication in one (AMF)
ngksi_t ngksi = 0; ngksi_t ngksi = 0;
if (nc.get()->security_ctx && if (nc.get()->security_ctx &&
nc.get()->ngKsi != NAS_KEY_SET_IDENTIFIER_NOT_AVAILABLE) { nc.get()->ngKsi != NAS_KEY_SET_IDENTIFIER_NOT_AVAILABLE) {
...@@ -1115,22 +1121,22 @@ void amf_n1::run_registration_procedure(std::shared_ptr<nas_context>& nc) { ...@@ -1115,22 +1121,22 @@ void amf_n1::run_registration_procedure(std::shared_ptr<nas_context>& nc) {
// ngksi = (nc.get()->ngKsi + 1) % (NGKSI_MAX_VALUE + 1); // ngksi = (nc.get()->ngKsi + 1) % (NGKSI_MAX_VALUE + 1);
ngksi = (nc.get()->amf_ue_ngap_id + 1); // % (NGKSI_MAX_VALUE + 1); ngksi = (nc.get()->amf_ue_ngap_id + 1); // % (NGKSI_MAX_VALUE + 1);
Logger::amf_n1().debug("New ngKsi(%d)", ngksi); Logger::amf_n1().debug("New ngKsi(%d)", ngksi);
// ... how to handle? //TODO: How to handle?
} }
nc.get()->ngKsi = ngksi; nc.get()->ngKsi = ngksi;
handle_auth_vector_successful_result(nc); handle_auth_vector_successful_result(nc);
} }
} else if (nc.get()->is_5g_guti_present) { } else if (nc.get()->is_5g_guti_present) {
Logger::amf_n1().debug("Start to run identification procedure"); Logger::amf_n1().debug("Start to run UE Identification Request procedure");
nc.get()->is_auth_vectors_present = false; nc.get()->is_auth_vectors_present = false;
// ... identification procedure //IdentityRequest* ir = new IdentityRequest();
IdentityRequest* ir = new IdentityRequest(); std::unique_ptr<IdentityRequest> ir = std::make_unique<IdentityRequest>();
// itti_msg->cause = 28;//cause nas(2)--deregister
ir->setHeader(PLAIN_5GS_MSG); ir->setHeader(PLAIN_5GS_MSG);
ir->set_5GS_Identity_Type(SUCI); ir->set_5GS_Identity_Type(SUCI);
uint8_t buffer[100]; uint8_t buffer[100];
int encoded_size = ir->encode2buffer(buffer, 100); int encoded_size = ir->encode2buffer(buffer, 100);
delete ir; //delete ir;
itti_dl_nas_transport* dnt = itti_dl_nas_transport* dnt =
new itti_dl_nas_transport(TASK_AMF_N1, TASK_AMF_N2); new itti_dl_nas_transport(TASK_AMF_N1, TASK_AMF_N2);
dnt->nas = blk2bstr(buffer, encoded_size); dnt->nas = blk2bstr(buffer, encoded_size);
...@@ -1446,7 +1452,8 @@ bool amf_n1::start_authentication_procedure( ...@@ -1446,7 +1452,8 @@ bool amf_n1::start_authentication_procedure(
} }
nc.get()->is_common_procedure_for_authentication_running = true; nc.get()->is_common_procedure_for_authentication_running = true;
AuthenticationRequest* authReq = new AuthenticationRequest(); //AuthenticationRequest* authReq = new AuthenticationRequest();
std::unique_ptr<AuthenticationRequest> authReq = std::make_unique<AuthenticationRequest>();
authReq->setHeader(PLAIN_5GS_MSG); authReq->setHeader(PLAIN_5GS_MSG);
authReq->setngKSI(NAS_KEY_SET_IDENTIFIER_NATIVE, ngksi); authReq->setngKSI(NAS_KEY_SET_IDENTIFIER_NATIVE, ngksi);
uint8_t abba[2]; uint8_t abba[2];
...@@ -1468,7 +1475,7 @@ bool amf_n1::start_authentication_procedure( ...@@ -1468,7 +1475,7 @@ bool amf_n1::start_authentication_procedure(
Logger::nas_mm().error("Encode Authentication Request message error"); Logger::nas_mm().error("Encode Authentication Request message error");
return false; return false;
} else { } else {
delete authReq; //delete authReq;
} }
bstring b = blk2bstr(buffer, encoded_size); bstring b = blk2bstr(buffer, encoded_size);
print_buffer( print_buffer(
...@@ -1751,7 +1758,8 @@ void amf_n1::security_mode_complete_handle( ...@@ -1751,7 +1758,8 @@ void amf_n1::security_mode_complete_handle(
ue_context_key.c_str()); ue_context_key.c_str());
// encoding REGISTRATION ACCEPT // encoding REGISTRATION ACCEPT
RegistrationAccept* regAccept = new RegistrationAccept(); //RegistrationAccept* regAccept = new RegistrationAccept();
std::unique_ptr<RegistrationAccept> regAccept= std::make_unique<RegistrationAccept>();
regAccept->setHeader(PLAIN_5GS_MSG); regAccept->setHeader(PLAIN_5GS_MSG);
regAccept->set_5GS_Registration_Result(false, false, false, 0x01); regAccept->set_5GS_Registration_Result(false, false, false, 0x01);
std::string mcc; std::string mcc;
...@@ -1803,7 +1811,7 @@ void amf_n1::security_mode_complete_handle( ...@@ -1803,7 +1811,7 @@ void amf_n1::security_mode_complete_handle(
Logger::nas_mm().error("Encode Registration-Accept message error"); Logger::nas_mm().error("Encode Registration-Accept message error");
return; return;
} else { } else {
delete regAccept; //delete regAccept;
} }
if (!uc.get()->isUeContextRequest) { if (!uc.get()->isUeContextRequest) {
...@@ -2314,7 +2322,8 @@ void amf_n1::sha256( ...@@ -2314,7 +2322,8 @@ void amf_n1::sha256(
void amf_n1::run_mobility_registration_update_procedure( void amf_n1::run_mobility_registration_update_procedure(
std::shared_ptr<nas_context> nc) { std::shared_ptr<nas_context> nc) {
// encoding REGISTRATION ACCEPT // encoding REGISTRATION ACCEPT
RegistrationAccept* regAccept = new RegistrationAccept(); //RegistrationAccept* regAccept = new RegistrationAccept();
std::unique_ptr<RegistrationAccept> regAccept= std::make_unique<RegistrationAccept>();
regAccept->setHeader(PLAIN_5GS_MSG); regAccept->setHeader(PLAIN_5GS_MSG);
regAccept->set_5GS_Registration_Result(false, false, false, 0x01); regAccept->set_5GS_Registration_Result(false, false, false, 0x01);
regAccept->set5G_GUTI( regAccept->set5G_GUTI(
...@@ -2357,7 +2366,7 @@ void amf_n1::run_mobility_registration_update_procedure( ...@@ -2357,7 +2366,7 @@ void amf_n1::run_mobility_registration_update_procedure(
Logger::nas_mm().error("Encode Registration-Accept message error"); Logger::nas_mm().error("Encode Registration-Accept message error");
return; return;
} else { } else {
delete regAccept; //delete regAccept;
} }
nas_secu_ctx* secu = nc.get()->security_ctx; nas_secu_ctx* secu = nc.get()->security_ctx;
// protect nas message // protect nas message
......
...@@ -100,6 +100,7 @@ class amf_n1 { ...@@ -100,6 +100,7 @@ class amf_n1 {
database_t* db_desc; database_t* db_desc;
// procedures // procedures
// specific procedures running logic
void run_registration_procedure(std::shared_ptr<nas_context>& nc); void run_registration_procedure(std::shared_ptr<nas_context>& nc);
void run_initial_registration_procedure(); void run_initial_registration_procedure();
void run_mobility_registration_update_procedure( void run_mobility_registration_update_procedure(
......
...@@ -830,7 +830,8 @@ void amf_n2::handle_itti_message(itti_ue_context_release_command& itti_msg) { ...@@ -830,7 +830,8 @@ void amf_n2::handle_itti_message(itti_ue_context_release_command& itti_msg) {
return; return;
} }
UEContextReleaseCommandMsg* ueCtxRelCmd = new UEContextReleaseCommandMsg(); //UEContextReleaseCommandMsg* ueCtxRelCmd = new UEContextReleaseCommandMsg();
std::unique_ptr<UEContextReleaseCommandMsg> ueCtxRelCmd = std::make_unique<UEContextReleaseCommandMsg>();
ueCtxRelCmd->setMessageType(); ueCtxRelCmd->setMessageType();
ueCtxRelCmd->setUeNgapIdPair( ueCtxRelCmd->setUeNgapIdPair(
itti_msg.amf_ue_ngap_id, itti_msg.ran_ue_ngap_id); itti_msg.amf_ue_ngap_id, itti_msg.ran_ue_ngap_id);
...@@ -843,7 +844,7 @@ void amf_n2::handle_itti_message(itti_ue_context_release_command& itti_msg) { ...@@ -843,7 +844,7 @@ void amf_n2::handle_itti_message(itti_ue_context_release_command& itti_msg) {
} }
uint8_t buffer[200]; uint8_t buffer[200];
int encoded_size = ueCtxRelCmd->encode2buffer(buffer, 200); int encoded_size = ueCtxRelCmd->encode2buffer(buffer, 200);
delete ueCtxRelCmd; //delete ueCtxRelCmd;
bstring b = blk2bstr(buffer, encoded_size); bstring b = blk2bstr(buffer, encoded_size);
sctp_s_38412.sctp_send_msg( sctp_s_38412.sctp_send_msg(
gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, &b); gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, &b);
......
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