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