Commit 65dadfb3 authored by Melissa's avatar Melissa Committed by Melissa Elkadi

Merge branch 'episys/master-nsa-nfapi-errors' into 'episys/master-nsa'

nfapi.c: Add on_error()

See merge request aburger/openairinterface5g!96
parent a1dee602
......@@ -46,11 +46,26 @@
#include <unistd.h>
#include <errno.h>
#include <pthread.h>
#include <execinfo.h>
#include <nfapi_interface.h>
#include <nfapi.h>
#include <debug.h>
// What to do when an error happens (e.g., a push or pull fails)
static inline void on_error()
{
// show the call stack
int fd = STDERR_FILENO;
static const char msg[] = "---stack trace---\n";
__attribute__((unused)) int r =
write(fd, msg, sizeof(msg) - 1);
void *buffer[100];
int nptrs = backtrace(buffer, sizeof(buffer) / sizeof(buffer[0]));
backtrace_symbols_fd(buffer, nptrs, fd);
//abort();
}
// Fundamental routines
......@@ -63,6 +78,7 @@ uint8_t push8(uint8_t in, uint8_t **out, uint8_t *end) {
return 1;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -76,6 +92,7 @@ uint8_t pushs8(int8_t in, uint8_t **out, uint8_t *end) {
return 1;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -90,6 +107,7 @@ uint8_t push16(uint16_t in, uint8_t **out, uint8_t *end) {
return 2;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -104,6 +122,7 @@ uint8_t pushs16(int16_t in, uint8_t **out, uint8_t *end) {
return 2;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -120,6 +139,7 @@ uint8_t push32(uint32_t in, uint8_t **out, uint8_t *end) {
return 4;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -136,6 +156,7 @@ uint8_t pushs32(int32_t in, uint8_t **out, uint8_t *end) {
return 4;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -149,6 +170,7 @@ uint8_t pull8(uint8_t **in, uint8_t *out, uint8_t *end) {
return 1;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -162,6 +184,7 @@ uint8_t pulls8(uint8_t **in, int8_t *out, uint8_t *end) {
return 1;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -175,6 +198,7 @@ uint8_t pull16(uint8_t **in, uint16_t *out, uint8_t *end) {
return 2;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -188,6 +212,7 @@ uint8_t pulls16(uint8_t **in, int16_t *out, uint8_t *end) {
return 2;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -201,6 +226,7 @@ uint8_t pull32(uint8_t **in, uint32_t *out, uint8_t *end) {
return 4;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -214,6 +240,7 @@ uint8_t pulls32(uint8_t **in, int32_t *out, uint8_t *end) {
return 4;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -230,6 +257,7 @@ uint32_t pullarray16(uint8_t **in, uint16_t out[], uint32_t max_len, uint32_t le
if(len > max_len) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
on_error();
return 0;
}
......@@ -244,6 +272,7 @@ uint32_t pullarray16(uint8_t **in, uint16_t out[], uint32_t max_len, uint32_t le
return sizeof(uint16_t) * len;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -254,6 +283,7 @@ uint32_t pullarrays16(uint8_t **in, int16_t out[], uint32_t max_len, uint32_t le
if(len > max_len) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
on_error();
return 0;
}
......@@ -268,6 +298,7 @@ uint32_t pullarrays16(uint8_t **in, int16_t out[], uint32_t max_len, uint32_t le
return sizeof(uint16_t) * len;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -277,6 +308,7 @@ uint32_t pusharray16(uint16_t in[], uint32_t max_len, uint32_t len, uint8_t **ou
if(len > max_len) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
on_error();
return 0;
}
......@@ -291,6 +323,7 @@ uint32_t pusharray16(uint16_t in[], uint32_t max_len, uint32_t len, uint8_t **ou
return sizeof(uint16_t) * len;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -300,6 +333,7 @@ uint32_t pusharrays16(int16_t in[], uint32_t max_len, uint32_t len, uint8_t **ou
if(len > max_len) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
on_error();
return 0;
}
......@@ -307,12 +341,14 @@ uint32_t pusharrays16(int16_t in[], uint32_t max_len, uint32_t len, uint8_t **ou
uint32_t idx;
for(idx = 0; idx < len; ++idx) {
pushs16(in[idx], out, end);
if (!pushs16(in[idx], out, end))
return 0;
}
return sizeof(uint16_t) * len;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -322,6 +358,7 @@ uint32_t pullarray32(uint8_t **in, uint32_t out[], uint32_t max_len, uint32_t le
if(len > max_len) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
on_error();
return 0;
}
......@@ -336,6 +373,7 @@ uint32_t pullarray32(uint8_t **in, uint32_t out[], uint32_t max_len, uint32_t le
return sizeof(uint32_t) * len;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -346,6 +384,7 @@ uint32_t pullarrays32(uint8_t **in, int32_t out[], uint32_t max_len, uint32_t le
if(len > max_len) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
on_error();
return 0;
}
......@@ -360,6 +399,7 @@ uint32_t pullarrays32(uint8_t **in, int32_t out[], uint32_t max_len, uint32_t le
return sizeof(uint32_t) * len;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -369,6 +409,7 @@ uint32_t pusharray32(uint32_t in[], uint32_t max_len, uint32_t len, uint8_t **ou
if(len > max_len) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
on_error();
return 0;
}
......@@ -383,6 +424,7 @@ uint32_t pusharray32(uint32_t in[], uint32_t max_len, uint32_t len, uint8_t **ou
return sizeof(uint32_t) * len;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -392,6 +434,7 @@ uint32_t pusharrays32(int32_t in[], uint32_t max_len, uint32_t len, uint8_t **ou
if(len > max_len) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
on_error();
return 0;
}
......@@ -399,12 +442,14 @@ uint32_t pusharrays32(int32_t in[], uint32_t max_len, uint32_t len, uint8_t **ou
uint32_t idx;
for(idx = 0; idx < len; ++idx) {
pushs32(in[idx], out, end);
if (!pushs32(in[idx], out, end))
return 0;
}
return sizeof(uint32_t) * len;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -414,6 +459,7 @@ uint32_t pullarray8(uint8_t **in, uint8_t out[], uint32_t max_len, uint32_t len,
if(len > max_len) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
on_error();
return 0;
}
......@@ -423,6 +469,7 @@ uint32_t pullarray8(uint8_t **in, uint8_t out[], uint32_t max_len, uint32_t len,
return sizeof(uint8_t) * len;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -433,6 +480,7 @@ uint32_t pusharray8(uint8_t in[], uint32_t max_len, uint32_t len, uint8_t **out,
if(len > max_len) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
on_error();
return 0;
}
......@@ -442,6 +490,7 @@ uint32_t pusharray8(uint8_t in[], uint32_t max_len, uint32_t len, uint8_t **out,
return sizeof(uint8_t) * len;
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
on_error();
return 0;
}
}
......@@ -449,6 +498,7 @@ uint32_t pusharray8(uint8_t in[], uint32_t max_len, uint32_t len, uint8_t **out,
uint8_t packarray(void *array, uint16_t array_element_size, uint16_t max_count, uint16_t count, uint8_t **ppwritepackedmsg, uint8_t *end, pack_array_elem_fn fn) {
if(count > max_count) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, count, max_count);
on_error();
return 0;
}
......@@ -467,6 +517,7 @@ uint8_t packarray(void *array, uint16_t array_element_size, uint16_t max_count,
uint8_t unpackarray(uint8_t **ppReadPackedMsg, void *array, uint16_t array_element_size, uint16_t max_count, uint16_t count, uint8_t *end, unpack_array_elem_fn fn) {
if(count > max_count) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, count, max_count);
on_error();
return 0;
}
......@@ -586,6 +637,7 @@ int unpack_tlv_list(unpack_tlv_t unpack_fns[], uint16_t size, uint8_t **ppReadPa
// check if the length was right;
if(tl->length != (*ppReadPackedMsg - pStartOfValue)) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Warning tlv tag 0x%x length %d not equal to unpack %ld\n", tl->tag, tl->length, (*ppReadPackedMsg - pStartOfValue));
on_error();
}
}
}
......@@ -600,9 +652,11 @@ int unpack_tlv_list(unpack_tlv_t unpack_fns[], uint16_t size, uint8_t **ppReadPa
return 0;
} else if(result < 0) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unknown VE TAG value: 0x%04x\n", generic_tl.tag);
on_error();
if (++numBadTags > MAX_BAD_TAG) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Supplied message has had too many bad tags\n");
on_error();
return 0;
}
......@@ -616,9 +670,11 @@ int unpack_tlv_list(unpack_tlv_t unpack_fns[], uint16_t size, uint8_t **ppReadPa
}
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unknown TAG value: 0x%04x\n", generic_tl.tag);
on_error();
if (++numBadTags > MAX_BAD_TAG) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Supplied message has had too many bad tags\n");
on_error();
return 0;
}
......@@ -663,6 +719,7 @@ int unpack_p7_tlv_list(unpack_p7_tlv_t unpack_fns[], uint16_t size, uint8_t **pp
// check if the length was right;
if(tl->length != (*ppReadPackedMsg - pStartOfValue)) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Warning tlv tag 0x%x length %d not equal to unpack %ld\n", tl->tag, tl->length, (*ppReadPackedMsg - pStartOfValue));
on_error();
}
}
}
......@@ -677,9 +734,11 @@ int unpack_p7_tlv_list(unpack_p7_tlv_t unpack_fns[], uint16_t size, uint8_t **pp
return 0;
} else if(result < 0) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unknown TAG value: 0x%04x\n", generic_tl.tag);
on_error();
if (++numBadTags > MAX_BAD_TAG) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Supplied message has had too many bad tags\n");
on_error();
return -1;
}
......@@ -693,9 +752,11 @@ int unpack_p7_tlv_list(unpack_p7_tlv_t unpack_fns[], uint16_t size, uint8_t **pp
}
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unknown TAG value: 0x%04x\n", generic_tl.tag);
on_error();
if (++numBadTags > MAX_BAD_TAG) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Supplied message has had too many bad tags\n");
on_error();
return -1;
}
......
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