Coverage Report

Created: 2025-02-15 06:25

/src/wireshark/epan/dissectors/packet-gsmtap_log.c
Line
Count
Source
1
/* packet-gsmtap-log.c
2
 * Routines for GSMTAP logging packets
3
 *
4
 * (C) 2016 by Harald Welte <laforge@gnumonks.org>
5
 *
6
 * Wireshark - Network traffic analyzer
7
 * By Gerald Combs <gerald@wireshark.org>
8
 * Copyright 1998 Gerald Combs
9
 *
10
 * SPDX-License-Identifier: GPL-2.0-or-later
11
 */
12
13
#include "config.h"
14
15
#include <epan/packet.h>
16
#include "packet-gsmtap.h"
17
18
void proto_register_gsmtap_log(void);
19
void proto_reg_handoff_gsmtap_log(void);
20
21
static dissector_handle_t gsmtap_log_handle;
22
23
static int proto_gsmtap_log;
24
25
static int hf_log_ident;
26
static int hf_log_subsys;
27
static int hf_log_file_name;
28
static int hf_log_file_line;
29
static int hf_log_ts;
30
static int hf_log_pid;
31
static int hf_log_level;
32
static int hf_log_string;
33
34
static int ett_gsmtap_log;
35
36
/* from libosmocore include/osmocom/core/logging.h */
37
static const value_string gsmtap_log_levels[] = {
38
  { 1,  "DEBUG" },
39
  { 3,  "INFO" },
40
  { 5,  "NOTICE" },
41
  { 7,  "ERROR" },
42
  { 8,  "FATAL" },
43
  { 0, NULL }
44
};
45
46
/* dissect a GSMTAP header and hand payload off to respective dissector */
47
static int
48
dissect_gsmtap_log(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void * data _U_)
49
16
{
50
16
  proto_item *ti;
51
16
  proto_tree *log_tree;
52
16
  int offset = 0;
53
16
  int log_str_len;
54
16
  unsigned log_pid, log_level, log_src_line;
55
16
  const char *log_str;
56
16
  const uint8_t *log_ident, *log_subsys, *log_src_fname;
57
58
16
  ti = proto_tree_add_item(tree, proto_gsmtap_log, tvb, 0, -1, ENC_NA);
59
16
  log_tree = proto_item_add_subtree(ti, ett_gsmtap_log);
60
61
16
  proto_tree_add_item(log_tree, hf_log_ts, tvb, offset, 8, ENC_TIME_SECS_USECS|ENC_BIG_ENDIAN);
62
16
  offset += 8;
63
16
  proto_tree_add_item_ret_string(log_tree, hf_log_ident, tvb, offset, 16, ENC_NA, pinfo->pool, &log_ident);
64
16
  offset += 16;
65
16
  proto_tree_add_item_ret_uint(log_tree, hf_log_pid, tvb, offset, 4, ENC_BIG_ENDIAN, &log_pid);
66
16
  offset += 4;
67
16
  proto_tree_add_item_ret_uint(log_tree, hf_log_level, tvb, offset++, 1, ENC_NA, &log_level);
68
16
  offset += 3; /* pad octets */
69
16
  proto_tree_add_item_ret_string(log_tree, hf_log_subsys, tvb, offset, 16, ENC_NA, pinfo->pool, &log_subsys);
70
16
  offset += 16;
71
16
  proto_tree_add_item_ret_string(log_tree, hf_log_file_name, tvb, offset, 32, ENC_NA, pinfo->pool, &log_src_fname);
72
16
  offset += 32;
73
16
  proto_tree_add_item_ret_uint(log_tree, hf_log_file_line, tvb, offset, 4, ENC_BIG_ENDIAN, &log_src_line);
74
16
  offset += 4;
75
76
  /* actual log message */
77
16
  log_str_len = tvb_captured_length_remaining(tvb, offset);
78
16
  proto_tree_add_item(log_tree, hf_log_string, tvb, offset, log_str_len, ENC_ASCII);
79
80
16
  log_str = tvb_format_stringzpad_wsp(pinfo->pool, tvb, offset, log_str_len);
81
16
  col_append_str(pinfo->cinfo, COL_INFO, log_str);
82
83
16
  proto_item_append_text(ti, " %s(%u): %s/%d: %s:%u %s",
84
16
      log_ident, log_pid, log_subsys, log_level,
85
16
      log_src_fname, log_src_line, log_str);
86
16
  return tvb_captured_length(tvb);
87
16
}
88
89
void
90
proto_register_gsmtap_log(void)
91
14
{
92
14
  static hf_register_info hf[] = {
93
14
    { &hf_log_ident, { "Application", "gsmtap_log.ident",
94
14
      FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL } },
95
14
    { &hf_log_subsys, { "Subsystem", "gsmtap_log.subsys",
96
14
      FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL } },
97
14
    { &hf_log_file_name, { "Source File Name", "gsmtap_log.src_file.name",
98
14
      FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL } },
99
14
    { &hf_log_file_line, { "Source File Line Number", "gsmtap_log.src_file.line_nr",
100
14
      FT_UINT32, BASE_DEC, NULL, 0, NULL, HFILL } },
101
14
    { &hf_log_ts, { "Timestamp", "gsmtap_log.timestamp",
102
14
      FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0, NULL, HFILL } },
103
14
    { &hf_log_pid, { "Process ID", "gsmtap_log.pid",
104
14
      FT_UINT32, BASE_DEC, NULL, 0, NULL, HFILL } },
105
14
    { &hf_log_level, { "Log Level", "gsmtap_log.level",
106
14
      FT_UINT8, BASE_DEC, VALS(gsmtap_log_levels), 0, NULL, HFILL } },
107
14
    { &hf_log_string, { "String", "gsmtap_log.string",
108
14
      FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL } },
109
14
  };
110
111
14
  static int *ett[] = {
112
14
    &ett_gsmtap_log,
113
14
  };
114
115
14
  proto_gsmtap_log = proto_register_protocol("GSMTAP libosmocore logging", "GSMTAP-LOG", "gsmtap_log");
116
14
  proto_register_field_array(proto_gsmtap_log, hf, array_length(hf));
117
14
  proto_register_subtree_array(ett, array_length(ett));
118
119
14
  gsmtap_log_handle = register_dissector("gsmtap_log", dissect_gsmtap_log, proto_gsmtap_log);
120
14
}
121
122
void
123
proto_reg_handoff_gsmtap_log(void)
124
14
{
125
14
  dissector_add_uint("gsmtap.type", GSMTAP_TYPE_OSMOCORE_LOG, gsmtap_log_handle);
126
14
}
127
128
/*
129
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
130
 *
131
 * Local variables:
132
 * c-basic-offset: 8
133
 * tab-width: 8
134
 * indent-tabs-mode: t
135
 * End:
136
 *
137
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
138
 * :indentSize=8:tabSize=8:noTabs=false:
139
 */