From 931c335680caa01cc556845b1da43aafdcc46a69 Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Thu, 27 May 2010 19:18:59 +0200 Subject: [PATCH] debug: make debugging more colorful Add definitions for the various libdect subsystems, pass them to the registered debugging handlers and add a handler to the example programs to colorize debugging messages. Still could use some cleanup, but causes too many clashes. Signed-off-by: Patrick McHardy --- example/Makefile.in | 2 +- example/common.c | 3 +- example/common.h | 3 +- example/debug.c | 53 +++++++++++++ example/dummy_ops.c | 2 +- include/debug.h | 41 ++++++++++ include/dect/debug.h | 35 +++++++++ include/dect/libdect.h | 3 +- include/dect/utils.h | 2 + include/lce.h | 5 +- include/libdect.h | 1 + include/utils.h | 31 -------- src/Makefile.in | 1 + src/cc.c | 10 +-- src/debug.c | 126 +++++++++++++++++++++++++++++++ src/identities.c | 47 ++++++------ src/lce.c | 14 ++-- src/libdect.c | 24 ------ src/mm.c | 4 +- src/netlink.c | 9 ++- src/s_msg.c | 165 +++++++++++++++++++++-------------------- src/ss.c | 6 +- src/utils.c | 73 ------------------ 23 files changed, 400 insertions(+), 260 deletions(-) create mode 100644 example/debug.c create mode 100644 include/debug.h create mode 100644 include/dect/debug.h create mode 100644 src/debug.c diff --git a/example/Makefile.in b/example/Makefile.in index 874380f..d516d9f 100644 --- a/example/Makefile.in +++ b/example/Makefile.in @@ -4,7 +4,7 @@ PROGRAMS += cc ss mm-fp mm-pp pp-access-rights discover hijack destdir := usr/share/dect/examples -common-obj += common.o event_ops.o keys.o dummy_ops.o +common-obj += common.o event_ops.o keys.o dummy_ops.o debug.o cc-destdir := $(destdir) cc-obj += $(common-obj) diff --git a/example/common.c b/example/common.c index a11e1d3..ef4968c 100644 --- a/example/common.c +++ b/example/common.c @@ -13,7 +13,8 @@ void pexit(const char *str) void dect_common_init(struct dect_ops *ops) { - dummy_ops_init(ops); + dect_debug_init(); + dect_dummy_ops_init(ops); if (dect_event_ops_init(ops)) pexit("dect_event_ops_init"); diff --git a/example/common.h b/example/common.h index 2bc674d..5bf68ad 100644 --- a/example/common.h +++ b/example/common.h @@ -11,7 +11,8 @@ extern int dect_event_ops_init(struct dect_ops *ops); extern void dect_event_loop(void); extern void dect_event_loop_stop(void); extern void dect_event_ops_cleanup(void); -extern void dummy_ops_init(struct dect_ops *ops); +extern void dect_dummy_ops_init(struct dect_ops *ops); +extern void dect_debug_init(void); extern void dect_common_init(struct dect_ops *ops); extern void dect_common_cleanup(struct dect_handle *dh); diff --git a/example/debug.c b/example/debug.c new file mode 100644 index 0000000..4bc6e05 --- /dev/null +++ b/example/debug.c @@ -0,0 +1,53 @@ +#include +#include +#include + +#include +#include "common.h" + +#define NORMAL "\033[0;m" +#define RED "\033[0;31m" +#define GREEN "\033[0;32m" +#define BROWN "\033[0;33m" +#define BLUE "\033[0;34m" +#define PURPLE "\033[0;35m" +#define CYAN "\033[0;36m" +#define LIGHT_GRAY "\033[0;37m" +#define DARK_GRAY "\033[1;30m" +#define LIGHT_RED "\033[1;31m" +#define LIGHT_GREEN "\033[1;32m" +#define YELLOW "\033[1;33m" +#define LIGHT_BLUE "\033[1;34m" +#define LIGHT_PURPLE "\033[1;35m" +#define LIGHT_CYAN "\033[1;36m" +#define WHITE "\033[1;37m" + +static const char * const debug_colors[] = { + [DECT_DEBUG_UNKNOWN] = NORMAL, + [DECT_DEBUG_LCE] = LIGHT_BLUE, + [DECT_DEBUG_CC] = YELLOW, + [DECT_DEBUG_SS] = LIGHT_CYAN, + [DECT_DEBUG_MM] = YELLOW, + [DECT_DEBUG_SFMT] = LIGHT_GREEN, + [DECT_DEBUG_NL] = LIGHT_PURPLE, +}; + +static bool tty; + +static void __fmtstring(2, 0) dect_debug_fn(enum dect_debug_subsys subsys, + const char *fmt, va_list ap) +{ + char buf[1024]; + + vsnprintf(buf, sizeof(buf), fmt, ap); + printf("%s%s%s", + tty ? debug_colors[subsys] : "", + buf, + tty ? NORMAL : ""); +} + +void dect_debug_init(void) +{ + tty = isatty(fileno(stdout)); + dect_set_debug_hook(dect_debug_fn); +} diff --git a/example/dummy_ops.c b/example/dummy_ops.c index 5f7f91e..5ad82ca 100644 --- a/example/dummy_ops.c +++ b/example/dummy_ops.c @@ -268,7 +268,7 @@ static void mnss_release_ind(struct dect_handle *dh, struct dect_ss_endpoint *ss static struct dect_ss_ops dummy_ss_ops; -void dummy_ops_init(struct dect_ops *ops) +void dect_dummy_ops_init(struct dect_ops *ops) { struct dect_cc_ops *cc_ops; struct dect_mm_ops *mm_ops; diff --git a/include/debug.h b/include/debug.h new file mode 100644 index 0000000..50371e4 --- /dev/null +++ b/include/debug.h @@ -0,0 +1,41 @@ +#ifndef _LIBDECT_DEBUG_H +#define _LIBDECT_DEBUG_H + +#include + +extern void __dect_debug(enum dect_debug_subsys subsys, const char *fmt, ...) __fmtstring(2, 3); +extern void __dect_hexdump(enum dect_debug_subsys subsys, const char *prefix, + const uint8_t *buf, size_t size); + +#ifdef DEBUG +#define dect_debug(subsys, fmt, ...) \ + __dect_debug(subsys, fmt, ## __VA_ARGS__) +#define dect_hexdump(subsys, pfx, buf, size) \ + __dect_hexdump(subsys, pfx, buf, size) +#else +#define dect_debug(subsys, fmt, ...) \ + ({ if (0) __dect_debug(subsys, fmt, ## __VA_ARGS__); }) +#define dect_hexdump(subsys, pfx, buf, size) \ + ({ if (0) __dect_hexdump(subsys, pfx, buf, size); }) +#endif + +struct dect_trans_tbl { + uint64_t val; + const char *str; +}; + +#define TRANS_TBL(_val, _str) { .val = (_val), .str = (_str) } + +extern const char *__dect_flags2str(const struct dect_trans_tbl *tbl, unsigned int nelem, + char *buf, size_t size, uint64_t val); + +#define dect_val2str(trans, buf, val) \ + __dect_val2str(trans, array_size(trans), buf, sizeof(buf), val) + +extern const char *__dect_val2str(const struct dect_trans_tbl *tbl, unsigned int nelem, + char *buf, size_t len, uint64_t val); + +#define dect_flags2str(trans, buf, val) \ + __dect_flags2str(trans, array_size(trans), buf, sizeof(buf), val) + +#endif /* _LIBDECT_DEBUG_H */ diff --git a/include/dect/debug.h b/include/dect/debug.h new file mode 100644 index 0000000..5433fca --- /dev/null +++ b/include/dect/debug.h @@ -0,0 +1,35 @@ +#ifndef _LIBDECT_DECT_DEBUG_H +#define _LIBDECT_DECT_DEBUG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup debug + * @{ + */ + +/** + * Debugging subsystems + */ +enum dect_debug_subsys { + DECT_DEBUG_UNKNOWN, /**< Unknown */ + DECT_DEBUG_LCE, /**< Link Control Entity */ + DECT_DEBUG_CC, /**< Call Control */ + DECT_DEBUG_SS, /**< Supplementary Services */ + DECT_DEBUG_MM, /**< Mobility Management */ + DECT_DEBUG_SFMT, /**< S-Format message parsing/construction */ + DECT_DEBUG_NL, /**< Netlink communication */ +}; + +extern void dect_set_debug_hook(void (*fn)(enum dect_debug_subsys subsys, + const char *fmt, va_list ap) + __fmtstring(2, 0)); + +/**< @} */ + +#ifdef __cplusplus +} +#endif +#endif /* _LIBDECT_DECT_DEBUG_H */ diff --git a/include/dect/libdect.h b/include/dect/libdect.h index 151047c..424a7c7 100644 --- a/include/dect/libdect.h +++ b/include/dect/libdect.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #ifdef __cplusplus @@ -140,8 +141,6 @@ extern void dect_close_handle(struct dect_handle *dh); extern int dect_init(struct dect_handle *dh); -extern void dect_set_debug_hook(int (*fn)(const char *fmt, va_list ap)); - #ifdef __cplusplus } #endif diff --git a/include/dect/utils.h b/include/dect/utils.h index 6dc6e7d..e818730 100644 --- a/include/dect/utils.h +++ b/include/dect/utils.h @@ -11,6 +11,8 @@ extern "C" { const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) +#define __fmtstring(x, y) __attribute__((format(printf, x, y))) + #ifdef __cplusplus } #endif diff --git a/include/lce.h b/include/lce.h index 16b672d..b83432f 100644 --- a/include/lce.h +++ b/include/lce.h @@ -13,10 +13,11 @@ #include #include -static inline void dect_mbuf_dump(const struct dect_msg_buf *mb, +static inline void dect_mbuf_dump(enum dect_debug_subsys subsys, + const struct dect_msg_buf *mb, const char *prefix) { - dect_hexdump(prefix, mb->data, mb->len); + dect_hexdump(subsys, prefix, mb->data, mb->len); } /** diff --git a/include/libdect.h b/include/libdect.h index a09ade9..eb6f425 100644 --- a/include/libdect.h +++ b/include/libdect.h @@ -3,6 +3,7 @@ #include #include +#include #include struct dect_fp_capabilities { diff --git a/include/utils.h b/include/utils.h index 9379733..4e731d9 100644 --- a/include/utils.h +++ b/include/utils.h @@ -24,41 +24,10 @@ #define __must_check __attribute__((warn_unused_result)) #define __maybe_unused __attribute__((unused)) #define __noreturn __attribute__((__noreturn__)) -#define __fmtstring(x, y) __attribute__((format(printf, x, y))) #define __aligned(x) __attribute__((aligned(x))) #define __packed __attribute__((packed)) #define __visible __attribute__((visibility("default"))) -extern void __dect_debug(const char *fmt, ...) __fmtstring(1, 2); -extern void __dect_hexdump(const char *prefix, const uint8_t *buf, size_t size); - -#ifdef DEBUG -#define dect_debug(fmt, ...) __dect_debug(fmt, ## __VA_ARGS__) -#define dect_hexdump(pfx, buf, size) __dect_hexdump(pfx, buf, size) -#else -#define dect_debug(fmt, ...) ({ if (0) __dect_debug(fmt, ## __VA_ARGS__); }) -#define dect_hexdump(pfx, buf, size) ({ if (0) __dect_hexdump(pfx, buf, size); }) -#endif - -struct dect_trans_tbl { - uint64_t val; - const char *str; -}; - -#define TRANS_TBL(_val, _str) { .val = (_val), .str = (_str) } - -extern const char *__dect_flags2str(const struct dect_trans_tbl *tbl, unsigned int nelem, - char *buf, size_t size, uint64_t val); - -#define dect_val2str(trans, buf, val) \ - __dect_val2str(trans, array_size(trans), buf, sizeof(buf), val) - -extern const char *__dect_val2str(const struct dect_trans_tbl *tbl, unsigned int nelem, - char *buf, size_t len, uint64_t val); - -#define dect_flags2str(trans, buf, val) \ - __dect_flags2str(trans, array_size(trans), buf, sizeof(buf), val) - struct dect_handle; extern void *dect_malloc(const struct dect_handle *dh, size_t size); extern void *dect_zalloc(const struct dect_handle *dh, size_t size); diff --git a/src/Makefile.in b/src/Makefile.in index 4f26120..edb65f5 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -19,6 +19,7 @@ dect-obj += io.o dect-obj += timer.o dect-obj += utils.o dect-obj += raw.o +dect-obj += debug.o dect-obj += ccitt-adpcm/g711.o dect-obj += ccitt-adpcm/g72x.o diff --git a/src/cc.c b/src/cc.c index 87a13a4..082338a 100644 --- a/src/cc.c +++ b/src/cc.c @@ -325,7 +325,7 @@ static DECT_SFMT_MSG_DESC(crss_hold, ); #define __cc_debug(call, pfx, fmt, args...) \ - dect_debug("%sCC: call %p (%s): " fmt "\n", pfx, \ + dect_debug(DECT_DEBUG_CC, "%sCC: call %p (%s): " fmt "\n", pfx, \ (call), call_states[(call)->state], ## args) #define cc_debug(call, fmt, args...) \ @@ -1354,7 +1354,7 @@ static void dect_cc_rcv_setup(struct dect_handle *dh, struct dect_cc_setup_msg msg; struct dect_call *call; - dect_debug("CC-SETUP\n"); + dect_debug(DECT_DEBUG_CC, "CC-SETUP\n"); if (dect_parse_sfmt_msg(dh, &cc_setup_msg_desc, &msg.common, mb) < 0) return; @@ -1363,10 +1363,10 @@ static void dect_cc_rcv_setup(struct dect_handle *dh, goto out; dect_foreach_ie(call_attributes, &msg.call_attributes) - dect_debug("call attributes\n"); + dect_debug(DECT_DEBUG_CC, "call attributes\n"); dect_foreach_ie(connection_attributes, &msg.connection_attributes) - dect_debug("connection attributes\n"); + dect_debug(DECT_DEBUG_CC, "connection attributes\n"); call = dect_call_alloc(dh); if (call == NULL) @@ -1386,7 +1386,7 @@ static void dect_cc_open(struct dect_handle *dh, const struct dect_transaction *req, struct dect_msg_buf *mb) { - dect_debug("CC: unknown transaction: msg type: %x\n", mb->type); + dect_debug(DECT_DEBUG_CC, "CC: unknown transaction: msg type: %x\n", mb->type); switch (mb->type) { case CC_SETUP: return dect_cc_rcv_setup(dh, req, mb); diff --git a/src/debug.c b/src/debug.c new file mode 100644 index 0000000..5615dba --- /dev/null +++ b/src/debug.c @@ -0,0 +1,126 @@ +/* + * libdect debugging helpers + * + * Copyright (c) 2010 Patrick McHardy + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/** + * @defgroup debug Debugging + * @{ + */ + +static void __fmtstring(2, 0) (*debug_hook)(enum dect_debug_subsys subsys, + const char *fmt, va_list ap); + +/** + * Set callback hook for debugging messages + * + * @param fn callback function + */ +void dect_set_debug_hook(void (*fn)(enum dect_debug_subsys subsys, + const char *fmt, va_list ap)) +{ + debug_hook = fn; +} +EXPORT_SYMBOL(dect_set_debug_hook); + +#ifdef DEBUG +void __fmtstring(2, 3) __dect_debug(enum dect_debug_subsys subsys, + const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + if (debug_hook != NULL) + debug_hook(subsys, fmt, ap); + else + vprintf(fmt, ap); + va_end(ap); +} + +#define BLOCKSIZE 16 + +void __dect_hexdump(enum dect_debug_subsys subsys, const char *prefix, + const uint8_t *buf, size_t size) +{ + unsigned int i, off; + char hbuf[3 * BLOCKSIZE + 1], abuf[BLOCKSIZE + 1]; + + for (i = 0; i < size; i++) { + off = i % BLOCKSIZE; + + sprintf(hbuf + 3 * off, "%.2x ", buf[i]); + abuf[off] = isascii(buf[i]) && isprint(buf[i]) ? buf[i] : '.'; + + if (off == BLOCKSIZE - 1 || i == size - 1) { + abuf[off + 1] = '\0'; + dect_debug(subsys, "%s: %-48s |%s|\n", + prefix, hbuf, abuf); + } + } +} + +const char *__dect_flags2str(const struct dect_trans_tbl *tbl, unsigned int nelem, + char *buf, size_t size, uint64_t val) +{ + char tmp[sizeof("unknown (0xffffffffffffffff)")]; + const char *delim = NULL; + uint64_t flags = val; + unsigned int i; + + buf[0] = '\0'; + for (i = 0; i < nelem && flags ; i++) { + if (tbl[i].val & flags) { + flags &= ~tbl[i].val; + if (delim) + strncat(buf, delim, size - strlen(buf) - 1); + strncat(buf, tbl[i].str, size - strlen(buf) - 1); + delim = ","; + } + } + + if (flags) { + snprintf(tmp, size - strlen(buf), "unknown (%" PRIx64 ")", flags); + if (delim) + strncat(tmp, delim, size - strlen(buf) - 1); + strncat(buf, tmp, size - strlen(buf) - 1); + } + + snprintf(tmp, size - strlen(buf), " (%" PRIx64 ")", val); + strncat(buf, tmp, size - strlen(buf) - 1); + + return buf; +} + +const char *__dect_val2str(const struct dect_trans_tbl *tbl, unsigned int nelem, + char *buf, size_t size, uint64_t val) +{ + unsigned int i; + + for (i = 0; i < nelem; i++) { + if (tbl[i].val == val) { + snprintf(buf, size, "%s (%" PRIx64 ")", tbl[i].str, val); + return buf; + } + } + + snprintf(buf, size, "unknown (%" PRIx64 ")", val); + return buf; +} +#endif + +/** @} */ diff --git a/src/identities.c b/src/identities.c index b2fb999..16dab8c 100644 --- a/src/identities.c +++ b/src/identities.c @@ -19,6 +19,9 @@ #include #include +#define sfmt_debug(fmt, args...) \ + dect_debug(DECT_DEBUG_SFMT, fmt, ## args) + static const char * const ari_classes[] = { [DECT_ARC_A] = "A", [DECT_ARC_B] = "B", @@ -29,17 +32,17 @@ static const char * const ari_classes[] = { void dect_dump_ari(const struct dect_ari *ari) { - dect_debug("\tclass: %s\n", ari_classes[ari->arc]); + sfmt_debug("\tclass: %s\n", ari_classes[ari->arc]); switch (ari->arc) { case DECT_ARC_A: - dect_debug("\tEMC: %.4x\n", ari->emc); - dect_debug("\tFPN: %.5x\n", ari->fpn); + sfmt_debug("\tEMC: %.4x\n", ari->emc); + sfmt_debug("\tFPN: %.5x\n", ari->fpn); break; case DECT_ARC_B: - dect_debug("\tEIC: %x\n", ari->eic); - dect_debug("\tFPN: %x\n", ari->fpn); - dect_debug("\tFPS: %x\n", ari->fps); + sfmt_debug("\tEIC: %x\n", ari->eic); + sfmt_debug("\tFPN: %x\n", ari->fpn); + sfmt_debug("\tFPS: %x\n", ari->fps); break; case DECT_ARC_C: case DECT_ARC_D: @@ -113,8 +116,8 @@ uint64_t dect_build_ari(const struct dect_ari *ari) static void dect_dump_ipei(const struct dect_ipei *ipei) { - dect_debug("\tEMC: %.4x\n", ipei->emc); - dect_debug("\tPSN: %.5x\n", ipei->psn); + sfmt_debug("\tEMC: %.4x\n", ipei->emc); + sfmt_debug("\tPSN: %.5x\n", ipei->psn); } static bool dect_parse_ipei(struct dect_ipei *ipei, uint64_t i) @@ -137,11 +140,11 @@ void dect_dump_ipui(const struct dect_ipui *ipui) { switch (ipui->put) { case DECT_IPUI_N: - dect_debug("\tPUT: N (IPEI)\n"); + sfmt_debug("\tPUT: N (IPEI)\n"); return dect_dump_ipei(&ipui->pun.n.ipei); case DECT_IPUI_O: - dect_debug("\tPUT: O (private)\n"); - dect_debug("\tNumber: %" PRIx64 "\n", ipui->pun.o.number); + sfmt_debug("\tPUT: O (private)\n"); + sfmt_debug("\tNumber: %" PRIx64 "\n", ipui->pun.o.number); return; case DECT_IPUI_P: case DECT_IPUI_Q: @@ -150,7 +153,7 @@ void dect_dump_ipui(const struct dect_ipui *ipui) case DECT_IPUI_T: case DECT_IPUI_U: default: - dect_debug("\tIPUI: unhandled type %u\n", ipui->put); + sfmt_debug("\tIPUI: unhandled type %u\n", ipui->put); } } @@ -184,7 +187,7 @@ bool dect_parse_ipui(struct dect_ipui *ipui, const uint8_t *ptr, uint8_t len) case DECT_IPUI_T: case DECT_IPUI_U: default: - dect_debug("\tIPUI: unhandled type %u\n", ipui->put); + sfmt_debug("\tIPUI: unhandled type %u\n", ipui->put); return false; } } @@ -257,26 +260,26 @@ void dect_dump_tpui(const struct dect_tpui *tpui) switch (tpui->type) { case DECT_TPUI_INDIVIDUAL_ASSIGNED: - dect_debug("\ttype: individual assigned\n"); - dect_debug("\tdigits: "); + sfmt_debug("\ttype: individual assigned\n"); + sfmt_debug("\tdigits: "); for (i = 0; i < 5; i++) { if (tpui->ia.digits[i] != 0xb) - dect_debug("%u", tpui->ia.digits[i]); + sfmt_debug("%u", tpui->ia.digits[i]); } - dect_debug("\n"); + sfmt_debug("\n"); return; case DECT_TPUI_CONNECTIONLESS_GROUP: - dect_debug("\ttype: connectionless group\n"); + sfmt_debug("\ttype: connectionless group\n"); return; case DECT_TPUI_CALL_GROUP: - dect_debug("\ttype: call group\n"); + sfmt_debug("\ttype: call group\n"); return; case DECT_TPUI_INDIVIDUAL_DEFAULT: - dect_debug("\ttype: individual default\n"); - dect_debug("\tIPUI: %.4x\n", tpui->id.ipui); + sfmt_debug("\ttype: individual default\n"); + sfmt_debug("\tIPUI: %.4x\n", tpui->id.ipui); return; case DECT_TPUI_EMERGENCY: - dect_debug("\ttype: emergency\n"); + sfmt_debug("\ttype: emergency\n"); return; } } diff --git a/src/lce.c b/src/lce.c index 84bb8de..780d7f5 100644 --- a/src/lce.c +++ b/src/lce.c @@ -49,7 +49,7 @@ static DECT_SFMT_MSG_DESC(lce_page_reject, static const struct dect_nwk_protocol *protocols[DECT_PD_MAX + 1]; #define lce_debug(fmt, args...) \ - dect_debug("LCE: " fmt, ## args) + dect_debug(DECT_DEBUG_LCE, "LCE: " fmt, ## args) void dect_lce_register_protocol(const struct dect_nwk_protocol *protocol) { @@ -139,7 +139,7 @@ static int dect_lce_broadcast(const struct dect_handle *dh, { ssize_t size; - dect_hexdump("LCE: BCAST TX", msg, len); + dect_hexdump(DECT_DEBUG_LCE, "LCE: BCAST TX", msg, len); size = send(dh->b_sap->fd, msg, len, 0); assert(size == (ssize_t)len); return 0; @@ -202,7 +202,7 @@ static void dect_lce_bsap_event(struct dect_handle *dh, struct dect_fd *dfd, if (dect_mbuf_rcv(dfd, &msg, mb) < 0) return; - dect_mbuf_dump(mb, "LCE: BCAST RX"); + dect_mbuf_dump(DECT_DEBUG_LCE, mb, "LCE: BCAST RX"); switch (mb->len) { case 3: @@ -462,7 +462,7 @@ static int dect_send(const struct dect_handle *dh, { ssize_t len; - dect_mbuf_dump(mb, "LCE: TX"); + dect_mbuf_dump(DECT_DEBUG_LCE, mb, "LCE: TX"); len = send(ddl->dfd->fd, mb->data, mb->len, 0); if (len < 0) ddl_debug(ddl, "send %u bytes: %s", mb->len, strerror(errno)); @@ -805,7 +805,7 @@ static void dect_ddl_rcv_msg(struct dect_handle *dh, struct dect_data_link *ddl) } } - dect_mbuf_dump(mb, "LCE: RX"); + dect_mbuf_dump(DECT_DEBUG_LCE, mb, "LCE: RX"); if (mb->len < DECT_S_HDR_SIZE) return; @@ -852,7 +852,7 @@ static void dect_lce_data_link_event(struct dect_handle *dh, { struct dect_data_link *ddl = dfd->data; - dect_debug("\n"); + dect_debug(DECT_DEBUG_LCE, "\n"); if (events & DECT_FD_WRITE) { switch (ddl->state) { case DECT_DATA_LINK_ESTABLISH_PENDING: @@ -987,7 +987,7 @@ static void dect_lce_ssap_listener_event(struct dect_handle *dh, struct dect_data_link *ddl; struct dect_fd *nfd; - dect_debug("\n"); + dect_debug(DECT_DEBUG_LCE, "\n"); ddl = dect_ddl_alloc(dh); if (ddl == NULL) goto err1; diff --git a/src/libdect.c b/src/libdect.c index 0ffa222..8a8a2e5 100644 --- a/src/libdect.c +++ b/src/libdect.c @@ -9,8 +9,6 @@ */ #include -#include -#include #include #include @@ -18,28 +16,6 @@ #include #include -static int __fmtstring(1, 0) (*debug_hook)(const char *fmt, va_list ap); - -void dect_set_debug_hook(int (*fn)(const char *fmt, va_list ap)) -{ - debug_hook = fn; -} -EXPORT_SYMBOL(dect_set_debug_hook); - -#ifdef DEBUG -void __fmtstring(1, 2) __dect_debug(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - if (debug_hook != NULL) - debug_hook(fmt, ap); - else - vprintf(fmt, ap); - va_end(ap); -} -#endif - struct dect_handle *dect_alloc_handle(struct dect_ops *ops) { struct dect_handle *dh; diff --git a/src/mm.c b/src/mm.c index 59ce1b9..7440496 100644 --- a/src/mm.c +++ b/src/mm.c @@ -331,7 +331,7 @@ static DECT_SFMT_MSG_DESC(mm_notify_msg, ); #define __mm_debug(mme, pfx, fmt, args...) \ - dect_debug("%sMM: link %d (%s): " fmt "\n", (pfx), \ + dect_debug(DECT_DEBUG_MM, "%sMM: link %d (%s): " fmt "\n", (pfx), \ (mme)->link && (mme)->link->dfd ? (mme)->link->dfd->fd : -1, \ (mme)->current ? dect_mm_proc[(mme)->current->type].name : "none", \ ## args) @@ -3075,7 +3075,7 @@ static void dect_mm_open(struct dect_handle *dh, struct dect_mm_endpoint *mme; struct dect_transaction *ta; - dect_debug("MM: unknown transaction: msg type: %x\n", mb->type); + dect_debug(DECT_DEBUG_MM, "MM: unknown transaction: msg type: %x\n", mb->type); switch (mb->type) { case DECT_MM_AUTHENTICATION_REQUEST: case DECT_MM_CIPHER_REQUEST: diff --git a/src/netlink.c b/src/netlink.c index 17f4a79..c2afe06 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -25,9 +25,9 @@ #include #define nl_debug_entry(fmt, args...) \ - dect_debug("\nnetlink: " fmt, ## args) + dect_debug(DECT_DEBUG_NL, "\nnetlink: " fmt, ## args) #define nl_debug(fmt, args...) \ - dect_debug("netlink: " fmt, ## args) + dect_debug(DECT_DEBUG_NL, "netlink: " fmt, ## args) struct dect_netlink_handler { struct dect_handle *dh; @@ -47,7 +47,7 @@ static void __maybe_unused dect_netlink_obj_dump(struct nl_object *obj) buf[0] = '\0'; nl_object_dump(obj, &dp); - dect_debug("%s", buf); + dect_debug(DECT_DEBUG_NL, "%s", buf); #endif } @@ -305,7 +305,8 @@ err2: nl_close(dh->nlsock); nl_socket_free(dh->nlsock); err1: - dect_debug("dect_netlink_init: %s\n", err == 0 ? strerror(errno) : nl_geterror(err)); + dect_debug(DECT_DEBUG_NL, "dect_netlink_init: %s\n", + err == 0 ? strerror(errno) : nl_geterror(err)); return -1; } diff --git a/src/s_msg.c b/src/s_msg.c index 274bf33..a8b139d 100644 --- a/src/s_msg.c +++ b/src/s_msg.c @@ -21,6 +21,9 @@ #include #include +#define sfmt_debug(fmt, args...) \ + dect_debug(DECT_DEBUG_SFMT, fmt, ## args) + static const struct dect_trans_tbl dect_repeat_indicators[] = { TRANS_TBL(DECT_IE_LIST_NORMAL, "Non prioritized list"), TRANS_TBL(DECT_IE_LIST_PRIORITIZED, "Prioritized list"), @@ -31,7 +34,7 @@ static void dect_sfmt_dump_repeat_indicator(const struct dect_ie_common *_ie) const struct dect_ie_list *ie = dect_ie_container(ie, _ie); char buf[64]; - dect_debug("\trepeat indicator: %s\n", + sfmt_debug("\trepeat indicator: %s\n", dect_val2str(dect_repeat_indicators, buf, ie->type)); } @@ -47,7 +50,7 @@ static int dect_sfmt_parse_repeat_indicator(const struct dect_handle *dh, case DECT_IE_LIST_PRIORITIZED: return 0; default: - dect_debug("invalid list type\n"); + sfmt_debug("invalid list type\n"); return -1; } } @@ -105,9 +108,9 @@ static void dect_sfmt_dump_basic_service(const struct dect_ie_common *_ie) const struct dect_ie_basic_service *ie = dect_ie_container(ie, _ie); char buf[64]; - dect_debug("\tcall class: %s\n", + sfmt_debug("\tcall class: %s\n", dect_val2str(dect_call_classes, buf, ie->class)); - dect_debug("\tservice: %s\n", + sfmt_debug("\tservice: %s\n", dect_val2str(dect_basic_services, buf, ie->service)); } @@ -143,7 +146,7 @@ static void dect_sfmt_dump_display(const struct dect_ie_common *_ie) ie->info[i] : '.'; info[ie->len] = '\0'; - dect_debug("\tinfo: '%s'\n", info); + sfmt_debug("\tinfo: '%s'\n", info); } static int dect_sfmt_parse_single_display(const struct dect_handle *dh, @@ -177,7 +180,7 @@ static void dect_sfmt_dump_keypad(const struct dect_ie_common *_ie) ie->info[i] : '.'; info[ie->len] = '\0'; - dect_debug("\tinfo: '%s'\n", info); + sfmt_debug("\tinfo: '%s'\n", info); } static int dect_sfmt_parse_single_keypad(const struct dect_handle *dh, @@ -237,7 +240,7 @@ static void dect_sfmt_dump_info_type(const struct dect_ie_common *_ie) char buf[64]; for (i = 0; i < ie->num; i++) - dect_debug("\tparameter type[%u]: %s\n", i, + sfmt_debug("\tparameter type[%u]: %s\n", i, dect_val2str(dect_info_type_parameters, buf, ie->type[i])); } @@ -304,26 +307,26 @@ static void dect_sfmt_dump_identity_type(const struct dect_ie_common *_ie) const struct dect_ie_identity_type *ie = dect_ie_container(ie, _ie); char buf[64]; - dect_debug("\tidentity group: %s\n", + sfmt_debug("\tidentity group: %s\n", dect_val2str(dect_identity_groups, buf, ie->group)); switch (ie->group) { case DECT_IDENTITY_PORTABLE_IDENTITY: - dect_debug("\tidentity type: %s\n", + sfmt_debug("\tidentity type: %s\n", dect_val2str(dect_portable_identity_types, buf, ie->type)); break; case DECT_IDENTITY_FIXED_IDENTITY: - dect_debug("\tidentity type: %s\n", + sfmt_debug("\tidentity type: %s\n", dect_val2str(dect_fixed_identity_types, buf, ie->type)); break; case DECT_IDENTITY_NETWORK_ASSIGNED_IDENTITY: - dect_debug("\tidentity type: %s\n", + sfmt_debug("\tidentity type: %s\n", dect_val2str(dect_nwk_identity_types, buf, ie->type)); break; case DECT_IDENTITY_APPLICATION_ASSIGNED: case DECT_IDENTITY_PROPRIETARY: default: - dect_debug("\tidentity type: %u\n", ie->type); + sfmt_debug("\tidentity type: %u\n", ie->type); break; } } @@ -390,7 +393,7 @@ static void dect_sfmt_dump_release_reason(const struct dect_ie_common *_ie) const struct dect_ie_release_reason *ie = dect_ie_container(ie, _ie); char buf[64]; - dect_debug("\trelease reason: %s\n", + sfmt_debug("\trelease reason: %s\n", dect_val2str(dect_release_reasons, buf, ie->reason)); } @@ -442,7 +445,7 @@ static void dect_sfmt_dump_signal(const struct dect_ie_common *_ie) struct dect_ie_signal *ie = dect_ie_container(ie, _ie); char buf[64]; - dect_debug("\tsignal: %s\n", dect_val2str(dect_signal_codes, buf, ie->code)); + sfmt_debug("\tsignal: %s\n", dect_val2str(dect_signal_codes, buf, ie->code)); } static int dect_sfmt_parse_signal(const struct dect_handle *dh, @@ -485,7 +488,7 @@ static void dect_sfmt_dump_portable_identity(const struct dect_ie_common *_ie) const struct dect_ie_portable_identity *ie = dect_ie_container(ie, _ie); char buf[64]; - dect_debug("\ttype: %s\n", + sfmt_debug("\ttype: %s\n", dect_val2str(dect_portable_identity_types, buf, ie->type)); switch (ie->type) { @@ -519,14 +522,14 @@ static int dect_sfmt_parse_portable_identity(const struct dect_handle *dh, switch (dst->type) { case DECT_PORTABLE_ID_TYPE_IPUI: if (!dect_parse_ipui(&dst->ipui, src->data + 4, len)) - dect_debug("parsing failed\n"); + sfmt_debug("parsing failed\n"); return 0; case DECT_PORTABLE_ID_TYPE_IPEI: return 0; case DECT_PORTABLE_ID_TYPE_TPUI: return 0; default: - dect_debug("invalid type %u\n", dst->type); + sfmt_debug("invalid type %u\n", dst->type); return -1; } } @@ -568,7 +571,7 @@ static void dect_sfmt_dump_fixed_identity(const struct dect_ie_common *_ie) const struct dect_ie_fixed_identity *ie = dect_ie_container(ie, _ie); char buf[64]; - dect_debug("\ttype: %s\n", + sfmt_debug("\ttype: %s\n", dect_val2str(dect_fixed_identity_types, buf, ie->type)); switch (ie->type) { @@ -578,7 +581,7 @@ static void dect_sfmt_dump_fixed_identity(const struct dect_ie_common *_ie) return dect_dump_ari(&ie->ari); case DECT_FIXED_ID_TYPE_ARI_RPN: dect_dump_ari(&ie->ari); - dect_debug("\tRPN: %u\n", ie->rpn); + sfmt_debug("\tRPN: %u\n", ie->rpn); return; case DECT_FIXED_ID_TYPE_ARI_WRS: return dect_dump_ari(&ie->ari); @@ -617,7 +620,7 @@ static int dect_sfmt_parse_fixed_identity(const struct dect_handle *dh, case DECT_FIXED_ID_TYPE_ARI_WRS: return 0; default: - dect_debug("invalid type %u\n", dst->type); + sfmt_debug("invalid type %u\n", dst->type); return -1; } } @@ -644,7 +647,7 @@ static void dect_sfmt_dump_location_area(const struct dect_ie_common *_ie) { const struct dect_ie_location_area *ie = dect_ie_container(ie, _ie); - dect_debug("\ttype: %x level: %u\n", ie->type, ie->level); + sfmt_debug("\ttype: %x level: %u\n", ie->type, ie->level); } static int dect_sfmt_parse_location_area(const struct dect_handle *dh, @@ -688,10 +691,10 @@ static void dect_sfmt_dump_allocation_type(const struct dect_ie_common *_ie) const struct dect_ie_allocation_type *ie = dect_ie_container(ie, _ie); char buf[64]; - dect_debug("\tauthentication algorithm: %s\n", + sfmt_debug("\tauthentication algorithm: %s\n", dect_val2str(dect_auth_algs, buf, ie->auth_id)); - dect_debug("\tauthentication key number: %u\n", ie->auth_key_num); - dect_debug("\tauthentication code number: %u\n", ie->auth_code_num); + sfmt_debug("\tauthentication key number: %u\n", ie->auth_key_num); + sfmt_debug("\tauthentication code number: %u\n", ie->auth_code_num); } static int dect_sfmt_parse_allocation_type(const struct dect_handle *dh, @@ -723,13 +726,13 @@ static void dect_sfmt_dump_auth_type(const struct dect_ie_common *_ie) const struct dect_ie_auth_type *ie = dect_ie_container(ie, _ie); char buf[64]; - dect_debug("\tauthentication algorithm: %s\n", + sfmt_debug("\tauthentication algorithm: %s\n", dect_val2str(dect_auth_algs, buf, ie->auth_id)); - dect_debug("\tauthentication key type: %s\n", + sfmt_debug("\tauthentication key type: %s\n", dect_val2str(dect_auth_key_types, buf, ie->auth_key_type)); - dect_debug("\tauthentication key number: %u\n", ie->auth_key_num); - dect_debug("\tcipher key number: %u\n", ie->cipher_key_num); - dect_debug("\tINC: %u DEF: %u TXC: %u UPC: %u\n", + sfmt_debug("\tauthentication key number: %u\n", ie->auth_key_num); + sfmt_debug("\tcipher key number: %u\n", ie->cipher_key_num); + sfmt_debug("\tINC: %u DEF: %u TXC: %u UPC: %u\n", ie->flags & DECT_AUTH_FLAG_INC ? 1 : 0, ie->flags & DECT_AUTH_FLAG_DEF ? 1 : 0, ie->flags & DECT_AUTH_FLAG_TXC ? 1 : 0, @@ -782,7 +785,7 @@ static void dect_sfmt_dump_auth_value(const struct dect_ie_common *_ie) { const struct dect_ie_auth_value *ie = dect_ie_container(ie, _ie); - dect_debug("\tvalue: %.16" PRIx64 "\n", ie->value); + sfmt_debug("\tvalue: %.16" PRIx64 "\n", ie->value); } static int dect_sfmt_parse_auth_value(const struct dect_handle *dh, @@ -811,7 +814,7 @@ static void dect_sfmt_dump_auth_res(const struct dect_ie_common *_ie) { const struct dect_ie_auth_res *ie = dect_ie_container(ie, _ie); - dect_debug("\tvalue: %.8x\n", ie->value); + sfmt_debug("\tvalue: %.8x\n", ie->value); } static int dect_sfmt_parse_auth_res(const struct dect_handle *dh, @@ -859,12 +862,12 @@ static void dect_sfmt_dump_cipher_info(const struct dect_ie_common *_ie) const struct dect_ie_cipher_info *ie = dect_ie_container(ie, _ie); char buf[64]; - dect_debug("\tenable: %u\n", ie->enable); - dect_debug("\tcipher algorithm: %s\n", + sfmt_debug("\tenable: %u\n", ie->enable); + sfmt_debug("\tcipher algorithm: %s\n", dect_val2str(dect_cipher_algs, buf, ie->cipher_alg_id)); - dect_debug("\tcipher key type: %s\n", + sfmt_debug("\tcipher key type: %s\n", dect_val2str(dect_cipher_key_types, buf, ie->cipher_key_type)); - dect_debug("\tcipher key num: %u\n", ie->cipher_key_num); + sfmt_debug("\tcipher key num: %u\n", ie->cipher_key_num); } static int dect_sfmt_parse_cipher_info(const struct dect_handle *dh, @@ -981,7 +984,7 @@ static void dect_sfmt_dump_feature_activate(const struct dect_ie_common *_ie) const struct dect_ie_feature_activate *ie = dect_ie_container(ie, _ie); char buf[64]; - dect_debug("\tfeature: %s\n", dect_val2str(dect_features, buf, ie->feature)); + sfmt_debug("\tfeature: %s\n", dect_val2str(dect_features, buf, ie->feature)); } static int dect_sfmt_build_feature_activate(struct dect_sfmt_ie *dst, @@ -1000,8 +1003,8 @@ static void dect_sfmt_dump_feature_indicate(const struct dect_ie_common *_ie) const struct dect_ie_feature_indicate *ie = dect_ie_container(ie, _ie); char buf[64]; - dect_debug("\tfeature: %s\n", dect_val2str(dect_features, buf, ie->feature)); - dect_debug("\tstatus: %x\n", ie->status); + sfmt_debug("\tfeature: %s\n", dect_val2str(dect_features, buf, ie->feature)); + sfmt_debug("\tstatus: %x\n", ie->status); } static int dect_sfmt_parse_feature_indicate(const struct dect_handle *dh, @@ -1054,7 +1057,7 @@ static void dect_sfmt_dump_reject_reason(const struct dect_ie_common *_ie) struct dect_ie_reject_reason *ie = dect_ie_container(ie, _ie); char buf[64]; - dect_debug("\treject reason: %s (%x)\n", + sfmt_debug("\treject reason: %s (%x)\n", dect_val2str(dect_reject_reasons, buf, ie->reason), ie->reason); } @@ -1208,27 +1211,27 @@ static void dect_sfmt_dump_terminal_capability(const struct dect_ie_common *_ie) const struct dect_ie_terminal_capability *ie = dect_ie_container(ie, _ie); char buf[64]; - dect_debug("\tdisplay capability: %s\n", + sfmt_debug("\tdisplay capability: %s\n", dect_val2str(dect_display_capabilities, buf, ie->display)); - dect_debug("\ttone capability: %s\n", + sfmt_debug("\ttone capability: %s\n", dect_val2str(dect_tone_capabilities, buf, ie->tone)); - dect_debug("\techo parameters: %s\n", + sfmt_debug("\techo parameters: %s\n", dect_val2str(dect_echo_parameters, buf, ie->echo)); - dect_debug("\tnoise rejection capability: %s\n", + sfmt_debug("\tnoise rejection capability: %s\n", dect_val2str(dect_noise_rejection_capabilities, buf, ie->noise_rejection)); - dect_debug("\tadaptive volume control provision: %s\n", + sfmt_debug("\tadaptive volume control provision: %s\n", dect_val2str(dect_volume_ctrl_provisions, buf, ie->volume_ctrl)); - dect_debug("\tslot capabilities: %s\n", + sfmt_debug("\tslot capabilities: %s\n", dect_flags2str(dect_slot_capabilities, buf, ie->slot)); - dect_debug("\tdisplay memory: %u\n", ie->display_memory); - dect_debug("\tdisplay lines: %u\n", ie->display_lines); - dect_debug("\tdisplay columns: %u\n", ie->display_columns); - dect_debug("\tscrolling behaviour: %s\n", + sfmt_debug("\tdisplay memory: %u\n", ie->display_memory); + sfmt_debug("\tdisplay lines: %u\n", ie->display_lines); + sfmt_debug("\tdisplay columns: %u\n", ie->display_columns); + sfmt_debug("\tscrolling behaviour: %s\n", dect_val2str(dect_scrolling_behaviour, buf, ie->scrolling)); - dect_debug("\tprofile indicator: %s\n", + sfmt_debug("\tprofile indicator: %s\n", dect_flags2str(dect_profile_indicators, buf, ie->profile_indicator)); - dect_debug("\tdisplay control: %x\n", ie->display_control); - dect_debug("\tdisplay charsets: %x\n", ie->display_charsets); + sfmt_debug("\tdisplay control: %x\n", ie->display_control); + sfmt_debug("\tdisplay charsets: %x\n", ie->display_charsets); } static int dect_sfmt_parse_terminal_capability(const struct dect_handle *dh, @@ -1384,9 +1387,9 @@ static void dect_sfmt_dump_called_party_number(const struct dect_ie_common *_ie) memcpy(address, ie->address, ie->len); address[ie->len] = '\0'; - dect_debug("\tNumber type: %s\n", dect_val2str(dect_number_types, buf, ie->type)); - dect_debug("\tNumbering Plan: %s\n", dect_val2str(dect_npis, buf, ie->npi)); - dect_debug("\tAddress: %s\n", address); + sfmt_debug("\tNumber type: %s\n", dect_val2str(dect_number_types, buf, ie->type)); + sfmt_debug("\tNumbering Plan: %s\n", dect_val2str(dect_npis, buf, ie->npi)); + sfmt_debug("\tAddress: %s\n", address); } static int dect_sfmt_parse_called_party_number(const struct dect_handle *dh, @@ -1437,9 +1440,9 @@ static void dect_sfmt_dump_duration(const struct dect_ie_common *_ie) struct dect_ie_duration *ie = dect_ie_container(ie, _ie); char buf[64]; - dect_debug("\tlock: %s\n", dect_val2str(dect_lock_limits, buf, ie->lock)); - dect_debug("\ttime: %s\n", dect_val2str(dect_time_limits, buf, ie->time)); - dect_debug("\tduration: %u\n", ie->duration); + sfmt_debug("\tlock: %s\n", dect_val2str(dect_lock_limits, buf, ie->lock)); + sfmt_debug("\ttime: %s\n", dect_val2str(dect_time_limits, buf, ie->time)); + sfmt_debug("\tduration: %u\n", ie->duration); } static int dect_sfmt_parse_duration(const struct dect_handle *dh, @@ -1509,9 +1512,9 @@ static void dect_sfmt_dump_iwu_to_iwu(const struct dect_ie_common *_ie) struct dect_ie_iwu_to_iwu *ie = dect_ie_container(ie, _ie); char buf[64]; - dect_debug("\tSend/Reject (S/R) bit: %s\n", + sfmt_debug("\tSend/Reject (S/R) bit: %s\n", dect_val2str(dect_iwu_to_iwu_sr, buf, ie->sr)); - dect_debug("\tProtocol Discriminator: %s\n", + sfmt_debug("\tProtocol Discriminator: %s\n", dect_val2str(dect_iwu_to_iwu_pds, buf, ie->pd)); } @@ -1551,11 +1554,11 @@ static void dect_sfmt_dump_escape_to_proprietary(const struct dect_ie_common *_i struct dect_ie_escape_to_proprietary *ie = dect_ie_container(ie, _ie); unsigned int i; - dect_debug("\tEMC: %x\n", ie->emc); - dect_debug("\tContent: "); + sfmt_debug("\tEMC: %x\n", ie->emc); + sfmt_debug("\tContent: "); for (i = 0; i < ie->len; i++) - dect_debug("%.2x ", ie->content[i]); - dect_debug("\n"); + sfmt_debug("%.2x ", ie->content[i]); + sfmt_debug("\n"); } static int dect_sfmt_build_escape_to_proprietary(struct dect_sfmt_ie *dst, @@ -1637,18 +1640,18 @@ static void dect_sfmt_dump_codec_list(const struct dect_ie_common *_ie) unsigned int i; char buf[64]; - dect_debug("\tNegotiation Indicator: %s\n", + sfmt_debug("\tNegotiation Indicator: %s\n", dect_val2str(dect_negotiation_indicators, buf, ie->negotiation)); for (i = 0; i < ie->num; i++) { - dect_debug("\tCodec %u:\n", i + 1); - dect_debug("\t Codec: %s\n", + sfmt_debug("\tCodec %u:\n", i + 1); + sfmt_debug("\t Codec: %s\n", dect_val2str(dect_codecs, buf, ie->entry[i].codec)); - dect_debug("\t MAC/DLC Service: %s\n", + sfmt_debug("\t MAC/DLC Service: %s\n", dect_val2str(dect_mac_dlc_services, buf, ie->entry[i].service)); - dect_debug("\t Slot size: %s\n", + sfmt_debug("\t Slot size: %s\n", dect_val2str(dect_slot_sizes, buf, ie->entry[i].slot)); - dect_debug("\t C-Plane routing: %s\n", + sfmt_debug("\t C-Plane routing: %s\n", dect_val2str(dect_cplane_routing, buf, ie->entry[i].cplane)); } } @@ -2114,7 +2117,7 @@ static void dect_msg_ie_init(const struct dect_sfmt_ie_desc *desc, else return; #if 0 - dect_debug("init message IE %p: <%s>\n", + sfmt_debug("init message IE %p: <%s>\n", ie, dect_ie_handlers[desc->type].name); #endif } @@ -2149,7 +2152,7 @@ static int dect_parse_sfmt_ie_header(struct dect_sfmt_ie *ie, } ie->data = mb->data; -// dect_debug("found IE: <%s> (%x) len: %u\n", dect_ie_handlers[ie->id].name, +// sfmt_debug("found IE: <%s> (%x) len: %u\n", dect_ie_handlers[ie->id].name, // ie->id, ie->len); return 0; } @@ -2193,7 +2196,7 @@ static int dect_parse_sfmt_ie(const struct dect_handle *dh, goto err1; } - dect_debug(" IE: <%s> id: %x len: %u dst: %p\n", + sfmt_debug(" IE: <%s> id: %x len: %u dst: %p\n", ieh->name, ie->id, ie->len, *dst); err = ieh->parse(dh, dst, ie); @@ -2207,11 +2210,11 @@ err2: dect_free(dh, *dst); *dst = NULL; err1: - dect_debug("smsg: IE parsing error\n"); + sfmt_debug("smsg: IE parsing error\n"); return err; } -static void dect_debug_msg(const struct dect_sfmt_msg_desc *mdesc, const char *msg) +static void sfmt_debug_msg(const struct dect_sfmt_msg_desc *mdesc, const char *msg) { char buf[strlen(mdesc->name) + 1]; unsigned int i; @@ -2223,7 +2226,7 @@ static void dect_debug_msg(const struct dect_sfmt_msg_desc *mdesc, const char *m if (buf[i] == '_') buf[i] = '-'; } - dect_debug("%s {%s} message\n", msg, buf); + sfmt_debug("%s {%s} message\n", msg, buf); } enum dect_sfmt_error dect_parse_sfmt_msg(const struct dect_handle *dh, @@ -2236,7 +2239,7 @@ enum dect_sfmt_error dect_parse_sfmt_msg(const struct dect_handle *dh, struct dect_sfmt_ie _ie[2], *ie; uint8_t idx = 0; - dect_debug_msg(mdesc, "parse"); + sfmt_debug_msg(mdesc, "parse"); dect_msg_ie_init(desc, dst); while (mb->len > 0) { @@ -2279,7 +2282,7 @@ enum dect_sfmt_error dect_parse_sfmt_msg(const struct dect_handle *dh, found: /* Treat empty variable length IEs as absent */ if (!(ie->id & DECT_SFMT_IE_FIXED_LEN) && ie->len == 2) { - dect_debug(" IE: <%s> id: %x len: %u (empty)\n", + sfmt_debug(" IE: <%s> id: %x len: %u (empty)\n", dect_ie_handlers[ie->id].name, ie->id, ie->len); goto next; } @@ -2337,7 +2340,7 @@ dect_build_sfmt_ie(const struct dect_handle *dh, if (ieh->build == NULL) goto err1; - dect_debug(" IE: <%s> id: %x %p\n", ieh->name, type, ie); + sfmt_debug(" IE: <%s> id: %x %p\n", ieh->name, type, ie); if (ieh->dump != NULL) ieh->dump(ie); @@ -2365,7 +2368,7 @@ enum dect_sfmt_error dect_build_sfmt_msg(const struct dect_handle *dh, struct dect_ie_list *iel; enum dect_sfmt_error err; - dect_debug_msg(mdesc, "build"); + sfmt_debug_msg(mdesc, "build"); while (!(desc->flags & DECT_SFMT_IE_END)) { next = dect_next_ie(desc, (struct dect_ie_common **)src); @@ -2407,7 +2410,7 @@ next: return DECT_SFMT_OK; err_mandatory: - dect_debug(" IE <%s> id: %x missing\n", + sfmt_debug(" IE <%s> id: %x missing\n", dect_ie_handlers[desc->type].name, desc->type); return DECT_SFMT_MANDATORY_IE_MISSING; } diff --git a/src/ss.c b/src/ss.c index e8293f8..434ffc8 100644 --- a/src/ss.c +++ b/src/ss.c @@ -68,7 +68,7 @@ static DECT_SFMT_MSG_DESC(ciss_facility, ); #define __ss_debug(pfx, fmt, args...) \ - dect_debug("%sSS (link %d): " fmt "\n", pfx, \ + dect_debug(DECT_DEBUG_SS, "%sSS (link %d): " fmt "\n", pfx, \ (sse)->transaction.link ? (sse)->transaction.link->dfd->fd : -1, \ ## args) @@ -288,7 +288,7 @@ static void dect_ciss_rcv_register(struct dect_handle *dh, struct dect_mnss_param *param; struct dect_ss_endpoint *sse; - dect_debug("CISS-REGISTER"); + dect_debug(DECT_DEBUG_SS, "CISS-REGISTER"); if (dect_parse_sfmt_msg(dh, &ciss_register_msg_desc, &msg.common, mb) < 0) return; @@ -320,7 +320,7 @@ static void dect_ciss_open(struct dect_handle *dh, const struct dect_transaction *req, struct dect_msg_buf *mb) { - dect_debug("SS: unknown transaction: msg type: %x\n", mb->type); + dect_debug(DECT_DEBUG_SS, "SS: unknown transaction: msg type: %x\n", mb->type); switch (mb->type) { case CISS_REGISTER: return dect_ciss_rcv_register(dh, req, mb); diff --git a/src/utils.c b/src/utils.c index 5242bbd..094c67b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -10,85 +10,12 @@ #include #include -#include -#include #include #include -#include #include #include -#define BLOCKSIZE 16 - -#ifdef DEBUG -void __dect_hexdump(const char *prefix, const uint8_t *buf, size_t size) -{ - unsigned int i, off; - char hbuf[3 * BLOCKSIZE + 1], abuf[BLOCKSIZE + 1]; - - for (i = 0; i < size; i++) { - off = i % BLOCKSIZE; - - sprintf(hbuf + 3 * off, "%.2x ", buf[i]); - abuf[off] = isascii(buf[i]) && isprint(buf[i]) ? buf[i] : '.'; - - if (off == BLOCKSIZE - 1 || i == size - 1) { - abuf[off + 1] = '\0'; - dect_debug("%s: %-48s |%s|\n", prefix, hbuf, abuf); - } - } -} - -const char *__dect_flags2str(const struct dect_trans_tbl *tbl, unsigned int nelem, - char *buf, size_t size, uint64_t val) -{ - char tmp[sizeof("unknown (0xffffffffffffffff)")]; - const char *delim = NULL; - uint64_t flags = val; - unsigned int i; - - buf[0] = '\0'; - for (i = 0; i < nelem && flags ; i++) { - if (tbl[i].val & flags) { - flags &= ~tbl[i].val; - if (delim) - strncat(buf, delim, size - strlen(buf) - 1); - strncat(buf, tbl[i].str, size - strlen(buf) - 1); - delim = ","; - } - } - - if (flags) { - snprintf(tmp, size - strlen(buf), "unknown (%" PRIx64 ")", flags); - if (delim) - strncat(tmp, delim, size - strlen(buf) - 1); - strncat(buf, tmp, size - strlen(buf) - 1); - } - - snprintf(tmp, size - strlen(buf), " (%" PRIx64 ")", val); - strncat(buf, tmp, size - strlen(buf) - 1); - - return buf; -} - -const char *__dect_val2str(const struct dect_trans_tbl *tbl, unsigned int nelem, - char *buf, size_t size, uint64_t val) -{ - unsigned int i; - - for (i = 0; i < nelem; i++) { - if (tbl[i].val == val) { - snprintf(buf, size, "%s (%" PRIx64 ")", tbl[i].str, val); - return buf; - } - } - - snprintf(buf, size, "unknown (%" PRIx64 ")", val); - return buf; -} -#endif - void *dect_malloc(const struct dect_handle *dh, size_t size) { return dh->ops->malloc(size);