Commit 82634cdd authored by Raphael Defosseux's avatar Raphael Defosseux

Merge branch 'set_log_level' into 'develop'

Turn off log in with build option MinSizeRel

See merge request oai/cn5g/oai-cn5g-amf!189
parents 2d0fe283 147ab5fb
{
"files.associations": {
"deque": "cpp",
"string": "cpp",
"vector": "cpp"
}
}
\ No newline at end of file
......@@ -37,7 +37,7 @@
#include "amf_n2.hpp"
#include "amf_sbi.hpp"
#include "amf_statistics.hpp"
#include "comUt.hpp"
#include "output_wrapper.hpp"
#include "itti.hpp"
#include "ngap_app.hpp"
......@@ -337,7 +337,8 @@ void amf_app::handle_itti_message(
uint8_t nas[BUFFER_SIZE_1024];
int encoded_size = dl->Encode(nas, BUFFER_SIZE_1024);
comUt::print_buffer("amf_app", "n1n2 transfer", nas, encoded_size);
output_wrapper::print_buffer(
"amf_app", "N1N2 message transfer", nas, encoded_size);
std::shared_ptr<itti_downlink_nas_transfer> dl_msg =
std::make_shared<itti_downlink_nas_transfer>(TASK_AMF_APP, TASK_AMF_N1);
......
This diff is collapsed.
......@@ -50,7 +50,7 @@
#include "amf_n1.hpp"
#include "amf_sbi.hpp"
#include "amf_statistics.hpp"
#include "comUt.hpp"
#include "output_wrapper.hpp"
#include "itti.hpp"
#include "itti_msg_amf_app.hpp"
#include "logger.hpp"
......@@ -675,7 +675,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) {
memcpy(
(void*) unc->initialUEMsg.buf, (void*) initial_ue_msg_buf,
encoded_size);
comUt::print_buffer(
output_wrapper::print_buffer(
"ngap", "InitialUEMessage", unc->initialUEMsg.buf, encoded_size);
unc->initialUEMsg.size = encoded_size;
}
......@@ -1006,10 +1006,8 @@ void amf_n2::handle_itti_message(
int encoded_size = 0;
psrsr->encode2NewBuffer(buffer, encoded_size);
#if DEBUG_IS_ON
Logger::amf_n2().debug("N2 SM buffer data: ");
for (int i = 0; i < encoded_size; i++) printf("%02x ", (char) buffer[i]);
#endif
output_wrapper::print_buffer(
"amf_n2", "N2 SM buffer data:", buffer, encoded_size);
Logger::amf_n2().debug(" (%d bytes) \n", encoded_size);
bstring b = blk2bstr(buffer, encoded_size);
......@@ -1062,10 +1060,8 @@ void amf_n2::handle_itti_message(
uint8_t* buffer = (uint8_t*) calloc(1, BUFFER_SIZE_4096);
int encoded_size = 0;
modify_request_msg->encode2NewBuffer(buffer, encoded_size);
#if DEBUG_IS_ON
Logger::amf_n2().debug("N2 SM buffer data: ");
for (int i = 0; i < encoded_size; i++) printf("%02x ", (char) buffer[i]);
#endif
output_wrapper::print_buffer(
"amf_n2", "N2 SM buffer data:", buffer, encoded_size);
Logger::amf_n2().debug(" (%d bytes) \n", encoded_size);
bstring b = blk2bstr(buffer, encoded_size);
......@@ -1113,10 +1109,8 @@ void amf_n2::handle_itti_message(
uint8_t* buffer = (uint8_t*) calloc(1, BUFFER_SIZE_4096);
int encoded_size = 0;
release_cmd_msg->encode2NewBuffer(buffer, encoded_size);
#if DEBUG_IS_ON
Logger::amf_n2().debug("N2 SM buffer data: ");
for (int i = 0; i < encoded_size; i++) printf("%02x ", (char) buffer[i]);
#endif
output_wrapper::print_buffer(
"amf_n2", "N2 SM buffer data:", buffer, encoded_size);
Logger::amf_n2().debug(" (%d bytes) \n", encoded_size);
bstring b = blk2bstr(buffer, encoded_size);
......
......@@ -33,7 +33,7 @@
#include "amf_app.hpp"
#include "amf_config.hpp"
#include "amf_n1.hpp"
#include "comUt.hpp"
#include "output_wrapper.hpp"
#include "conversions.hpp"
#include "fqdn.hpp"
#include "itti.hpp"
......@@ -71,7 +71,7 @@ void octet_stream_2_hex_stream(uint8_t* buf, int len, std::string& out) {
}
tmp[2 * len] = '\0';
out = tmp;
printf("n1sm buffer: %s\n", out.c_str());
Logger::amf_sbi().debug("n1sm buffer: %s", out.c_str());
}
//------------------------------------------------------------------------------
......@@ -793,8 +793,8 @@ bool amf_sbi::smf_selection_from_configuration(
void amf_sbi::handle_post_sm_context_response_error(
const long code, const std::string& cause, bstring n1sm,
const std::string& supi, const uint8_t pdu_session_id) {
comUt::print_buffer(
"amf_sbi", "n1 sm", (uint8_t*) bdata(n1sm), blength(n1sm));
output_wrapper::print_buffer(
"amf_sbi", "N1 SM", (uint8_t*) bdata(n1sm), blength(n1sm));
itti_n1n2_message_transfer_request* itti_msg =
new itti_n1n2_message_transfer_request(TASK_AMF_SBI, TASK_AMF_APP);
itti_msg->n1sm = bstrcpy(n1sm);
......@@ -1079,7 +1079,9 @@ void amf_sbi::curl_http_client(
curl_easy_setopt(curl, CURLOPT_INTERFACE, amf_cfg.sbi.if_name.c_str());
if (http_version == 2) {
#if DEBUG_IS_ON
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
#endif
// we use a self-signed test server, skip verification during debugging
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
......@@ -1170,7 +1172,7 @@ void amf_sbi::curl_http_client(
Logger::amf_sbi().debug(
"Get response with json_data: %s", json_data_response.c_str());
conv::msg_str_2_msg_hex(n1sm, n1sm_hex);
comUt::print_buffer(
output_wrapper::print_buffer(
"amf_sbi", "Get response with n1sm:", (uint8_t*) bdata(n1sm_hex),
blength(n1sm_hex));
......@@ -1265,16 +1267,16 @@ void amf_sbi::curl_http_client(
if (n1sm.size() > 0) {
conv::msg_str_2_msg_hex(n1sm, n1sm_hex);
comUt::print_buffer(
"amf_sbi", "Get response n1sm:", (uint8_t*) bdata(n1sm_hex),
output_wrapper::print_buffer(
"amf_sbi", "Get response N1 SM:", (uint8_t*) bdata(n1sm_hex),
blength(n1sm_hex));
itti_msg->n1sm = bstrcpy(n1sm_hex);
itti_msg->is_n1sm_set = true;
}
if (n2sm.size() > 0) {
conv::msg_str_2_msg_hex(n2sm, n2sm_hex);
comUt::print_buffer(
"amf_sbi", "Get response n2sm:", (uint8_t*) bdata(n2sm_hex),
output_wrapper::print_buffer(
"amf_sbi", "Get response N2 SM:", (uint8_t*) bdata(n2sm_hex),
blength(n2sm_hex));
itti_msg->n2sm = bstrcpy(n2sm_hex);
itti_msg->is_n2sm_set = true;
......@@ -1366,7 +1368,9 @@ void amf_sbi::curl_http_client(
curl_easy_setopt(curl, CURLOPT_INTERFACE, amf_cfg.sbi.if_name.c_str());
if (http_version == 2) {
#if DEBUG_IS_ON
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
#endif
// we use a self-signed test server, skip verification during debugging
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
......@@ -1509,7 +1513,9 @@ void amf_sbi::curl_http_client(
curl_easy_setopt(curl, CURLOPT_INTERFACE, amf_cfg.sbi.if_name.c_str());
if (http_version == 2) {
#if DEBUG_IS_ON
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
#endif
// we use a self-signed test server, skip verification during debugging
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
......
......@@ -30,5 +30,5 @@ file(GLOB COMMON_SRC ${SRC_TOP_DIR}/common/conversions.cpp)
add_library(3GPP_COMMON_TYPES STATIC
${SRC_TOP_DIR}/common/logger.cpp
${SRC_TOP_DIR}/common/conversions.cpp
${SRC_TOP_DIR}/common/comUt.cpp
${SRC_TOP_DIR}/common/output_wrapper.cpp
)
......@@ -32,6 +32,7 @@
#include "amf.hpp"
#include "logger.hpp"
#include "output_wrapper.hpp"
constexpr uint8_t kUint32Length =
8; // 4 bytes -8 characters representation in hex
......@@ -166,11 +167,8 @@ void conv::convert_string_2_hex(
}
memset(data, 0, input_str.length() + 1);
memcpy((void*) data, (void*) input_str.c_str(), input_str.length());
for (int i = 0; i < input_str.length(); i++) {
printf("%02x ", data[i]);
}
printf("\n");
output_wrapper::print_buffer(
"amf_app", "Data input", data, input_str.length());
char* datahex = (char*) malloc(input_str.length() * 2 + 1);
if (!datahex) {
......@@ -202,9 +200,8 @@ unsigned char* conv::format_string_as_hex(std::string str) {
memset(data, 0, str_len + 1);
memcpy((void*) data, (void*) str.c_str(), str_len);
// TODO: use logger
std::cout << "Data: " << data << " (" << str_len << " bytes)" << std::endl;
std::cout << "Data (formatted): \n";
Logger::amf_app().debug("Data %s (%d bytes)", data, str_len);
Logger::amf_app().debug("Data (formatted):");
for (int i = 0; i < str_len; i++) {
char datatmp[3] = {0};
memcpy(datatmp, &data[i], 2);
......@@ -218,14 +215,18 @@ unsigned char* conv::format_string_as_hex(std::string str) {
// Convert two hexadecimal characters into one character
unsigned int nAsciiCharacter;
sscanf(datatmp, "%x", &nAsciiCharacter);
#if DEBUG_IS_ON
printf("%x ", nAsciiCharacter);
#endif
// Concatenate this character onto the output
datavalue[i / 2] = (unsigned char) nAsciiCharacter;
// Skip the next character
i++;
}
#if DEBUG_IS_ON
printf("\n");
#endif
free_wrapper((void**) &data);
return datavalue;
......@@ -248,7 +249,7 @@ char* conv::bstring2charString(bstring b) {
void conv::msg_str_2_msg_hex(std::string msg, bstring& b) {
std::string msg_hex_str = {};
convert_string_2_hex(msg, msg_hex_str);
printf("tmp string: %s\n", msg_hex_str.c_str());
Logger::amf_app().debug("Msg hex %s", msg_hex_str.c_str());
unsigned int msg_len = msg_hex_str.length();
char* data = (char*) malloc(msg_len + 1);
if (!data) {
......@@ -258,7 +259,7 @@ void conv::msg_str_2_msg_hex(std::string msg, bstring& b) {
memset(data, 0, msg_len + 1);
memcpy((void*) data, (void*) msg_hex_str.c_str(), msg_len);
printf("data: %s\n", data);
uint8_t* msg_hex = (uint8_t*) malloc(msg_len / 2 + 1);
if (!msg_hex) {
free_wrapper((void**) &msg_hex);
......
......@@ -42,8 +42,9 @@ void Logger::_init(
#elif INFO_IS_ON
spdlog::level::level_enum llevel = spdlog::level::info;
#else
spdlog::level::level_enum llevel = spdlog::level::warn;
spdlog::level::level_enum llevel = spdlog::level::off;
#endif
// TODO: Log leve: "start", "warn ", "error"
if (log_stdout) {
std::string filename = fmt::format("./{}.log", app);
......@@ -87,8 +88,9 @@ _Logger::_Logger(
#elif INFO_IS_ON
m_log.set_level(spdlog::level::info);
#else
m_log.set_level(spdlog::level::warn);
m_log.set_level(spdlog::level::off);
#endif
// TODO: Log leve: "start", "warn ", "error"
}
//------------------------------------------------------------------------------
......
......@@ -19,38 +19,29 @@
* contact@openairinterface.org
*/
#include "comUt.hpp"
#include "output_wrapper.hpp"
#include "logger.hpp"
//------------------------------------------------------------------------------
void comUt::print_buffer(
const std::string app, const std::string commit, uint8_t* buf, int len) {
if (!app.compare("amf_app")) Logger::amf_app().debug(commit.c_str());
if (!app.compare("amf_n1")) Logger::amf_n1().debug(commit.c_str());
if (!app.compare("amf_server")) Logger::amf_server().debug(commit.c_str());
if (!app.compare("amf_sbi")) Logger::amf_sbi().debug(commit.c_str());
void output_wrapper::print_buffer(
const std::string app, const std::string sink, uint8_t* buf, int len) {
if (!app.compare("amf_app")) Logger::amf_app().debug(sink.c_str());
if (!app.compare("amf_n1")) Logger::amf_n1().debug(sink.c_str());
if (!app.compare("amf_n2")) Logger::amf_n2().debug(sink.c_str());
if (!app.compare("ngap")) Logger::ngap().debug(sink.c_str());
if (!app.compare("amf_server")) Logger::amf_server().debug(sink.c_str());
if (!app.compare("amf_sbi")) Logger::amf_sbi().debug(sink.c_str());
#if DEBUG_IS_ON
for (int i = 0; i < len; i++) printf("%x ", buf[i]);
for (int i = 0; i < len; i++) printf("%02x ", buf[i]);
printf("\n");
#endif
}
//------------------------------------------------------------------------------
void comUt::hexStr2Byte(const char* src, unsigned char* dest, int len) {
short i;
unsigned char hBy, lBy;
for (i = 0; i < len; i += 2) {
hBy = toupper(src[i]);
lBy = toupper(src[i + 1]);
if (hBy > 0x39)
hBy -= 0x37;
else
hBy -= 0x30;
if (lBy > 0x39)
lBy -= 0x37;
else
lBy -= 0x30;
dest[i / 2] = (hBy << 4) | lBy;
}
void output_wrapper::print_asn_msg(
const asn_TYPE_descriptor_t* td, const void* struct_ptr) {
#if DEBUG_IS_ON
asn_fprint(stdout, td, struct_ptr);
#endif
}
......@@ -19,18 +19,21 @@
* contact@openairinterface.org
*/
#ifndef _PRINT_BUFFER_H
#define _PRINT_BUFFER_H
#include <string>
#ifndef _OUTPUT_WRAPPER_H
#define _OUTPUT_WRAPPER_H
#include "logger.hpp"
class comUt {
extern "C" {
#include "constr_TYPE.h"
}
class output_wrapper {
public:
static void print_buffer(
const std::string app, const std::string commit, uint8_t* buf, int len);
static void hexStr2Byte(const char* src, unsigned char* dest, int len);
const std::string app, const std::string sink, uint8_t* buf, int len);
static void print_asn_msg(
const asn_TYPE_descriptor_t* td, const void* struct_ptr);
};
#endif
......@@ -22,8 +22,7 @@
#include "AMFSetID.hpp"
#include "String2Value.hpp"
#include <string>
#include "output_wrapper.hpp"
namespace ngap {
......@@ -77,10 +76,9 @@ bool AMFSetID::encode(Ngap_AMFSetID_t& amf_set_id) const {
//------------------------------------------------------------------------------
bool AMFSetID::decode(const Ngap_AMFSetID_t& amf_set_id) {
if (!amf_set_id.buf) return false;
for (int i = 0; i < amf_set_id.size; i++) {
printf("%x ", amf_set_id.buf[i]);
}
printf("\n");
output_wrapper::print_buffer(
"ngap", "AMFSetID", amf_set_id.buf, amf_set_id.size);
uint16_t temp = 0;
temp |= amf_set_id.buf[0] << 8;
temp |= amf_set_id.buf[1];
......
......@@ -20,6 +20,8 @@
*/
#include "PDUSessionResourceHandoverCommandTransfer.hpp"
#include "output_wrapper.hpp"
extern "C" {
#include "asn_codecs.h"
#include "constr_TYPE.h"
......@@ -101,8 +103,8 @@ void PDUSessionResourceHandoverCommandTransfer::setUPTransportLayerInformation(
int PDUSessionResourceHandoverCommandTransfer::
encodePDUSessionResourceHandoverCommandTransfer(
uint8_t* buf, int buf_size) {
asn_fprint(
stderr, &asn_DEF_Ngap_HandoverCommandTransfer, handovercommandtransferIE);
output_wrapper::print_asn_msg(
&asn_DEF_Ngap_HandoverCommandTransfer, handovercommandtransferIE);
asn_enc_rval_t er = aper_encode_to_buffer(
&asn_DEF_Ngap_HandoverCommandTransfer, NULL, handovercommandtransferIE,
buf, buf_size);
......
......@@ -21,6 +21,8 @@
#include "PDUSessionResourceHandoverRequiredTransfer.hpp"
#include "output_wrapper.hpp"
extern "C" {
#include "asn_codecs.h"
#include "constr_TYPE.h"
......@@ -53,9 +55,8 @@ void PDUSessionResourceHandoverRequiredTransfer::
int PDUSessionResourceHandoverRequiredTransfer::Encode(
uint8_t* buf, int buf_size) {
asn_fprint(
stderr, &asn_DEF_Ngap_HandoverRequiredTransfer,
handoverrquiredTransferIEs);
output_wrapper::print_asn_msg(
&asn_DEF_Ngap_HandoverRequiredTransfer, handoverrquiredTransferIEs);
asn_enc_rval_t er = aper_encode_to_buffer(
&asn_DEF_Ngap_HandoverRequiredTransfer, NULL, handoverrquiredTransferIEs,
buf, buf_size);
......
......@@ -21,6 +21,8 @@
#include "PDUSessionResourceReleaseCommandTransfer.hpp"
#include "output_wrapper.hpp"
extern "C" {
#include "asn_codecs.h"
#include "constr_TYPE.h"
......@@ -122,8 +124,8 @@ void PDUSessionResourceReleaseCommandTransfer::setCauseMisc(
int PDUSessionResourceReleaseCommandTransfer::Encode(
uint8_t* buf, int buf_size) {
asn_fprint(
stderr, &asn_DEF_Ngap_PDUSessionResourceReleaseCommandTransfer,
output_wrapper::print_asn_msg(
&asn_DEF_Ngap_PDUSessionResourceReleaseCommandTransfer,
pduSessionResourceReleaseCommandTransferIEs);
asn_enc_rval_t er = aper_encode_to_buffer(
&asn_DEF_Ngap_PDUSessionResourceReleaseCommandTransfer, NULL,
......
......@@ -21,6 +21,8 @@
#include "PDUSessionResourceSetupRequestTransfer.hpp"
#include "output_wrapper.hpp"
extern "C" {
#include "asn_codecs.h"
#include "constr_TYPE.h"
......@@ -480,8 +482,8 @@ void PduSessionResourceSetupRequestTransferIE::setQosFlowSetupRequestList(
//------------------------------------------------------------------------------
int PduSessionResourceSetupRequestTransferIE::Encode(
uint8_t* buf, int buf_size) {
asn_fprint(
stderr, &asn_DEF_Ngap_PDUSessionResourceSetupRequestTransfer,
output_wrapper::print_asn_msg(
&asn_DEF_Ngap_PDUSessionResourceSetupRequestTransfer,
pduSessionResourceSetupRequestTransferIEs);
asn_enc_rval_t er = aper_encode_to_buffer(
&asn_DEF_Ngap_PDUSessionResourceSetupRequestTransfer, NULL,
......
......@@ -21,6 +21,8 @@
#include "PDUSessionResourceSetupResponseTransfer.hpp"
#include "output_wrapper.hpp"
extern "C" {
#include "asn_codecs.h"
#include "constr_TYPE.h"
......@@ -168,8 +170,8 @@ void PduSessionResourceSetupResponseTransferIE::setSecurityResult(
//------------------------------------------------------------------------------
int PduSessionResourceSetupResponseTransferIE::Encode(
uint8_t* buf, int buf_size) {
asn_fprint(
stderr, &asn_DEF_Ngap_PDUSessionResourceSetupResponseTransfer,
output_wrapper::print_asn_msg(
&asn_DEF_Ngap_PDUSessionResourceSetupResponseTransfer,
pduSessionResourceSetupResponseTransferIEs);
asn_enc_rval_t er = aper_encode_to_buffer(
&asn_DEF_Ngap_PDUSessionResourceSetupResponseTransfer, NULL,
......
......@@ -21,6 +21,8 @@
#include "PDUSessionResourceSetupUnsuccessfulTransfer.hpp"
#include "output_wrapper.hpp"
extern "C" {
#include "asn_codecs.h"
#include "constr_TYPE.h"
......@@ -130,8 +132,8 @@ void PduSessionResourceSetupUnSuccessfulTransferIE::setCauseMisc(
//------------------------------------------------------------------------------
int PduSessionResourceSetupUnSuccessfulTransferIE::Encode(
uint8_t* buf, int buf_size) {
asn_fprint(
stderr, &asn_DEF_Ngap_PDUSessionResourceSetupUnsuccessfulTransfer,
output_wrapper::output_wrapper::print_asn_msg(
&asn_DEF_Ngap_PDUSessionResourceSetupUnsuccessfulTransfer,
pduSessionResourceSetupUnsuccessfulTransferIEs);
asn_enc_rval_t er = aper_encode_to_buffer(
&asn_DEF_Ngap_PDUSessionResourceSetupUnsuccessfulTransfer, NULL,
......
......@@ -23,6 +23,7 @@
#include "conversions.hpp"
#include "logger.hpp"
#include "output_wrapper.hpp"
extern "C" {
#include "dynamic_memory_check.h"
......@@ -264,7 +265,7 @@ void HandoverRequest::setAllowedNSSAI(std::vector<S_NSSAI>& list) {
Logger::ngap().error(
"Encode PDUSessionResourceHandoverListItem IE error");
}
asn_fprint(stderr, &asn_DEF_Ngap_AllowedNSSAI, &allowedNSSAI);
output_wrapper::print_asn_msg(&asn_DEF_Ngap_AllowedNSSAI, &allowedNSSAI);
Ngap_HandoverRequestIEs_t* ie =
(Ngap_HandoverRequestIEs_t*) calloc(1, sizeof(Ngap_HandoverRequestIEs_t));
ie->id = Ngap_ProtocolIE_ID_id_AllowedNSSAI;
......
......@@ -20,7 +20,9 @@
*/
#include "NgapMessage.hpp"
#include "logger.hpp"
#include "output_wrapper.hpp"
extern "C" {
#include "asn_codecs.h"
......@@ -461,7 +463,7 @@ void NgapMessage::setMessageType(NgapMessageType messageType) {
//------------------------------------------------------------------------------
int NgapMessage::Encode(uint8_t* buf, int bufSize) {
asn_fprint(stderr, &asn_DEF_Ngap_NGAP_PDU, ngapPdu);
output_wrapper::print_asn_msg(&asn_DEF_Ngap_NGAP_PDU, ngapPdu);
asn_enc_rval_t er = aper_encode_to_buffer(
&asn_DEF_Ngap_NGAP_PDU, NULL, ngapPdu, buf, bufSize);
......@@ -472,7 +474,7 @@ int NgapMessage::Encode(uint8_t* buf, int bufSize) {
//------------------------------------------------------------------------------
void NgapMessage::encode2NewBuffer(uint8_t*& buf, int& encoded_size) {
asn_fprint(stderr, &asn_DEF_Ngap_NGAP_PDU, ngapPdu);
output_wrapper::print_asn_msg(&asn_DEF_Ngap_NGAP_PDU, ngapPdu);
encoded_size = aper_encode_to_new_buffer(
&asn_DEF_Ngap_NGAP_PDU, NULL, ngapPdu, (void**) &buf);
Logger::ngap().debug("Encoded message size ( %d )", encoded_size);
......
......@@ -62,7 +62,7 @@ void ngap_app::handle_receive(
"Decoded NGAP message, procedure code %d, present %d",
ngap_msg_pdu->choice.initiatingMessage->procedureCode,
ngap_msg_pdu->present);
asn_fprint(stderr, &asn_DEF_Ngap_NGAP_PDU, ngap_msg_pdu);
output_wrapper::print_asn_msg(&asn_DEF_Ngap_NGAP_PDU, ngap_msg_pdu);
if ((ngap_msg_pdu->choice.initiatingMessage->procedureCode >
(NGAP_PROCEDURE_CODE_MAX_VALUE - 1)) or
......
......@@ -37,6 +37,7 @@
#include "logger.hpp"
#include "nas_context.hpp"
#include "pdu_session_context.hpp"
#include "output_wrapper.hpp"
using namespace sctp;
using namespace ngap;
......@@ -60,7 +61,7 @@ int ngap_amf_handle_ng_setup_request(
const sctp_assoc_id_t assoc_id, const sctp_stream_id_t stream,
struct Ngap_NGAP_PDU* message_p) {
Logger::ngap().debug("Sending ITTI NG Setup Request message to TASK_AMF_N2");
asn_fprint(stderr, &asn_DEF_Ngap_NGAP_PDU, message_p);
output_wrapper::print_asn_msg(&asn_DEF_Ngap_NGAP_PDU, message_p);
NGSetupRequestMsg* ng_setup_req = new NGSetupRequestMsg();
if (!ng_setup_req->decodeFromPdu(message_p)) {
Logger::ngap().error("Decoding NGSetupRequest message error");
......@@ -107,7 +108,7 @@ int ngap_amf_handle_initial_ue_message(
struct Ngap_NGAP_PDU* message_p) {
Logger::ngap().debug("Sending ITTI Initial UE Message to TASK_AMF_N2");
asn_fprint(stderr, &asn_DEF_Ngap_NGAP_PDU, message_p);
output_wrapper::print_asn_msg(&asn_DEF_Ngap_NGAP_PDU, message_p);
InitialUEMessageMsg* init_ue_msg = new InitialUEMessageMsg();
if (!init_ue_msg->decodeFromPdu(message_p)) {
Logger::ngap().error("Decoding InitialUEMessage error");
......@@ -136,7 +137,7 @@ int ngap_amf_handle_uplink_nas_transport(
struct Ngap_NGAP_PDU* message_p) {
Logger::ngap().debug(
"Sending ITTI Uplink NAS Transport message to TASK_AMF_N2");
asn_fprint(stderr, &asn_DEF_Ngap_NGAP_PDU, message_p);
output_wrapper::print_asn_msg(&asn_DEF_Ngap_NGAP_PDU, message_p);
UplinkNASTransportMsg* uplink_nas_transport = new UplinkNASTransportMsg();
if (!uplink_nas_transport->decodeFromPdu(message_p)) {
Logger::ngap().error("Decoding UplinkNasTransport message error");
......@@ -736,7 +737,7 @@ int handover_preparation(
struct Ngap_NGAP_PDU* message_p) {
Logger::ngap().debug("Sending ITTI Handover Preparation to TASK_AMF_N2");
asn_fprint(stderr, &asn_DEF_Ngap_NGAP_PDU, message_p);
output_wrapper::print_asn_msg(&asn_DEF_Ngap_NGAP_PDU, message_p);
HandoverRequiredMsg* handover_required = new HandoverRequiredMsg();
if (!handover_required->decodeFromPdu(message_p)) {
Logger::ngap().error("Decoding HandoverRequired message error");
......@@ -782,7 +783,7 @@ int handover_notification(
const sctp_assoc_id_t assoc_id, const sctp_stream_id_t stream,
struct Ngap_NGAP_PDU* message_p) {
Logger::ngap().debug("Sending ITTI Handover Notification to TASK_AMF_N2");
asn_fprint(stderr, &asn_DEF_Ngap_NGAP_PDU, message_p);
output_wrapper::print_asn_msg(&asn_DEF_Ngap_NGAP_PDU, message_p);
HandoverNotifyMsg* handover_notify = new HandoverNotifyMsg();
if (!handover_notify->decodeFromPdu(message_p)) {
Logger::ngap().error("Decoding HandoverNotify message error");
......@@ -813,7 +814,7 @@ int handover_request(
"Sending ITTI Handover Resource Allocation (HandoverRequest) to "
"TASK_AMF_N2");
asn_fprint(stderr, &asn_DEF_Ngap_NGAP_PDU, message_p);
output_wrapper::print_asn_msg(&asn_DEF_Ngap_NGAP_PDU, message_p);
HandoverRequestAck* handover_request_ack = new HandoverRequestAck();
if (!handover_request_ack->decodeFromPdu(message_p)) {
Logger::ngap().error("Decoding Handover Request Acknowledge message error");
......@@ -899,7 +900,7 @@ int ng_reset(
struct Ngap_NGAP_PDU* message_p) {
Logger::ngap().debug("Sending ITTI NG Reset to TASK_AMF_N2");
asn_fprint(stderr, &asn_DEF_Ngap_NGAP_PDU, message_p);
output_wrapper::print_asn_msg(&asn_DEF_Ngap_NGAP_PDU, message_p);
NGResetMsg* ng_reset = new NGResetMsg();
if (!ng_reset->decodeFromPdu(message_p)) {
Logger::ngap().error("Decoding NGReset message error");
......@@ -1198,7 +1199,7 @@ int uplink_ran_status_transfer(
Logger::ngap().debug(
"Sending ITTI Uplink RAN Status Transfer to TASK_AMF_N2");
asn_fprint(stderr, &asn_DEF_Ngap_NGAP_PDU, message_p);
output_wrapper::print_asn_msg(&asn_DEF_Ngap_NGAP_PDU, message_p);
UplinkRANStatusTransfer* uplink_ran_status_transfer =
new UplinkRANStatusTransfer();
if (!uplink_ran_status_transfer->decodeFromPdu(message_p)) {
......
......@@ -18,7 +18,7 @@
#include "amf_sbi.hpp"
#include "pdu_session_context.hpp"
#include "conversions.hpp"
#include "comUt.hpp"
#include "output_wrapper.hpp"
using namespace amf_application;
......@@ -76,7 +76,7 @@ void N1N2MessageCollectionDocumentApiImpl::n1_n2_message_transfer(
bstring n1sm = nullptr;
conv::msg_str_2_msg_hex(
n1sm_str.substr(0, n1sm_str.length()), n1sm); // TODO: verify n1sm_length
comUt::print_buffer(
output_wrapper::print_buffer(
"amf_server", "Received N1 SM", (uint8_t*) bdata(n1sm), blength(n1sm));
psc->n1sm = bstrcpy(n1sm);
......
......@@ -48,9 +48,8 @@ void f5star(u8 k[16], u8 rand[16], u8 ak[6]);
*-----------------------------------------------------------------*/
void f1(u8 k[16], u8 rand[16], u8 sqn[6], u8 amf[2], u8 mac_a[8]) {
printf("opc: ");
for (int i = 0; i < 16; i++) printf("0x%x", op_c[i]);
printf("\n");
output_wrapper::print_buffer("amf_app", "OPC", op_c, 16);
// u8 op_c[16];
u8 temp[16];
u8 in1[16];
......
......@@ -30,7 +30,7 @@
#include <string.h>
#include "OCTET_STRING.h"
#include "comUt.hpp"
#include "output_wrapper.hpp"
#include "logger.hpp"
/************ algorithm f1 **************/
......@@ -304,18 +304,18 @@ void Authentication_5gaka::derive_kseaf(
OCTET_STRING_t netName;
OCTET_STRING_fromBuf(
&netName, serving_network.c_str(), serving_network.length());
// comUt::print_buffer("amf_n1", "inputstring: snn(hex)", netName.buf,
// netName.size);
// output_wrapper::print_buffer("amf_n1", "inputstring: snn(hex)",
// netName.buf, netName.size);
uint8_t S[100];
S[0] = 0x6C; // FC
memcpy(&S[1], netName.buf, netName.size);
// memcpy (&S[1+netName.size], &netName.size, 2);
S[1 + netName.size] = (uint8_t)((netName.size & 0xff00) >> 8);
S[2 + netName.size] = (uint8_t)(netName.size & 0x00ff);
// comUt::print_buffer("amf_n1", "inputstring S", S, 3+netName.size);
// comUt::print_buffer("amf_n1", "key KEY", kausf, 32);
// output_wrapper::print_buffer("amf_n1", "inputstring S", S, 3+netName.size);
// output_wrapper::print_buffer("amf_n1", "key KEY", kausf, 32);
kdf(kausf, 32, S, 3 + netName.size, kseaf, 32);
// comUt::print_buffer("amf_n1", "KDF out: Kseaf", kseaf, 32);
// output_wrapper::print_buffer("amf_n1", "KDF out: Kseaf", kseaf, 32);
// Logger::amf_n1().debug("derive kseaf finished!");
}
......@@ -327,8 +327,8 @@ void Authentication_5gaka::derive_kausf(
OCTET_STRING_t netName;
OCTET_STRING_fromBuf(
&netName, serving_network.c_str(), serving_network.length());
// comUt::print_buffer("amf_n1", "inputstring: snn(hex)", netName.buf,
// netName.size);
// output_wrapper::print_buffer("amf_n1", "inputstring: snn(hex)",
// netName.buf, netName.size);
uint8_t S[100];
uint8_t key[32];
memcpy(&key[0], ck, 16);
......@@ -343,10 +343,11 @@ void Authentication_5gaka::derive_kausf(
}
S[9 + netName.size] = 0x00;
S[10 + netName.size] = 0x06;
// comUt::print_buffer("amf_n1", "inputstring S", S, 11+netName.size);
// comUt::print_buffer("amf_n1", "key KEY", key, 32);
// output_wrapper::print_buffer("amf_n1", "inputstring S", S,
// 11+netName.size); output_wrapper::print_buffer("amf_n1", "key KEY", key,
// 32);
kdf(key, 32, S, 11 + netName.size, kausf, 32);
// comUt::print_buffer("amf_n1", "KDF out: Kausf", kausf, 32);
// output_wrapper::print_buffer("amf_n1", "KDF out: Kausf", kausf, 32);
// Logger::amf_n1().debug("derive kausf finished!");
}
......@@ -362,7 +363,8 @@ void Authentication_5gaka::derive_kamf(
OCTET_STRING_fromBuf(&supi, ueSupi.c_str(), ueSupi.length());
// uint8_t supi[8] = {0x64, 0xf0, 0x11, 0x10, 0x32, 0x54, 0x76, 0x98};
int supiLen = supi.size;
// comUt::print_buffer("amf_n1", "inputstring: supi(hex)", supi.buf, supiLen);
// output_wrapper::print_buffer("amf_n1", "inputstring: supi(hex)", supi.buf,
// supiLen);
uint8_t S[100];
S[0] = 0x6D; // FC = 0x6D
memcpy(&S[1], supi.buf, supiLen);
......@@ -373,10 +375,10 @@ void Authentication_5gaka::derive_kamf(
S[4 + supiLen] = (abba & 0xff00) >> 8;
S[5 + supiLen] = 0x00;
S[6 + supiLen] = 0x02;
// comUt::print_buffer("amf_n1", "inputstring S", S, 7+supiLen);
// comUt::print_buffer("amf_n1", "key KEY", kseaf, 32);
// output_wrapper::print_buffer("amf_n1", "inputstring S", S, 7+supiLen);
// output_wrapper::print_buffer("amf_n1", "key KEY", kseaf, 32);
kdf(kseaf, 32, S, 7 + supiLen, kamf, 32);
// comUt::print_buffer("amf_n1", "KDF out: Kamf", kamf, 32);
// output_wrapper::print_buffer("amf_n1", "KDF out: Kamf", kamf, 32);
// Logger::amf_n1().debug("derive kamf finished!");
}
......@@ -393,12 +395,12 @@ void Authentication_5gaka::derive_knas(
S[4] = nas_alg_id;
S[5] = 0x00;
S[6] = 0x01;
// comUt::print_buffer("amf_n1", "inputstring S", S, 7);
// comUt::print_buffer("amf_n1", "key KEY", kamf, 32);
// output_wrapper::print_buffer("amf_n1", "inputstring S", S, 7);
// output_wrapper::print_buffer("amf_n1", "key KEY", kamf, 32);
kdf(kamf, 32, S, 7, out, 32);
// memcpy (knas, &out[31 - 16 + 1], 16);
for (int i = 0; i < 16; i++) knas[i] = out[16 + i];
// comUt::print_buffer("amf_n1", "knas", knas, 16);
// output_wrapper::print_buffer("amf_n1", "knas", knas, 16);
// Logger::amf_n1().debug("derive knas finished!");
}
......@@ -413,10 +415,10 @@ void Authentication_5gaka::derive_kgnb(
S[7] = accessType;
S[8] = 0x00;
S[9] = 0x01;
// comUt::print_buffer("amf_n1", "inputstring S", S, 10);
// comUt::print_buffer("amf_n1", "key KEY", kamf, 32);
// output_wrapper::print_buffer("amf_n1", "inputstring S", S, 10);
// output_wrapper::print_buffer("amf_n1", "key KEY", kamf, 32);
kdf(kamf, 32, S, 10, kgnb, 32);
// comUt::print_buffer("amf_n1", "kgnb", kgnb, 32);
// output_wrapper::print_buffer("amf_n1", "kgnb", kgnb, 32);
// Logger::amf_n1().debug("derive kgnb finished!");
}
void Authentication_5gaka::handover_ncc_derive_knh(
......@@ -446,8 +448,8 @@ void Authentication_5gaka::handover_ncc_derive_knh(
SS[i][34] = 0x20;
kdf(kamf, 32, SS[i], 35, knh, 32);
}
comUt::print_buffer("amf_n1", "SS", SS[i], 35);
comUt::print_buffer("amf_n1", "Knh", knh, 32);
output_wrapper::print_buffer("amf_n1", "SS", SS[i], 35);
output_wrapper::print_buffer("amf_n1", "Knh", knh, 32);
}
}
void Authentication_5gaka::derive_kasme(
......@@ -507,24 +509,24 @@ int Authentication_5gaka::generate_vector(
* Compute MAC
*/
f1(opc, key, vector->rand, sqn, amf, mac_a);
// comUt::print_buffer ("MAC_A : ", mac_a, 8);
// comUt::print_buffer ("SQN : ", sqn, 6);
// comUt::print_buffer ("RAND : ", vector->rand, 16);
// output_wrapper::print_buffer ("MAC_A : ", mac_a, 8);
// output_wrapper::print_buffer ("SQN : ", sqn, 6);
// output_wrapper::print_buffer ("RAND : ", vector->rand, 16);
/*
* Compute XRES, CK, IK, AK
*/
f2345(opc, key, vector->rand, vector->xres, ck, ik, ak);
// comUt::print_buffer ("AK : ", ak, 6);
// comUt::print_buffer ("CK : ", ck, 16);
// comUt::print_buffer ("IK : ", ik, 16);
// comUt::print_buffer ("XRES : ", vector->xres, 8);
// output_wrapper::print_buffer ("AK : ", ak, 6);
// output_wrapper::print_buffer ("CK : ", ck, 16);
// output_wrapper::print_buffer ("IK : ", ik, 16);
// output_wrapper::print_buffer ("XRES : ", vector->xres, 8);
/*
* AUTN = SQN ^ AK || AMF || MAC
*/
generate_autn(sqn, ak, amf, mac_a, vector->autn);
// comUt::print_buffer ("AUTN : ", vector->autn, 16);
// output_wrapper::print_buffer ("AUTN : ", vector->autn, 16);
derive_kasme(ck, ik, plmn, sqn, ak, vector->kasme);
// comUt::print_buffer ("KASME : ", vector->kasme, 32);
// output_wrapper::print_buffer ("KASME : ", vector->kasme, 32);
return 0;
}
......@@ -556,14 +558,17 @@ uint8_t* Authentication_5gaka::sqn_ms_derive(
sqn_ms[i] = ak[i] ^ conc_sqn_ms[i];
}
comUt::print_buffer("amf_n1", "sqn_ms_derive() KEY : ", key, 16);
comUt::print_buffer("amf_n1", "sqn_ms_derive() RAND : ", rand_p, 16);
comUt::print_buffer("amf_n1", "sqn_ms_derive() AUTS : ", auts, 14);
comUt::print_buffer("amf_n1", "sqn_ms_derive() AK : ", ak, 6);
comUt::print_buffer("amf_n1", "sqn_ms_derive() SQN_MS : ", sqn_ms, 6);
comUt::print_buffer("amf_n1", "sqn_ms_derive() MAC_S : ", mac_s, 8);
output_wrapper::print_buffer("amf_n1", "sqn_ms_derive() KEY : ", key, 16);
output_wrapper::print_buffer(
"amf_n1", "sqn_ms_derive() RAND : ", rand_p, 16);
output_wrapper::print_buffer("amf_n1", "sqn_ms_derive() AUTS : ", auts, 14);
output_wrapper::print_buffer("amf_n1", "sqn_ms_derive() AK : ", ak, 6);
output_wrapper::print_buffer(
"amf_n1", "sqn_ms_derive() SQN_MS : ", sqn_ms, 6);
output_wrapper::print_buffer("amf_n1", "sqn_ms_derive() MAC_S : ", mac_s, 8);
f1star(opc, key, rand_p, sqn_ms, amf, mac_s_computed);
comUt::print_buffer("amf_n1", "MAC_S computed : ", mac_s_computed, 8);
output_wrapper::print_buffer(
"amf_n1", "MAC_S computed : ", mac_s_computed, 8);
if (memcmp(mac_s_computed, mac_s, 8) != 0) {
// FPRINTF_ERROR ( "Failed to verify computed SQN_MS\n");
......
......@@ -94,15 +94,6 @@ void Authentication_5gaka::RijndaelKeySchedule(const uint8_t key[16]) {
roundConst = (2*roundConst) ^ 283;
*/
}
//#if AUTH_ALG_ON
#if 0
for(int m=0; m<11; m++){
printf("roundKeys(%d)\n0x", m);
for(int i=0; i<16; i++)
printf("%x ", roundKeys[m][i & 0x3][i >> 2]);
printf("\n");
}
#endif
return;
}
......@@ -187,8 +178,11 @@ void Authentication_5gaka::RijndaelEncrypt(
#if AUTH_ALG_ON
printf("end of round(%d)\n0x", 0);
#endif
#if DEBUG_IS_ON
for (int i = 0; i < 16; i++) printf("%x ", state[i & 0x3][i >> 2]);
printf("\n");
#endif
for (r = 1; r <= 9; r++) {
ByteSub(state);
ShiftRow(state);
......
......@@ -22,6 +22,7 @@
#include "mime_parser.hpp"
#include "conversions.hpp"
#include "output_wrapper.hpp"
#include "logger.hpp"
extern "C" {
......@@ -110,11 +111,9 @@ unsigned char* mime_parser::format_string_as_hex(const std::string& str) {
Logger::amf_app().debug(
"[Format string as Hex] Input string (%d bytes): %s ", str_len,
str.c_str());
Logger::amf_app().debug("Data (formatted):");
#if DEBUG_IS_ON
for (int i = 0; i < str_len / 2; i++) printf(" %02x ", data_hex[i]);
printf("\n");
#endif
output_wrapper::print_buffer(
"amf_app", "Data (formatted):", data_hex, str_len / 2);
// free memory
free_wrapper((void**) &data);
return data_hex;
......
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