Always put editor-modelines at the end of the file ...
[metze/wireshark/wip.git] / plugins / ethercat / packet-ioraw.c
1 /* packet-ioraw.c
2  * Routines for ethercat packet disassembly
3  *
4  * Copyright (c) 2007 by Beckhoff Automation GmbH
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 /* Include files */
26
27 #include "config.h"
28
29 #include <glib.h>
30
31 #include <epan/packet.h>
32
33 #include "packet-ioraw.h"
34
35 void proto_register_ioraw(void);
36 void proto_reg_handoff_ioraw(void);
37
38 /* Define the ioraw proto */
39 int proto_ioraw  = -1;
40
41 static int ett_ioraw = -1;
42
43 /* static int hf_ioraw_summary = -1; */
44 static int hf_ioraw_header = -1;
45 static int hf_ioraw_data = -1;
46
47 /*ioraw*/
48 static void IoRawSummaryFormater( char *szText, int nMax)
49 {
50    g_snprintf ( szText, nMax, "Raw IO Data" );
51 }
52
53 static void dissect_ioraw(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
54 {
55    proto_item *ti;
56    proto_tree *ioraw_tree;
57    gint offset = 0;
58    char szText[200];
59    int nMax = sizeof(szText)-1;
60
61    guint ioraw_length = tvb_reported_length(tvb);
62
63    col_set_str(pinfo->cinfo, COL_PROTOCOL, "IO-RAW");
64
65    IoRawSummaryFormater(szText, nMax);
66    col_add_str(pinfo->cinfo, COL_INFO, szText);
67
68    if (tree)
69    {
70       ti = proto_tree_add_item(tree, proto_ioraw, tvb, 0, -1, ENC_NA);
71       ioraw_tree = proto_item_add_subtree(ti, ett_ioraw);
72
73       proto_item_append_text(ti,": %s",szText);
74       proto_tree_add_item(ioraw_tree, hf_ioraw_header, tvb, offset, IoRawParserHDR_Len, ENC_NA);
75       offset+=IoRawParserHDR_Len;
76
77       proto_tree_add_item(ioraw_tree, hf_ioraw_data, tvb, offset, ioraw_length - offset, ENC_NA);
78    }
79 }
80
81 void proto_register_ioraw(void)
82 {
83    static hf_register_info hf[] =
84       {
85 #if 0
86          { &hf_ioraw_summary,
87            { "Summary of the IoRaw Packet", "ioraw.summary",
88              FT_STRING, BASE_NONE, NULL, 0x0,
89              NULL, HFILL }
90          },
91 #endif
92          { &hf_ioraw_header, { "Header", "ioraw.header",
93                                FT_NONE, BASE_NONE, NULL, 0x0,
94                                NULL, HFILL }
95          },
96          { &hf_ioraw_data, { "VarData", "ioraw.data",
97                              FT_NONE, BASE_NONE, NULL, 0x0,
98                              NULL, HFILL }
99          }
100       };
101
102    static gint *ett[] =
103       {
104          &ett_ioraw
105       };
106
107    proto_ioraw = proto_register_protocol("TwinCAT IO-RAW",
108                                          "IO-RAW","ioraw");
109    proto_register_field_array(proto_ioraw,hf,array_length(hf));
110    proto_register_subtree_array(ett,array_length(ett));
111 }
112
113 void proto_reg_handoff_ioraw(void)
114 {
115    dissector_handle_t ioraw_handle;
116
117    ioraw_handle = create_dissector_handle(dissect_ioraw, proto_ioraw);
118
119    dissector_add_uint("ecatf.type", 3, ioraw_handle);
120 }
121
122 /*
123  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
124  *
125  * Local Variables:
126  * c-basic-offset: 3
127  * tab-width: 8
128  * indent-tabs-mode: nil
129  * End:
130  *
131  * vi: set shiftwidth=3 tabstop=8 expandtab:
132  * :indentSize=3:tabSize=8:noTabs=true:
133  */