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