diff options
author | Harald Welte <laforge@gnumonks.org> | 2016-12-24 01:32:10 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2016-12-24 01:32:10 +0100 |
commit | 0e5091695445522a938d3fc1660fcf6743ffcd0d (patch) | |
tree | d703d607dd83278721a42d3ae933a2f2c21ec262 /src | |
parent | 98f6fadd96f69892e9c322f39754602ead6e3285 (diff) |
move DIAG MSG handling to separate file diag_msg.c
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/diag_msg.c | 54 | ||||
-rw-r--r-- | src/diag_msg.h | 7 | ||||
-rw-r--r-- | src/qxdm-log.c | 42 |
4 files changed, 64 insertions, 41 deletions
diff --git a/src/Makefile b/src/Makefile index e81eb5c..e78b5f9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,7 +4,7 @@ all: qxdm-log MODS_LOG = gprs_rlc.o gprs_mac.o diag_gsm.o diag_log.o diag_log_gsm.o diag_log_gprs.o diag_log_umts.o diag_log_qmi.o -qxdm-log: diagchar_hdlc.o diag_io.o qxdm-log.o protocol.o $(MODS_LOG) +qxdm-log: diagchar_hdlc.o diag_io.o qxdm-log.o diag_msg.o protocol.o $(MODS_LOG) $(CC) $(CPPFLAGS) -o $@ $^ $(LIBS) clean: diff --git a/src/diag_msg.c b/src/diag_msg.c new file mode 100644 index 0000000..71ec9ea --- /dev/null +++ b/src/diag_msg.c @@ -0,0 +1,54 @@ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include <osmocom/core/msgb.h> + +#include "protocol.h" +#include "diag_msg.h" +#include "diagcmd.h" + + +/* handler for EXT MSG */ +int diag_rx_ext_msg_f(struct diag_instance *di, struct msgb *msgb) +{ + const uint8_t *data = msgb_data(msgb); + const size_t len = msgb_length(msgb); + const struct ext_log_msg *msg; + const char *file = NULL, *fmt; + unsigned int num_args; + + if (len < sizeof(struct ext_log_msg)) { + printf("too short ext_log_msg.\n"); + return -1; + } + + msg = (struct ext_log_msg *) data; + num_args = msg->num_args; + fmt = (const char *) msg->params + num_args*sizeof(msg->params[0]); + file = fmt + strlen(fmt) + 1; + + printf("MSG(%u|%s:%u): ", diag_ts_to_epoch(msg->timestamp), file, msg->line_nr); + switch (num_args) { + case 0: + fputs(fmt, stdout); + break; + case 1: + printf(fmt, msg->params[0]); + break; + case 2: + printf(fmt, msg->params[0], msg->params[1]); + break; + case 3: + printf(fmt, msg->params[0], msg->params[1], msg->params[2]); + break; + case 4: + printf(fmt, msg->params[0], msg->params[1], msg->params[2], msg->params[3]); + break; + } + fputc('\n', stdout); + return 0; +} + + diff --git a/src/diag_msg.h b/src/diag_msg.h new file mode 100644 index 0000000..917afc2 --- /dev/null +++ b/src/diag_msg.h @@ -0,0 +1,7 @@ +#pragma once + +#include <osmocom/core/msgb.h> +#include "diag_io.h" + + +int diag_rx_ext_msg_f(struct diag_instance *di, struct msgb *msg); diff --git a/src/qxdm-log.c b/src/qxdm-log.c index 14f494a..c432d54 100644 --- a/src/qxdm-log.c +++ b/src/qxdm-log.c @@ -17,47 +17,9 @@ #include "diag_io.h" #include "protocol.h" #include "diag_log.h" +#include "diag_msg.h" #include "diagcmd.h" -/* handler for EXT MSG */ -static int diag_rx_ext_msg_f(const uint8_t *data, const size_t len) -{ - const struct ext_log_msg *msg; - const char *file = NULL, *fmt; - unsigned int num_args; - - if (len < sizeof(struct ext_log_msg)) { - printf("too short ext_log_msg.\n"); - return -1; - } - - msg = (struct ext_log_msg *) data; - num_args = msg->num_args; - fmt = (const char *) msg->params + num_args*sizeof(msg->params[0]); - file = fmt + strlen(fmt) + 1; - - printf("MSG(%u|%s:%u): ", diag_ts_to_epoch(msg->timestamp), file, msg->line_nr); - switch (num_args) { - case 0: - fputs(fmt, stdout); - break; - case 1: - printf(fmt, msg->params[0]); - break; - case 2: - printf(fmt, msg->params[0], msg->params[1]); - break; - case 3: - printf(fmt, msg->params[0], msg->params[1], msg->params[2]); - break; - case 4: - printf(fmt, msg->params[0], msg->params[1], msg->params[2], msg->params[3]); - break; - } - fputc('\n', stdout); - return 0; -} - /*********/ static void diag_process_msg(struct diag_instance *di, struct msgb *msg) @@ -67,7 +29,7 @@ static void diag_process_msg(struct diag_instance *di, struct msgb *msg) diag_log_handle(di, msg); break; case DIAG_EXT_MSG_F: - diag_rx_ext_msg_f(msgb_data(msg), msgb_length(msg)); + diag_rx_ext_msg_f(di, msg); break; default: printf("Got %d bytes data of unknown payload type 0x%02x: %s\n", |