Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-gsmtap_log.c
blobd17a5524bb73c31d86e133cc8f7e9be5fa8f1dcb
1 /* packet-gsmtap-log.c
2 * Routines for GSMTAP logging packets
4 * (C) 2016 by Harald Welte <laforge@gnumonks.org>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "config.h"
15 #include <epan/packet.h>
16 #include "packet-gsmtap.h"
18 void proto_register_gsmtap_log(void);
19 void proto_reg_handoff_gsmtap_log(void);
21 static dissector_handle_t gsmtap_log_handle;
23 static int proto_gsmtap_log;
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;
34 static int ett_gsmtap_log;
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 }
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_)
50 proto_item *ti;
51 proto_tree *log_tree;
52 int offset = 0;
53 int log_str_len;
54 unsigned log_pid, log_level, log_src_line;
55 const char *log_str;
56 const uint8_t *log_ident, *log_subsys, *log_src_fname;
58 ti = proto_tree_add_item(tree, proto_gsmtap_log, tvb, 0, -1, ENC_NA);
59 log_tree = proto_item_add_subtree(ti, ett_gsmtap_log);
61 proto_tree_add_item(log_tree, hf_log_ts, tvb, offset, 8, ENC_TIME_SECS_USECS|ENC_BIG_ENDIAN);
62 offset += 8;
63 proto_tree_add_item_ret_string(log_tree, hf_log_ident, tvb, offset, 16, ENC_NA, pinfo->pool, &log_ident);
64 offset += 16;
65 proto_tree_add_item_ret_uint(log_tree, hf_log_pid, tvb, offset, 4, ENC_BIG_ENDIAN, &log_pid);
66 offset += 4;
67 proto_tree_add_item_ret_uint(log_tree, hf_log_level, tvb, offset++, 1, ENC_NA, &log_level);
68 offset += 3; /* pad octets */
69 proto_tree_add_item_ret_string(log_tree, hf_log_subsys, tvb, offset, 16, ENC_NA, pinfo->pool, &log_subsys);
70 offset += 16;
71 proto_tree_add_item_ret_string(log_tree, hf_log_file_name, tvb, offset, 32, ENC_NA, pinfo->pool, &log_src_fname);
72 offset += 32;
73 proto_tree_add_item_ret_uint(log_tree, hf_log_file_line, tvb, offset, 4, ENC_BIG_ENDIAN, &log_src_line);
74 offset += 4;
76 /* actual log message */
77 log_str_len = tvb_captured_length_remaining(tvb, offset);
78 proto_tree_add_item(log_tree, hf_log_string, tvb, offset, log_str_len, ENC_ASCII);
80 log_str = tvb_format_stringzpad_wsp(pinfo->pool, tvb, offset, log_str_len);
81 col_append_str(pinfo->cinfo, COL_INFO, log_str);
83 proto_item_append_text(ti, " %s(%u): %s/%d: %s:%u %s",
84 log_ident, log_pid, log_subsys, log_level,
85 log_src_fname, log_src_line, log_str);
86 return tvb_captured_length(tvb);
89 void
90 proto_register_gsmtap_log(void)
92 static hf_register_info hf[] = {
93 { &hf_log_ident, { "Application", "gsmtap_log.ident",
94 FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL } },
95 { &hf_log_subsys, { "Subsystem", "gsmtap_log.subsys",
96 FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL } },
97 { &hf_log_file_name, { "Source File Name", "gsmtap_log.src_file.name",
98 FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL } },
99 { &hf_log_file_line, { "Source File Line Number", "gsmtap_log.src_file.line_nr",
100 FT_UINT32, BASE_DEC, NULL, 0, NULL, HFILL } },
101 { &hf_log_ts, { "Timestamp", "gsmtap_log.timestamp",
102 FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0, NULL, HFILL } },
103 { &hf_log_pid, { "Process ID", "gsmtap_log.pid",
104 FT_UINT32, BASE_DEC, NULL, 0, NULL, HFILL } },
105 { &hf_log_level, { "Log Level", "gsmtap_log.level",
106 FT_UINT8, BASE_DEC, VALS(gsmtap_log_levels), 0, NULL, HFILL } },
107 { &hf_log_string, { "String", "gsmtap_log.string",
108 FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL } },
111 static int *ett[] = {
112 &ett_gsmtap_log,
115 proto_gsmtap_log = proto_register_protocol("GSMTAP libosmocore logging", "GSMTAP-LOG", "gsmtap_log");
116 proto_register_field_array(proto_gsmtap_log, hf, array_length(hf));
117 proto_register_subtree_array(ett, array_length(ett));
119 gsmtap_log_handle = register_dissector("gsmtap_log", dissect_gsmtap_log, proto_gsmtap_log);
122 void
123 proto_reg_handoff_gsmtap_log(void)
125 dissector_add_uint("gsmtap.type", GSMTAP_TYPE_OSMOCORE_LOG, gsmtap_log_handle);
129 * Editor modelines - https://www.wireshark.org/tools/modelines.html
131 * Local variables:
132 * c-basic-offset: 8
133 * tab-width: 8
134 * indent-tabs-mode: t
135 * End:
137 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
138 * :indentSize=8:tabSize=8:noTabs=false: