aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2016-12-23 20:04:27 +0100
committerHarald Welte <laforge@gnumonks.org>2016-12-23 20:14:51 +0100
commitcd877f1398b5261308c08e63facd3544b92115dc (patch)
treefea0acf258d0b912ce64223e9c135173e47e8d85
parente1d8ef99cdabf6b8df5e37f71322248c829b50cb (diff)
dump_log: better understanding of "ext_msg" log header
I now have a much better understanding of the extended message header that is used for formatting "printf" style log messages from the target.
-rw-r--r--src/protocol.h17
-rw-r--r--src/qxdm-log.c69
2 files changed, 35 insertions, 51 deletions
diff --git a/src/protocol.h b/src/protocol.h
index 13a2da9..ac9a8b9 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -12,14 +12,19 @@
*/
struct ext_log_msg {
+ /* msg_hdr_type equivalent */
uint8_t type;
- uint16_t unknown1; /* 0x00 0x03 type??? */
- uint16_t unknown2; /* 0x00 0x06 type??? */
+ uint8_t ts_type; /* timestamp tyoe */
+ uint8_t num_args; /* number of arguments */
+ uint8_t drop_cnt; /* dropped messages */
uint64_t timestamp; /* More 32 bit but dm-commands.h */
- uint8_t unknown3[3]; /* 0x00 0x00 0x00 */
- uint32_t unknown4; /* 0x02 0x00 0x00 0x00 */
- int32_t params[3]; /* three params */
- uint8_t data[0]; /* two NULL terminated strings from here */
+
+ /* msg_desc_type */
+ uint16_t line_nr;
+ uint16_t subsys_id;
+ uint32_t subsys_mask;
+
+ int32_t params[0]; /* three params */
} __attribute__((packed));
diff --git a/src/qxdm-log.c b/src/qxdm-log.c
index 05cfe59..e9f268b 100644
--- a/src/qxdm-log.c
+++ b/src/qxdm-log.c
@@ -122,16 +122,9 @@ static int transmit_packet(int fd, const uint8_t *data, size_t data_len)
static int dump_log(const uint8_t *data, const size_t len)
{
- size_t i, file_len;
- size_t params = 0;
const struct ext_log_msg *msg;
- const char *file = NULL, *log;
- struct tm *tm;
- time_t now;
- const size_t str_len = len - offsetof(struct ext_log_msg, data);
-
- time(&now);
- tm = localtime(&now);
+ const char *file = NULL, *fmt;
+ unsigned int num_args;
if (len < sizeof(struct ext_log_msg)) {
printf("too short log message.\n");
@@ -139,43 +132,29 @@ static int dump_log(const uint8_t *data, const size_t len)
}
msg = (struct ext_log_msg *) data;
- log = (const char *) msg->data;
-
- /*
- * Check if it is null terminated and how many parameters it
- * might have. This counts all '%' but doesn't take '%%' into
- * account.
- */
- for (i = 0; i < str_len; ++i) {
- if (log[i] == '%')
- params += 1;
- else if (log[i] == '\0' && i + 1 < str_len) {
- file = &log[i + 1];
- file_len = str_len - i - 1;
- break;
- }
- }
-
- if (file_len == 0 || file[file_len - 1] != '\0') {
- printf("File too short or not null terminated\n");
- return -2;
- }
-
- if (params > 3) {
- printf("Too many parameters in the log message.\n");
- return -1;
- }
-
- if (!file) {
- printf("The file is not present..\n");
- return -2;
+ num_args = msg->num_args;
+ fmt = (const char *) msg->params + num_args*sizeof(msg->params[0]);
+ file = fmt + strlen(fmt) + 1;
+
+ printf("%"PRIu64" %-20s(%u): ", 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;
}
-
- printf("%.2d:%.2d:%.2d %-20s: ",
- tm->tm_hour, tm->tm_min, tm->tm_sec,
- file);
- printf(log, msg->params[0], msg->params[1], msg->params[2]);
- printf("\n");
+ fputc('\n', stdout);
return 0;
}