csn1.cpp: Rework ProcessError() function to print errors
Same API is kept to more easily keep code compatibility with wireshark's packet-csn1.c implementation. Change-Id: I1ce2c52e2357841aa1f31babfdce9011435f866b
This commit is contained in:
parent
f960d5bcf4
commit
d636f74923
49
src/csn1.cpp
49
src/csn1.cpp
|
@ -37,6 +37,10 @@
|
||||||
#include "csn1.h"
|
#include "csn1.h"
|
||||||
#include <gprs_debug.h>
|
#include <gprs_debug.h>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <osmocom/core/logging.h>
|
||||||
|
#include <osmocom/core/utils.h>
|
||||||
|
}
|
||||||
|
|
||||||
#define pvDATA(_pv, _offset) ((void*) ((unsigned char*)_pv + _offset))
|
#define pvDATA(_pv, _offset) ((void*) ((unsigned char*)_pv + _offset))
|
||||||
#define pui8DATA(_pv, _offset) ((guint8*) pvDATA(_pv, _offset))
|
#define pui8DATA(_pv, _offset) ((guint8*) pvDATA(_pv, _offset))
|
||||||
|
@ -92,35 +96,34 @@ csnStreamInit(csnStream_t* ar, gint bit_offset, gint remaining_bits_len)
|
||||||
ar->direction = 0;
|
ar->direction = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* ErrCodes[] =
|
static const struct value_string csn1_error_names[] = {
|
||||||
{
|
{ CSN_OK, "General 0" },
|
||||||
"General 0",
|
{ CSN_ERROR_GENERAL, "General -1" },
|
||||||
"General -1",
|
{ CSN_ERROR_DATA_NOT_VALID, "DATA_NOT VALID" },
|
||||||
"DATA_NOT VALID",
|
{ CSN_ERROR_IN_SCRIPT, "IN SCRIPT" },
|
||||||
"IN SCRIPT",
|
{ CSN_ERROR_INVALID_UNION_INDEX, "INVALID UNION INDEX" },
|
||||||
"INVALID UNION INDEX",
|
{ CSN_ERROR_NEED_MORE_BITS_TO_UNPACK, "NEED_MORE BITS TO UNPACK" },
|
||||||
"NEED_MORE BITS TO UNPACK",
|
{ CSN_ERROR_NEED_MORE_BITS_TO_UNPACK, "ILLEGAL BIT VALUE" },
|
||||||
"ILLEGAL BIT VALUE",
|
{ CSN_ERROR_ILLEGAL_BIT_VALUE, "Internal" },
|
||||||
"Internal",
|
{ CSN_ERROR_STREAM_NOT_SUPPORTED, "STREAM_NOT_SUPPORTED" },
|
||||||
"STREAM_NOT_SUPPORTED",
|
{ CSN_ERROR_MESSAGE_TOO_LONG, "MESSAGE_TOO_LONG" },
|
||||||
"MESSAGE_TOO_LONG"
|
{ 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static gint16
|
|
||||||
ProcessError( unsigned readIndex, const char* sz, gint16 err, const CSN_DESCR* pDescr)
|
static gint16 ProcessError_impl(const char *file, int line, unsigned readIndex,
|
||||||
|
const char* sz, gint16 err, const CSN_DESCR* pDescr)
|
||||||
{
|
{
|
||||||
gint16 i = MIN(-err, ((gint16) ElementsOf(ErrCodes)-1));
|
if (err != CSN_OK)
|
||||||
if (i >= 0)
|
LOGPSRC(DCSN1, LOGL_ERROR, file, line, "%s: error %s (%d) at %s (idx %d)\n",
|
||||||
{
|
sz, get_value_string(csn1_error_names, err), err,
|
||||||
//LOG(ERR) << sz << "Error code: "<< ErrCodes[i] << pDescr?(pDescr->sz):"-";
|
pDescr ? pDescr->sz : "-", readIndex);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//LOG(ERR) << sz << ": " << pDescr?(pDescr->sz):"-";
|
|
||||||
}
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ProcessError(readIndex, sz, err, pDescr) \
|
||||||
|
ProcessError_impl(__FILE__, __LINE__, readIndex, sz, err, pDescr)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ================================================================================================
|
* ================================================================================================
|
||||||
|
|
Loading…
Reference in New Issue