Fix for bug 5422:
[obnox/wireshark/wip.git] / epan / dissectors / packet-tte-pcf.c
1 /* packet-tte-pcf.c
2  * Routines for Time Triggered Ethernet Protocol Control Frame dissection
3  *
4  * Author: Valentin Ecker
5  * Author: Benjamin Roch, benjamin.roch (AT) tttech.com
6  *
7  * TTTech Computertechnik AG, Austria.
8  * http://www.tttech.com/solutions/ttethernet/
9  *
10  * $Id$
11  *
12  * Wireshark - Network traffic analyzer
13  * By Gerald Combs <gerald@wireshark.org>
14  * Copyright 1998 Gerald Combs
15  *
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
29  * USA.
30  */
31
32 #ifdef HAVE_CONFIG_H
33  #include "config.h"
34 #endif
35
36 #include <stdlib.h>
37 #include <glib.h>
38
39 #include <epan/packet.h>
40 #include <epan/etypes.h>
41
42 #include "packet-tte.h"
43
44 /* Initialize the protocol and registered fields */
45 static int proto_tte_pcf = -1;
46
47 static int hf_tte_pcf = -1;
48 static int hf_tte_pcf_ic = -1;
49 static int hf_tte_pcf_mn = -1;
50 static int hf_tte_pcf_res0 = -1;
51 static int hf_tte_pcf_sp = -1;
52 static int hf_tte_pcf_sd = -1;
53 static int hf_tte_pcf_type = -1;
54 static int hf_tte_pcf_res1 = -1;
55 static int hf_tte_pcf_tc = -1;
56
57 /* Initialize the subtree pointers */
58 static gint ett_tte_pcf = -1;
59
60 static const value_string pcf_type_str_vals[] = 
61     { {2, "integration frame"}
62     , {4, "coldstart frame"}
63     , {8, "coldstart ack frame"}
64     , {0, NULL}
65     };
66
67
68 /* Code to actually dissect the packets */
69 static void
70 dissect_tte_pcf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
71 {
72     /* Set up structures needed to add the protocol subtree and manage it */
73     proto_item *tte_pcf_root_item;
74     proto_tree *tte_pcf_tree;
75
76     /* variables used to store the fields displayed in the info_column */
77     guint8 sync_priority = 0;
78     guint8 sync_domain   = 0;
79
80     /* Check that there's enough data */
81     if (tvb_length(tvb) < TTE_PCF_LENGTH )
82     {
83         return;
84     }
85
86     /* get sync_priority and sync_domain */
87     sync_priority = tvb_get_guint8(tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
88         TTE_PCF_RES0_LENGTH);
89     sync_domain = tvb_get_guint8(tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
90         TTE_PCF_RES0_LENGTH+TTE_PCF_SP_LENGTH);
91
92     /* Make entries in Protocol column and Info column on summary display */
93     col_set_str(pinfo->cinfo, COL_PROTOCOL, "PCF");
94
95     col_add_fstr(pinfo->cinfo, COL_INFO,
96             "Sync Domain: 0x%02X  Sync Priority: 0x%02X",
97             sync_domain, sync_priority);
98
99     if (tree) {
100
101         /* create display subtree for the protocol */
102         tte_pcf_root_item = proto_tree_add_item(tree, proto_tte_pcf, tvb, 0,
103             TTE_PCF_LENGTH, FALSE);
104
105         tte_pcf_tree = proto_item_add_subtree(tte_pcf_root_item, ett_tte_pcf);
106
107         proto_tree_add_item(tte_pcf_tree,
108             hf_tte_pcf_ic, tvb, 0, TTE_PCF_IC_LENGTH, FALSE);
109
110         proto_tree_add_item(tte_pcf_tree,
111             hf_tte_pcf_mn, tvb, TTE_PCF_IC_LENGTH, TTE_PCF_MN_LENGTH, FALSE);
112
113      /* RESERVED FIELD --- will not be displayed */
114      /* proto_tree_add_item(tte_pcf_tree,
115             hf_tte_pcf_res0, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH,
116             TTE_PCF_RES0_LENGTH, FALSE); */
117
118         proto_tree_add_item(tte_pcf_tree,
119             hf_tte_pcf_sp, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
120             TTE_PCF_RES0_LENGTH, TTE_PCF_SP_LENGTH, FALSE);
121
122         proto_tree_add_item(tte_pcf_tree,
123             hf_tte_pcf_sd, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
124             TTE_PCF_RES0_LENGTH+TTE_PCF_SP_LENGTH, TTE_PCF_SD_LENGTH, FALSE);
125
126         proto_tree_add_item(tte_pcf_tree,
127             hf_tte_pcf_type, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
128             TTE_PCF_RES0_LENGTH+TTE_PCF_SP_LENGTH+TTE_PCF_SD_LENGTH,
129             TTE_PCF_TYPE_LENGTH, FALSE);
130
131      /* RESERVED FIELD --- will not be displayed */
132      /* proto_tree_add_item(tte_pcf_tree,
133             hf_tte_pcf_res1, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
134             TTE_PCF_RES0_LENGTH+TTE_PCF_SP_LENGTH+TTE_PCF_SD_LENGTH+
135             TTE_PCF_TYPE_LENGTH, TTE_PCF_RES1_LENGTH, FALSE); */
136
137         proto_tree_add_item(tte_pcf_tree,
138             hf_tte_pcf_tc, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
139             TTE_PCF_RES0_LENGTH+TTE_PCF_SP_LENGTH+TTE_PCF_SD_LENGTH+
140             TTE_PCF_TYPE_LENGTH+TTE_PCF_RES1_LENGTH, TTE_PCF_TC_LENGTH, FALSE);
141     }
142
143 }
144
145
146 void
147 proto_register_tte_pcf(void)
148 {
149     static hf_register_info hf[] = {
150
151         { &hf_tte_pcf,
152             { "Protocol Control Frame", "tte.pcf",
153             FT_BYTES, BASE_NONE, NULL, 0x0,
154             NULL, HFILL }
155         },
156         { &hf_tte_pcf_ic,
157             { "Integration Cycle", "tte.pcf.ic",
158             FT_UINT32, BASE_HEX, NULL, 0x0,
159             NULL, HFILL }
160         },
161             { &hf_tte_pcf_mn,
162             { "Membership New", "tte.pcf.mn",
163             FT_UINT32, BASE_HEX, NULL, 0x0,
164             NULL, HFILL }
165         },
166             { &hf_tte_pcf_res0,
167             { "Reserved 0", "tte.pcf.res0",
168             FT_UINT32, BASE_HEX, NULL, 0x0,
169             NULL, HFILL }
170         },
171         { &hf_tte_pcf_sp,
172             { "Sync Priority", "tte.pcf.sp",
173             FT_UINT8, BASE_HEX, NULL, 0x0,
174             NULL, HFILL }
175         },
176         { &hf_tte_pcf_sd,
177             { "Sync Domain", "tte.pcf.sd",
178             FT_UINT8, BASE_HEX, NULL, 0x0,
179             NULL, HFILL }
180         },
181         { &hf_tte_pcf_type,
182             { "Type", "tte.pcf.type",
183             FT_UINT8, BASE_HEX, VALS(pcf_type_str_vals), 0x0F,
184             NULL, HFILL }
185         },
186         { &hf_tte_pcf_res1,
187             { "Reserved 1", "tte.pcf.res1",
188             FT_BYTES, BASE_NONE, NULL, 0x0,
189             NULL, HFILL }
190         },
191         { &hf_tte_pcf_tc,
192             { "Transparent Clock", "tte.pcf.tc",
193             FT_UINT64, BASE_HEX, NULL, 0x0,
194             NULL, HFILL }
195         }
196     };
197
198     /* Setup protocol subtree array */
199     static gint *ett[] = {
200         &ett_tte_pcf
201     };
202
203     /* Register the protocol name and description */
204     proto_tte_pcf = proto_register_protocol("TTEthernet Protocol Control Frame",
205         "TTE PCF", "tte_pcf");
206
207     /* Required function calls to register header fields and subtrees used */
208     proto_register_field_array(proto_tte_pcf, hf, array_length(hf));
209     proto_register_subtree_array(ett, array_length(ett));
210
211     register_dissector("tte_pcf", dissect_tte_pcf, proto_tte_pcf);
212
213 }
214
215
216 void
217 proto_reg_handoff_tte_pcf(void)
218 {
219     dissector_handle_t tte_pcf_handle;
220
221     /* initialize the pcf handle */
222     tte_pcf_handle = find_dissector("tte_pcf");
223
224     dissector_add("ethertype", ETHERTYPE_TTE_PCF, tte_pcf_handle);
225
226 }
227