From 0b5a816356a9f74d5ac05b6d2171f571b869f2b8 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Thu, 22 Sep 2022 01:50:43 +0700 Subject: [PATCH] llc: make logging category configurable Similar to Icfef6de126304da81120f1d7b212992ead3409aa, let's add osmo_gprs_llc_set_log_cat() allowing the API users to change logging category for libosmo-gprs-llc (DLGLOBAL is default). Change-Id: I9deb794db1c80257ba81523f815232208381bc27 --- include/osmocom/gprs/llc/llc.h | 2 ++ src/llc/Makefile.am | 1 + src/llc/llc_pdu.c | 17 ++++++++--------- src/llc/misc.c | 25 +++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 src/llc/misc.c diff --git a/include/osmocom/gprs/llc/llc.h b/include/osmocom/gprs/llc/llc.h index 4723a4b..510b11c 100644 --- a/include/osmocom/gprs/llc/llc.h +++ b/include/osmocom/gprs/llc/llc.h @@ -145,3 +145,5 @@ int osmo_gprs_llc_pdu_decode(struct osmo_gprs_llc_pdu_decoded *pdu, int osmo_gprs_llc_pdu_encode(struct msgb *msg, const struct osmo_gprs_llc_pdu_decoded *pdu); uint32_t osmo_gprs_llc_fcs(const uint8_t *data, size_t len); + +void osmo_gprs_llc_set_log_cat(int cat); diff --git a/src/llc/Makefile.am b/src/llc/Makefile.am index e24a3b3..a301a89 100644 --- a/src/llc/Makefile.am +++ b/src/llc/Makefile.am @@ -24,6 +24,7 @@ lib_LTLIBRARIES = \ libosmo_gprs_llc_la_SOURCES = \ crc24.c \ llc_pdu.c \ + misc.c \ $(NULL) libosmo_gprs_llc_la_LDFLAGS = \ diff --git a/src/llc/llc_pdu.c b/src/llc/llc_pdu.c index e55e311..5430377 100644 --- a/src/llc/llc_pdu.c +++ b/src/llc/llc_pdu.c @@ -29,13 +29,12 @@ #include -/* TODO: make logging category configurable */ -#define DLLC DLGLOBAL - #define UI_HDR_LEN 3 #define N202 4 #define CRC24_LENGTH 3 +extern int g_log_cat; + const struct value_string osmo_gprs_llc_sapi_names[] = { { OSMO_GPRS_LLC_SAPI_GMM, "GMM" }, { OSMO_GPRS_LLC_SAPI_TOM2, "TOM2" }, @@ -254,7 +253,7 @@ int osmo_gprs_llc_pdu_encode(struct msgb *msg, const struct osmo_gprs_llc_pdu_de ctrl[0] |= GPRS_LLC_U_XID; break; default: - LOGP(DLLC, LOGL_ERROR, + LOGP(g_log_cat, LOGL_ERROR, "Unknown UI func=0x%02x\n", pdu->func); return -EINVAL; } @@ -269,7 +268,7 @@ int osmo_gprs_llc_pdu_encode(struct msgb *msg, const struct osmo_gprs_llc_pdu_de /* 5.5a Message Authentication Code (MAC) field */ if (pdu->flags & OSMO_GPRS_LLC_PDU_F_MAC_PRES) { /* TODO: calculate MAC (see 3GPP TS 43.020) */ - LOGP(DLLC, LOGL_ERROR, + LOGP(g_log_cat, LOGL_ERROR, "Message Authentication Code (MAC) is not implemented\n"); return -ENOTSUP; } @@ -296,7 +295,7 @@ int osmo_gprs_llc_pdu_decode(struct osmo_gprs_llc_pdu_decoded *pdu, #define check_len(len, text) \ do { \ if (data_len < (len)) { \ - LOGP(DLLC, LOGL_ERROR, "Failed to parse LLC PDU: %s\n", text); \ + LOGP(g_log_cat, LOGL_ERROR, "Failed to parse LLC PDU: %s\n", text); \ return -EINVAL; \ } \ } while (0) @@ -317,7 +316,7 @@ int osmo_gprs_llc_pdu_decode(struct osmo_gprs_llc_pdu_decoded *pdu, /* 6.2.1 Protocol Discriminator bit (PD): shall be 0 */ if (*addr & 0x80) { - LOGP(DLLC, LOGL_ERROR, "Protocol Discriminator shall be 0\n"); + LOGP(g_log_cat, LOGL_ERROR, "Protocol Discriminator shall be 0\n"); return -EINVAL; } @@ -337,7 +336,7 @@ int osmo_gprs_llc_pdu_decode(struct osmo_gprs_llc_pdu_decoded *pdu, case 0x0c: case 0x0d: case 0x0f: - LOGP(DLLC, LOGL_ERROR, "Unknown SAPI=%u\n", pdu->sapi); + LOGP(g_log_cat, LOGL_ERROR, "Unknown SAPI=%u\n", pdu->sapi); return -EINVAL; } @@ -486,7 +485,7 @@ int osmo_gprs_llc_pdu_decode(struct osmo_gprs_llc_pdu_decoded *pdu, pdu->data_len = data_len; break; default: - LOGP(DLLC, LOGL_ERROR, "Unknown U func=0x%02x\n", ctrl[0] & 0x0f); + LOGP(g_log_cat, LOGL_ERROR, "Unknown U func=0x%02x\n", ctrl[0] & 0x0f); return -ENOTSUP; } } diff --git a/src/llc/misc.c b/src/llc/misc.c new file mode 100644 index 0000000..06e2a6c --- /dev/null +++ b/src/llc/misc.c @@ -0,0 +1,25 @@ +/* + * (C) 2022 by sysmocom - s.f.m.c. GmbH + * Author: Vadim Yanitskiy + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include + +int g_log_cat = DLGLOBAL; + +void osmo_gprs_llc_set_log_cat(int cat) +{ + g_log_cat = cat; +}