From fe4d5748c6f68251bdea2af34a2e56c5d21be42c Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Thu, 10 Jan 2013 18:31:30 +0100 Subject: [PATCH] ftmod_pritap: Hexdump I/O buffers if q921_raw debug is enabled, improve parse_debug() Add support for "q921_all"/"q931_all" to parse_debug() ("debug" span parameter), taken from ftmod_libpri. Passive libpri's raw dump feature is broken (e.g. I-frames missing), so add "q921_raw" hexdump support to the pritap I/O read/write function. Signed-off-by: Stefan Knoblich --- .../src/ftmod/ftmod_pritap/ftmod_pritap.c | 61 +++++++++++++++---- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_pritap/ftmod_pritap.c b/libs/freetdm/src/ftmod/ftmod_pritap/ftmod_pritap.c index 75d8b2a81c..d716287910 100644 --- a/libs/freetdm/src/ftmod/ftmod_pritap/ftmod_pritap.c +++ b/libs/freetdm/src/ftmod/ftmod_pritap/ftmod_pritap.c @@ -101,14 +101,29 @@ static FIO_CHANNEL_OUTGOING_CALL_FUNCTION(pritap_outgoing_call) static void s_pri_error(struct pri *pri, char *s) { - ftdm_log(FTDM_LOG_ERROR, "%s", s); + pritap_t *pritap = pri_get_userdata(pri); + + if (pritap && pritap->dchan) { + ftdm_log_chan(pritap->dchan, FTDM_LOG_ERROR, "%s", s); + } else { + ftdm_log(FTDM_LOG_ERROR, "%s", s); + } } static void s_pri_message(struct pri *pri, char *s) { - ftdm_log(FTDM_LOG_DEBUG, "%s", s); + pritap_t *pritap = pri_get_userdata(pri); + + if (pritap && pritap->dchan) { + ftdm_log_chan(pritap->dchan, FTDM_LOG_DEBUG, "%s", s); + } else { + ftdm_log(FTDM_LOG_DEBUG, "%s", s); + } } +#define PRI_DEBUG_Q921_ALL (PRI_DEBUG_Q921_RAW | PRI_DEBUG_Q921_DUMP | PRI_DEBUG_Q921_STATE) +#define PRI_DEBUG_Q931_ALL (PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE | PRI_DEBUG_Q931_ANOMALY) + static int parse_debug(const char *in) { int flags = 0; @@ -117,6 +132,18 @@ static int parse_debug(const char *in) return 0; } + if (strstr(in, "all")) { + return PRI_DEBUG_ALL; + } + + if (strstr(in, "none")) { + return 0; + } + + if (strstr(in, "q921_all")) { + flags |= PRI_DEBUG_Q921_ALL; + } + if (strstr(in, "q921_raw")) { flags |= PRI_DEBUG_Q921_RAW; } @@ -133,6 +160,10 @@ static int parse_debug(const char *in) flags |= PRI_DEBUG_CONFIG; } + if (strstr(in, "q931_all")) { + flags |= PRI_DEBUG_Q931_ALL; + } + if (strstr(in, "q931_dump")) { flags |= PRI_DEBUG_Q931_DUMP; } @@ -153,14 +184,6 @@ static int parse_debug(const char *in) flags |= PRI_DEBUG_AOC; } - if (strstr(in, "all")) { - flags |= PRI_DEBUG_ALL; - } - - if (strstr(in, "none")) { - flags = 0; - } - return flags; } @@ -400,16 +423,30 @@ static int pri_io_read(struct pri *pri, void *buf, int buflen) res = (int)len; memset(&((unsigned char*)buf)[res],0,2); - res += 2; + /* libpri passive q921 raw dump does not work for all frames */ + if (pritap->debug & PRI_DEBUG_Q921_RAW) { + char hbuf[2048] = { 0 }; + + print_hex_bytes(buf, len, hbuf, sizeof(hbuf)); + ftdm_log_chan(pritap->dchan, FTDM_LOG_DEBUG, "READ %"FTDM_SIZE_FMT"\n%s\n", len, hbuf); + } return res; } static int pri_io_write(struct pri *pri, void *buf, int buflen) { pritap_t *pritap = pri_get_userdata(pri); - ftdm_size_t len = buflen - 2; + ftdm_size_t len = buflen - 2; + + /* libpri passive q921 raw dump does not work for all frames */ + if (pritap->debug & PRI_DEBUG_Q921_RAW) { + char hbuf[2048] = { 0 }; + + print_hex_bytes(buf, len, hbuf, sizeof(hbuf)); + ftdm_log_chan(pritap->dchan, FTDM_LOG_DEBUG, "WRITE %"FTDM_SIZE_FMT"\n%s\n", len, hbuf); + } if (ftdm_channel_write(pritap->dchan, buf, buflen, &len) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_CRIT, "span %d D channel write failed! [%s]\n", pritap->span->span_id, pritap->dchan->last_error);