Harald Welte | ccea8dd | 2016-12-24 10:27:55 +0100 | [diff] [blame] | 1 | /* |
| 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 Welte | faea754 | 2016-12-24 01:21:03 +0100 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | |
| 21 | #include "diag_log.h" |
Harald Welte | 84ec50f | 2016-12-24 10:16:00 +0100 | [diff] [blame] | 22 | #include "protocol/diag_log_gsm.h" |
Harald Welte | faea754 | 2016-12-24 01:21:03 +0100 | [diff] [blame] | 23 | |
| 24 | |
| 25 | static 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 | |
Harald Welte | 1570b9f | 2017-01-21 11:15:50 +0100 | [diff] [blame^] | 29 | printf("RR: %s %02x %u: %s\n", |
| 30 | get_value_string(diag_gsm_l2_chantype_vals, rm->chan_type & 0x7f), |
| 31 | rm->msg_type, rm->length, osmo_hexdump(msgb_data(msg), rm->length)); |
Harald Welte | faea754 | 2016-12-24 01:21:03 +0100 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static void handle_rr_state_msg(struct log_hdr *lh, struct msgb *msg) |
| 35 | { |
| 36 | struct diag_gsm_rr_state *rrs = (struct diag_gsm_rr_state *) msgb_data(msg); |
| 37 | printf("RR-STATE { state=%s, substate=%u, status=%u, mode=%u }\n", |
| 38 | get_value_string(diag_gsm_rr_st_vals, rrs->state) |
| 39 | , rrs->substate, rrs->status, rrs->mode); |
| 40 | |
| 41 | } |
| 42 | |
Harald Welte | 0512d9d | 2017-01-21 11:01:45 +0100 | [diff] [blame] | 43 | static void handle_mdsp_cmd(struct log_hdr *lh, struct msgb *msg) |
| 44 | { |
| 45 | struct diag_mdsp_log_cmds *dmlcs = (struct diag_mdsp_log_cmds *) msgb_data(msg); |
| 46 | int i; |
| 47 | |
| 48 | printf("MDSP-COMMANDS { num_cmds=%u, cmds=[ ", dmlcs->num_cmds); |
| 49 | |
| 50 | for (i = 0; i < dmlcs->num_cmds; i++) { |
| 51 | struct diag_mdsp_log_cmd *cmd = &dmlcs->cmds[i]; |
| 52 | printf("{ fn=%u, cnt=%u, seq=%u, cmd=%u, params=[ %u, %u, %u, %u, %u ] }", |
| 53 | cmd->fn, cmd->cnt, cmd->seq, cmd->cmd, |
| 54 | cmd->params[0], cmd->params[1], cmd->params[2], cmd->params[3], |
| 55 | cmd->params[4]); |
| 56 | if (i+1 != dmlcs->num_cmds) |
| 57 | printf(", "); |
| 58 | |
| 59 | } |
| 60 | printf(" ] }\n"); |
| 61 | } |
| 62 | |
| 63 | static void handle_l2_state(struct log_hdr *lh, struct msgb *msg) |
| 64 | { |
| 65 | struct diag_gsm_l2_state *l2s = (struct diag_gsm_l2_state *) msgb_data(msg); |
| 66 | |
| 67 | printf("L2-STATE { sapi=%u, ", l2s->sapi); |
| 68 | switch (l2s->sapi) { |
| 69 | case 0: |
| 70 | printf("l2_state=%s, ", |
| 71 | get_value_string(diag_gsm_l2_sapi0_st_vals, l2s->l2_state)); |
| 72 | break; |
| 73 | case 3: |
| 74 | printf("l2_state=%s, ", |
| 75 | get_value_string(diag_gsm_l2_sapi3_st_vals, l2s->l2_state)); |
| 76 | break; |
| 77 | default: |
| 78 | break; |
| 79 | } |
| 80 | printf("l2_event=%s }\n", |
| 81 | get_value_string(diag_gsm_l2_event_vals, l2s->l2_event)); |
| 82 | } |
| 83 | |
| 84 | static void handle_l2_transm_status(struct log_hdr *lh, struct msgb *msg) |
| 85 | { |
| 86 | struct diag_gsm_l2_transm_status *lts = (struct diag_gsm_l2_transm_status *) msgb_data(msg); |
| 87 | |
Harald Welte | 1570b9f | 2017-01-21 11:15:50 +0100 | [diff] [blame^] | 88 | printf("L2-TRANSM-STATUS { sapi=%u, chan_type=%s, vs=%u, va=%u, vr=%u, retrans_ctr=%u, seq_err=%u, frame_type=%u, msg_entries=%u, seg_entries=%u }\n", |
| 89 | lts->sapi, |
| 90 | get_value_string(diag_gsm_l2_chantype_vals, lts->channel_type), |
| 91 | lts->vs, lts->va, lts->vr, lts->retrans_ctr, |
Harald Welte | 0512d9d | 2017-01-21 11:01:45 +0100 | [diff] [blame] | 92 | lts->seq_err, lts->frame_type, lts->msg_entries, lts->seg_entries); |
| 93 | } |
| 94 | |
Harald Welte | faea754 | 2016-12-24 01:21:03 +0100 | [diff] [blame] | 95 | static const struct diag_log_dispatch_tbl log_tbl[] = { |
| 96 | { GSM(LOG_GSM_RR_SIGNALING_MESSAGE_C), handle_rr_sig_msg }, |
| 97 | { GSM(LOG_GSM_RR_STATE_C), handle_rr_state_msg }, |
Harald Welte | 0512d9d | 2017-01-21 11:01:45 +0100 | [diff] [blame] | 98 | { GSM(LOG_GSM_MDSP_CMD_C), handle_mdsp_cmd }, |
| 99 | { GSM(LOG_GSM_L2_STATE_C), handle_l2_state }, |
| 100 | { GSM(LOG_GSM_L2_TRANSMISSION_STATUS_C), handle_l2_transm_status}, |
Harald Welte | faea754 | 2016-12-24 01:21:03 +0100 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | static __attribute__((constructor)) void on_dso_load_gsm(void) |
| 104 | { |
| 105 | diag_log_reg_dispatch(log_tbl, ARRAY_SIZE(log_tbl)); |
| 106 | } |