From 7a75a1635039675292197edd8f28efb710b79d10 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Wed, 26 Jul 2023 19:01:35 +0200 Subject: [PATCH] llc: Introduce function to log XID fields and use upon Rx/Tx Change-Id: I8c6b07305c0bcecb4e1681967884a3e62c813592 --- include/osmocom/gprs/llc/llc_private.h | 2 ++ src/llc/llc.c | 4 ++++ src/llc/llc_xid.c | 30 ++++++++++++++++++++++++++ tests/llc/llc_prim_test.err | 4 ++++ 4 files changed, 40 insertions(+) diff --git a/include/osmocom/gprs/llc/llc_private.h b/include/osmocom/gprs/llc/llc_private.h index b2b9047..e5c197e 100644 --- a/include/osmocom/gprs/llc/llc_private.h +++ b/include/osmocom/gprs/llc/llc_private.h @@ -345,6 +345,8 @@ int gprs_llc_xid_encode(uint8_t *data, size_t data_len, struct gprs_llc_xid_field *gprs_llc_xid_deepcopy(void *ctx, const struct gprs_llc_xid_field *src_xid, size_t src_xid_len); +void gprs_llc_dump_xid_fields(const struct gprs_llc_xid_field *xid_fields, + size_t xid_fields_len, unsigned int logl); /* llc_pdu.c: */ int gprs_llc_pdu_decode(struct gprs_llc_pdu_decoded *pdu, diff --git a/src/llc/llc.c b/src/llc/llc.c index 93a11ec..827b067 100644 --- a/src/llc/llc.c +++ b/src/llc/llc.c @@ -471,6 +471,8 @@ static int gprs_llc_lle_generate_xid(struct gprs_llc_lle *lle, uint8_t *bytes, i xid_fields_len--; } + gprs_llc_dump_xid_fields(xid_fields, xid_fields_len, LOGL_DEBUG); + /* Store generated XID for later reference */ talloc_free(lle->xid); lle->xid = xid_fields; @@ -562,6 +564,8 @@ static int gprs_llc_lle_process_xid_ind(struct gprs_llc_lle *lle, } xid_fields_len = rc; + gprs_llc_dump_xid_fields(xid_fields, xid_fields_len, LOGL_DEBUG); + /* FIXME: Check the incoming XID parameters for * for validity. Currently we just blindly * accept all XID fields by just echoing them. diff --git a/src/llc/llc_xid.c b/src/llc/llc_xid.c index 9280416..c46083d 100644 --- a/src/llc/llc_xid.c +++ b/src/llc/llc_xid.c @@ -320,3 +320,33 @@ struct gprs_llc_xid_field *gprs_llc_xid_deepcopy(void *ctx, } return dst_xid; } + +/* Dump a list with XID fields (Debug) */ +void gprs_llc_dump_xid_fields(const struct gprs_llc_xid_field *xid_fields, + size_t xid_fields_len, unsigned int logl) +{ + unsigned int i; + + OSMO_ASSERT(xid_fields); + + for (i = 0; i < xid_fields_len; i++) { + const struct gprs_llc_xid_field *xid_field = &xid_fields[i]; + const uint8_t len = gprs_llc_xid_field_get_len(xid_field); + if (len > 0) { + if (gprs_llc_xid_type_is_variable_len(xid_field->type)) { + OSMO_ASSERT(xid_field->var.val); + LOGLLC(logl, "XID: type %s, data_len=%d, data=%s\n", + gprs_llc_xid_type_name(xid_field->type), + xid_field->var.val_len, + osmo_hexdump_nospc(xid_field->var.val, xid_field->var.val_len)); + } else { + LOGLLC(logl, "XID: type %s, val_len=%d, val=%u\n", + gprs_llc_xid_type_name(xid_field->type), + len, xid_field->val); + } + } else { + LOGLLC(logl, "XID: type %s, data_len=0\n", + gprs_llc_xid_type_name(xid_field->type)); + } + } +} diff --git a/tests/llc/llc_prim_test.err b/tests/llc/llc_prim_test.err index 7cc72f5..27867c4 100644 --- a/tests/llc/llc_prim_test.err +++ b/tests/llc/llc_prim_test.err @@ -22,5 +22,9 @@ DLGLOBAL INFO LLME(e1c5d364/e1c5d364){ASSIGNED} LLGMM-RESET.request DLGLOBAL INFO Rx from upper layers: LL-ESTABLISH.request DLGLOBAL ERROR LLE(e1c5d364/e1c5d364,SNDCP3){UNASSIGNED} Tx SABM: ABM mode not supported yet! DLGLOBAL INFO Rx from upper layers: LL-XID.request +DLGLOBAL DEBUG XID: type LLC-Version, val_len=1, val=0 +DLGLOBAL DEBUG XID: type N201-U, val_len=2, val=500 +DLGLOBAL DEBUG XID: type N201-I, val_len=2, val=1503 +DLGLOBAL DEBUG XID: type L3-Params, data_len=20, data=7869642d6c332d64756d6d792d62756666657200 DLGLOBAL NOTICE LLE(e1c5d364/e1c5d364,SNDCP3){UNASSIGNED} Sending XID type L3-Params (30 bytes) request to MS... DLGLOBAL INFO Rx from upper layers: LL-UNITDATA.request