#include <prefs.h> not required
[obnox/wireshark/wip.git] / plugins / sercosiii / packet-sercosiii_1v1_hp.c
1 /* packet-sercosiii_1v1_hp.c
2  * Routines for SERCOS III dissection
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include <glib.h>
34
35 #include <epan/packet.h>
36
37 #include "packet-sercosiii.h"
38
39 static gint hf_siii_mdt_hotplug_address = -1;
40 static gint hf_siii_mdt_hp_ctrl = -1;
41 static gint hf_siii_mdt_hp_info = -1;
42 static gint hf_siii_at_hotplug_address = -1;
43 static gint hf_siii_at_hp_stat = -1;
44 static gint hf_siii_at_hp_info = -1;
45 static gint hf_siii_mdt_hotplug_control_param = -1;
46 static gint hf_siii_mdt_hotplug_control_svc_switch = -1;
47 static gint hf_siii_at_hotplug_status_param = -1;
48 static gint hf_siii_at_hotplug_status_hp0_finished = -1;
49 static gint hf_siii_at_hotplug_status_error = -1;
50
51 static gint ett_siii_mdt_hp = -1;
52 static gint ett_siii_at_hp = -1;
53 static gint ett_siii_mdt_hp_ctrl = -1;
54 static gint ett_siii_mdt_hp_info = -1;
55 static gint ett_siii_at_hp_stat = -1;
56 static gint ett_siii_at_hp_info = -1;
57
58 static const value_string siii_mdt_hotplug_control_functioncode_text[]=
59 {
60   {0x00, "No data"},
61   {0x01, "tScyc"},
62   {0x02, "t1"},
63   {0x03, "t6"},
64   {0x04, "t7"},
65   {0x05, "Communication Version"},
66   {0x06, "Communication timeout"},
67   {0x10, "MDT0 Length"},
68   {0x11, "MDT1 Length"},
69   {0x12, "MDT2 Length"},
70   {0x13, "MDT3 Length"},
71   {0x20, "AT0 Length"},
72   {0x21, "AT1 Length"},
73   {0x22, "AT2 Length"},
74   {0x23, "AT3 Length"},
75   {0x80, "MDT-SVC pointer"},
76   {0x81, "MDT-RTD pointer"},
77   {0x82, "AT-SVC pointer"},
78   {0x83, "AT-RTD pointer"},
79   {0, NULL}
80 };
81
82 static const value_string siii_mdt_hotplug_control_svc_switch_text[]=
83 {
84   {0, "Transmission via HP-field"},
85   {1, "Switch to SVC"},
86   {0, NULL}
87 };
88
89 static const value_string siii_mdt_hotplug_status_ackcode_text[]=
90 {
91   {0x80, "MDT-SVC pointer"},
92   {0x81, "MDT-RTD pointer"},
93   {0x82, "AT-SVC pointer"},
94   {0x83, "AT-RTD pointer"},
95   {255, "Next Sercos Slave has same address"},
96   {0, NULL}
97 };
98
99 static const value_string siii_at_hotplug_status_error_text[]=
100 {
101   {0, "Acknowledgement in HP-1"},
102   {1, "Error in HP-1"},
103   {0, NULL}
104 };
105
106 void dissect_siii_mdt_hp(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
107 {
108   proto_tree* subtree;
109   proto_tree* subtree2;
110   proto_item* ti;
111
112   ti = proto_tree_add_text(tree, tvb, 0, 8, "Hot-Plug");
113   subtree = proto_item_add_subtree(ti, ett_siii_mdt_hp);
114
115   proto_tree_add_item(subtree, hf_siii_mdt_hotplug_address, tvb, 2, 2, TRUE);
116
117   ti = proto_tree_add_item(subtree, hf_siii_mdt_hp_ctrl, tvb, 2, 2, TRUE);
118   subtree2 = proto_item_add_subtree(ti, ett_siii_mdt_hp_ctrl);
119
120   proto_tree_add_item(subtree2, hf_siii_mdt_hotplug_control_svc_switch, tvb, 2, 2, TRUE);
121   proto_tree_add_item(subtree2, hf_siii_mdt_hotplug_control_param, tvb, 2, 2, TRUE);
122
123   proto_tree_add_item(subtree, hf_siii_mdt_hp_info, tvb, 4, 4, TRUE);
124 }
125
126 void dissect_siii_at_hp(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
127 {
128   proto_tree* subtree;
129   proto_tree* subtree2;
130   proto_item* ti;
131
132   ti = proto_tree_add_text(tree, tvb, 0, 8, "Hot-Plug");
133   subtree = proto_item_add_subtree(ti, ett_siii_at_hp);
134
135   proto_tree_add_item(subtree, hf_siii_at_hotplug_address, tvb, 2, 2, TRUE);
136
137   ti = proto_tree_add_item(subtree, hf_siii_at_hp_stat, tvb, 2, 2, TRUE);
138   subtree2 = proto_item_add_subtree(ti, ett_siii_at_hp_stat);
139
140   proto_tree_add_item(subtree2, hf_siii_at_hotplug_status_error, tvb, 2, 2, TRUE);
141   proto_tree_add_item(subtree2, hf_siii_at_hotplug_status_hp0_finished, tvb, 2, 2, TRUE);
142   proto_tree_add_item(subtree2, hf_siii_at_hotplug_status_param, tvb, 2, 2, TRUE);
143
144   proto_tree_add_item(subtree, hf_siii_at_hp_info, tvb, 4, 4, TRUE);
145 }
146
147 void dissect_siii_hp_init(gint proto_siii)
148 {
149   /* Setup list of header fields  See Section 1.6.1 for details*/
150   static hf_register_info hf_siii_header[] = {
151     { &hf_siii_mdt_hotplug_address,
152       {"Sercos address", "siii.mdt.hp.sercosaddress",
153         FT_UINT16, BASE_HEX, NULL, 0,
154         NULL, HFILL }
155     },
156     { &hf_siii_mdt_hp_ctrl,
157       {"HP control", "siii.mdt.hp.ctrl",
158         FT_UINT16, BASE_HEX, NULL, 0,
159         NULL, HFILL }
160     },
161     { &hf_siii_mdt_hp_info,
162       {"HP info", "siii.mdt.hp.info",
163         FT_BYTES, BASE_HEX, NULL, 0,
164         NULL, HFILL }
165     },
166     { &hf_siii_at_hotplug_address,
167       {"Sercos address", "siii.at.hp.sercosaddress",
168         FT_UINT16, BASE_HEX, NULL, 0,
169         NULL, HFILL }
170     },
171     { &hf_siii_at_hp_stat,
172       {"HP status", "siii.mdt.hp.stat",
173         FT_UINT16, BASE_HEX, NULL, 0,
174         NULL, HFILL }
175     },
176     { &hf_siii_at_hp_info,
177       {"HP info", "siii.at.hp.info",
178         FT_BYTES, BASE_HEX, NULL, 0,
179         NULL, HFILL }
180     },
181     { &hf_siii_mdt_hotplug_control_param,
182       {"Parameter", "siii.mdt.hp.parameter",
183         FT_UINT16, BASE_DEC, VALS(siii_mdt_hotplug_control_functioncode_text), 0xFF,
184         NULL, HFILL }
185     },
186     { &hf_siii_mdt_hotplug_control_svc_switch,
187       {"Switch to SVC", "siii.mdt.hp.switch",
188         FT_UINT16, BASE_DEC, VALS(siii_mdt_hotplug_control_svc_switch_text), 0x100,
189         NULL, HFILL }
190     },
191
192     { &hf_siii_at_hotplug_status_param,
193       {"Parameter Received", "siii.at.hp.parameter",
194         FT_UINT16, BASE_DEC, VALS(siii_mdt_hotplug_status_ackcode_text), 0xFF,
195         NULL, HFILL }
196     },
197     { &hf_siii_at_hotplug_status_hp0_finished,
198       {"HP/SVC", "siii.at.hp.hp0_finished",
199         FT_UINT16, BASE_DEC, NULL, 0x100,
200         NULL, HFILL }
201     },
202     { &hf_siii_at_hotplug_status_error,
203       {"Error", "siii.at.hp.error",
204         FT_UINT16, BASE_DEC, VALS(siii_at_hotplug_status_error_text), 0x200,
205         NULL, HFILL }
206     }
207   };
208
209   /* Setup protocol subtree array */
210   static gint *ett[] = {
211     &ett_siii_mdt_hp,
212     &ett_siii_at_hp,
213     &ett_siii_mdt_hp_ctrl,
214     &ett_siii_mdt_hp_info,
215     &ett_siii_at_hp_stat,
216     &ett_siii_at_hp_info
217   };
218
219   /* Required function calls to register the header fields and subtrees used */
220   proto_register_field_array(proto_siii, hf_siii_header, array_length(hf_siii_header));
221   proto_register_subtree_array(ett, array_length(ett));
222 }