1 /* packet-sercosiii_1v1_at.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 ett_siii_at = -1;
40 static gint ett_siii_at_svc = -1;
41 static gint ett_siii_at_devstats = -1;
43 static gint ett_siii_at_svc_channel[MAX_SERCOS_DEVICES];
44 static gint ett_siii_at_dev_status[MAX_SERCOS_DEVICES];
46 void dissect_siii_at_cp0(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
48 guint16 seqcnt; /* sequence counter */
49 guint16 tfield; /* topology field for sercos addresses */
51 char devices[]="Recognized Devices"; /* fixme: it would be nice to have this as subtree */
52 static char outbuf[200];
54 proto_tree_add_text(tree, tvb, 0, 1024, "%s", devices);
56 /* check sequence count field */
57 seqcnt = tvb_get_letohs(tvb, 0);
58 g_snprintf(outbuf, sizeof(outbuf), "Number of Devices: %u", (0x1FF & seqcnt)-1);
59 proto_tree_add_text(tree, tvb, 0, 2, "%s", outbuf);
61 /* check SERCOS address of each topology field */
62 for(i=1;i < MAX_SERCOS_DEVICES; ++i)
64 tfield = tvb_get_letohs(tvb, i*2);
68 g_snprintf(outbuf, sizeof(outbuf), "Device Address %u: No SERCOS Address", i);
70 else if(tfield == 0xFFFF)
72 g_snprintf(outbuf, sizeof(outbuf), "Device Address %u: No Device", i);
76 g_snprintf(outbuf, sizeof(outbuf), "Device Address %u: %u", i, tfield);
78 proto_tree_add_text(tree, tvb, i*2, 2, "%s", outbuf);
82 void dissect_siii_at_cp1_2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint telno)
84 guint devstart = telno * 128; /* AT0: slaves 0-127; AT1: slaves 128-255; ... */
89 proto_item* ti; /* temporary item */
91 proto_tree* subtree_svc;
92 proto_tree* subtree_devstat;
94 ti = proto_tree_add_text(tree, tvb, 0, 128 * 6, "Service Channel");
95 subtree_svc = proto_item_add_subtree(ti, ett_siii_at_svc);
97 ti = proto_tree_add_text(tree, tvb, 128 * 6, 512, "Device Status");
98 subtree_devstat = proto_item_add_subtree(ti, ett_siii_at_devstats);
100 for(idx = 0; idx < 128; ++idx) /* each AT of CP1/2 has data of 128 different slaves */
102 tvb_n = tvb_new_subset(tvb, 6 * idx, 6, 6); /* subset for service channel data */
104 ti = proto_tree_add_text(subtree_svc, tvb_n, 0, 6, "Device %u", idx + devstart);
105 subtree = proto_item_add_subtree(ti, ett_siii_at_svc_channel[idx]);
106 dissect_siii_at_svc(tvb_n, pinfo, subtree, idx + devstart);
108 tvb_n = tvb_new_subset(tvb, 128 * 6 + 4 * idx, 2, 2); /* subset for device status information */
110 ti = proto_tree_add_text(subtree_devstat, tvb_n, 0, 2, "Device %u", idx + devstart);
111 subtree = proto_item_add_subtree(ti, ett_siii_at_dev_status[idx]);
112 dissect_siii_at_devstat(tvb_n, pinfo, subtree);
116 void dissect_siii_at_cp3_4(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint telno)
119 proto_tree* subtree_svc;
120 proto_tree* subtree_devstat;
122 if(0 == telno) /* dissect hotplug field in AT0 only */
123 dissect_siii_at_hp(tvb, pinfo, tree);
125 /* offsets of service channel, device status and connections are unknown
126 * this data could be extracted from svc communication during CP2
128 ti = proto_tree_add_text(tree, tvb, 0, 0, "Service Channels");
129 subtree_svc = proto_item_add_subtree(ti, ett_siii_at_svc);
131 ti = proto_tree_add_text(tree, tvb, 0, 0, "Device Status");
132 subtree_devstat = proto_item_add_subtree(ti, ett_siii_at_devstats);
136 void dissect_siii_at(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
138 proto_item* ti; /* temporary item */
145 phase = (tvb_get_guint8(tvb, 1)&0x8F); /* read communication phase out of SERCOS III header*/
146 telno = (tvb_get_guint8(tvb, 0) & 0xF); /* read number of AT out of SERCOS III header */
148 if(check_col(pinfo->cinfo, COL_PROTOCOL))
149 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SIII AT");
151 if(check_col(pinfo->cinfo, COL_INFO))
153 if(phase & 0x80) /* communication phase switching in progress */
155 col_append_fstr(pinfo->cinfo, COL_INFO, " Phase=CP?s -> CP%u",
158 else /* communication as usual */
160 col_append_fstr(pinfo->cinfo, COL_INFO, " Phase=CP%u",
165 ti = proto_tree_add_text(tree, tvb, 0, -1, "AT%u", telno);
166 subtree = proto_item_add_subtree(ti, ett_siii_at);
168 dissect_siii_mst(tvb, pinfo, subtree); /* dissect SERCOS III header */
170 switch(phase) /* call the AT dissector depending on the current communication phase */
172 case COMMUNICATION_PHASE_0: /* CP0 */
173 tvb_n = tvb_new_subset(tvb, 6, 1024, 1024);
174 dissect_siii_at_cp0(tvb_n, pinfo, subtree);
177 case COMMUNICATION_PHASE_1: /* CP1 */
178 case COMMUNICATION_PHASE_2: /* CP2 */
179 tvb_n = tvb_new_subset(tvb, 6, 1280, 1280);
180 dissect_siii_at_cp1_2(tvb_n, pinfo, subtree, telno);
183 case COMMUNICATION_PHASE_3: /* CP3 */
184 case COMMUNICATION_PHASE_4: /* CP4 */
185 tvb_n = tvb_new_subset(tvb, 6, -1, -1);
186 dissect_siii_at_cp3_4(tvb_n, pinfo, subtree, telno);
190 proto_tree_add_text(tree, tvb, 6, -1, "CP is unknown");
195 void dissect_siii_at_init(gint proto_siii _U_)
199 /* Setup protocol subtree array */
200 static gint *ett[] = {
203 &ett_siii_at_devstats
206 static gint* etts[MAX_SERCOS_DEVICES];
208 for(idx = 0; idx < MAX_SERCOS_DEVICES; ++idx)
210 ett_siii_at_svc_channel[idx] = -1;
211 etts[idx] = &ett_siii_at_svc_channel[idx];
213 proto_register_subtree_array(etts, array_length(etts));
215 for(idx = 0; idx < MAX_SERCOS_DEVICES; ++idx)
217 ett_siii_at_dev_status[idx] = -1;
218 etts[idx] = &ett_siii_at_dev_status[idx];
220 proto_register_subtree_array(etts, array_length(etts));
222 /* Required function calls to register the header fields and subtrees used */
223 proto_register_subtree_array(ett, array_length(ett));