This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/14478
Change subject: cbsp: Introduce osmo_cbsp_errstr
......................................................................
cbsp: Introduce osmo_cbsp_errstr
Rather than having the encoder/decoder library print some log
messages in case of encoding/decoding errors, let's provide something
akin to 'errno', but with a string instead of a numeric error code.
The 'osmo_cbsp_errstr' global variable (if set) contains a
human-readable string describing the most recent encoding/decoding error.
It exists separately for each thread and hence can be used safely in
multi-threaded environments.
Change-Id: Id9a5a595a76ba278647aee9470ded213d8464103
---
M include/osmocom/gsm/cbsp.h
M src/gsm/cbsp.c
M src/gsm/libosmogsm.map
3 files changed, 102 insertions(+), 28 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/78/14478/1
diff --git a/include/osmocom/gsm/cbsp.h b/include/osmocom/gsm/cbsp.h
index 7e5cc64..6be60eb 100644
--- a/include/osmocom/gsm/cbsp.h
+++ b/include/osmocom/gsm/cbsp.h
@@ -258,6 +258,8 @@
} u;
};
+extern const __thread char *osmo_cbsp_errstr;
+
struct msgb *osmo_cbsp_msgb_alloc(void *ctx, const char *name);
struct msgb *osmo_cbsp_encode(void *ctx, const struct osmo_cbsp_decoded *in);
struct osmo_cbsp_decoded *osmo_cbsp_decode(void *ctx, struct msgb *in);
diff --git a/src/gsm/cbsp.c b/src/gsm/cbsp.c
index f371500..0311f56 100644
--- a/src/gsm/cbsp.c
+++ b/src/gsm/cbsp.c
@@ -32,6 +32,8 @@
#include <osmocom/gsm/cbsp.h>
#include <osmocom/gsm/gsm0808_utils.h>
+const __thread char *osmo_cbsp_errstr;
+
struct msgb *osmo_cbsp_msgb_alloc(void *ctx, const char *name)
{
/* make the messages rather large as the cell lists can be long! */
@@ -133,6 +135,7 @@
return (secs-120)/10;
if (secs <= 60*60)
return (secs-600)/30;
+ osmo_cbsp_errstr = "warning period out of range";
return -1;
}
@@ -151,8 +154,10 @@
if (in->is_cbs) {
int num_of_pages = llist_count(&in->u.cbs.msg_content);
struct osmo_cbsp_content *ce;
- if (num_of_pages == 0 || num_of_pages > 15)
+ if (num_of_pages == 0 || num_of_pages > 15) {
+ osmo_cbsp_errstr = "invalid number of pages";
return -EINVAL;
+ }
msgb_tv_put(msg, CBSP_IEI_CHANNEL_IND, in->u.cbs.channel_ind);
msgb_tv_put(msg, CBSP_IEI_CATEGORY, in->u.cbs.category);
msgb_tv16_put(msg, CBSP_IEI_REP_PERIOD, in->u.cbs.rep_period);
@@ -383,6 +388,8 @@
unsigned int len;
int rc;
+ osmo_cbsp_errstr = NULL;
+
if (!msg)
return NULL;
@@ -450,9 +457,11 @@
case CBSP_MSGT_SET_DRX:
case CBSP_MSGT_SET_DRX_COMPL:
case CBSP_MSGT_SET_DRX_FAIL:
+ osmo_cbsp_errstr = "message type not implemented";
rc = -1;
break;
default:
+ osmo_cbsp_errstr = "message type not known in spec";
rc = -1;
break;
}
@@ -490,8 +499,10 @@
unsigned int len_remain = len - (cur - buf);
OSMO_ASSERT(ent);
rc = gsm0808_decode_cell_id_u(&ent->cell_id, cl->id_discr, cur, len_remain);
- if (rc < 0)
+ if (rc < 0) {
+ osmo_cbsp_errstr = "cell list: error decoding cell_id_union";
return rc;
+ }
cur += rc;
llist_add_tail(&ent->list, &cl->list);
}
@@ -511,8 +522,10 @@
OSMO_ASSERT(ent);
ent->id_discr = cur[0];
rc = gsm0808_decode_cell_id_u(&ent->cell_id, ent->id_discr, cur+1, len_remain-1);
- if (rc < 0)
+ if (rc < 0) {
+ osmo_cbsp_errstr = "fail list: error decoding cell_id_union";
return rc;
+ }
cur += rc;
ent->cause = *cur++;
llist_add_tail(&ent->list, fl);
@@ -533,11 +546,14 @@
unsigned int len_remain = len - (cur - buf);
OSMO_ASSERT(ent);
rc = gsm0808_decode_cell_id_u(&ent->cell_id, ll->id_discr, cur, len_remain);
- if (rc < 0)
+ if (rc < 0) {
+ osmo_cbsp_errstr = "load list: error decoding cell_id_union";
return rc;
+ }
cur += rc;
if (cur + 2 > buf + len) {
talloc_free(ent);
+ osmo_cbsp_errstr = "load list: truncated IE";
return -EINVAL;
}
ent->load[0] = *cur++;
@@ -560,11 +576,14 @@
unsigned int len_remain = len - (cur - buf);
OSMO_ASSERT(ent);
rc = gsm0808_decode_cell_id_u(&ent->cell_id, cl->id_discr, cur, len_remain);
- if (rc < 0)
+ if (rc < 0) {
+ osmo_cbsp_errstr = "completed list: error decoding cell_id_union";
return rc;
+ }
cur += rc;
if (cur + 3 > buf + len) {
talloc_free(ent);
+ osmo_cbsp_errstr = "completed list: truncated IE";
return -EINVAL;
}
ent->num_compl = osmo_load16be(cur); cur += 2;
@@ -607,8 +626,10 @@
/* check for mandatory IEs */
if (!TLVP_PRESENT(tp, CBSP_IEI_MSG_ID) ||
!TLVP_PRESENT(tp, CBSP_IEI_NEW_SERIAL_NR) ||
- !TLVP_PRESENT(tp, CBSP_IEI_CELL_LIST))
+ !TLVP_PRESENT(tp, CBSP_IEI_CELL_LIST)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
out->msg_id = tlvp_val16be(tp, CBSP_IEI_MSG_ID);
out->new_serial_nr = tlvp_val16be(tp, CBSP_IEI_NEW_SERIAL_NR);
@@ -624,14 +645,18 @@
if (TLVP_PRESENT(tp, CBSP_IEI_CHANNEL_IND)) {
uint8_t num_of_pages;
INIT_LLIST_HEAD(&out->u.cbs.msg_content);
- if (TLVP_PRESENT(tp, CBSP_IEI_EMERG_IND))
+ if (TLVP_PRESENT(tp, CBSP_IEI_EMERG_IND)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
if (!TLVP_PRESENT(tp, CBSP_IEI_CATEGORY) ||
!TLVP_PRESENT(tp, CBSP_IEI_REP_PERIOD) ||
!TLVP_PRESENT(tp, CBSP_IEI_NUM_BCAST_REQ) ||
!TLVP_PRESENT(tp, CBSP_IEI_NUM_OF_PAGES) ||
- !TLVP_PRESENT(tp, CBSP_IEI_DCS))
+ !TLVP_PRESENT(tp, CBSP_IEI_DCS)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
out->is_cbs = true;
out->u.cbs.channel_ind = *TLVP_VAL(tp, CBSP_IEI_CHANNEL_IND);
out->u.cbs.category = *TLVP_VAL(tp, CBSP_IEI_CATEGORY);
@@ -644,8 +669,10 @@
for (i = 0; i < num_of_pages; i++) {
const uint8_t *ie = TLVP_VAL(&tp[i], CBSP_IEI_MSG_CONTENT);
struct osmo_cbsp_content *page;
- if (!ie)
+ if (!ie) {
+ osmo_cbsp_errstr = "insufficient message content IEs";
return -EINVAL;
+ }
page = talloc_zero(ctx, struct osmo_cbsp_content);
OSMO_ASSERT(page);
page->user_len = *(ie-1); /* length byte before payload */
@@ -656,8 +683,10 @@
if (!TLVP_PRES_LEN(tp, CBSP_IEI_EMERG_IND, 1) ||
!TLVP_PRES_LEN(tp, CBSP_IEI_WARN_TYPE, 2) ||
!TLVP_PRES_LEN(tp, CBSP_IEI_WARN_SEC_INFO, 50) ||
- !TLVP_PRES_LEN(tp, CBSP_IEI_WARNING_PERIOD, 1))
+ !TLVP_PRES_LEN(tp, CBSP_IEI_WARNING_PERIOD, 1)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
out->u.emergency.indicator = *TLVP_VAL(tp, CBSP_IEI_EMERG_IND);
out->u.emergency.warning_type = tlvp_val16be(tp, CBSP_IEI_WARN_TYPE);
memcpy(&out->u.emergency.warning_sec_info, TLVP_VAL(tp, CBSP_IEI_WARN_SEC_INFO),
@@ -672,8 +701,10 @@
const struct tlv_parsed *tp, struct msgb *in, void *ctx)
{
if (!TLVP_PRES_LEN(tp, CBSP_IEI_MSG_ID, 2) ||
- !TLVP_PRES_LEN(tp, CBSP_IEI_NEW_SERIAL_NR, 2))
+ !TLVP_PRES_LEN(tp, CBSP_IEI_NEW_SERIAL_NR, 2)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
out->msg_id = tlvp_val16be(tp, CBSP_IEI_MSG_ID);
out->new_serial_nr = tlvp_val16be(tp, CBSP_IEI_NEW_SERIAL_NR);
@@ -706,8 +737,10 @@
{
if (!TLVP_PRES_LEN(tp, CBSP_IEI_MSG_ID, 2) ||
!TLVP_PRES_LEN(tp, CBSP_IEI_NEW_SERIAL_NR, 2) ||
- !TLVP_PRES_LEN(tp, CBSP_IEI_FAILURE_LIST, 5))
+ !TLVP_PRES_LEN(tp, CBSP_IEI_FAILURE_LIST, 5)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
out->msg_id = tlvp_val16be(tp, CBSP_IEI_MSG_ID);
out->new_serial_nr = tlvp_val16be(tp, CBSP_IEI_NEW_SERIAL_NR);
@@ -747,8 +780,11 @@
{
if (!TLVP_PRES_LEN(tp, CBSP_IEI_MSG_ID, 2) ||
!TLVP_PRES_LEN(tp, CBSP_IEI_OLD_SERIAL_NR, 2) ||
- !TLVP_PRES_LEN(tp, CBSP_IEI_CELL_LIST, 1))
+ !TLVP_PRES_LEN(tp, CBSP_IEI_CELL_LIST, 1)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
+
out->msg_id = tlvp_val16be(tp, CBSP_IEI_MSG_ID);
out->old_serial_nr = tlvp_val16be(tp, CBSP_IEI_OLD_SERIAL_NR);
@@ -769,8 +805,10 @@
{
if (!TLVP_PRES_LEN(tp, CBSP_IEI_MSG_ID, 2) ||
!TLVP_PRES_LEN(tp, CBSP_IEI_OLD_SERIAL_NR, 2) ||
- !TLVP_PRES_LEN(tp, CBSP_IEI_CELL_LIST, 1))
+ !TLVP_PRES_LEN(tp, CBSP_IEI_CELL_LIST, 1)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
out->msg_id = tlvp_val16be(tp, CBSP_IEI_MSG_ID);
out->old_serial_nr = tlvp_val16be(tp, CBSP_IEI_OLD_SERIAL_NR);
@@ -799,8 +837,10 @@
{
if (!TLVP_PRES_LEN(tp, CBSP_IEI_MSG_ID, 2) ||
!TLVP_PRES_LEN(tp, CBSP_IEI_OLD_SERIAL_NR, 2) ||
- !TLVP_PRES_LEN(tp, CBSP_IEI_FAILURE_LIST, 5))
+ !TLVP_PRES_LEN(tp, CBSP_IEI_FAILURE_LIST, 5)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
out->msg_id = tlvp_val16be(tp, CBSP_IEI_MSG_ID);
out->old_serial_nr = tlvp_val16be(tp, CBSP_IEI_OLD_SERIAL_NR);
@@ -835,8 +875,10 @@
struct msgb *in, void *ctx)
{
if (!TLVP_PRES_LEN(tp, CBSP_IEI_CELL_LIST, 1) ||
- !TLVP_PRES_LEN(tp, CBSP_IEI_CHANNEL_IND, 1))
+ !TLVP_PRES_LEN(tp, CBSP_IEI_CHANNEL_IND, 1)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
INIT_LLIST_HEAD(&out->cell_list.list);
cbsp_decode_cell_list(&out->cell_list, ctx, TLVP_VAL(tp, CBSP_IEI_CELL_LIST),
@@ -851,8 +893,10 @@
const struct tlv_parsed *tp, struct msgb *in, void *ctx)
{
if (!TLVP_PRES_LEN(tp, CBSP_IEI_RR_LOADING_LIST, 6) ||
- !TLVP_PRES_LEN(tp, CBSP_IEI_CHANNEL_IND, 1))
+ !TLVP_PRES_LEN(tp, CBSP_IEI_CHANNEL_IND, 1)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
INIT_LLIST_HEAD(&out->loading_list.list);
cbsp_decode_loading_list(&out->loading_list, ctx,
@@ -868,8 +912,10 @@
const struct tlv_parsed *tp, struct msgb *in, void *ctx)
{
if (!TLVP_PRES_LEN(tp, CBSP_IEI_FAILURE_LIST, 5) ||
- !TLVP_PRES_LEN(tp, CBSP_IEI_CHANNEL_IND, 1))
+ !TLVP_PRES_LEN(tp, CBSP_IEI_CHANNEL_IND, 1)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
INIT_LLIST_HEAD(&out->fail_list);
cbsp_decode_fail_list(&out->fail_list, ctx,
@@ -894,8 +940,11 @@
if (!TLVP_PRES_LEN(tp, CBSP_IEI_MSG_ID, 2) ||
!TLVP_PRES_LEN(tp, CBSP_IEI_OLD_SERIAL_NR, 2) ||
!TLVP_PRES_LEN(tp, CBSP_IEI_CELL_LIST, 1) ||
- !TLVP_PRES_LEN(tp, CBSP_IEI_CHANNEL_IND, 1))
+ !TLVP_PRES_LEN(tp, CBSP_IEI_CHANNEL_IND, 1)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
+
out->msg_id = tlvp_val16be(tp, CBSP_IEI_MSG_ID);
out->old_serial_nr = tlvp_val16be(tp, CBSP_IEI_OLD_SERIAL_NR);
@@ -914,8 +963,10 @@
if (!TLVP_PRES_LEN(tp, CBSP_IEI_MSG_ID, 2) ||
!TLVP_PRES_LEN(tp, CBSP_IEI_OLD_SERIAL_NR, 2) ||
!TLVP_PRES_LEN(tp, CBSP_IEI_NUM_BCAST_COMPL_LIST, 7) ||
- !TLVP_PRES_LEN(tp, CBSP_IEI_CHANNEL_IND, 1))
+ !TLVP_PRES_LEN(tp, CBSP_IEI_CHANNEL_IND, 1)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
out->msg_id = tlvp_val16be(tp, CBSP_IEI_MSG_ID);
out->old_serial_nr = tlvp_val16be(tp, CBSP_IEI_OLD_SERIAL_NR);
@@ -935,8 +986,10 @@
if (!TLVP_PRES_LEN(tp, CBSP_IEI_MSG_ID, 2) ||
!TLVP_PRES_LEN(tp, CBSP_IEI_OLD_SERIAL_NR, 2) ||
!TLVP_PRES_LEN(tp, CBSP_IEI_FAILURE_LIST, 5) ||
- !TLVP_PRES_LEN(tp, CBSP_IEI_CHANNEL_IND, 1))
+ !TLVP_PRES_LEN(tp, CBSP_IEI_CHANNEL_IND, 1)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
out->msg_id = tlvp_val16be(tp, CBSP_IEI_MSG_ID);
out->old_serial_nr = tlvp_val16be(tp, CBSP_IEI_OLD_SERIAL_NR);
@@ -961,8 +1014,10 @@
static int cbsp_dec_reset(struct osmo_cbsp_reset *out, const struct tlv_parsed *tp,
struct msgb *in, void *ctx)
{
- if (!TLVP_PRES_LEN(tp, CBSP_IEI_CELL_LIST, 1))
+ if (!TLVP_PRES_LEN(tp, CBSP_IEI_CELL_LIST, 1)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
INIT_LLIST_HEAD(&out->cell_list.list);
cbsp_decode_cell_list(&out->cell_list, ctx, TLVP_VAL(tp, CBSP_IEI_CELL_LIST),
@@ -974,8 +1029,10 @@
static int cbsp_dec_reset_compl(struct osmo_cbsp_reset_complete *out, const struct tlv_parsed *tp,
struct msgb *in, void *ctx)
{
- if (!TLVP_PRES_LEN(tp, CBSP_IEI_CELL_LIST, 1))
+ if (!TLVP_PRES_LEN(tp, CBSP_IEI_CELL_LIST, 1)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
INIT_LLIST_HEAD(&out->cell_list.list);
cbsp_decode_cell_list(&out->cell_list, ctx, TLVP_VAL(tp, CBSP_IEI_CELL_LIST),
@@ -987,8 +1044,10 @@
static int cbsp_dec_reset_fail(struct osmo_cbsp_reset_failure *out, const struct tlv_parsed *tp,
struct msgb *in, void *ctx)
{
- if (!TLVP_PRES_LEN(tp, CBSP_IEI_FAILURE_LIST, 5))
+ if (!TLVP_PRES_LEN(tp, CBSP_IEI_FAILURE_LIST, 5)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
INIT_LLIST_HEAD(&out->fail_list);
cbsp_decode_fail_list(&out->fail_list, ctx,
@@ -1007,8 +1066,10 @@
static int cbsp_dec_keep_alive(struct osmo_cbsp_keep_alive *out, const struct tlv_parsed *tp,
struct msgb *in, void *ctx)
{
- if (!TLVP_PRES_LEN(tp, CBSP_IEI_KEEP_ALIVE_REP_PERIOD, 1))
+ if (!TLVP_PRES_LEN(tp, CBSP_IEI_KEEP_ALIVE_REP_PERIOD, 1)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
out->repetition_period = *TLVP_VAL(tp, CBSP_IEI_KEEP_ALIVE_REP_PERIOD);
return 0;
@@ -1027,8 +1088,10 @@
{
if (!TLVP_PRES_LEN(tp, CBSP_IEI_CELL_LIST, 1) ||
!TLVP_PRES_LEN(tp, CBSP_IEI_BCAST_MSG_TYPE, 1) ||
- !TLVP_PRES_LEN(tp, CBSP_IEI_RECOVERY_IND, 1))
+ !TLVP_PRES_LEN(tp, CBSP_IEI_RECOVERY_IND, 1)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
INIT_LLIST_HEAD(&out->cell_list.list);
cbsp_decode_cell_list(&out->cell_list, ctx, TLVP_VAL(tp, CBSP_IEI_CELL_LIST),
@@ -1044,8 +1107,10 @@
struct msgb *in, void *ctx)
{
if (!TLVP_PRES_LEN(tp, CBSP_IEI_FAILURE_LIST, 5) ||
- !TLVP_PRES_LEN(tp, CBSP_IEI_BCAST_MSG_TYPE, 1))
+ !TLVP_PRES_LEN(tp, CBSP_IEI_BCAST_MSG_TYPE, 1)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
INIT_LLIST_HEAD(&out->fail_list);
cbsp_decode_fail_list(&out->fail_list, ctx,
@@ -1060,8 +1125,10 @@
static int cbsp_dec_error_ind(struct osmo_cbsp_error_ind *out, const struct tlv_parsed *tp,
struct msgb *in, void *ctx)
{
- if (!TLVP_PRES_LEN(tp, CBSP_IEI_CAUSE, 1))
+ if (!TLVP_PRES_LEN(tp, CBSP_IEI_CAUSE, 1)) {
+ osmo_cbsp_errstr = "missing/short mandatory IE";
return -EINVAL;
+ }
out->cause = *TLVP_VAL(tp, CBSP_IEI_CAUSE);
if (TLVP_PRES_LEN(tp, CBSP_IEI_MSG_ID, 2)) {
@@ -1095,6 +1162,8 @@
unsigned int len;
int rc;
+ osmo_cbsp_errstr = NULL;
+
if (!out)
return NULL;
@@ -1182,9 +1251,11 @@
case CBSP_MSGT_SET_DRX:
case CBSP_MSGT_SET_DRX_COMPL:
case CBSP_MSGT_SET_DRX_FAIL:
+ osmo_cbsp_errstr = "message type not implemented";
rc = -1;
break;
default:
+ osmo_cbsp_errstr = "message type not known in spec";
rc = -1;
break;
}
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index eefcf61..ea1f759 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -656,6 +656,7 @@
osmo_cbsp_encode;
osmo_cbsp_decode;
osmo_cbsp_recv_buffered;
+osmo_cbsp_errstr;
local: *;
};
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/14478
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Id9a5a595a76ba278647aee9470ded213d8464103
Gerrit-Change-Number: 14478
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at gnumonks.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190616/b5898d4f/attachment.htm>