Commit f3e73efb authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

fix isssue for encode/decode N1 SM container (Hex)

parent 12fa7ade
......@@ -14,6 +14,7 @@
#include "logger.hpp"
#include "smf_msg.hpp"
#include "itti_msg_n11.hpp"
#include "3gpp_29.502.h"
extern "C" {
#include "nas_message.h"
......@@ -44,19 +45,39 @@ void SMContextsCollectionApiImpl::post_sm_contexts(const SmContextMessage &smCon
SmContextCreateData smContextCreateData = smContextMessage.getJsonData();
std::string n1_sm_msg = smContextMessage.getBinaryDataN1SmMessage();
//FOR DEBUG ONLY!!, GENERATE A PDU SESSION ESTABLISHMENT MESSAGE HERE!!
//FOR DEBUG ONLY!!, GENERATE A PDU SESSION ESTABLISHMENT MESSAGE HERE!!
//sm_encode_establishment_request();
//m_smf_app->create_n1_sm_container(PDU_SESSION_ESTABLISHMENT_REQUEST, n1_sm_msg);
m_smf_app->create_n1_sm_container(PDU_SESSION_ESTABLISHMENT_REQUEST, n1_sm_msg);
std::string n1_sm_msg_hex;
m_smf_app->convert_string_2_hex(n1_sm_msg, n1_sm_msg_hex);
Logger::smf_api_server().debug("smContextMessage, n1 sm msg %s",n1_sm_msg.c_str());
//Step1. Decode N1 SM container into decoded nas msg
int decoder_rc = m_smf_app->decode_nas_message_n1_sm_container(decoded_nas_msg, n1_sm_msg);
if (decoder_rc != RETURNok){
//error, should send reply to AMF with error code!!
int decoder_rc = m_smf_app->decode_nas_message_n1_sm_container(decoded_nas_msg, n1_sm_msg_hex);
if (decoder_rc != RETURNok) {
//error, should send reply to AMF with error code!!
Logger::smf_api_server().warn("N1 SM container cannot be decoded correctly!\n");
SmContextCreateError smContextCreateError;
ProblemDetails problem_details;
RefToBinaryData binary_data;
std::string n1_container;
problem_details.setCause(pdu_session_application_error_e2str[PDU_SESSION_APPLICATION_ERROR_N1_SM_ERROR]);
smContextCreateError.setError(problem_details);
//PDU Session Establishment Reject
//24.501: response with a 5GSM STATUS message including cause "#95 Semantically incorrect message"
m_smf_app->create_n1_sm_container(PDU_SESSION_ESTABLISHMENT_REJECT, n1_container, 95); //TODO: should define 5GSM cause in 24.501
binary_data.setContentId(n1_container);
smContextCreateError.setN1SmMsg(binary_data);
//Send response to AMF
nlohmann::json jsonData;
to_json(jsonData, smContextCreateError);
std::string resBody = jsonData.dump();
//httpResponse.headers().add<Pistache::Http::Header::Location>(url);
response.send(Pistache::Http::Code::Forbidden, resBody);
return;
}
Logger::smf_api_server().debug("nas header decode extended_protocol_discriminator %d, security_header_type:%d,sequence_number:%d,message_authentication_code:%d\n",
......@@ -108,7 +129,6 @@ void SMContextsCollectionApiImpl::post_sm_contexts(const SmContextMessage &smCon
//Message type (Mandatory) (PDU SESSION ESTABLISHMENT REQUEST message identity)
sm_context_req_msg.set_message_type(decoded_nas_msg.plain.sm.header.message_type);
sm_context_req_msg.set_message_type (PDU_SESSION_ESTABLISHMENT_REQUEST); //Temporary - should be removed (get from NAS)
//Integrity protection maximum data rate (Mandatory)
......
......@@ -295,6 +295,7 @@ int nas_message_decode (
}
//return bytes;
//OAILOG_FUNC_RETURN (LOG_NAS, bytes);
return RETURNok;
}
......
......@@ -362,7 +362,7 @@ add_executable(smf
${SRC_TOP_DIR}/oai_smf/options.cpp
${SRC_TOP_DIR}/itti/itti.cpp
${SRC_TOP_DIR}/itti/itti_msg.cpp
# ${SRC_TOP_DIR}/oai_smf/nas_sm_encode_to_json.c
${SRC_TOP_DIR}/oai_smf/nas_sm_encode_to_json.c
)
IF(STATIC_LINKING)
......
This diff is collapsed.
......@@ -208,7 +208,15 @@ public:
* @param [std::string&] n1_sm_msg N1 SM Container from AMF
* @return status of the decode process
*/
uint8_t decode_nas_message_n1_sm_container(nas_message_t& nas_msg, std::string& n1_sm_msg);
int decode_nas_message_n1_sm_container(nas_message_t& nas_msg, std::string& n1_sm_msg);
/*
* Convert a string to hex representing this string
* @param [std::string&] input_str Input string
* @param [std::string&] output_str String represents string in hex format
* @return void
*/
void convert_string_2_hex(std::string& input_str, std::string& output_str);
};
}
......
......@@ -134,19 +134,23 @@ void smf_n11::send_msg_to_amf(std::shared_ptr<itti_n11_create_sm_context_respons
CURL *curl = curl_easy_init();
//hardcoded for the moment, should get from NRF/configuration file
std::string url = std::string(inet_ntoa (*((struct in_addr *)&smf_cfg.amf_addr.ipv4_addr))) + ":" + std::to_string(smf_cfg.amf_addr.port) + "/namf-comm/v1/ue-contexts/" + std::to_string(supi64) +"/n1-n2-messages";
Logger::smf_n11().debug("[get_sm_data] UDM's URL: %s ", url.c_str());
Logger::smf_n11().debug("[Send Communication_N1N2MessageTransfer to AMF] AMF's URL: %s ", url.c_str());
//N1 SM container
if (sm_context_res->res.get_cause() != REQUEST_ACCEPTED) { //PDU Session Establishment Reject
Logger::smf_n11().debug("[Send Communication_N1N2MessageTransfer to AMF] PDU Session Establishment Reject\n");
smf_app_inst->create_n1_sm_container(sm_context_res, PDU_SESSION_ESTABLISHMENT_REJECT, n1_message); //need cause?
} else { //PDU Session Establishment Accept
smf_app_inst->create_n1_sm_container(sm_context_res, PDU_SESSION_ESTABLISHMENT_REJECT, n1_message); //need cause?
//smf_app_inst->create_n1_sm_container(sm_context_res, PDU_SESSION_ESTABLISHMENT_ACCPET, n1_message); //need cause?
Logger::smf_n11().debug("[Send Communication_N1N2MessageTransfer to AMF] PDU Session Establishment Accept \n");
smf_app_inst->create_n1_sm_container(sm_context_res, PDU_SESSION_ESTABLISHMENT_ACCPET, n1_message); //need cause?
}
std::string n1_msg_hex;
smf_app_inst->convert_string_2_hex(n1_message, n1_msg_hex);
jsonData["n1MessageContainer"]["n1MessageClass"] = "SM";
jsonData["n1MessageContainer"]["n1MessageContent"]["contentId"] = n1_message.c_str();
Logger::smf_n11().debug("n1MessageContent: %s\n ", n1_message.c_str());
jsonData["n1MessageContainer"]["n1MessageContent"]["contentId"] = n1_msg_hex;
Logger::smf_n11().debug("n1MessageContent: %s\n ", n1_msg_hex.c_str());
//TODO: fill the content of N1N2MessageTransferReqData
//jsonData["n2InfoContainer"]["n2InformationClass"] = "SM";
......
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