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