blob: 71ec9ea9cc1b7186094a2a3aa8974d37fe02d2b2 [file] [log] [blame]
Harald Welte0e509162016-12-24 01:32:10 +01001
2#include <stdlib.h>
3#include <stdio.h>
4#include <string.h>
5
6#include <osmocom/core/msgb.h>
7
8#include "protocol.h"
9#include "diag_msg.h"
10#include "diagcmd.h"
11
12
13/* handler for EXT MSG */
14int diag_rx_ext_msg_f(struct diag_instance *di, struct msgb *msgb)
15{
16 const uint8_t *data = msgb_data(msgb);
17 const size_t len = msgb_length(msgb);
18 const struct ext_log_msg *msg;
19 const char *file = NULL, *fmt;
20 unsigned int num_args;
21
22 if (len < sizeof(struct ext_log_msg)) {
23 printf("too short ext_log_msg.\n");
24 return -1;
25 }
26
27 msg = (struct ext_log_msg *) data;
28 num_args = msg->num_args;
29 fmt = (const char *) msg->params + num_args*sizeof(msg->params[0]);
30 file = fmt + strlen(fmt) + 1;
31
32 printf("MSG(%u|%s:%u): ", diag_ts_to_epoch(msg->timestamp), file, msg->line_nr);
33 switch (num_args) {
34 case 0:
35 fputs(fmt, stdout);
36 break;
37 case 1:
38 printf(fmt, msg->params[0]);
39 break;
40 case 2:
41 printf(fmt, msg->params[0], msg->params[1]);
42 break;
43 case 3:
44 printf(fmt, msg->params[0], msg->params[1], msg->params[2]);
45 break;
46 case 4:
47 printf(fmt, msg->params[0], msg->params[1], msg->params[2], msg->params[3]);
48 break;
49 }
50 fputc('\n', stdout);
51 return 0;
52}
53
54