2 * Routines for PN-DCP (PROFINET Discovery and basic Configuration Protocol)
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1999 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 #include <sys/types.h>
38 #include <epan/packet.h>
39 #include <epan/emem.h>
40 #include <epan/dissectors/packet-dcerpc.h>
41 #include <epan/expert.h>
43 static int proto_pn_dcp = -1;
45 static int hf_pn_dcp = -1;
47 static int hf_pn_dcp_service_id = -1;
48 static int hf_pn_dcp_service_type = -1;
49 static int hf_pn_dcp_xid = -1;
50 static int hf_pn_dcp_reserved8 = -1;
51 static int hf_pn_dcp_reserved16 = -1;
52 static int hf_pn_dcp_response_delay = -1;
53 static int hf_pn_dcp_data_length = -1;
54 static int hf_pn_dcp_block_length = -1;
56 static int hf_pn_dcp_block = -1;
58 static int hf_pn_dcp_result = -1;
60 static int hf_pn_dcp_option = -1;
61 static int hf_pn_dcp_suboption = -1;
62 static int hf_pn_dcp_req_status = -1;
63 static int hf_pn_dcp_res_status = -1;
65 static int hf_pn_dcp_suboption_ip = -1;
66 static int hf_pn_dcp_suboption_ip_status = -1;
67 static int hf_pn_dcp_suboption_ip_ip = -1;
68 static int hf_pn_dcp_suboption_ip_subnetmask = -1;
69 static int hf_pn_dcp_suboption_ip_default_router = -1;
71 static int hf_pn_dcp_suboption_device = -1;
72 static int hf_pn_dcp_suboption_device_typeofstation = -1;
73 static int hf_pn_dcp_suboption_device_nameofstation = -1;
74 static int hf_pn_dcp_suboption_vendor_id = -1;
75 static int hf_pn_dcp_suboption_device_id = -1;
76 static int hf_pn_dcp_suboption_device_role = -1;
78 static int hf_pn_dcp_suboption_dhcp = -1;
79 static int hf_pn_dcp_suboption_dhcp_device_id = -1;
81 static int hf_pn_dcp_suboption_lldp = -1;
83 static int hf_pn_dcp_suboption_control = -1;
84 static int hf_pn_dcp_suboption_control_status = -1;
86 static int hf_pn_dcp_suboption_all = -1;
88 static int hf_pn_dcp_suboption_manuf = -1;
90 static int hf_pn_dcp_data = -1;
93 static gint ett_pn_dcp = -1;
94 static gint ett_pn_dcp_block = -1;
96 #define FRAME_ID_UC 0xfefd
97 #define FRAME_ID_MC 0xfefe
98 #define FRAME_ID_MC_RESP 0xfeff
101 #define PNDCP_SERVICE_ID_GET 0x03
102 #define PNDCP_SERVICE_ID_SET 0x04
103 #define PNDCP_SERVICE_ID_IDENTIFY 0x05
105 static const value_string pn_dcp_service_id[] = {
106 { 0x00, "reserved" },
107 { 0x01, "Manufacturer specific" },
108 { 0x02, "Manufacturer specific" },
109 { PNDCP_SERVICE_ID_GET, "Get" },
110 { PNDCP_SERVICE_ID_SET, "Set" },
111 { PNDCP_SERVICE_ID_IDENTIFY, "Identify" },
112 /* 0x06 - 0xff reserved */
116 #define PNDCP_SERVICE_TYPE_REQUEST 0
117 #define PNDCP_SERVICE_TYPE_RESPONSE_SUCCESS 1
118 #define PNDCP_SERVICE_TYPE_RESPONSE_UNSUPPORTED 5
120 static const value_string pn_dcp_service_type[] = {
121 { PNDCP_SERVICE_TYPE_REQUEST, "Request" },
122 { PNDCP_SERVICE_TYPE_RESPONSE_SUCCESS, "Response Success" },
123 { PNDCP_SERVICE_TYPE_RESPONSE_UNSUPPORTED, "Response - Request not supported" },
124 /* all others reserved */
128 static const value_string pn_dcp_result[] = {
130 { 0x01, "Option unsupp." },
131 { 0x02, "Suboption unsupp." },
132 { 0x03, "Suboption not set" },
133 { 0x04, "Manufacturer specific" },
134 { 0x05, "Manufacturer specific" },
135 { 0x06, "Ressource Error" },
136 /* all others reserved */
140 static const value_string pn_dcp_req_status[] = {
141 { 0x0000, "Don't save data permanent" },
142 { 0x0001, "Save data permanent" },
143 /*0x0002 - 0xffff reserved */
148 #define PNDCP_OPTION_IP 0x01
149 #define PNDCP_OPTION_DEVICE 0x02
150 #define PNDCP_OPTION_DHCP 0x03
151 #define PNDCP_OPTION_LLDP 0x04
152 #define PNDCP_OPTION_CONTROL 0x05
153 #define PNDCP_OPTION_MANUF_X80 0x80
154 #define PNDCP_OPTION_MANUF_X81 0x81
155 #define PNDCP_OPTION_MANUF_X82 0x82
156 #define PNDCP_OPTION_MANUF_X83 0x83
157 #define PNDCP_OPTION_MANUF_X84 0x84
158 #define PNDCP_OPTION_MANUF_X85 0x85
159 #define PNDCP_OPTION_MANUF_X86 0x86
160 #define PNDCP_OPTION_ALLSELECTOR 0xff
162 static const value_string pn_dcp_option[] = {
163 { 0x00, "reserved" },
164 { PNDCP_OPTION_IP, "IP" },
165 { PNDCP_OPTION_DEVICE, "Device properties" },
166 { PNDCP_OPTION_DHCP, "DHCP" },
167 { PNDCP_OPTION_LLDP, "LLDP" },
168 { PNDCP_OPTION_CONTROL, "Control" },
169 /*0x06 - 0x7f reserved */
170 /*0x80 - 0xfe manufacturer specific */
171 { PNDCP_OPTION_MANUF_X80, "Manufacturer specific" },
172 { PNDCP_OPTION_MANUF_X81, "Manufacturer specific" },
173 { PNDCP_OPTION_MANUF_X82, "Manufacturer specific" },
174 { PNDCP_OPTION_MANUF_X83, "Manufacturer specific" },
175 { PNDCP_OPTION_MANUF_X84, "Manufacturer specific" },
176 { PNDCP_OPTION_MANUF_X85, "Manufacturer specific" },
177 { PNDCP_OPTION_MANUF_X86, "Manufacturer specific" },
178 { PNDCP_OPTION_ALLSELECTOR, "All Selector" },
182 #define PNDCP_SUBOPTION_IP_MAC 0x01
183 #define PNDCP_SUBOPTION_IP_IP 0x02
185 static const value_string pn_dcp_suboption_ip[] = {
186 { 0x00, "Reserved" },
187 { PNDCP_SUBOPTION_IP_MAC, "MAC address" },
188 { PNDCP_SUBOPTION_IP_IP, "IP parameter" },
189 /*0x03 - 0xff reserved */
193 static const value_string pn_dcp_suboption_ip_status[] = {
194 { 0x0000, "IP not set" },
195 { 0x0001, "IP set" },
196 { 0x0002, "IP set by DHCP" },
197 /*0x0003 - 0xffff reserved */
201 #define PNDCP_SUBOPTION_DEVICE_MANUF 0x01
202 #define PNDCP_SUBOPTION_DEVICE_NAMEOFSTATION 0x02
203 #define PNDCP_SUBOPTION_DEVICE_DEV_ID 0x03
204 #define PNDCP_SUBOPTION_DEVICE_DEV_ROLE 0x04
205 #define PNDCP_SUBOPTION_DEVICE_DEV_OPTIONS 0x05
207 static const value_string pn_dcp_suboption_device[] = {
208 { 0x00, "Reserved" },
209 { PNDCP_SUBOPTION_DEVICE_MANUF, "Manufacturer specific (Type of Station)" },
210 { PNDCP_SUBOPTION_DEVICE_NAMEOFSTATION, "Name of Station" },
211 { PNDCP_SUBOPTION_DEVICE_DEV_ID, "Device ID" },
212 { PNDCP_SUBOPTION_DEVICE_DEV_ROLE, "Device Role" },
213 { PNDCP_SUBOPTION_DEVICE_DEV_OPTIONS, "Device Options" },
214 /*0x06 - 0xff reserved */
218 #define PNDCP_SUBOPTION_DHCP_CLIENT_ID 61
220 static const value_string pn_dcp_suboption_dhcp[] = {
222 { 43, "Vendor specific" },
223 { 54, "Server identifier" },
224 { 55, "Parameter request list" },
225 { 60, "Class identifier" },
226 { PNDCP_SUBOPTION_DHCP_CLIENT_ID, "DHCP client identifier" },
227 { 81, "FQDN, Fully Qualified Domain Name" },
228 { 97, "UUID/GUID-based Client" },
229 { 255, "Control DHCP for address resolution" },
230 /*all others reserved */
234 static const value_string pn_dcp_suboption_lldp[] = {
235 /* currently unknown */
239 #define PNDCP_SUBOPTION_CONTROL_START_TRANS 0x01
240 #define PNDCP_SUBOPTION_CONTROL_END_TRANS 0x02
241 #define PNDCP_SUBOPTION_CONTROL_SIGNAL 0x03
242 #define PNDCP_SUBOPTION_CONTROL_RESPONSE 0x04
244 static const value_string pn_dcp_suboption_control[] = {
245 { 0x00, "Reserved" },
246 { PNDCP_SUBOPTION_CONTROL_START_TRANS, "Start Transaction" },
247 { PNDCP_SUBOPTION_CONTROL_END_TRANS, "End Transaction" },
248 { PNDCP_SUBOPTION_CONTROL_SIGNAL, "Signal" },
249 { PNDCP_SUBOPTION_CONTROL_RESPONSE, "Response" },
250 /*0x05 - 0xff reserved */
254 static const value_string pn_dcp_suboption_all[] = {
255 { 0xff, "ALL Selector" },
256 /* all other reserved */
260 static const value_string pn_dcp_suboption_manuf[] = {
267 /* dissect an 8 bit unsigned integer */
269 dissect_pn_uint8(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_,
270 proto_tree *tree, int hfindex, guint8 *pdata)
274 data = tvb_get_guint8 (tvb, offset);
276 proto_tree_add_uint(tree, hfindex, tvb, offset, 1, data);
283 /* dissect a 16 bit unsigned integer */
285 dissect_pn_uint16(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_,
286 proto_tree *tree, int hfindex, guint16 *pdata)
290 data = tvb_get_ntohs (tvb, offset);
293 proto_tree_add_uint(tree, hfindex, tvb, offset, 2, data);
300 /* dissect a 32 bit unsigned integer */
302 dissect_pn_uint32(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_,
303 proto_tree *tree, int hfindex, guint32 *pdata)
307 data = tvb_get_ntohl (tvb, offset);
310 proto_tree_add_uint(tree, hfindex, tvb, offset, 4, data);
317 /* dissect an IPv4 address */
319 dissect_pn_ipv4(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
320 proto_tree *tree, int hfindex, guint32 *pdata)
324 data = tvb_get_ipv4(tvb, offset);
326 proto_tree_add_ipv4(tree, hfindex, tvb, offset, 4, data);
334 /* dissect some padding data (with the given length) */
336 dissect_pn_padding(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
337 proto_tree *tree, int length)
339 proto_tree_add_string_format(tree, hf_pn_dcp_data, tvb, offset, length, "data",
340 "Padding: %u byte", length);
342 return offset + length;
345 /* append the given info text */
347 pn_append_info(packet_info *pinfo, proto_item *dcp_item, const char *text)
349 if (check_col(pinfo->cinfo, COL_INFO))
350 col_append_fstr(pinfo->cinfo, COL_INFO, text);
352 proto_item_append_text(dcp_item, "%s", text);
356 /* dissect the option field */
358 dissect_PNDCP_Option(tvbuff_t *tvb, int offset, packet_info *pinfo,
359 proto_tree *tree, proto_item *block_item, int hfindex, gboolean append_col)
363 const value_string *val_str;
365 offset = dissect_pn_uint8 (tvb, offset, pinfo, tree, hfindex, &option);
367 case(PNDCP_OPTION_IP):
368 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_ip, &suboption);
369 val_str = pn_dcp_suboption_ip;
371 case(PNDCP_OPTION_DEVICE):
372 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_device, &suboption);
373 val_str = pn_dcp_suboption_device;
375 case(PNDCP_OPTION_DHCP):
376 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_dhcp, &suboption);
377 val_str = pn_dcp_suboption_dhcp;
379 case(PNDCP_OPTION_LLDP):
380 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_lldp, &suboption);
381 val_str = pn_dcp_suboption_lldp;
383 case(PNDCP_OPTION_CONTROL):
384 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_control, &suboption);
385 val_str = pn_dcp_suboption_control;
387 case(PNDCP_OPTION_ALLSELECTOR):
388 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_all, &suboption);
389 val_str = pn_dcp_suboption_all;
392 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_manuf, &suboption);
393 val_str = pn_dcp_suboption_manuf;
396 proto_item_append_text(block_item, ", Status from %s - %s",
397 val_to_str(option, pn_dcp_option, "Unknown"), val_to_str(suboption, val_str, "Unknown"));
400 if (check_col(pinfo->cinfo, COL_INFO))
401 col_append_fstr(pinfo->cinfo, COL_INFO, ", %s", val_to_str(suboption, val_str, "Unknown"));
408 /* dissect the "IP" suboption */
410 dissect_PNDCP_Suboption_IP(tvbuff_t *tvb, int offset, packet_info *pinfo,
411 proto_tree *tree, proto_item *block_item, proto_item *dcp_item,
412 gboolean is_response)
415 guint16 block_length;
422 offset = dissect_pn_uint8 (tvb, offset, pinfo, tree, hf_pn_dcp_suboption_ip, &suboption);
423 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_block_length, &block_length);
426 case(PNDCP_SUBOPTION_IP_MAC):
427 pn_append_info(pinfo, dcp_item, ", MAC");
428 proto_item_append_text(block_item, "IP/MAC");
430 /* XXX - improve this */
431 proto_tree_add_string_format(tree, hf_pn_dcp_data, tvb, offset, block_length, "data",
432 "Block data(0x%x/0x%x): %d bytes", PNDCP_OPTION_IP, suboption, block_length);
433 offset += block_length;
435 case(PNDCP_SUBOPTION_IP_IP):
436 pn_append_info(pinfo, dcp_item, ", IP");
437 proto_item_append_text(block_item, "IP/IP");
440 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_ip_status, &status);
441 proto_item_append_text(block_item, ", Status: %s", val_to_str(status, pn_dcp_suboption_ip_status, "Unknown"));
443 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_req_status, &req_status);
444 proto_item_append_text(block_item, ", Status: %s", val_to_str(req_status, pn_dcp_req_status, "Unknown"));
448 offset = dissect_pn_ipv4(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_ip_ip, &ip);
449 proto_item_append_text(block_item, ", IP: %s", ip_to_str((guint8*)&ip));
452 offset = dissect_pn_ipv4(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_ip_subnetmask, &ip);
453 proto_item_append_text(block_item, ", Subnet: %s", ip_to_str((guint8*)&ip));
456 offset = dissect_pn_ipv4(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_ip_default_router, &ip);
457 proto_item_append_text(block_item, ", Router: %s", ip_to_str((guint8*)&ip));
460 item = proto_tree_add_string_format(tree, hf_pn_dcp_data, tvb, offset, block_length, "data",
461 "Block data(0x%x/0x%x): %d bytes", PNDCP_OPTION_IP, suboption, block_length);
462 expert_add_info_format(pinfo, item, PI_UNDECODED, PI_WARN,
463 "Undecoded suboption %u, %u bytes",
464 suboption, block_length);
465 offset += block_length;
472 /* dissect the "device" suboption */
474 dissect_PNDCP_Suboption_Device(tvbuff_t *tvb, int offset, packet_info *pinfo,
475 proto_tree *tree, proto_item *block_item, proto_item *dcp_item,
476 gboolean is_response)
479 guint16 block_length;
489 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_device, &suboption);
490 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_block_length, &block_length);
492 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_res_status, &status);
497 case(PNDCP_SUBOPTION_DEVICE_MANUF):
498 typeofstation = ep_alloc(block_length+1);
499 tvb_memcpy(tvb, (guint8 *) typeofstation, offset, block_length);
500 typeofstation[block_length] = '\0';
501 proto_tree_add_string (tree, hf_pn_dcp_suboption_device_typeofstation, tvb, offset, block_length, typeofstation);
502 pn_append_info(pinfo, dcp_item, ", TypeOfStation");
503 proto_item_append_text(block_item, "Device/Manufacturer specific");
505 proto_item_append_text(block_item, ", Status: %u", status);
506 proto_item_append_text(block_item, ", TypeOfStation: \"%s\"", typeofstation);
507 offset += block_length;
509 case(PNDCP_SUBOPTION_DEVICE_NAMEOFSTATION):
510 nameofstation = ep_alloc(block_length+1);
511 tvb_memcpy(tvb, (guint8 *) nameofstation, offset, block_length);
512 nameofstation[block_length] = '\0';
513 proto_tree_add_string (tree, hf_pn_dcp_suboption_device_nameofstation, tvb, offset, block_length, nameofstation);
514 pn_append_info(pinfo, dcp_item, ", NameOfStation");
515 proto_item_append_text(block_item, "Device/NameOfStation");
517 proto_item_append_text(block_item, ", Status: %u", status);
518 proto_item_append_text(block_item, ", \"%s\"", nameofstation);
519 offset += block_length;
521 case(PNDCP_SUBOPTION_DEVICE_DEV_ID):
522 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_vendor_id, &vendor_id);
523 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_device_id, &device_id);
524 pn_append_info(pinfo, dcp_item, ", Dev-ID");
525 proto_item_append_text(block_item, "Device/Device ID");
527 proto_item_append_text(block_item, ", Status: %u", status);
528 proto_item_append_text(block_item, ", VendorID: 0x%04x / DeviceID: 0x%04x", vendor_id, device_id);
530 case(PNDCP_SUBOPTION_DEVICE_DEV_ROLE):
531 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_device_role, &device_role);
532 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_reserved8, NULL);
533 pn_append_info(pinfo, dcp_item, ", Dev-Role");
534 proto_item_append_text(block_item, "Device/Device Role");
536 proto_item_append_text(block_item, ", Status: %u", status);
537 if(device_role & 0x01)
538 proto_item_append_text(block_item, ", IO-Device");
539 if(device_role & 0x02)
540 proto_item_append_text(block_item, ", IO-Controller");
541 if(device_role & 0x04)
542 proto_item_append_text(block_item, ", IO-Multidevice");
543 if(device_role & 0x08)
544 proto_item_append_text(block_item, ", PN-Supervisor");
546 case(PNDCP_SUBOPTION_DEVICE_DEV_OPTIONS):
547 info_str = ep_strdup_printf(", Dev-Options(%u)", block_length/2);
548 pn_append_info(pinfo, dcp_item, info_str);
549 proto_item_append_text(block_item, "Device/Device Options");
551 proto_item_append_text(block_item, ", Status: %u", status);
552 proto_item_append_text(block_item, ", %u options", block_length/2);
553 for( ; block_length != 0; block_length -= 2) {
554 offset = dissect_PNDCP_Option(tvb, offset, pinfo, tree, NULL /*block_item*/, hf_pn_dcp_option,
555 FALSE /* append_col */);
559 item = proto_tree_add_string_format(tree, hf_pn_dcp_data, tvb, offset, block_length, "data",
560 "Block data(0x%x/0x%x): %d bytes", PNDCP_OPTION_DEVICE, suboption, block_length);
561 expert_add_info_format(pinfo, item, PI_UNDECODED, PI_WARN,
562 "Undecoded suboption %u, %u bytes",
563 suboption, block_length);
564 offset += block_length;
571 /* dissect the "DHCP" suboption */
573 dissect_PNDCP_Suboption_DHCP(tvbuff_t *tvb, int offset, packet_info *pinfo,
574 proto_tree *tree, proto_item *block_item, proto_item *dcp_item,
575 gboolean is_response _U_)
578 guint16 block_length;
582 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_dhcp, &suboption);
583 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_block_length, &block_length);
586 case(PNDCP_SUBOPTION_DHCP_CLIENT_ID):
587 pn_append_info(pinfo, dcp_item, ", DHCP client identifier");
588 proto_item_append_text(block_item, "DHCP/Client-ID");
589 proto_tree_add_item(tree, hf_pn_dcp_suboption_dhcp_device_id, tvb, offset, block_length, FALSE);
590 offset += block_length;
593 item = proto_tree_add_string_format(tree, hf_pn_dcp_data, tvb, offset, block_length, "data",
594 "Block data(0x%x/0x%x): %d bytes", PNDCP_OPTION_DHCP, suboption, block_length);
595 expert_add_info_format(pinfo, item, PI_UNDECODED, PI_WARN,
596 "Undecoded suboption %u, %u bytes",
597 suboption, block_length);
598 offset += block_length;
605 /* dissect the "LLDP" suboption */
607 dissect_PNDCP_Suboption_LLDP(tvbuff_t *tvb, int offset, packet_info *pinfo,
608 proto_tree *tree, proto_item *block_item _U_, proto_item *dcp_item _U_,
609 gboolean is_response _U_)
612 guint16 block_length;
616 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_lldp, &suboption);
617 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_block_length, &block_length);
619 /* XXX - improve this */
620 item = proto_tree_add_string_format(tree, hf_pn_dcp_data, tvb, offset, block_length, "data",
621 "Block data(0x%x/0x%x): %d bytes", PNDCP_OPTION_LLDP, suboption, block_length);
622 expert_add_info_format(pinfo, item, PI_UNDECODED, PI_WARN,
623 "Undecoded suboption %u", suboption);
629 /* dissect the "control" suboption */
631 dissect_PNDCP_Suboption_Control(tvbuff_t *tvb, int offset, packet_info *pinfo,
632 proto_tree *tree, proto_item *block_item, proto_item *dcp_item,
633 gboolean is_response _U_)
637 guint16 block_length;
643 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_control, &suboption);
644 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_block_length, &block_length);
647 case(PNDCP_SUBOPTION_CONTROL_START_TRANS):
648 pn_append_info(pinfo, dcp_item, ", Start-Trans");
649 proto_item_append_text(block_item, "Control/Start-Transaction");
650 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_res_status, &status);
652 case(PNDCP_SUBOPTION_CONTROL_END_TRANS):
653 pn_append_info(pinfo, dcp_item, ", End-Trans");
654 proto_item_append_text(block_item, "Control/End-Transaction");
655 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_res_status, &status);
657 case(PNDCP_SUBOPTION_CONTROL_SIGNAL):
658 pn_append_info(pinfo, dcp_item, ", Signal");
659 proto_item_append_text(block_item, "Control/Signal");
660 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_res_status, &status);
663 /* XXX - improve this */
664 proto_tree_add_string_format(tree, hf_pn_dcp_data, tvb, offset, block_length, "data",
665 "Block data: %d bytes", block_length);
666 offset += block_length;
668 case(PNDCP_SUBOPTION_CONTROL_RESPONSE):
669 proto_item_append_text(block_item, "Control/Response");
670 offset = dissect_PNDCP_Option(tvb, offset, pinfo, tree, block_item, hf_pn_dcp_suboption_control_status,
671 FALSE /* append_col */);
672 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_result, &result);
673 info_str = ep_strdup_printf(", Response(%s)", val_to_str(result, pn_dcp_result, "Unknown"));
674 pn_append_info(pinfo, dcp_item, info_str);
675 proto_item_append_text(block_item, ", Result: %s", val_to_str(result, pn_dcp_result, "Unknown"));
678 item = proto_tree_add_string_format(tree, hf_pn_dcp_data, tvb, offset, block_length, "data",
679 "Block data(0x%x/0x%x): %d bytes", PNDCP_OPTION_CONTROL, suboption, block_length);
680 expert_add_info_format(pinfo, item, PI_UNDECODED, PI_WARN,
681 "Undecoded suboption %u, %u bytes",
682 suboption, block_length);
683 offset += block_length;
690 /* dissect the "all" suboption */
692 dissect_PNDCP_Suboption_All(tvbuff_t *tvb, int offset, packet_info *pinfo,
693 proto_tree *tree, proto_item *block_item, proto_item *dcp_item,
694 gboolean is_response _U_)
697 guint16 block_length;
700 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_all, &suboption);
701 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_block_length, &block_length);
705 pn_append_info(pinfo, dcp_item, ", All");
706 proto_item_append_text(block_item, "All/All");
709 item = proto_tree_add_string_format(tree, hf_pn_dcp_data, tvb, offset, block_length, "data",
710 "Block data(0x%x/0x%x): %d bytes", PNDCP_OPTION_ALLSELECTOR, suboption, block_length);
711 expert_add_info_format(pinfo, item, PI_UNDECODED, PI_WARN,
712 "Undecoded suboption %u, %u bytes",
713 suboption, block_length);
714 offset += block_length;
721 /* dissect the "manufacturer" suboption */
723 dissect_PNDCP_Suboption_Manuf(tvbuff_t *tvb, int offset, packet_info *pinfo,
724 proto_tree *tree, proto_item *block_item, proto_item *dcp_item,
725 gboolean is_response _U_)
728 guint16 block_length;
731 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_manuf, &suboption);
732 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_block_length, &block_length);
736 pn_append_info(pinfo, dcp_item, ", Manufacturer Specific");
737 proto_item_append_text(block_item, "Manufacturer Specific");
738 item = proto_tree_add_string_format(tree, hf_pn_dcp_data, tvb, offset, block_length, "data",
739 "Block data: %d bytes", block_length);
740 expert_add_info_format(pinfo, item, PI_UNDECODED, PI_WARN,
741 "Undecoded suboption %u, %u bytes",
742 suboption, block_length);
743 offset += block_length;
750 /* dissect one DCP block */
752 dissect_PNDCP_Block(tvbuff_t *tvb, int offset, packet_info *pinfo,
753 proto_tree *tree, proto_item *dcp_item,
754 gboolean is_response)
757 proto_item *block_item;
758 proto_tree *block_tree;
759 int ori_offset = offset;
761 /* subtree for block */
762 block_item = proto_tree_add_none_format(tree, hf_pn_dcp_block,
763 tvb, offset, 0, "Block: ");
764 block_tree = proto_item_add_subtree(block_item, ett_pn_dcp_block);
767 offset = dissect_pn_uint8(tvb, offset, pinfo, block_tree, hf_pn_dcp_option, &option);
770 case(PNDCP_OPTION_IP):
771 offset = dissect_PNDCP_Suboption_IP(tvb, offset, pinfo, block_tree, block_item, dcp_item, is_response);
773 case(PNDCP_OPTION_DEVICE):
774 offset = dissect_PNDCP_Suboption_Device(tvb, offset, pinfo, block_tree, block_item, dcp_item, is_response);
776 case(PNDCP_OPTION_DHCP):
777 offset = dissect_PNDCP_Suboption_DHCP(tvb, offset, pinfo, block_tree, block_item, dcp_item, is_response);
779 case(PNDCP_OPTION_LLDP):
780 offset = dissect_PNDCP_Suboption_LLDP(tvb, offset, pinfo, block_tree, block_item, dcp_item, is_response);
782 case(PNDCP_OPTION_CONTROL):
783 offset = dissect_PNDCP_Suboption_Control(tvb, offset, pinfo, block_tree, block_item, dcp_item, is_response);
785 case(PNDCP_OPTION_ALLSELECTOR):
786 offset = dissect_PNDCP_Suboption_All(tvb, offset, pinfo, block_tree, block_item, dcp_item, is_response);
788 case(PNDCP_OPTION_MANUF_X80):
789 case(PNDCP_OPTION_MANUF_X81):
791 offset = dissect_PNDCP_Suboption_Manuf(tvb, offset, pinfo, block_tree, block_item, dcp_item, is_response);
794 proto_item_set_len(block_item, offset-ori_offset);
796 if((offset-ori_offset) & 1) {
797 /* we have an odd number of bytes in this block, add a padding byte */
798 offset = dissect_pn_padding(tvb, offset, pinfo, tree, 1);
805 /* dissect a whole DCP PDU */
807 dissect_PNDCP_PDU(tvbuff_t *tvb,
808 packet_info *pinfo, proto_tree *tree, proto_item *dcp_item)
813 guint16 response_delay;
817 gboolean is_response = FALSE;
821 offset = dissect_pn_uint8 (tvb, offset, pinfo, tree, hf_pn_dcp_service_id, &service_id);
822 offset = dissect_pn_uint8 (tvb, offset, pinfo, tree, hf_pn_dcp_service_type, &service_type);
823 offset = dissect_pn_uint32(tvb, offset, pinfo, tree, hf_pn_dcp_xid, &xid);
824 if(service_id == PNDCP_SERVICE_ID_IDENTIFY && service_type == PNDCP_SERVICE_TYPE_REQUEST) {
825 /* multicast header */
826 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_response_delay, &response_delay);
829 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_reserved16, NULL);
831 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_data_length, &data_length);
834 case(PNDCP_SERVICE_ID_GET):
835 pn_append_info(pinfo, dcp_item, "Get");
837 case(PNDCP_SERVICE_ID_SET):
838 pn_append_info(pinfo, dcp_item, "Set");
840 case(PNDCP_SERVICE_ID_IDENTIFY):
841 pn_append_info(pinfo, dcp_item, "Ident");
844 item = proto_tree_add_string_format(tree, hf_pn_dcp_data, tvb, offset, tvb_length_remaining(tvb, offset), "data",
845 "PN-DCP Unknown service ID %u, Data: %d bytes", service_id, tvb_length_remaining(tvb, offset));
846 expert_add_info_format(pinfo, item, PI_UNDECODED, PI_WARN,
847 "Undecoded service ID %u, %u bytes",
848 service_id, tvb_length_remaining(tvb, offset));
852 switch(service_type) {
853 case(PNDCP_SERVICE_TYPE_REQUEST):
854 pn_append_info(pinfo, dcp_item, " Req");
856 case(PNDCP_SERVICE_TYPE_RESPONSE_SUCCESS):
857 pn_append_info(pinfo, dcp_item, " Ok ");
860 case(PNDCP_SERVICE_TYPE_RESPONSE_UNSUPPORTED):
861 pn_append_info(pinfo, dcp_item, " unsupported");
865 item = proto_tree_add_string_format(tree, hf_pn_dcp_data, tvb, offset, tvb_length_remaining(tvb, offset), "data",
866 "PN-DCP Unknown service type %u, Data: %d bytes", service_type, tvb_length_remaining(tvb, offset));
867 expert_add_info_format(pinfo, item, PI_UNDECODED, PI_WARN,
868 "Undecoded service type %u, %u bytes",
869 service_type, tvb_length_remaining(tvb, offset));
873 xid_str = ep_strdup_printf(", Xid:0x%x", xid);
874 pn_append_info(pinfo, dcp_item, xid_str);
876 /* dissect a number of blocks (depending on the remaining length) */
878 int ori_offset = offset;
880 if(service_id == PNDCP_SERVICE_ID_GET && service_type == PNDCP_SERVICE_TYPE_REQUEST) {
882 offset = dissect_PNDCP_Option(tvb, offset, pinfo,
883 tree, dcp_item, hf_pn_dcp_option, TRUE /* append_col */);
885 offset = dissect_PNDCP_Block(tvb, offset, pinfo, tree, dcp_item, is_response);
887 /* prevent an infinite loop */
888 if(offset <= ori_offset || data_length < (offset - ori_offset)) {
889 THROW(ReportedBoundsError);
891 data_length -= (offset - ori_offset);
896 /* possibly dissect a PN-RT packet (frame ID must be in the appropriate range) */
898 dissect_PNDCP_Data_heur(tvbuff_t *tvb,
899 packet_info *pinfo, proto_tree *tree)
902 proto_item *item = NULL;
903 proto_tree *dcp_tree = NULL;
906 /* the tvb will NOT contain the frame_id here, so get it from our private data! */
907 u16FrameID = GPOINTER_TO_UINT(pinfo->private_data);
909 /* frame id must be in valid range (acyclic Real-Time, DCP) */
910 if (u16FrameID < FRAME_ID_UC || u16FrameID > FRAME_ID_MC_RESP) {
911 /* we are not interested in this packet */
915 if (check_col(pinfo->cinfo, COL_PROTOCOL))
916 col_add_str(pinfo->cinfo, COL_PROTOCOL, "PN-DCP");
917 if (check_col(pinfo->cinfo, COL_INFO))
918 col_add_str(pinfo->cinfo, COL_INFO, "");
920 /* subtree for DCP */
921 item = proto_tree_add_protocol_format(tree, proto_pn_dcp, tvb, 0, tvb_get_ntohs(tvb, 8) + 10,
923 dcp_tree = proto_item_add_subtree(item, ett_pn_dcp);
925 /* dissect this PDU */
926 dissect_PNDCP_PDU(tvb, pinfo, dcp_tree, item);
933 proto_register_pn_dcp (void)
935 static hf_register_info hf[] = {
937 { "PROFINET DCP", "pn_dcp", FT_NONE, BASE_NONE, NULL, 0x0, "", HFILL }},
938 { &hf_pn_dcp_service_id,
939 { "Service-ID", "pn_dcp.service_id", FT_UINT8, BASE_DEC, VALS(pn_dcp_service_id), 0x0, "", HFILL }},
940 { &hf_pn_dcp_service_type,
941 { "Service-Type", "pn_dcp.service_type", FT_UINT8, BASE_DEC, VALS(pn_dcp_service_type), 0x0, "", HFILL }},
943 { "xid", "pn_dcp.xid", FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
944 { &hf_pn_dcp_reserved8,
945 { "Reserved", "pn_dcp.reserved8", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
946 { &hf_pn_dcp_reserved16,
947 { "Reserved", "pn_dcp.reserved16", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
948 { &hf_pn_dcp_response_delay,
949 { "ResponseDelay", "pn_dcp.response_delay", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
950 { &hf_pn_dcp_data_length,
951 { "DCPDataLength", "pn_dcp.data_length", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
952 { &hf_pn_dcp_block_length,
953 { "DataBlockLength", "pn_dcp.block_length", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
955 { "Option", "pn_dcp.option", FT_UINT8, BASE_DEC, VALS(pn_dcp_option), 0x0, "", HFILL }},
956 { &hf_pn_dcp_suboption,
957 { "Suboption", "pn_dcp.suboption", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
959 { "Result", "pn_dcp.result", FT_UINT8, BASE_DEC, VALS(pn_dcp_result), 0x0, "", HFILL }},
961 { "Block", "pn_dcp.block", FT_NONE, BASE_NONE, NULL, 0x0, "", HFILL }},
962 { &hf_pn_dcp_req_status,
963 { "Status", "pn_dcp.req_status", FT_UINT16, BASE_DEC, VALS(pn_dcp_req_status), 0x0, "", HFILL }},
964 { &hf_pn_dcp_res_status,
965 { "ResponseStatus", "pn_dcp.res_status", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
966 { &hf_pn_dcp_suboption_ip,
967 { "Suboption", "pn_dcp.suboption_ip", FT_UINT8, BASE_DEC, VALS(pn_dcp_suboption_ip), 0x0, "", HFILL }},
968 { &hf_pn_dcp_suboption_ip_status,
969 { "Status", "pn_dcp.suboption_ip_status", FT_UINT16, BASE_DEC, VALS(pn_dcp_suboption_ip_status), 0x0, "", HFILL }},
970 { &hf_pn_dcp_suboption_ip_ip,
971 { "IPaddress", "pn_dcp.subobtion_ip_ip", FT_IPv4, BASE_NONE, NULL, 0x0, "", HFILL }},
972 { &hf_pn_dcp_suboption_ip_subnetmask,
973 { "Subnetmask", "pn_dcp.subobtion_ip_subnetmask", FT_IPv4, BASE_NONE, NULL, 0x0, "", HFILL }},
974 { &hf_pn_dcp_suboption_ip_default_router,
975 { "Default-router", "pn_dcp.subobtion_ip_default_router", FT_IPv4, BASE_NONE, NULL, 0x0, "", HFILL }},
977 { &hf_pn_dcp_suboption_device,
978 { "Suboption", "pn_dcp.suboption_device", FT_UINT8, BASE_DEC, VALS(pn_dcp_suboption_device), 0x0, "", HFILL }},
979 { &hf_pn_dcp_suboption_device_typeofstation,
980 { "TypeOfStation", "pn_dcp.suboption_device_typeofstation", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
981 { &hf_pn_dcp_suboption_device_nameofstation,
982 { "NameOfStation", "pn_dcp.suboption_device_nameofstation", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
983 { &hf_pn_dcp_suboption_vendor_id,
984 { "VendorID", "pn_dcp.suboption_vendor_id", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }},
985 { &hf_pn_dcp_suboption_device_id,
986 { "DeviceID", "pn_dcp.suboption_device_id", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }},
987 { &hf_pn_dcp_suboption_device_role,
988 { "Device-role", "pn_dcp.suboption_device_role", FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
990 { &hf_pn_dcp_suboption_dhcp,
991 { "Suboption", "pn_dcp.suboption_dhcp", FT_UINT8, BASE_DEC, VALS(pn_dcp_suboption_dhcp), 0x0, "", HFILL }},
992 { &hf_pn_dcp_suboption_dhcp_device_id,
993 { "Device ID", "pn_dcp.suboption_dhcp_device_id", FT_BYTES, BASE_HEX, NULL, 0x0, "", HFILL }},
995 { &hf_pn_dcp_suboption_lldp,
996 { "Suboption", "pn_dcp.suboption_lldp", FT_UINT8, BASE_DEC, VALS(pn_dcp_suboption_lldp), 0x0, "", HFILL }},
998 { &hf_pn_dcp_suboption_control,
999 { "Suboption", "pn_dcp.suboption_control", FT_UINT8, BASE_DEC, VALS(pn_dcp_suboption_control), 0x0, "", HFILL }},
1000 { &hf_pn_dcp_suboption_control_status,
1001 { "ResponseStatus", "pn_dcp.suboption_control_status", FT_UINT8, BASE_DEC, VALS(pn_dcp_option), 0x0, "", HFILL }},
1003 { &hf_pn_dcp_suboption_all,
1004 { "Suboption", "pn_dcp.suboption_all", FT_UINT8, BASE_DEC, VALS(pn_dcp_suboption_all), 0x0, "", HFILL }},
1006 { &hf_pn_dcp_suboption_manuf,
1007 { "Suboption", "pn_dcp.suboption_manuf", FT_UINT8, BASE_DEC, VALS(pn_dcp_suboption_manuf), 0x0, "", HFILL }},
1010 { "Undecoded Data", "pn_dcp.data", FT_STRING, BASE_DEC, NULL, 0x0, "", HFILL }},
1013 static gint *ett[] = {
1017 proto_pn_dcp = proto_register_protocol ("PROFINET DCP", "PN-DCP", "pn_dcp");
1018 proto_register_field_array (proto_pn_dcp, hf, array_length (hf));
1019 proto_register_subtree_array (ett, array_length (ett));
1023 proto_reg_handoff_pn_dcp (void)
1025 /* register ourself as an heuristic pn-rt payload dissector */
1026 heur_dissector_add("pn_rt", dissect_PNDCP_Data_heur, proto_pn_dcp);