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