fixed some logs. Also now use one single log obj for all the asn1

This commit is contained in:
Francisco Paisana 2020-03-03 19:33:45 +00:00
parent 5bdc603113
commit 62609fdc11
8 changed files with 1406 additions and 1364 deletions

View File

@ -22,7 +22,6 @@
#ifndef SRSASN_COMMON_UTILS_H
#define SRSASN_COMMON_UTILS_H
#include "srslte/common/logmap.h"
#include <algorithm>
#include <array>
#include <cmath>
@ -46,6 +45,15 @@ constexpr Integer ceil_frac(Integer n, Integer d)
return (n + (d - 1)) / d;
}
/************************
logging
************************/
void log_error(const char* format, ...);
void log_warning(const char* format, ...);
void log_info(const char* format, ...);
void log_debug(const char* format, ...);
/************************
error handling
************************/
@ -237,7 +245,7 @@ public:
void push_back(const T& elem)
{
if (current_size >= MAX_N) {
srslte::logmap::get("ASN1")->error("Maximum size %d achieved for bounded_array.\n", MAX_N);
log_error("Maximum size %d achieved for bounded_array.\n", MAX_N);
}
data_[current_size++] = elem;
}
@ -600,8 +608,7 @@ public:
fixed_octstring<N, aligned>& from_string(const std::string& hexstr)
{
if (hexstr.size() != 2 * N) {
srslte::logmap::get("ASN1")->error(
"The provided hex string size is not valid (%zd!=2*%zd).\n", hexstr.size(), (size_t)N);
log_error("The provided hex string size is not valid (%zd!=2*%zd).\n", hexstr.size(), (size_t)N);
} else {
string_to_octstring(&octets_[0], hexstr);
}
@ -770,8 +777,7 @@ public:
this_type& from_string(const std::string& s)
{
if (s.size() < lb or s.size() > ub) {
srslte::logmap::get("ASN1")->error(
"The provided string size=%zd is not withing the bounds [%d, %d]\n", s.size(), lb, ub);
log_error("The provided string size=%zd is not withing the bounds [%d, %d]\n", s.size(), lb, ub);
} else {
resize(s.size());
for (uint32_t i = 0; i < s.size(); ++i) {
@ -1260,17 +1266,17 @@ int test_pack_unpack_consistency(const Msg& msg)
// unpack and last pack done for the same number of bits
if (bref3.distance() != bref2.distance()) {
srslte::logmap::get("ASN1")->error("[%s][%d] .\n", __FILE__, __LINE__);
log_error("[%s][%d] .\n", __FILE__, __LINE__);
return -1;
}
// ensure packed messages are the same
if (bref3.distance() != bref.distance()) {
srslte::logmap::get("ASN1")->error("[%s][%d] .\n", __FILE__, __LINE__);
log_error("[%s][%d] .\n", __FILE__, __LINE__);
return -1;
}
if (memcmp(buf, buf2, bref.distance_bytes()) != 0) {
srslte::logmap::get("ASN1")->error("[%s][%d] .\n", __FILE__, __LINE__);
log_error("[%s][%d] .\n", __FILE__, __LINE__);
return -1;
}
return SRSASN_SUCCESS;

View File

@ -20,13 +20,70 @@
*/
#include "srslte/asn1/asn1_utils.h"
#include "srslte/common/logmap.h"
#include <cmath>
#include <stdio.h>
using srslte::logmap;
namespace asn1 {
/************************
logging
************************/
void vlog_print(srslte::LOG_LEVEL_ENUM log_level, const char* format, va_list args)
{
char* args_msg = nullptr;
if (vasprintf(&args_msg, format, args) > 0) {
switch (log_level) {
case srslte::LOG_LEVEL_ERROR:
srslte::logmap::get("ASN1")->error("%s", args_msg);
break;
case srslte::LOG_LEVEL_WARNING:
srslte::logmap::get("ASN1")->warning("%s", args_msg);
break;
case srslte::LOG_LEVEL_INFO:
srslte::logmap::get("ASN1")->info("%s", args_msg);
break;
case srslte::LOG_LEVEL_DEBUG:
srslte::logmap::get("ASN1")->debug("%s", args_msg);
default:
break;
}
}
if (args_msg) {
free(args_msg);
}
}
void log_error(const char* format, ...)
{
va_list args;
va_start(args, format);
vlog_print(srslte::LOG_LEVEL_ERROR, format, args);
va_end(args);
}
void log_warning(const char* format, ...)
{
va_list args;
va_start(args, format);
vlog_print(srslte::LOG_LEVEL_WARNING, format, args);
va_end(args);
}
void log_info(const char* format, ...)
{
va_list args;
va_start(args, format);
vlog_print(srslte::LOG_LEVEL_INFO, format, args);
va_end(args);
}
void log_debug(const char* format, ...)
{
va_list args;
va_start(args, format);
vlog_print(srslte::LOG_LEVEL_DEBUG, format, args);
va_end(args);
}
/************************
error handling
************************/
@ -35,13 +92,13 @@ void log_error_code(SRSASN_CODE code, const char* filename, int line)
{
switch (code) {
case SRSASN_ERROR_ENCODE_FAIL:
logmap::get("ASN1")->error("[%s][%d] Encoding failure.\n", filename, line);
log_error("[%s][%d] Encoding failure.\n", filename, line);
break;
case SRSASN_ERROR_DECODE_FAIL:
logmap::get("ASN1")->error("[%s][%d] Decoding failure.\n", filename, line);
log_error("[%s][%d] Decoding failure.\n", filename, line);
break;
default:
logmap::get("ASN1")->warning("[%s][%d] SRSASN_CODE=%d not recognized.\n", filename, line, (int)code);
log_warning("[%s][%d] SRSASN_CODE=%d not recognized.\n", filename, line, (int)code);
}
}
@ -78,13 +135,13 @@ int bit_ref_impl<Ptr>::distance_bytes() const
SRSASN_CODE bit_ref::pack(uint32_t val, uint32_t n_bits)
{
if (n_bits >= 32) {
logmap::get("ASN1")->error("This method only supports packing up to 32 bits\n");
log_error("This method only supports packing up to 32 bits\n");
return SRSASN_ERROR_ENCODE_FAIL;
}
uint32_t mask;
while (n_bits > 0) {
if (ptr >= max_ptr) {
logmap::get("ASN1")->error("Buffer size limit was achieved\n");
log_error("Buffer size limit was achieved\n");
return SRSASN_ERROR_ENCODE_FAIL;
}
mask = ((1u << n_bits) - 1u);
@ -110,13 +167,13 @@ template <typename T, typename Ptr>
SRSASN_CODE unpack_bits(T& val, Ptr& ptr, uint8_t& offset, const uint8_t* max_ptr, uint32_t n_bits)
{
if (n_bits > sizeof(T) * 8) {
logmap::get("ASN1")->error("This method only supports unpacking up to %d bits\n", (int)sizeof(T) * 8);
log_error("This method only supports unpacking up to %d bits\n", (int)sizeof(T) * 8);
return SRSASN_ERROR_DECODE_FAIL;
}
val = 0;
while (n_bits > 0) {
if (ptr >= max_ptr) {
logmap::get("ASN1")->error("Buffer size limit was achieved\n");
log_error("Buffer size limit was achieved\n");
return SRSASN_ERROR_DECODE_FAIL;
}
if ((uint32_t)(8 - offset) > n_bits) {
@ -178,7 +235,7 @@ SRSASN_CODE bit_ref_impl<Ptr>::unpack_bytes(uint8_t* buf, uint32_t n_bytes)
return SRSASN_SUCCESS;
}
if (ptr + n_bytes >= max_ptr) {
logmap::get("ASN1")->error("Buffer size limit was achieved\n");
log_error("Buffer size limit was achieved\n");
return SRSASN_ERROR_DECODE_FAIL;
}
if (offset == 0) {
@ -199,7 +256,7 @@ SRSASN_CODE bit_ref_impl<Ptr>::align_bytes()
if (offset == 0)
return SRSASN_SUCCESS;
if (ptr >= max_ptr) {
logmap::get("ASN1")->error("Buffer size limit was achieved\n");
log_error("Buffer size limit was achieved\n");
return SRSASN_ERROR_DECODE_FAIL;
}
offset = 0;
@ -215,7 +272,7 @@ SRSASN_CODE bit_ref_impl<Ptr>::advance_bits(uint32_t n_bits)
uint32_t bytes_offset = floorf((offset + n_bits) / 8.0f);
if (ptr + bytes_required >= max_ptr) {
logmap::get("ASN1")->error("Buffer size limit was achieved\n");
log_error("Buffer size limit was achieved\n");
return SRSASN_ERROR_DECODE_FAIL;
}
ptr += bytes_offset;
@ -241,7 +298,7 @@ SRSASN_CODE bit_ref::pack_bytes(const uint8_t* buf, uint32_t n_bytes)
return SRSASN_SUCCESS;
}
if (ptr + n_bytes >= max_ptr) {
logmap::get("ASN1")->error("Buffer size limit was achieved\n");
log_error("Buffer size limit was achieved\n");
return SRSASN_ERROR_ENCODE_FAIL;
}
if (offset == 0) {
@ -261,7 +318,7 @@ SRSASN_CODE bit_ref::align_bytes_zero()
if (offset == 0)
return SRSASN_SUCCESS;
if (ptr >= max_ptr) {
logmap::get("ASN1")->error("Buffer size limit was achieved\n");
log_error("Buffer size limit was achieved\n");
return SRSASN_ERROR_ENCODE_FAIL;
}
uint8_t mask = (uint8_t)(256u - (1u << (8u - offset)));
@ -279,7 +336,7 @@ SRSASN_CODE pack_unsupported_ext_flag(bit_ref& bref, bool ext)
{
HANDLE_CODE(bref.pack(ext, 1));
if (ext) {
logmap::get("ASN1")->error("asn1 error: ASN extensions not currently supported\n");
log_error("asn1 error: ASN extensions not currently supported\n");
return SRSASN_ERROR_ENCODE_FAIL;
}
return SRSASN_SUCCESS;
@ -289,7 +346,7 @@ SRSASN_CODE unpack_unsupported_ext_flag(bool& ext, bit_ref& bref)
{
SRSASN_CODE ret = bref.unpack(ext, 1);
if (ext) {
logmap::get("ASN1")->error("asn1 error: ASN extensions not currently supported\n");
log_error("asn1 error: ASN extensions not currently supported\n");
return SRSASN_ERROR_DECODE_FAIL;
}
return ret;
@ -322,7 +379,7 @@ SRSASN_CODE pack_enum(bit_ref& bref, uint32_t enum_val, uint32_t nbits, uint32_t
SRSASN_CODE pack_enum(bit_ref& bref, uint32_t e, uint32_t nof_types, uint32_t nof_exts, bool has_ext)
{
if (e >= nof_types) {
logmap::get("ASN1")->error(
log_error(
"The provided enum is not within the range of possible values (%u>=%u)\n", (unsigned)e, (unsigned)nof_types);
return SRSASN_ERROR_ENCODE_FAIL;
}
@ -358,9 +415,9 @@ ValOrError unpack_enum(uint32_t nof_types, uint32_t nof_exts, bool has_ext, cbit
ret.code = bref.unpack(ret.val, nof_bits);
}
if (ret.val >= nof_types) {
logmap::get("ASN1")->error("The provided enum is not within the range of possible values (%u>=%u)\n",
(unsigned)ret.val,
(unsigned)nof_types);
log_error("The provided enum is not within the range of possible values (%u>=%u)\n",
(unsigned)ret.val,
(unsigned)nof_types);
ret.code = SRSASN_ERROR_DECODE_FAIL;
}
return ret;
@ -384,8 +441,7 @@ template <class IntType>
SRSASN_CODE pack_constrained_whole_number(bit_ref& bref, IntType n, IntType lb, IntType ub, bool aligned)
{
if (ub < lb or n < lb or n > ub) {
logmap::get("ASN1")->error(
"The condition lb <= n <= ub (%ld <= %ld <= %ld) was not met\n", (long)lb, (long)n, (long)ub);
log_error("The condition lb <= n <= ub (%ld <= %ld <= %ld) was not met\n", (long)lb, (long)n, (long)ub);
return SRSASN_ERROR_ENCODE_FAIL;
}
uint64_t ra = (uint64_t)(ub - lb) + 1; // NOTE: Can overflow if IntType is kept
@ -453,7 +509,7 @@ template <class IntType>
SRSASN_CODE unpack_constrained_whole_number(IntType& n, cbit_ref& bref, IntType lb, IntType ub, bool aligned)
{
if (ub < lb) {
logmap::get("ASN1")->error("The condition lb <= ub (%ld <= %ld) was not met\n", (long)lb, (long)ub);
log_error("The condition lb <= ub (%ld <= %ld) was not met\n", (long)lb, (long)ub);
return SRSASN_ERROR_DECODE_FAIL;
}
uint64_t ra = (uint64_t)(ub - lb) + 1; // NOTE: Can overflow if IntType is kept.
@ -467,8 +523,7 @@ SRSASN_CODE unpack_constrained_whole_number(IntType& n, cbit_ref& bref, IntType
HANDLE_CODE(bref.unpack(n, n_bits));
n += lb;
if (n > ub) {
logmap::get("ASN1")->error(
"The condition lb <= n <= ub (%ld <= %ld <= %ld) was not met\n", (long)lb, (long)n, (long)ub);
log_error("The condition lb <= n <= ub (%ld <= %ld <= %ld) was not met\n", (long)lb, (long)n, (long)ub);
return SRSASN_ERROR_DECODE_FAIL;
}
} else {
@ -525,7 +580,7 @@ SRSASN_CODE pack_norm_small_non_neg_whole_number(bit_ref& bref, UintType n)
HANDLE_CODE(bref.pack(n, 7)); // [1 bit: 0 | 6 bit: n]
} else {
HANDLE_CODE(bref.pack(1, 1));
logmap::get("ASN1")->error("Long small integers not supported\n");
log_error("Long small integers not supported\n");
return SRSASN_ERROR_ENCODE_FAIL;
}
return SRSASN_SUCCESS;
@ -539,7 +594,7 @@ SRSASN_CODE unpack_norm_small_non_neg_whole_number(UintType& n, cbit_ref& bref)
if (not ext) {
ret = bref.unpack(n, 6);
} else {
logmap::get("ASN1")->error("Long small integers not supported\n");
log_error("Long small integers not supported\n");
return SRSASN_ERROR_DECODE_FAIL;
}
return ret;
@ -658,7 +713,7 @@ SRSASN_CODE pack_length(bit_ref& bref, uint32_t val, bool aligned)
HANDLE_CODE(bref.pack(0b10, 2));
HANDLE_CODE(bref.pack(val, 14));
} else {
logmap::get("ASN1")->error("Not handling sizes longer than 16383 octets\n");
log_error("Not handling sizes longer than 16383 octets\n");
return SRSASN_ERROR_ENCODE_FAIL;
}
} else {
@ -697,7 +752,7 @@ SRSASN_CODE unpack_length(uint32_t& val, cbit_ref& bref, bool aligned)
if (not ext) {
ret = bref.unpack(val, 14);
} else {
logmap::get("ASN1")->error("Not handling octet strings longer than 16383 octets\n");
log_error("Not handling octet strings longer than 16383 octets\n");
val = 0;
return SRSASN_ERROR_DECODE_FAIL;
}
@ -737,8 +792,7 @@ SRSASN_CODE pack_integer(bit_ref& bref, IntType n, IntType lb, IntType ub, bool
if (has_ext) {
HANDLE_CODE(bref.pack(not within_bounds, 1));
} else if (not within_bounds) {
logmap::get("ASN1")->error(
"The condition lb <= n <= ub (%ld <= %ld <= %ld) was not met\n", (long)lb, (long)n, (long)ub);
log_error("The condition lb <= n <= ub (%ld <= %ld <= %ld) was not met\n", (long)lb, (long)n, (long)ub);
return SRSASN_ERROR_ENCODE_FAIL;
}
bool lower_bounded = lb != std::numeric_limits<IntType>::min() or lb == 0;
@ -888,7 +942,7 @@ template struct integer_packer<uint64_t>;
uint64_t octstring_to_number(const uint8_t* ptr, uint32_t nbytes)
{
if (nbytes > 8) {
logmap::get("ASN1")->error("octstring of size=%d does not fit in an uint64_t\n", nbytes);
log_error("octstring of size=%d does not fit in an uint64_t\n", nbytes);
return 0;
}
uint64_t val = 0;
@ -901,7 +955,7 @@ uint64_t octstring_to_number(const uint8_t* ptr, uint32_t nbytes)
void number_to_octstring(uint8_t* ptr, uint64_t number, uint32_t nbytes)
{
if (nbytes > 8) {
logmap::get("ASN1")->error("octstring of size=%d does not fit in an uint64_t\n", nbytes);
log_error("octstring of size=%d does not fit in an uint64_t\n", nbytes);
return;
}
for (uint32_t i = 0; i < nbytes; ++i) {
@ -930,7 +984,7 @@ std::string octstring_to_string(const uint8_t* ptr, uint32_t N)
void string_to_octstring(uint8_t* ptr, const std::string& str)
{
if (str.size() % 2 != 0) {
logmap::get("ASN1")->warning("The provided hex string size=%zd is not a multiple of 2\n.", str.size());
log_warning("The provided hex string size=%zd is not a multiple of 2\n.", str.size());
}
char cstr[] = "\0\0\0";
for (uint32_t i = 0; i < str.size(); i += 2) {
@ -999,12 +1053,12 @@ SRSASN_CODE pack_length_prefix(bit_ref& bref,
bool is_aligned = false)
{
if (has_ext and ub == std::numeric_limits<uint32_t>::max()) {
logmap::get("ASN1")->error("has extension marker but it is an unbounded prefix size\n");
log_error("has extension marker but it is an unbounded prefix size\n");
return SRSASN_ERROR_ENCODE_FAIL;
}
bool within_bounds = len >= lb and len <= ub;
if (not within_bounds and not has_ext) {
logmap::get("ASN1")->error("bitstring length=%d is not within bounds [%d, %d]\n", len, lb, ub);
log_error("bitstring length=%d is not within bounds [%d, %d]\n", len, lb, ub);
return SRSASN_ERROR_ENCODE_FAIL;
}
@ -1035,7 +1089,7 @@ SRSASN_CODE pack_length_prefix(bit_ref& bref,
SRSASN_CODE pack_bitfield(bit_ref& bref, const uint8_t* buf, uint32_t nbits, uint32_t lb, uint32_t ub, bool is_aligned)
{
if (nbits == 0) {
logmap::get("ASN1")->error("Invalid bitstring size=%d\n", nbits);
log_error("Invalid bitstring size=%d\n", nbits);
return SRSASN_ERROR_ENCODE_FAIL;
}
if (is_aligned and (lb != ub or ub > 16)) {
@ -1098,7 +1152,7 @@ SRSASN_CODE unpack_length_prefix(uint32_t& len, cbit_ref& bref, uint32_t lb, uin
SRSASN_CODE unpack_bitfield(uint8_t* buf, cbit_ref& bref, uint32_t n, uint32_t lb, uint32_t ub, bool is_aligned)
{
if (n > ASN_64K) {
logmap::get("ASN1")->error("bitstrings longer than 64K not supported\n");
log_error("bitstrings longer than 64K not supported\n");
return SRSASN_ERROR_DECODE_FAIL;
}
if (n == 0) {
@ -1121,7 +1175,7 @@ SRSASN_CODE unpack_bitfield(uint8_t* buf, cbit_ref& bref, uint32_t n, uint32_t l
void from_number(uint8_t* ptr, uint64_t number, uint32_t nbits)
{
if (nbits > 64) {
logmap::get("ASN1")->error("bitstring of size=%d does not fit in an uint64_t\n", nbits);
log_error("bitstring of size=%d does not fit in an uint64_t\n", nbits);
return;
}
uint32_t nof_bytes = (uint32_t)ceilf(nbits / 8.0f);
@ -1146,7 +1200,7 @@ std::string to_string(const uint8_t* ptr, uint32_t nbits)
uint64_t to_number(const uint8_t* ptr, uint32_t nbits)
{
if (nbits > 64) {
logmap::get("ASN1")->error("bitstring of size=%d does not fit in an uint64_t\n", nbits);
log_error("bitstring of size=%d does not fit in an uint64_t\n", nbits);
return 0;
}
uint64_t val = 0;
@ -1164,11 +1218,11 @@ uint64_t to_number(const uint8_t* ptr, uint32_t nbits)
*********************/
void log_invalid_access_choice_id(uint32_t val, uint32_t choice_id)
{
logmap::get("ASN1")->error("The access choide id is invalid (%zd!=%zd)\n", (size_t)val, (size_t)choice_id);
log_error("The access choide id is invalid (%zd!=%zd)\n", (size_t)val, (size_t)choice_id);
}
void log_invalid_choice_id(uint32_t val, const char* choice_type)
{
logmap::get("ASN1")->error("Invalid choice id=%zd for choice type %s\n", (size_t)val, choice_type);
log_error("Invalid choice id=%zd for choice type %s\n", (size_t)val, choice_type);
}
/*********************
@ -1205,8 +1259,7 @@ pack(bit_ref& bref, const std::string& s, size_t lb, size_t ub, size_t alb, size
if (not within_limits) {
// TODO: print error
// NOTE: This should be valid for exts
logmap::get("ASN1")->error(
"The PrintableString size=%zd is not within the limits [%zd, %zd]\n", s.size(), alb, aub);
log_error("The PrintableString size=%zd is not within the limits [%zd, %zd]\n", s.size(), alb, aub);
return SRSASN_ERROR_ENCODE_FAIL;
}
size_t b = asn_string_utils::get_nof_bits_per_char(lb, ub, aligned);
@ -1243,7 +1296,7 @@ SRSASN_CODE unpack(std::string& s, cbit_ref& bref, size_t lb, size_t ub, size_t
bool is_ext;
HANDLE_CODE(bref.unpack(is_ext, 1));
if (is_ext) {
logmap::get("ASN1")->error("Extension of PrintableString not supported\n");
log_error("Extension of PrintableString not supported\n");
return SRSASN_ERROR_DECODE_FAIL;
}
}
@ -1366,9 +1419,9 @@ varlength_field_pack_guard::~varlength_field_pack_guard()
// check how many bytes were written in total
uint32_t nof_bytes = bref_tracker->distance(bref0) / (uint32_t)8;
if (nof_bytes > sizeof(buffer)) {
logmap::get("ASN1")->error("The packed variable sized field is too long for the reserved buffer (%zd > %zd)\n",
(size_t)nof_bytes,
sizeof(buffer));
log_error("The packed variable sized field is too long for the reserved buffer (%zd > %zd)\n",
(size_t)nof_bytes,
sizeof(buffer));
}
// go back in time to pack length

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,6 @@
using namespace asn1;
using namespace asn1::rrc;
using srslte::logmap;
/*******************************************************************************
* Logging Utilities
@ -32,7 +31,7 @@ using srslte::logmap;
void asn1::rrc::log_invalid_access_choice_id(uint32_t val, uint32_t choice_id)
{
logmap::get("ASN1::RRC")->error("The access choice id is invalid (%d!=%d)\n", val, choice_id);
asn1::log_error("The access choice id is invalid (%d!=%d)\n", val, choice_id);
}
void asn1::rrc::assert_choice_type(uint32_t val, uint32_t choice_id)
@ -47,11 +46,10 @@ void asn1::rrc::assert_choice_type(const std::string& access_type,
const std::string& choice_type)
{
if (access_type != current_type) {
logmap::get("ASN1::RRC")
->error("Invalid field access for choice type \"%s\" (\"%s\"!=\"%s\")\n",
choice_type.c_str(),
access_type.c_str(),
current_type.c_str());
asn1::log_error("Invalid field access for choice type \"%s\" (\"%s\"!=\"%s\")\n",
choice_type.c_str(),
access_type.c_str(),
current_type.c_str());
}
}
@ -60,9 +58,9 @@ asn1::rrc::convert_enum_idx(const char* array[], uint32_t nof_types, uint32_t en
{
if (enum_val >= nof_types) {
if (enum_val == nof_types) {
logmap::get("ASN1::RRC")->error("The enum of type %s was not initialized.\n", enum_type);
asn1::log_error("The enum of type %s was not initialized.\n", enum_type);
} else {
logmap::get("ASN1::RRC")->error("The enum value=%d of type %s is not valid.\n", enum_val, enum_type);
asn1::log_error("The enum value=%d of type %s is not valid.\n", enum_val, enum_type);
}
return "";
}
@ -74,10 +72,9 @@ ItemType asn1::rrc::map_enum_number(ItemType* array, uint32_t nof_types, uint32_
{
if (enum_val >= nof_types) {
if (enum_val == nof_types) {
logmap::get("ASN1::RRC")->error("The enum of type %s is not initialized.\n", enum_type);
asn1::log_error("The enum of type %s is not initialized.\n", enum_type);
} else {
logmap::get("ASN1::RRC")
->error("The enum value=%d of type %s cannot be converted to a number.\n", enum_val, enum_type);
asn1::log_error("The enum value=%d of type %s cannot be converted to a number.\n", enum_val, enum_type);
}
return 0;
}
@ -123,12 +120,12 @@ template const float asn1::rrc::map_enum_number<const float>(const float* arr
void rrc_asn1_warn_assert(bool cond, const char* filename, int lineno)
{
if (cond) {
logmap::get("ASN1::RRC")->warning("Assertion in [%s][%d] failed.\n", filename, lineno);
asn1::log_warning("Assertion in [%s][%d] failed.\n", filename, lineno);
}
}
static void log_invalid_choice_id(uint32_t val, const char* choice_type)
{
logmap::get("ASN1::RRC")->error("Invalid choice id=%d for choice type %s\n", val, choice_type);
asn1::log_error("Invalid choice id=%d for choice type %s\n", val, choice_type);
}
/*******************************************************************************

View File

@ -24,7 +24,6 @@
using namespace asn1;
using namespace asn1::rrc;
using srslte::logmap;
/*******************************************************************************
* Logging Utilities
@ -32,8 +31,7 @@ using srslte::logmap;
static void invalid_enum_number(int value, const char* name)
{
logmap::get("ASN1::RRC")
->error("The provided enum value=%d of type %s cannot be translated into a number\n", value, name);
asn1::log_error("The provided enum value=%d of type %s cannot be translated into a number\n", value, name);
}
/*******************************************************************************

View File

@ -24,7 +24,6 @@
using namespace asn1;
using namespace asn1::rrc_nr;
using srslte::logmap;
/*******************************************************************************
* Logging Utilities
@ -32,7 +31,7 @@ using srslte::logmap;
void asn1::rrc_nr::log_invalid_access_choice_id(uint32_t val, uint32_t choice_id)
{
logmap::get("ASN1::RRC_NR")->error("The access choice id is invalid (%d!=%d)\n", val, choice_id);
asn1::log_error("The access choice id is invalid (%d!=%d)\n", val, choice_id);
}
void asn1::rrc_nr::assert_choice_type(uint32_t val, uint32_t choice_id)
@ -47,11 +46,10 @@ void asn1::rrc_nr::assert_choice_type(const std::string& access_type,
const std::string& choice_type)
{
if (access_type != current_type) {
logmap::get("ASN1::RRC_NR")
->error("Invalid field access for choice type \"%s\" (\"%s\"!=\"%s\")\n",
choice_type.c_str(),
access_type.c_str(),
current_type.c_str());
asn1::log_error("Invalid field access for choice type \"%s\" (\"%s\"!=\"%s\")\n",
choice_type.c_str(),
access_type.c_str(),
current_type.c_str());
}
}
@ -60,9 +58,9 @@ asn1::rrc_nr::convert_enum_idx(const char* array[], uint32_t nof_types, uint32_t
{
if (enum_val >= nof_types) {
if (enum_val == nof_types) {
logmap::get("ASN1::RRC_NR")->error("The enum of type %s was not initialized.\n", enum_type);
asn1::log_error("The enum of type %s was not initialized.\n", enum_type);
} else {
logmap::get("ASN1::RRC_NR")->error("The enum value=%d of type %s is not valid.\n", enum_val, enum_type);
asn1::log_error("The enum value=%d of type %s is not valid.\n", enum_val, enum_type);
}
return "";
}
@ -74,10 +72,9 @@ ItemType asn1::rrc_nr::map_enum_number(ItemType* array, uint32_t nof_types, uint
{
if (enum_val >= nof_types) {
if (enum_val == nof_types) {
logmap::get("ASN1::RRC_NR")->error("The enum of type %s is not initialized.\n", enum_type);
asn1::log_error("The enum of type %s is not initialized.\n", enum_type);
} else {
logmap::get("ASN1::RRC_NR")
->error("The enum value=%d of type %s cannot be converted to a number.\n", enum_val, enum_type);
asn1::log_error("The enum value=%d of type %s cannot be converted to a number.\n", enum_val, enum_type);
}
return 0;
}
@ -123,18 +120,17 @@ template const float asn1::rrc_nr::map_enum_number<const float>(const float*
void rrc_nr_asn1_warn_assert(bool cond, const char* filename, int lineno)
{
if (cond) {
logmap::get("ASN1::RRC_NR")->warning("Assertion in [%s][%d] failed.\n", filename, lineno);
asn1::log_warning("Assertion in [%s][%d] failed.\n", filename, lineno);
}
}
static void log_invalid_choice_id(uint32_t val, const char* choice_type)
{
logmap::get("ASN1::RRC_NR")->error("Invalid choice id=%d for choice type %s\n", val, choice_type);
asn1::log_error("Invalid choice id=%d for choice type %s\n", val, choice_type);
}
static void invalid_enum_number(int value, const char* name)
{
logmap::get("ASN1::RRC_NR")
->error("The provided enum value=%d of type %s cannot be translated into a number\n", value, name);
asn1::log_error("The provided enum value=%d of type %s cannot be translated into a number\n", value, name);
}
/*******************************************************************************

File diff suppressed because it is too large Load Diff

View File

@ -125,7 +125,7 @@ int test_proc_id_consistency()
TESTASSERT(is_same_type<ho_fail_s>(unsuc.value.ho_fail()));
// e-RABSetup (No Unsuccessful Outcome)
{
srslte::scoped_log<srslte::nullsink_log> sink("ASN1::S1AP");
srslte::scoped_log<srslte::nullsink_log> sink("ASN1");
TESTASSERT(not unsuc.load_info_obj(ASN1_S1AP_ID_ERAB_SETUP));
TESTASSERT(sink->error_counter == 1);
}