Fixup: tvb_get_string(z) -> tvb_get_string(z)_enc
[metze/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  * 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 #include "config.h"
31
32 #include <glib.h>
33
34 #include <epan/packet.h>
35 #include <epan/etypes.h>
36
37 #include "packet-tte.h"
38
39 void proto_register_tte_pcf(void);
40 void proto_reg_handoff_tte_pcf(void);
41
42 /* Initialize the protocol and registered fields */
43 static int proto_tte_pcf = -1;
44
45 /* static int hf_tte_pcf = -1; */
46 static int hf_tte_pcf_ic = -1;
47 static int hf_tte_pcf_mn = -1;
48 /* static int hf_tte_pcf_res0 = -1; */
49 static int hf_tte_pcf_sp = -1;
50 static int hf_tte_pcf_sd = -1;
51 static int hf_tte_pcf_type = -1;
52 /* static int hf_tte_pcf_res1 = -1; */
53 static int hf_tte_pcf_tc = -1;
54
55 /* Initialize the subtree pointers */
56 static gint ett_tte_pcf = -1;
57
58 static const value_string pcf_type_str_vals[] =
59     { {2, "integration frame"}
60     , {4, "coldstart frame"}
61     , {8, "coldstart ack frame"}
62     , {0, NULL}
63     };
64
65
66 /* Code to actually dissect the packets */
67 static void
68 dissect_tte_pcf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
69 {
70     /* Set up structures needed to add the protocol subtree and manage it */
71     proto_item *tte_pcf_root_item;
72     proto_tree *tte_pcf_tree;
73
74     /* variables used to store the fields displayed in the info_column */
75     guint8 sync_priority = 0;
76     guint8 sync_domain   = 0;
77
78     /* Check that there's enough data */
79     if (tvb_length(tvb) < TTE_PCF_LENGTH )
80     {
81         return;
82     }
83
84     /* get sync_priority and sync_domain */
85     sync_priority = tvb_get_guint8(tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
86         TTE_PCF_RES0_LENGTH);
87     sync_domain = tvb_get_guint8(tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
88         TTE_PCF_RES0_LENGTH+TTE_PCF_SP_LENGTH);
89
90     /* Make entries in Protocol column and Info column on summary display */
91     col_set_str(pinfo->cinfo, COL_PROTOCOL, "PCF");
92
93     col_add_fstr(pinfo->cinfo, COL_INFO,
94             "Sync Domain: 0x%02X  Sync Priority: 0x%02X",
95             sync_domain, sync_priority);
96
97     if (tree) {
98
99         /* create display subtree for the protocol */
100         tte_pcf_root_item = proto_tree_add_item(tree, proto_tte_pcf, tvb, 0,
101             TTE_PCF_LENGTH, ENC_NA);
102
103         tte_pcf_tree = proto_item_add_subtree(tte_pcf_root_item, ett_tte_pcf);
104
105         proto_tree_add_item(tte_pcf_tree,
106             hf_tte_pcf_ic, tvb, 0, TTE_PCF_IC_LENGTH, ENC_BIG_ENDIAN);
107
108         proto_tree_add_item(tte_pcf_tree,
109             hf_tte_pcf_mn, tvb, TTE_PCF_IC_LENGTH, TTE_PCF_MN_LENGTH, ENC_BIG_ENDIAN);
110
111      /* RESERVED FIELD --- will not be displayed */
112      /* proto_tree_add_item(tte_pcf_tree,
113             hf_tte_pcf_res0, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH,
114             TTE_PCF_RES0_LENGTH, ENC_BIG_ENDIAN); */
115
116         proto_tree_add_item(tte_pcf_tree,
117             hf_tte_pcf_sp, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
118             TTE_PCF_RES0_LENGTH, TTE_PCF_SP_LENGTH, ENC_BIG_ENDIAN);
119
120         proto_tree_add_item(tte_pcf_tree,
121             hf_tte_pcf_sd, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
122             TTE_PCF_RES0_LENGTH+TTE_PCF_SP_LENGTH, TTE_PCF_SD_LENGTH, ENC_BIG_ENDIAN);
123
124         proto_tree_add_item(tte_pcf_tree,
125             hf_tte_pcf_type, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
126             TTE_PCF_RES0_LENGTH+TTE_PCF_SP_LENGTH+TTE_PCF_SD_LENGTH,
127             TTE_PCF_TYPE_LENGTH, ENC_BIG_ENDIAN);
128
129      /* RESERVED FIELD --- will not be displayed */
130      /* proto_tree_add_item(tte_pcf_tree,
131             hf_tte_pcf_res1, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
132             TTE_PCF_RES0_LENGTH+TTE_PCF_SP_LENGTH+TTE_PCF_SD_LENGTH+
133             TTE_PCF_TYPE_LENGTH, TTE_PCF_RES1_LENGTH, ENC_NA); */
134
135         proto_tree_add_item(tte_pcf_tree,
136             hf_tte_pcf_tc, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
137             TTE_PCF_RES0_LENGTH+TTE_PCF_SP_LENGTH+TTE_PCF_SD_LENGTH+
138             TTE_PCF_TYPE_LENGTH+TTE_PCF_RES1_LENGTH, TTE_PCF_TC_LENGTH, ENC_BIG_ENDIAN);
139     }
140
141 }
142
143
144 void
145 proto_register_tte_pcf(void)
146 {
147     static hf_register_info hf[] = {
148
149 #if 0
150         { &hf_tte_pcf,
151             { "Protocol Control Frame", "tte.pcf",
152             FT_BYTES, BASE_NONE, NULL, 0x0,
153             NULL, HFILL }
154         },
155 #endif
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 #if 0
167             { &hf_tte_pcf_res0,
168             { "Reserved 0", "tte.pcf.res0",
169             FT_UINT32, BASE_HEX, NULL, 0x0,
170             NULL, HFILL }
171         },
172 #endif
173         { &hf_tte_pcf_sp,
174             { "Sync Priority", "tte.pcf.sp",
175             FT_UINT8, BASE_HEX, NULL, 0x0,
176             NULL, HFILL }
177         },
178         { &hf_tte_pcf_sd,
179             { "Sync Domain", "tte.pcf.sd",
180             FT_UINT8, BASE_HEX, NULL, 0x0,
181             NULL, HFILL }
182         },
183         { &hf_tte_pcf_type,
184             { "Type", "tte.pcf.type",
185             FT_UINT8, BASE_HEX, VALS(pcf_type_str_vals), 0x0F,
186             NULL, HFILL }
187         },
188 #if 0
189         { &hf_tte_pcf_res1,
190             { "Reserved 1", "tte.pcf.res1",
191             FT_BYTES, BASE_NONE, NULL, 0x0,
192             NULL, HFILL }
193         },
194 #endif
195         { &hf_tte_pcf_tc,
196             { "Transparent Clock", "tte.pcf.tc",
197             FT_UINT64, BASE_HEX, NULL, 0x0,
198             NULL, HFILL }
199         }
200     };
201
202     /* Setup protocol subtree array */
203     static gint *ett[] = {
204         &ett_tte_pcf
205     };
206
207     /* Register the protocol name and description */
208     proto_tte_pcf = proto_register_protocol("TTEthernet Protocol Control Frame",
209         "TTE PCF", "tte_pcf");
210
211     /* Required function calls to register header fields and subtrees used */
212     proto_register_field_array(proto_tte_pcf, hf, array_length(hf));
213     proto_register_subtree_array(ett, array_length(ett));
214
215     register_dissector("tte_pcf", dissect_tte_pcf, proto_tte_pcf);
216
217 }
218
219
220 void
221 proto_reg_handoff_tte_pcf(void)
222 {
223     dissector_handle_t tte_pcf_handle;
224
225     /* initialize the pcf handle */
226     tte_pcf_handle = find_dissector("tte_pcf");
227
228     dissector_add_uint("ethertype", ETHERTYPE_TTE_PCF, tte_pcf_handle);
229
230 }
231