Commit 46b7bb77 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen
Browse files

Move convert_string_2_hex from SMF App to Conv

parent 0244c541
......@@ -32,6 +32,11 @@
#include <ctype.h>
#include <inttypes.h>
#include <arpa/inet.h>
#include "logger.hpp"
extern "C" {
#include "dynamic_memory_check.h"
}
static const char hex_to_ascii_table[16] = {
'0', '1', '2', '3', '4', '5', '6', '7',
......@@ -185,3 +190,32 @@ std::string conv::toString(const struct in6_addr& in6addr) {
}
return s;
}
//---------------------------------------------------------------------------------------------
void conv::convert_string_2_hex(
const std::string& input_str, std::string& output_str) {
Logger::smf_app().debug("Convert string to Hex");
unsigned char* data = (unsigned char*) malloc(input_str.length() + 1);
memset(data, 0, input_str.length() + 1);
memcpy((void*) data, (void*) input_str.c_str(), input_str.length());
#if DEBUG_IS_ON
Logger::smf_app().debug("Input: ");
for (int i = 0; i < input_str.length(); i++) {
printf("%02x ", data[i]);
}
printf("\n");
#endif
char* datahex = (char*) malloc(input_str.length() * 2 + 1);
memset(datahex, 0, input_str.length() * 2 + 1);
for (int i = 0; i < input_str.length(); i++)
sprintf(datahex + i * 2, "%02x", data[i]);
output_str = reinterpret_cast<char*>(datahex);
Logger::smf_app().debug("Output: \n %s ", output_str.c_str());
// free memory
free_wrapper((void**) &data);
free_wrapper((void**) &datahex);
}
......@@ -63,5 +63,14 @@ class conv {
const uint8_t digit1, const uint8_t digit2, const uint8_t digit3);
static std::string mncToString(
const uint8_t digit1, const uint8_t digit2, const uint8_t digit3);
/*
* Convert a string to hex representing this string
* @param [const std::string&] input_str Input string
* @param [std::string&] output_str String represents string in hex format
* @return void
*/
static void convert_string_2_hex(
const std::string& input_str, std::string& output_str);
};
#endif /* FILE_CONVERSIONS_HPP_SEEN */
......@@ -133,11 +133,6 @@ scid_t smf_app::generate_smf_context_ref() {
return sm_context_ref_generator.get_uid();
}
//------------------------------------------------------------------------------
void smf_app::generate_ev_subscription_id(std::string& sub_id) {
sub_id = std::to_string(evsub_id_generator.get_uid());
}
//------------------------------------------------------------------------------
evsub_id_t smf_app::generate_ev_subscription_id() {
return evsub_id_generator.get_uid();
......@@ -718,7 +713,7 @@ void smf_app::handle_pdu_session_create_sm_context_request(
if (smf_n1::get_instance().create_n1_pdu_session_establishment_reject(
smreq->req, n1_sm_message,
cause_value_5gsm_e::CAUSE_95_SEMANTICALLY_INCORRECT_MESSAGE)) {
smf_app_inst->convert_string_2_hex(n1_sm_message, n1_sm_message_hex);
conv::convert_string_2_hex(n1_sm_message, n1_sm_message_hex);
// trigger to send reply to AMF
trigger_create_context_error_response(
http_status_code_e::HTTP_STATUS_CODE_403_FORBIDDEN,
......@@ -751,7 +746,7 @@ void smf_app::handle_pdu_session_create_sm_context_request(
// PDU Session Establishment Reject
if (smf_n1::get_instance().create_n1_pdu_session_establishment_reject(
smreq->req, n1_sm_message, cause_n1)) {
smf_app_inst->convert_string_2_hex(n1_sm_message, n1_sm_message_hex);
conv::convert_string_2_hex(n1_sm_message, n1_sm_message_hex);
// trigger to send reply to AMF
trigger_create_context_error_response(
http_status_code_e::HTTP_STATUS_CODE_403_FORBIDDEN,
......@@ -791,7 +786,7 @@ void smf_app::handle_pdu_session_create_sm_context_request(
if (smf_n1::get_instance().create_n1_pdu_session_establishment_reject(
smreq->req, n1_sm_message,
cause_value_5gsm_e::CAUSE_81_INVALID_PTI_VALUE)) {
smf_app_inst->convert_string_2_hex(n1_sm_message, n1_sm_message_hex);
conv::convert_string_2_hex(n1_sm_message, n1_sm_message_hex);
// trigger to send reply to AMF
trigger_create_context_error_response(
http_status_code_e::HTTP_STATUS_CODE_403_FORBIDDEN,
......@@ -832,7 +827,7 @@ void smf_app::handle_pdu_session_create_sm_context_request(
smreq->req, n1_sm_message,
cause_value_5gsm_e::
CAUSE_98_MESSAGE_TYPE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE)) {
smf_app_inst->convert_string_2_hex(n1_sm_message, n1_sm_message_hex);
conv::convert_string_2_hex(n1_sm_message, n1_sm_message_hex);
// trigger to send reply to AMF
trigger_create_context_error_response(
http_status_code_e::HTTP_STATUS_CODE_403_FORBIDDEN,
......@@ -883,7 +878,7 @@ void smf_app::handle_pdu_session_create_sm_context_request(
if (smf_n1::get_instance().create_n1_pdu_session_establishment_reject(
smreq->req, n1_sm_message,
cause_value_5gsm_e::CAUSE_27_MISSING_OR_UNKNOWN_DNN)) {
smf_app_inst->convert_string_2_hex(n1_sm_message, n1_sm_message_hex);
conv::convert_string_2_hex(n1_sm_message, n1_sm_message_hex);
// trigger to send reply to AMF
trigger_create_context_error_response(
http_status_code_e::HTTP_STATUS_CODE_403_FORBIDDEN,
......@@ -975,7 +970,7 @@ void smf_app::handle_pdu_session_create_sm_context_request(
smreq->req, n1_sm_message,
cause_value_5gsm_e::
CAUSE_29_USER_AUTHENTICATION_OR_AUTHORIZATION_FAILED)) {
smf_app_inst->convert_string_2_hex(n1_sm_message, n1_sm_message_hex);
conv::convert_string_2_hex(n1_sm_message, n1_sm_message_hex);
// trigger to send reply to AMF
trigger_create_context_error_response(
http_status_code_e::HTTP_STATUS_CODE_403_FORBIDDEN,
......@@ -1442,35 +1437,6 @@ bool smf_app::is_create_sm_context_request_valid() const {
return true;
}
//---------------------------------------------------------------------------------------------
void smf_app::convert_string_2_hex(
const std::string& input_str, std::string& output_str) {
Logger::smf_app().debug("Convert string to Hex");
unsigned char* data = (unsigned char*) malloc(input_str.length() + 1);
memset(data, 0, input_str.length() + 1);
memcpy((void*) data, (void*) input_str.c_str(), input_str.length());
#if DEBUG_IS_ON
Logger::smf_app().debug("Input: ");
for (int i = 0; i < input_str.length(); i++) {
printf("%02x ", data[i]);
}
printf("\n");
#endif
char* datahex = (char*) malloc(input_str.length() * 2 + 1);
memset(datahex, 0, input_str.length() * 2 + 1);
for (int i = 0; i < input_str.length(); i++)
sprintf(datahex + i * 2, "%02x", data[i]);
output_str = reinterpret_cast<char*>(datahex);
Logger::smf_app().debug("Output: \n %s ", output_str.c_str());
// free memory
free_wrapper((void**) &data);
free_wrapper((void**) &datahex);
}
//---------------------------------------------------------------------------------------------
void smf_app::update_pdu_session_status(
const scid_t& scid, const pdu_session_status_e& status) {
......
......@@ -432,13 +432,6 @@ class smf_app {
*/
scid_t generate_smf_context_ref();
/*
* Generate an Event Exposure Subscription ID in a form of string
* @param [std::string &] sub_id: Store the generated reference
* @return void
*/
void generate_ev_subscription_id(std::string& sub_id);
/*
* Generate an Event Exposure Subscription ID
* @param [void]
......@@ -493,6 +486,30 @@ class smf_app {
bool scid_2_smf_context(
const scid_t& scid, std::shared_ptr<smf_context_ref>& scf) const;
/*
* Verify if SM Context is existed for this Supi
* @param [supi_t] supi
* @return True if existed, otherwise false
*/
bool is_supi_2_smf_context(const supi64_t& supi) const;
/*
* Create/Update SMF context with the corresponding supi
* @param [const supi_t&] supi
* @param [std::shared_ptr<smf_context>] sc Shared_ptr Pointer to an SMF
* context
* @return True if existed, otherwise false
*/
void set_supi_2_smf_context(
const supi64_t& supi, std::shared_ptr<smf_context> sc);
/*
* Get SM Context
* @param [supi_t] Supi
* @return Shared pointer to SM context
*/
std::shared_ptr<smf_context> supi_2_smf_context(const supi64_t& supi) const;
/*
* Handle PDUSession_CreateSMContextRequest from AMF
* @param [std::shared_ptr<itti_n11_create_sm_context_request>&] Request
......@@ -527,6 +544,13 @@ class smf_app {
evsub_id_t handle_event_exposure_subscription(
std::shared_ptr<itti_sbi_event_exposure_request> msg);
/*
* Handle NF status notification (e.g., when an UPF becomes available)
* @param [std::shared_ptr<itti_sbi_notification_data>& ] msg: message
* @param [oai::smf_server::model::ProblemDetails& ] problem_details
* @param [uint8_t&] http_code
* @return true if handle sucessfully, otherwise return false
*/
bool handle_nf_status_notification(
std::shared_ptr<itti_sbi_notification_data>& msg,
oai::smf_server::model::ProblemDetails& problem_details,
......@@ -546,30 +570,6 @@ class smf_app {
const pdu_session_id_t pdu_session_id, const snssai_t& snssai,
const pfcp::qfi_t& qfi, const uint8_t& http_version);
/*
* Verify if SM Context is existed for this Supi
* @param [supi_t] supi
* @return True if existed, otherwise false
*/
bool is_supi_2_smf_context(const supi64_t& supi) const;
/*
* Create/Update SMF context with the corresponding supi
* @param [const supi_t&] supi
* @param [std::shared_ptr<smf_context>] sc Shared_ptr Pointer to an SMF
* context
* @return True if existed, otherwise false
*/
void set_supi_2_smf_context(
const supi64_t& supi, std::shared_ptr<smf_context> sc);
/*
* Get SM Context
* @param [supi_t] Supi
* @return Shared pointer to SM context
*/
std::shared_ptr<smf_context> supi_2_smf_context(const supi64_t& supi) const;
/*
* Check whether SMF uses local configuration instead of retrieving Session
* Management Data from UDM
......@@ -613,15 +613,6 @@ class smf_app {
*/
bool is_create_sm_context_request_valid() const;
/*
* Convert a string to hex representing this string
* @param [const std::string&] input_str Input string
* @param [std::string&] output_str String represents string in hex format
* @return void
*/
void convert_string_2_hex(
const std::string& input_str, std::string& output_str);
/*
* Update PDU session status
* @param [const scid_t &] id SM Context ID
......
......@@ -814,7 +814,7 @@ void smf_context::handle_itti_msg(
session_report_msg, n2_sm_info_type_e::PDU_RES_SETUP_REQ,
n2_sm_info);
smf_app_inst->convert_string_2_hex(n2_sm_info, n2_sm_info_hex);
conv::convert_string_2_hex(n2_sm_info, n2_sm_info_hex);
session_report_msg.set_n2_sm_information(n2_sm_info_hex);
// Fill the json part
......@@ -1239,7 +1239,7 @@ void smf_context::handle_pdu_session_create_sm_context_request(
smreq->req, n1_sm_message,
cause_value_5gsm_e::
CAUSE_29_USER_AUTHENTICATION_OR_AUTHORIZATION_FAILED)) {
smf_app_inst->convert_string_2_hex(n1_sm_message, n1_sm_msg_hex);
conv::convert_string_2_hex(n1_sm_message, n1_sm_msg_hex);
// trigger to send reply to AMF
smf_app_inst->trigger_create_context_error_response(
http_status_code_e::HTTP_STATUS_CODE_401_UNAUTHORIZED,
......@@ -1453,7 +1453,7 @@ void smf_context::handle_pdu_session_create_sm_context_request(
if (smf_n1::get_instance().create_n1_pdu_session_establishment_reject(
smreq->req, n1_sm_message,
cause_value_5gsm_e::CAUSE_28_UNKNOWN_PDU_SESSION_TYPE)) {
smf_app_inst->convert_string_2_hex(n1_sm_message, n1_sm_msg_hex);
conv::convert_string_2_hex(n1_sm_message, n1_sm_msg_hex);
// trigger to send reply to AMF
smf_app_inst->trigger_create_context_error_response(
http_status_code_e::HTTP_STATUS_CODE_403_FORBIDDEN,
......@@ -1604,7 +1604,7 @@ void smf_context::handle_pdu_session_create_sm_context_request(
smf_n1::get_instance().create_n1_pdu_session_establishment_reject(
sm_context_resp_pending->res, n1_sm_message, cause_n1);
smf_app_inst->convert_string_2_hex(n1_sm_message, n1_sm_msg_hex);
conv::convert_string_2_hex(n1_sm_message, n1_sm_msg_hex);
sm_context_resp_pending->res.set_n1_sm_message(n1_sm_msg_hex);
// get supi and put into URL
......@@ -1737,9 +1737,9 @@ bool smf_context::handle_pdu_session_modification_request(
return false;
}
smf_app_inst->convert_string_2_hex(
conv::convert_string_2_hex(
n1_sm_msg_to_be_created, n1_sm_msg_hex_to_be_created);
smf_app_inst->convert_string_2_hex(
conv::convert_string_2_hex(
n2_sm_info_to_be_created, n2_sm_info_hex_to_be_created);
sm_context_resp.get()->res.set_n1_sm_message(n1_sm_msg_hex_to_be_created);
......@@ -1880,7 +1880,7 @@ bool smf_context::handle_pdu_session_release_request(
if (smf_n1::get_instance().create_n1_pdu_session_release_reject(
sm_context_request.get()->req, n1_sm_msg,
cause_value_5gsm_e::CAUSE_43_INVALID_PDU_SESSION_IDENTITY)) {
smf_app_inst->convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
conv::convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
// trigger to send reply to AMF
smf_app_inst->trigger_update_context_error_response(
http_status_code_e::HTTP_STATUS_CODE_403_FORBIDDEN,
......@@ -2032,7 +2032,7 @@ bool smf_context::handle_pdu_session_resource_setup_response_transfer(
if (smf_n1::get_instance().create_n1_pdu_session_establishment_reject(
sm_context_request.get()->req, n1_sm_msg,
cause_value_5gsm_e::CAUSE_95_SEMANTICALLY_INCORRECT_MESSAGE)) {
smf_app_inst->convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
conv::convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
// trigger to send reply to AMF
smf_app_inst->trigger_update_context_error_response(
http_status_code_e::HTTP_STATUS_CODE_403_FORBIDDEN,
......@@ -2118,7 +2118,7 @@ bool smf_context::handle_pdu_session_resource_setup_unsuccessful_transfer(
if (smf_n1::get_instance().create_n1_pdu_session_establishment_reject(
sm_context_request.get()->req, n1_sm_msg,
cause_value_5gsm_e::CAUSE_26_INSUFFICIENT_RESOURCES)) {
smf_app_inst->convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
conv::convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
// trigger to send reply to AMF
smf_app_inst->trigger_update_context_error_response(
http_status_code_e::HTTP_STATUS_CODE_403_FORBIDDEN,
......@@ -2264,7 +2264,7 @@ bool smf_context::handle_service_request(
sm_context_resp.get()->res, n2_sm_info_type_e::PDU_RES_SETUP_REQ,
n2_sm_info);
smf_app_inst->convert_string_2_hex(n2_sm_info, n2_sm_info_hex);
conv::convert_string_2_hex(n2_sm_info, n2_sm_info_hex);
sm_context_resp.get()->res.set_n2_sm_information(n2_sm_info_hex);
// fill the content of SmContextUpdatedData
......@@ -2616,7 +2616,7 @@ void smf_context::handle_pdu_session_update_sm_context_request(
if (smf_n1::get_instance().create_n1_pdu_session_establishment_reject(
sm_context_req_msg, n1_sm_msg,
cause_value_5gsm_e::CAUSE_38_NETWORK_FAILURE)) {
smf_app_inst->convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
conv::convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
// trigger to send reply to AMF
smf_app_inst->trigger_update_context_error_response(
http_status_code_e::HTTP_STATUS_CODE_403_FORBIDDEN,
......@@ -2796,14 +2796,14 @@ void smf_context::handle_pdu_session_modification_network_requested(
// N1: PDU_SESSION_MODIFICATION_COMMAND
smf_n1::get_instance().create_n1_pdu_session_modification_command(
itti_msg->msg, n1_sm_msg, cause_value_5gsm_e::CAUSE_0_UNKNOWN);
smf_app_inst->convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
conv::convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
itti_msg->msg.set_n1_sm_message(n1_sm_msg_hex);
// N2: PDU Session Resource Modify Response Transfer
smf_n2::get_instance().create_n2_pdu_session_resource_modify_request_transfer(
itti_msg->msg, n2_sm_info_type_e::PDU_RES_MOD_REQ, n2_sm_info);
smf_app_inst->convert_string_2_hex(n2_sm_info, n2_sm_info_hex);
conv::convert_string_2_hex(n2_sm_info, n2_sm_info_hex);
itti_msg->msg.set_n2_sm_information(n2_sm_info_hex);
// Fill N1N2MesasgeTransferRequestData
......
......@@ -405,7 +405,7 @@ void session_create_sm_context_procedure::handle_itti_msg(
smf_n1::get_instance().create_n1_pdu_session_establishment_reject(
n11_triggered_pending->res, n1_sm_msg, cause_n1);
smf_app_inst->convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
conv::convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
n11_triggered_pending->res.set_n1_sm_message(n1_sm_msg_hex);
} else { // PDU Session Establishment Accept
......@@ -422,7 +422,7 @@ void session_create_sm_context_procedure::handle_itti_msg(
smf_n1::get_instance().create_n1_pdu_session_establishment_accept(
n11_triggered_pending->res, n1_sm_msg, cause_n1);
smf_app_inst->convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
conv::convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
n11_triggered_pending->res.set_n1_sm_message(n1_sm_msg_hex);
// N2 SM Information (Step 11, section 4.3.2.2.1 @ 3GPP TS 23.502):
// PDUSessionRessourceSetupRequestTransfer IE
......@@ -431,7 +431,7 @@ void session_create_sm_context_procedure::handle_itti_msg(
n11_triggered_pending->res, n2_sm_info_type_e::PDU_RES_SETUP_REQ,
n2_sm_info);
smf_app_inst->convert_string_2_hex(n2_sm_info, n2_sm_info_hex);
conv::convert_string_2_hex(n2_sm_info, n2_sm_info_hex);
n11_triggered_pending->res.set_n2_sm_information(n2_sm_info_hex);
}
......@@ -1149,7 +1149,7 @@ void session_update_sm_context_procedure::handle_itti_msg(
n11_triggered_pending->res, n2_sm_info_type_e::PDU_RES_SETUP_REQ,
n2_sm_info);
smf_app_inst->convert_string_2_hex(n2_sm_info, n2_sm_info_hex);
conv::convert_string_2_hex(n2_sm_info, n2_sm_info_hex);
n11_triggered_pending->res.set_n2_sm_information(n2_sm_info_hex);
// fill the content of SmContextUpdatedData
......@@ -1210,7 +1210,7 @@ void session_update_sm_context_procedure::handle_itti_msg(
n11_triggered_pending->res, n1_sm_msg,
cause_value_5gsm_e::CAUSE_26_INSUFFICIENT_RESOURCES); // TODO: check
// Cause
smf_app_inst->convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
conv::convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
n11_triggered_pending->res.set_n1_sm_message(n1_sm_msg_hex);
// include N2 SM Resource Release Request only when User Plane connection
......@@ -1221,7 +1221,7 @@ void session_update_sm_context_procedure::handle_itti_msg(
.create_n2_pdu_session_resource_release_command_transfer(
n11_triggered_pending->res, n2_sm_info_type_e::PDU_RES_REL_CMD,
n2_sm_info);
smf_app_inst->convert_string_2_hex(n2_sm_info, n2_sm_info_hex);
conv::convert_string_2_hex(n2_sm_info, n2_sm_info_hex);
n11_triggered_pending->res.set_n2_sm_information(n2_sm_info_hex);
// fill the content of SmContextUpdatedData
......
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