Revert "Fixup: tvb_* -> tvb_captured"
[metze/wireshark/wip.git] / epan / dissectors / packet-l1-events.c
1 /* packet-l1-events.c
2  * Routines for text-based layer 1 messages in EyeSDN trace files
3  *
4  * (C) Rolf Fiedler 2008, based on packet-text-media.c by Olivier Biot, 2004.
5  *
6  * Refer to the AUTHORS file or the AUTHORS section in the man page
7  * for contacting the author(s) of this file.
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26  */
27
28 /* Edit this file with 4-space tabs */
29
30 #include "config.h"
31
32 #include <glib.h>
33
34 #include <epan/packet.h>
35 #include <wiretap/wtap.h>
36 #include <epan/strutil.h>
37
38 void proto_register_l1_events(void);
39 void proto_reg_handoff_l1_events(void);
40
41 /*
42  * dissector for line-based text messages from layer 1
43  */
44
45 /* Filterable header fields */
46 static gint proto_l1_events = -1;
47
48 /* Subtrees */
49 static gint ett_l1_events = -1;
50
51 static int
52 dissect_l1_events(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
53 {
54         proto_tree      *subtree;
55         proto_item      *ti;
56         gint            offset = 0, next_offset;
57         gint            len;
58         const char      *data_name;
59
60         data_name = pinfo->match_string;
61         if (! (data_name && data_name[0])) {
62                 /*
63                  * No information from "match_string"
64                  */
65                 data_name = (char *)data;
66                 if (! (data_name && data_name[0])) {
67                         /*
68                          * No information from dissector data
69                          */
70                         data_name = (char *)(pinfo->private_data);
71                         if (! (data_name && data_name[0])) {
72                                 /*
73                                  * No information from "private_data"
74                                  */
75                                 data_name = NULL;
76                         }
77                 }
78         }
79
80         col_set_str(pinfo->cinfo, COL_PROTOCOL, "Layer1");
81         col_set_str(pinfo->cinfo, COL_DEF_SRC,
82                             pinfo->pseudo_header->l1event.uton? "TE" : "NT");
83         len = tvb_find_line_end(tvb, 0, tvb_ensure_length_remaining(tvb, 0),
84                                         &next_offset, FALSE);
85         if(len>0)
86                 col_add_str(pinfo->cinfo, COL_INFO, tvb_format_text(tvb, 0, len));
87
88         if (tree) {
89                 ti = proto_tree_add_item(tree, proto_l1_events,
90                                 tvb, 0, -1, ENC_NA);
91                 if (data_name)
92                         proto_item_append_text(ti, ": %s", data_name);
93                 subtree = proto_item_add_subtree(ti, ett_l1_events);
94                 /* Read the media line by line */
95                 while (tvb_reported_length_remaining(tvb, offset) != 0) {
96                         /*
97                          * XXX - we need to be passed the parameters
98                          * of the content type via "pinfo->private_data",
99                          * so that we know the character set.  We'd
100                          * have to handle that character set, which
101                          * might be a multibyte character set such
102                          * as "iso-10646-ucs-2", or might require other
103                          * special processing.
104                          */
105                         len = tvb_find_line_end(tvb, offset,
106                                         tvb_ensure_length_remaining(tvb, offset),
107                                         &next_offset, FALSE);
108                         if (len == -1)
109                                 break;
110
111                         /* We use next_offset - offset instead of len in the
112                          * call to proto_tree_add_format_text() so it will include the
113                          * line terminator(s) (\r and/or \n) in the display.
114                          */
115                         proto_tree_add_format_text(subtree, tvb, offset, next_offset - offset);
116                         offset = next_offset;
117                 }
118         }
119
120         return tvb_length(tvb);
121 }
122
123 void
124 proto_register_l1_events(void)
125 {
126         static gint *ett[] = {
127                 &ett_l1_events,
128         };
129
130         proto_register_subtree_array(ett, array_length(ett));
131
132         proto_l1_events = proto_register_protocol(
133                         "Layer 1 Event Messages", /* Long name */
134                         "Layer 1 Events",         /* Short name */
135                         "data-l1-events");              /* Filter name */
136         new_register_dissector("data-l1-events", dissect_l1_events, proto_l1_events);
137 }
138
139 void
140 proto_reg_handoff_l1_events(void)
141 {
142         dissector_handle_t l1_events_handle;
143
144         l1_events_handle = find_dissector("data-l1-events");
145         dissector_add_uint("wtap_encap", WTAP_ENCAP_LAYER1_EVENT, l1_events_handle); /* for text msgs from trace files */
146 }