blob: 40290b66c4536b8abc9d2870b5ac4109459f677e [file] [log] [blame]
Harald Welteccea8dd2016-12-24 10:27:55 +01001/*
2 * (C) 2013-2016 by Harald Welte <laforge@gnumonks.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
Harald Weltefaea7542016-12-24 01:21:03 +010019#include <stdio.h>
20
21#include "diag_log.h"
Harald Welte84ec50f2016-12-24 10:16:00 +010022#include "protocol/diag_log_gsm.h"
Harald Weltefaea7542016-12-24 01:21:03 +010023
24
25static void handle_rr_sig_msg(struct log_hdr *lh, struct msgb *msg)
26{
27 struct diag_gsm_rr_msg *rm = (struct diag_gsm_rr_msg *) msgb_data(msg);
28
29 printf("RR: %02x %02x %u: %s\n", rm->chan_type, rm->msg_type,
30 rm->length, osmo_hexdump(msgb_data(msg), rm->length));
31}
32
33static void handle_rr_state_msg(struct log_hdr *lh, struct msgb *msg)
34{
35 struct diag_gsm_rr_state *rrs = (struct diag_gsm_rr_state *) msgb_data(msg);
36 printf("RR-STATE { state=%s, substate=%u, status=%u, mode=%u }\n",
37 get_value_string(diag_gsm_rr_st_vals, rrs->state)
38 , rrs->substate, rrs->status, rrs->mode);
39
40}
41
Harald Welte0512d9d2017-01-21 11:01:45 +010042static void handle_mdsp_cmd(struct log_hdr *lh, struct msgb *msg)
43{
44 struct diag_mdsp_log_cmds *dmlcs = (struct diag_mdsp_log_cmds *) msgb_data(msg);
45 int i;
46
47 printf("MDSP-COMMANDS { num_cmds=%u, cmds=[ ", dmlcs->num_cmds);
48
49 for (i = 0; i < dmlcs->num_cmds; i++) {
50 struct diag_mdsp_log_cmd *cmd = &dmlcs->cmds[i];
51 printf("{ fn=%u, cnt=%u, seq=%u, cmd=%u, params=[ %u, %u, %u, %u, %u ] }",
52 cmd->fn, cmd->cnt, cmd->seq, cmd->cmd,
53 cmd->params[0], cmd->params[1], cmd->params[2], cmd->params[3],
54 cmd->params[4]);
55 if (i+1 != dmlcs->num_cmds)
56 printf(", ");
57
58 }
59 printf(" ] }\n");
60}
61
62static void handle_l2_state(struct log_hdr *lh, struct msgb *msg)
63{
64 struct diag_gsm_l2_state *l2s = (struct diag_gsm_l2_state *) msgb_data(msg);
65
66 printf("L2-STATE { sapi=%u, ", l2s->sapi);
67 switch (l2s->sapi) {
68 case 0:
69 printf("l2_state=%s, ",
70 get_value_string(diag_gsm_l2_sapi0_st_vals, l2s->l2_state));
71 break;
72 case 3:
73 printf("l2_state=%s, ",
74 get_value_string(diag_gsm_l2_sapi3_st_vals, l2s->l2_state));
75 break;
76 default:
77 break;
78 }
79 printf("l2_event=%s }\n",
80 get_value_string(diag_gsm_l2_event_vals, l2s->l2_event));
81}
82
83static void handle_l2_transm_status(struct log_hdr *lh, struct msgb *msg)
84{
85 struct diag_gsm_l2_transm_status *lts = (struct diag_gsm_l2_transm_status *) msgb_data(msg);
86
87 printf("L2-TRANSM-STATUS { sapi=%u, chan_type=%u, vs=%u, va=%u, vr=%u, retrans_ctr=%u, seq_err=%u, frame_type=%u, msg_entries=%u, seg_entries=%u }\n",
88 lts->sapi, lts->channel_type, lts->vs, lts->va, lts->vr, lts->retrans_ctr,
89 lts->seq_err, lts->frame_type, lts->msg_entries, lts->seg_entries);
90}
91
Harald Weltefaea7542016-12-24 01:21:03 +010092static const struct diag_log_dispatch_tbl log_tbl[] = {
93 { GSM(LOG_GSM_RR_SIGNALING_MESSAGE_C), handle_rr_sig_msg },
94 { GSM(LOG_GSM_RR_STATE_C), handle_rr_state_msg },
Harald Welte0512d9d2017-01-21 11:01:45 +010095 { GSM(LOG_GSM_MDSP_CMD_C), handle_mdsp_cmd },
96 { GSM(LOG_GSM_L2_STATE_C), handle_l2_state },
97 { GSM(LOG_GSM_L2_TRANSMISSION_STATUS_C), handle_l2_transm_status},
Harald Weltefaea7542016-12-24 01:21:03 +010098};
99
100static __attribute__((constructor)) void on_dso_load_gsm(void)
101{
102 diag_log_reg_dispatch(log_tbl, ARRAY_SIZE(log_tbl));
103}