1 /* packet-sercosiii_1v1_mdt.c
2 * Routines for SERCOS III dissection
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
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.
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.
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.
35 #include <epan/packet.h>
37 #include "packet-sercosiii.h"
39 static gint hf_siii_mdt_version = -1;
40 static gint hf_siii_mdt_version_initprocvers = -1;
41 static gint hf_siii_mdt_version_num_mdt_at_cp1_2 = -1;
42 static gint hf_siii_mdt_version_revision = -1;
44 static const value_string siii_mdt_version_num_mdtat_cp1_2_text[]=
46 {0x00, "2 MDTs/ATs in CP1/2"},
47 {0x01, "4 MDTs/ATs in CP1/2"},
51 static const value_string siii_mdt_version_initprocvers_text[]=
53 {0x00, "No remote address allocation"},
54 {0x01, "Remote address allocation"},
58 static gint ett_siii_mdt = -1;
59 static gint ett_siii_mdt_svc = -1;
60 static gint ett_siii_mdt_devctrls = -1;
61 static gint ett_siii_mdt_version = -1;
62 static gint ett_siii_mdt_svc_channel[MAX_SERCOS_DEVICES] = {-1};
63 static gint ett_siii_mdt_dev_control[MAX_SERCOS_DEVICES] = {-1};
65 void dissect_siii_mdt_cp0(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
69 ti = proto_tree_add_item(tree, hf_siii_mdt_version, tvb, 0, 4, TRUE);
70 subtree = proto_item_add_subtree(ti, ett_siii_mdt_version);
72 proto_tree_add_item(subtree, hf_siii_mdt_version_num_mdt_at_cp1_2, tvb, 0, 4, TRUE);
73 proto_tree_add_item(subtree, hf_siii_mdt_version_initprocvers, tvb, 0, 4, TRUE);
74 proto_tree_add_item(subtree, hf_siii_mdt_version_revision, tvb, 0, 4, TRUE);
78 void dissect_siii_mdt_cp1_2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint telno)
80 guint devstart = telno * 128; /* MDT0: slaves 0-127; MDT1: slaves 128-255; ... */
87 proto_tree* subtree_svc;
88 proto_tree* subtree_devctrl;
90 ti = proto_tree_add_text(tree, tvb, 0, 128 * 6, "Service Channels");
91 subtree_svc = proto_item_add_subtree(ti, ett_siii_mdt_svc);
93 ti = proto_tree_add_text(tree, tvb, 128 * 6, 512, "Device Control");
94 subtree_devctrl = proto_item_add_subtree(ti, ett_siii_mdt_svc);
96 for(idx = 0; idx < 128; ++idx) /* each MDT of CP1/2 has data for 128 different slaves */
98 tvb_n = tvb_new_subset(tvb, 6 * idx, 6, 6); /* subset for service channel data */
100 ti = proto_tree_add_text(subtree_svc, tvb_n, 0, 6, "Device %u", idx + devstart);
101 subtree = proto_item_add_subtree(ti, ett_siii_mdt_svc_channel[idx]);
102 dissect_siii_mdt_svc(tvb_n, pinfo, subtree, idx + devstart);
104 tvb_n = tvb_new_subset(tvb, 128 * 6 + 4 * idx, 2, 2); /* subset for device control information */
106 ti = proto_tree_add_text(subtree_devctrl, tvb_n, 0, 2, "Device %u", idx + devstart);
107 subtree = proto_item_add_subtree(ti, ett_siii_mdt_dev_control[idx]);
109 dissect_siii_mdt_devctrl(tvb_n, pinfo, subtree);
113 void dissect_siii_mdt_cp3_4(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint telno)
115 guint devstart _U_ = telno * 128;
118 proto_tree* subtree_svc;
119 proto_tree* subtree_devctrl;
121 if(0 == telno) /* dissect hotplug field in MDT0 only */
122 dissect_siii_mdt_hp(tvb, pinfo, tree);
124 /* offsets of service channel, device status and connections are unknown
125 * this data could be extracted from svc communication during CP2
127 ti = proto_tree_add_text(tree, tvb, 0, 0, "Service Channels");
128 subtree_svc = proto_item_add_subtree(ti, ett_siii_mdt_svc);
130 ti = proto_tree_add_text(tree, tvb, 0, 0, "Device Controls");
131 subtree_devctrl = proto_item_add_subtree(ti, ett_siii_mdt_svc);
135 void dissect_siii_mdt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
144 if(check_col(pinfo->cinfo, COL_PROTOCOL))
145 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SIII MDT");
147 t_phase = (tvb_get_guint8(tvb, 1)&0x8F); /* read communication phase out of SERCOS III header */
148 telno = (tvb_get_guint8(tvb, 0) & 0xF); /* read number of MDT out of SERCOS III header */
150 if(check_col(pinfo->cinfo, COL_INFO))
152 if(t_phase & 0x80) /* communication phase switching in progress */
154 col_append_fstr(pinfo->cinfo, COL_INFO, " Phase=CP?s -> CP%u",
157 else /* communication as usual */
159 col_append_fstr(pinfo->cinfo, COL_INFO, " Phase=CP%u",
164 ti = proto_tree_add_text(tree, tvb, 0, -1, "MDT%u", telno);
165 subtree = proto_item_add_subtree(ti, ett_siii_mdt);
167 dissect_siii_mst(tvb, pinfo, subtree); /* dissect SERCOS III header */
169 switch(t_phase) /* call the MDT dissector depending on the current communication phase */
171 case COMMUNICATION_PHASE_0: /* CP0 */
172 tvb_n = tvb_new_subset(tvb, 6, 40, 40);
173 dissect_siii_mdt_cp0(tvb_n, pinfo, subtree);
176 case COMMUNICATION_PHASE_1: /* CP1 */
177 case COMMUNICATION_PHASE_2: /* CP2 */
178 tvb_n = tvb_new_subset(tvb, 6, 1280, 1280);
179 dissect_siii_mdt_cp1_2(tvb_n, pinfo, subtree, telno);
182 case COMMUNICATION_PHASE_3: /* CP3 */
183 case COMMUNICATION_PHASE_4: /* CP4 */
184 tvb_n = tvb_new_subset(tvb, 6, -1, -1);
185 dissect_siii_mdt_cp3_4(tvb_n, pinfo, subtree, telno);
189 proto_tree_add_text(tree, tvb, 6, -1, "CP is unknown");
193 void dissect_siii_mdt_init(gint proto_siii)
197 /* Setup list of header fields See Section 1.6.1 for details*/
198 static hf_register_info hf_siii_header[] = {
199 { &hf_siii_mdt_version,
200 { "Communication Version", "siii.mdt.version",
201 FT_UINT32, BASE_HEX, NULL, 0,
204 { &hf_siii_mdt_version_revision,
205 { "Revision Number", "siii.mdt.version.revision",
206 FT_UINT32, BASE_HEX, NULL, 0x7F,
209 { &hf_siii_mdt_version_num_mdt_at_cp1_2,
210 { "Number of MDTs and ATS in CP1 and CP2", "siii.mdt.version.num_mdt_at_cp1_2",
211 FT_UINT32, BASE_HEX, VALS(siii_mdt_version_num_mdtat_cp1_2_text), 0x30000,
214 { &hf_siii_mdt_version_initprocvers,
215 { "Initialization Procedure Version Number", "siii.mdt.version.initprocvers",
216 FT_UINT32, BASE_HEX, VALS(siii_mdt_version_initprocvers_text), 0xFF00,
220 /* Setup protocol subtree array */
221 static gint *ett[] = {
223 &ett_siii_mdt_version,
225 &ett_siii_mdt_devctrls
228 static gint* etts[MAX_SERCOS_DEVICES];
230 for(idx = 0; idx < MAX_SERCOS_DEVICES; ++idx)
232 etts[idx] = &ett_siii_mdt_svc_channel[idx];
234 proto_register_subtree_array(etts, array_length(etts));
236 for(idx = 0; idx < MAX_SERCOS_DEVICES; ++idx)
238 etts[idx] = &ett_siii_mdt_dev_control[idx];
240 proto_register_subtree_array(etts, array_length(etts));
242 proto_register_field_array(proto_siii, hf_siii_header, array_length(hf_siii_header));
243 proto_register_subtree_array(ett, array_length(ett));