nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /* packet-pn-mrp.c
2 * Routines for PN-MRP (PROFINET Media Redundancy Protocol)
3 * packet dissection.
4 *
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23  
24 #include "config.h"
25  
26 #include <epan/packet.h>
27 #include <epan/oui.h>
28 #include <epan/etypes.h>
29 #include <epan/dissectors/packet-dcerpc.h>
30  
31 #include "packet-pn.h"
32  
33 void proto_register_pn_mrp(void);
34 void proto_reg_handoff_pn_mrp(void);
35  
36 static int proto_pn_mrp = -1;
37  
38 static int hf_pn_mrp_type = -1;
39 static int hf_pn_mrp_length = -1;
40 static int hf_pn_mrp_version = -1;
41 static int hf_pn_mrp_sequence_id = -1;
42 static int hf_pn_mrp_sa = -1;
43 static int hf_pn_mrp_prio = -1;
44 static int hf_pn_mrp_port_role = -1;
45 static int hf_pn_mrp_ring_state = -1;
46 static int hf_pn_mrp_interval = -1;
47 static int hf_pn_mrp_transition = -1;
48 static int hf_pn_mrp_time_stamp = -1;
49 static int hf_pn_mrp_blocked = -1;
50 static int hf_pn_manufacturer_data = -1;
51 static int hf_pn_mrp_domain_uuid = -1;
52 static int hf_pn_mrp_oui = -1;
53  
54  
55 static gint ett_pn_mrp = -1;
56  
57  
58  
59 static const value_string pn_mrp_block_type_vals[] = {
60 { 0x00, "End" },
61 { 0x01, "Common" },
62 { 0x02, "Test" },
63 { 0x03, "TopologyChange" },
64 { 0x04, "LinkDown" },
65 { 0x05, "LinkUp" },
66 /*0x06 - 0x7E Reserved */
67 { 0x7F, "Organizationally Specific"},
68 { 0, NULL },
69 };
70  
71 static const value_string pn_mrp_oui_vals[] = {
72 { OUI_PROFINET, "PROFINET" },
73 { OUI_SIEMENS, "SIEMENS" },
74  
75 { 0, NULL }
76 };
77  
78  
79  
80 static const value_string pn_mrp_port_role_vals[] = {
81 { 0x0000, "Primary ring port" },
82 { 0x0001, "Secondary ring port"},
83 /*0x0002 - 0xFFFF Reserved */
84  
85 { 0, NULL }
86 };
87  
88 #if 0
89 static const value_string pn_mrp_role_vals[] = {
90 { 0x0000, "Media redundancy disabled" },
91 { 0x0001, "Media redundancy client" },
92 { 0x0002, "Media redundancy manager" },
93 { 0x0003, "Media redundancy manager (auto)" },
94 /*0x0004 - 0xFFFF Reserved */
95  
96 { 0, NULL }
97 };
98 #endif
99  
100 static const value_string pn_mrp_ring_state_vals[] = {
101 { 0x0000, "Ring open" },
102 { 0x0001, "Ring closed"},
103 /*0x0002 - 0xFFFF Reserved */
104  
105 { 0, NULL }
106 };
107  
108  
109 #if 0
110 static const value_string pn_mrp_prio_vals[] = {
111 { 0x8000, "Default priority for redundancy manager" },
112  
113 { 0, NULL }
114 };
115 #endif
116  
117  
118 static int
119 dissect_PNMRP_Common(tvbuff_t *tvb, int offset,
120 packet_info *pinfo, proto_tree *tree, proto_item *item _U_)
121 {
122 guint16 sequence_id;
123 e_guid_t uuid;
124  
125  
126 /* MRP_SequenceID */
127 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_sequence_id, &sequence_id);
128  
129 /* MRP_DomainUUID */
130 offset = dissect_pn_uuid(tvb, offset, pinfo, tree, hf_pn_mrp_domain_uuid, &uuid);
131  
132 return offset;
133 }
134  
135  
136 static int
137 dissect_PNMRP_Link(tvbuff_t *tvb, int offset,
138 packet_info *pinfo, proto_tree *tree, proto_item *item _U_, guint8 type)
139 {
140 guint8 mac[6];
141 guint16 port_role;
142 guint16 interval;
143 guint16 blocked;
144 proto_item *sub_item;
145  
146 /* MRP_SA */
147 offset = dissect_pn_mac(tvb, offset, pinfo, tree, hf_pn_mrp_sa, mac);
148  
149 /* MRP_PortRole */
150 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_port_role, &port_role);
151  
152 /* MRP_Interval */
153 offset = dissect_pn_uint16_ret_item(tvb, offset, pinfo, tree, hf_pn_mrp_interval, &interval, &sub_item);
154 if (tree)
155 {
156 proto_item_append_text(sub_item,"Interval for next topology change event (in ms)");
157 if (interval <0x07D1)
158 proto_item_append_text(sub_item," Mandatory");
159 else
160 proto_item_append_text(sub_item," Optional");
161 }
162  
163 /* MRP_Blocked */
164 offset = dissect_pn_uint16_ret_item(tvb, offset, pinfo, tree, hf_pn_mrp_blocked, &blocked, &sub_item);
165 if (tree)
166 {
167 if (blocked == 0)
168 proto_item_append_text(sub_item," The MRC is not able to receive and forward frames to port in state blocked");
169 else
170 if (blocked == 1)
171 proto_item_append_text(sub_item," The MRC is able to receive and forward frames to port in state blocked");
172 else
173 proto_item_append_text(sub_item," Reserved");
174 }
175  
176 /* Padding */
177 offset = dissect_pn_align4(tvb, offset, pinfo, tree);
178 if(type == 4 /* LinkDown */ )
179 {
180 col_append_str(pinfo->cinfo, COL_INFO, "LinkDown");
181 proto_item_append_text(item, "LinkDown");
182 }
183 else
184 {
185 col_append_str(pinfo->cinfo, COL_INFO, "LinkUp");
186 proto_item_append_text(item, "LinkUp");
187 }
188 return offset;
189 }
190  
191 static const char * mrp_Prio2msg(guint16 prio)
192 {
193  
194 if (prio == 0x0000)
195 return(" Highest priority redundancy manager");
196 if ((prio >= 0x1000) && (prio <= 0x7000))
197 return(" High priorities");
198 if (prio == 0x8000)
199 return(" Default priority for redundancy manager");
200 if ((prio >= 0x8001) && (prio <= 0x8FFF))
201 return(" Low priorities for redundancy manager");
202 if ((prio >= 0x9000) && (prio <= 0x9FFF))
203 return(" High priorities for redundancy manager (auto)");
204 if (prio == 0xA000)
205 return(" Default priority for redundancy manager (auto)");
206 if ((prio >= 0xA001) && (prio <= 0xF000))
207 return(" Low priorities for redundancy manager (auto)");
208 if (prio ==0xFFFF)
209 return(" Lowest priority for redundancy manager (auto)");
210  
211 return(" Reserved");
212 }
213  
214 static int
215 dissect_PNMRP_Test(tvbuff_t *tvb, int offset,
216 packet_info *pinfo, proto_tree *tree, proto_item *item _U_)
217 {
218 guint16 prio;
219 guint8 mac[6];
220 guint16 port_role;
221 guint16 ring_state;
222 guint16 transition;
223 guint32 time_stamp;
224 proto_item *sub_item;
225  
226  
227 /* MRP_Prio */
228 offset = dissect_pn_uint16_ret_item(tvb, offset, pinfo, tree, hf_pn_mrp_prio, &prio, &sub_item);
229 if (tree)
230 proto_item_append_text(sub_item, "%s", mrp_Prio2msg(prio));
231  
232 /* MRP_SA */
233 offset = dissect_pn_mac(tvb, offset, pinfo, tree, hf_pn_mrp_sa, mac);
234  
235 /* MRP_PortRole */
236 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_port_role, &port_role);
237  
238 /* MRP_RingState */
239 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_ring_state, &ring_state);
240  
241 /* MRP_Transition */
242 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_transition, &transition);
243  
244 /* MRP_TimeStamp */
245 offset = dissect_pn_uint32(tvb, offset, pinfo, tree, hf_pn_mrp_time_stamp, &time_stamp);
246  
247 /* Padding */
248 offset = dissect_pn_align4(tvb, offset, pinfo, tree);
249  
250 return offset;
251 }
252  
253  
254 static int
255 dissect_PNMRP_TopologyChange(tvbuff_t *tvb, int offset,
256 packet_info *pinfo, proto_tree *tree, proto_item *item _U_)
257 {
258 guint16 prio;
259 guint8 mac[6];
260 guint16 interval;
261 proto_item *sub_item;
262  
263  
264 /* MRP_Prio */
265 offset = dissect_pn_uint16_ret_item(tvb, offset, pinfo, tree, hf_pn_mrp_prio, &prio, &sub_item);
266 if (tree)
267 proto_item_append_text(sub_item, "%s", mrp_Prio2msg(prio));
268  
269 /* MRP_SA */
270 offset = dissect_pn_mac(tvb, offset, pinfo, tree, hf_pn_mrp_sa, mac);
271  
272 /* MRP_Interval */
273 offset = dissect_pn_uint16_ret_item(tvb, offset, pinfo, tree, hf_pn_mrp_interval, &interval, &sub_item);
274 if (tree)
275 {
276 proto_item_append_text(sub_item," Interval for next topology change event (in ms) ");
277 if (interval <0x07D1)
278 proto_item_append_text(sub_item,"Mandatory");
279 else
280 proto_item_append_text(sub_item,"Optional");
281 }
282 /* Padding */
283 /*offset = dissect_pn_align4(tvb, offset, pinfo, tree);*/
284  
285 return offset;
286 }
287  
288 /* "dissect" Manufacture DATA */
289 static int
290 dissect_pn_ManuData(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
291 proto_tree *tree, guint32 length)
292 {
293  
294  
295 proto_tree_add_string_format(tree, hf_pn_manufacturer_data, tvb, offset, length, "data",
296 "MRP_ManufacturerData: %d bytes", length);
297  
298 return offset + length;
299 }
300  
301  
302 static int
303 dissect_PNMRP_Option(tvbuff_t *tvb, int offset,
304 packet_info *pinfo, proto_tree *tree, proto_item *item, guint8 length)
305 {
306 guint32 oui;
307  
308  
309 /* OUI (organizational unique id) */
310 offset = dissect_pn_oid(tvb, offset, pinfo,tree, hf_pn_mrp_oui, &oui);
311 length -= 3;
312  
313 switch (oui)
314 {
315 case OUI_SIEMENS:
316 proto_item_append_text(item, "(SIEMENS)");
317 /* No Padding !
318 if (offset % 4) {
319 length -= 4 - (offset % 4);
320 offset = dissect_pn_align4(tvb, offset, pinfo, tree);
321 } */
322 if (length != 0) {
323 offset = dissect_pn_ManuData(tvb, offset, pinfo, tree, length);
324 }
325 col_append_str(pinfo->cinfo, COL_INFO, "(Siemens)");
326 break;
327 default:
328 proto_item_append_text(item, " (Unknown-OUI)");
329 offset = dissect_pn_undecoded(tvb, offset, pinfo, tree, length);
330  
331 }
332  
333 /* Padding */
334 offset = dissect_pn_align4(tvb, offset, pinfo, tree);
335  
336 return offset;
337 }
338  
339  
340 static int
341 dissect_PNMRP_PDU(tvbuff_t *tvb, int offset,
342 packet_info *pinfo, proto_tree *tree, proto_item *item)
343 {
344 guint16 version;
345 guint8 type;
346 guint8 length;
347 gint i;
348 tvbuff_t *new_tvb;
349  
350  
351 /* MRP_Version */
352 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_version, &version);
353  
354 /* the rest of the packet has 4byte alignment regarding to the beginning of the next TLV block! */
355 /* XXX - do we have to free this new tvb below? */
356 new_tvb = tvb_new_subset_remaining(tvb, offset);
357 offset = 0;
358  
359 for(i=0; tvb_reported_length_remaining(tvb, offset) > 0; i++) {
360 /* MRP_TLVHeader.Type */
361 offset = dissect_pn_uint8(new_tvb, offset, pinfo, tree, hf_pn_mrp_type, &type);
362  
363 /* MRP_TLVHeader.Length */
364 offset = dissect_pn_uint8(new_tvb, offset, pinfo, tree, hf_pn_mrp_length, &length);
365  
366 if (i != 0) {
367 col_append_str(pinfo->cinfo, COL_INFO, ", ");
368  
369 proto_item_append_text(item, ", ");
370 } else {
371 proto_item_append_text(item, " ");
372 }
373 col_append_str(pinfo->cinfo, COL_INFO, val_to_str_const(type, pn_mrp_block_type_vals, "Unknown TLVType 0x%x"));
374 proto_item_append_text(item, "%s", val_to_str_const(type, pn_mrp_block_type_vals, "Unknown TLVType 0x%x"));
375  
376 switch(type) {
377 case 0x00:
378 /* no content */
379 return offset;
380 break;
381 case 0x01:
382 offset = dissect_PNMRP_Common(new_tvb, offset, pinfo, tree, item);
383 break;
384 case 0x02:
385 offset = dissect_PNMRP_Test(new_tvb, offset, pinfo, tree, item);
386 break;
387 case 0x03:
388 offset = dissect_PNMRP_TopologyChange(new_tvb, offset, pinfo, tree, item);
389 break;
390 case 0x04:
391 case 0x05: /* dissection of up and down is identical! */
392 offset = dissect_PNMRP_Link(new_tvb, offset, pinfo, tree, item, type);
393 break;
394 case 0x7f:
395 offset = dissect_PNMRP_Option(new_tvb, offset, pinfo, tree, item, length);
396 break;
397 default:
398 offset = dissect_pn_undecoded(tvb, offset, pinfo, tree, length);
399  
400 }
401 }
402  
403 return offset;
404 }
405  
406  
407 /* Dissect MRP packets */
408 static int
409 dissect_PNMRP(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
410 {
411 proto_item *ti = NULL;
412 proto_tree *mrp_tree = NULL;
413  
414 guint32 offset = 0;
415  
416 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PN-MRP");
417  
418 /* Clear the information column on summary display */
419 col_clear(pinfo->cinfo, COL_INFO);
420  
421 if (tree)
422 {
423 ti = proto_tree_add_item(tree, proto_pn_mrp, tvb, offset, -1, ENC_NA);
424 mrp_tree = proto_item_add_subtree(ti, ett_pn_mrp);
425 }
426  
427 dissect_PNMRP_PDU(tvb, offset, pinfo, mrp_tree, ti);
428 return tvb_captured_length(tvb);
429 }
430  
431  
432 void
433 proto_register_pn_mrp (void)
434 {
435 static hf_register_info hf[] = {
436 { &hf_pn_mrp_type,
437 { "MRP_TLVHeader.Type", "pn_mrp.type",
438 FT_UINT8, BASE_HEX, VALS(pn_mrp_block_type_vals), 0x0,
439 NULL, HFILL }},
440  
441 { &hf_pn_mrp_length,
442 { "MRP_TLVHeader.Length", "pn_mrp.length",
443 FT_UINT8, BASE_DEC, NULL, 0x0,
444 NULL, HFILL }},
445  
446 { &hf_pn_mrp_version,
447 { "MRP_Version", "pn_mrp.version",
448 FT_UINT16, BASE_DEC, NULL, 0x0,
449 NULL, HFILL }},
450  
451 { &hf_pn_mrp_sequence_id,
452 { "MRP_SequenceID", "pn_mrp.sequence_id",
453 FT_UINT16, BASE_HEX, NULL, 0x0,
454 "Unique sequence number to each outstanding service request", HFILL }},
455  
456 { &hf_pn_mrp_sa,
457 { "MRP_SA", "pn_mrp.sa",
458 FT_ETHER, BASE_NONE, 0x0, 0x0,
459 NULL, HFILL }},
460  
461 { &hf_pn_mrp_prio,
462 { "MRP_Prio", "pn_mrp.prio",
463 FT_UINT16, BASE_HEX, 0, 0x0,
464 NULL, HFILL }},
465  
466 { &hf_pn_mrp_port_role,
467 { "MRP_PortRole", "pn_mrp.port_role",
468 FT_UINT16, BASE_HEX, VALS(pn_mrp_port_role_vals), 0x0,
469 NULL, HFILL }},
470  
471 { &hf_pn_mrp_ring_state,
472 { "MRP_RingState", "pn_mrp.ring_state",
473 FT_UINT16, BASE_HEX, VALS(pn_mrp_ring_state_vals), 0x0,
474 NULL, HFILL }},
475  
476 { &hf_pn_mrp_interval,
477 { "MRP_Interval", "pn_mrp.interval",
478 FT_UINT16, BASE_DEC, NULL, 0x0,
479 "Interval for next topology change event (in ms)", HFILL }},
480  
481 { &hf_pn_mrp_transition,
482 { "MRP_Transition", "pn_mrp.transition",
483 FT_UINT16, BASE_HEX, NULL, 0x0,
484 "Number of transitions between media redundancy lost and ok states", HFILL }},
485  
486 { &hf_pn_mrp_time_stamp,
487 { "MRP_TimeStamp [ms]", "pn_mrp.time_stamp",
488 FT_UINT32, BASE_HEX, NULL, 0x0,
489 "Actual counter value of 1ms counter", HFILL }},
490  
491 { &hf_pn_mrp_blocked,
492 { "MRP_Blocked", "pn_mrp.blocked",
493 FT_UINT16, BASE_HEX, NULL, 0x0,
494 NULL, HFILL }},
495  
496 { &hf_pn_manufacturer_data,
497 { "MRP_ManufacturerData", "pn_mrp.ManufacturerData",
498 FT_STRING, BASE_NONE, NULL, 0x0,
499 NULL, HFILL }},
500  
501 { &hf_pn_mrp_domain_uuid,
502 { "MRP_DomainUUID", "pn_mrp.domain_uuid",
503 FT_GUID, BASE_NONE, NULL, 0x0,
504 NULL, HFILL }},
505  
506 { &hf_pn_mrp_oui,
507 { "MRP_ManufacturerOUI", "pn_mrp.oui",
508 FT_UINT24, BASE_HEX, VALS(pn_mrp_oui_vals), 0x0,
509 NULL, HFILL }},
510  
511 };
512  
513 static gint *ett[] = {
514 &ett_pn_mrp
515 };
516  
517 proto_pn_mrp = proto_register_protocol ("PROFINET MRP", "PN-MRP", "pn_mrp");
518 proto_register_field_array (proto_pn_mrp, hf, array_length (hf));
519 proto_register_subtree_array (ett, array_length (ett));
520 }
521  
522  
523 void
524 proto_reg_handoff_pn_mrp (void)
525 {
526 dissector_handle_t mrp_handle;
527  
528  
529 mrp_handle = create_dissector_handle(dissect_PNMRP,proto_pn_mrp);
530 dissector_add_uint("ethertype", ETHERTYPE_MRP, mrp_handle);
531  
532 }
533  
534 /*
535 * Editor modelines - http://www.wireshark.org/tools/modelines.html
536 *
537 * Local variables:
538 * c-basic-offset: 4
539 * tab-width: 8
540 * indent-tabs-mode: nil
541 * End:
542 *
543 * vi: set shiftwidth=4 tabstop=8 expandtab:
544 * :indentSize=4:tabSize=8:noTabs=true:
545 */