PROFINET: fix dissection of IO conversasion direction
authornakarlsson <se.nakarlsson@gmail.com>
Wed, 28 Nov 2018 11:51:56 +0000 (12:51 +0100)
committerAnders Broman <a.broman58@gmail.com>
Fri, 30 Nov 2018 11:25:59 +0000 (11:25 +0000)
Bug: 15313
Change-Id: I5255f8b03f9d86cd7da8be34a71f0a3932bfca5c
Reviewed-on: https://code.wireshark.org/review/30821
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
plugins/epan/profinet/packet-dcerpc-pn-io.c
plugins/epan/profinet/packet-pn-dcp.c

index e20c84a3218f94131869c2b3efb343c449378674..e2f34b78223c436a21ba0dfd2a743782e5f8c271 100644 (file)
@@ -7653,10 +7653,10 @@ dissect_ARBlockReq_block(tvbuff_t *tvb, int offset,
             /* Get current conversation endpoints using MAC addresses */
             conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_UDP, 0, 0, 0);
             if (conversation == NULL) {
-                /* If conversation is null, then create new conversation */
-                /* Connect Request is sent by controller and not by device. */
-                /* All conversations are based on Controller MAC as address */
-                conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_UDP, 0, 0, 0);
+                /* Create new conversation, if no "Ident OK" frame as been dissected yet!
+                 * Need to switch dl_src & dl_dst, as current packet is sent by controller and not by device.
+                 * All conversations are based on Device MAC as addr1 */
+                conversation = conversation_new(pinfo->num, &pinfo->dl_dst, &pinfo->dl_src, ENDPOINT_NONE, 0, 0, 0);
             }
 
             /* Try to get apdu status switch information from the conversation */
@@ -8672,7 +8672,10 @@ dissect_DataDescription(tvbuff_t *tvb, int offset,
         /* Get current conversation endpoints using MAC addresses */
         conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_NONE, 0, 0, 0);
         if (conversation == NULL) {
-            conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_NONE, 0, 0, 0);
+            /* Create new conversation, if no "Ident OK" frame as been dissected yet!
+             * Need to switch dl_src & dl_dst, as current packet is sent by controller and not by device.
+             * All conversations are based on Device MAC as addr1 */
+           conversation = conversation_new(pinfo->num, &pinfo->dl_dst, &pinfo->dl_src, ENDPOINT_NONE, 0, 0, 0);
         }
 
         station_info = (stationInfo*)conversation_get_proto_data(conversation, proto_pn_dcp);
@@ -8804,7 +8807,10 @@ dissect_ExpectedSubmoduleBlockReq_block(tvbuff_t *tvb, int offset,
     /* Get current conversation endpoints using MAC addresses */
     conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_NONE, 0, 0, 0);
     if (conversation == NULL) {
-        conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_NONE, 0, 0, 0);
+        /* Create new conversation, if no "Ident OK" frame as been dissected yet!
+        * Need to switch dl_src & dl_dst, as current packet is sent by controller and not by device.
+        * All conversations are based on Device MAC as addr1 */
+        conversation = conversation_new(pinfo->num, &pinfo->dl_dst, &pinfo->dl_src, ENDPOINT_NONE, 0, 0, 0);
     }
 
     station_info = (stationInfo*)conversation_get_proto_data(conversation, proto_pn_dcp);
@@ -10656,7 +10662,10 @@ dissect_ProfiSafeParameterRequest(tvbuff_t *tvb, int offset,
         /* Get current conversation endpoints using MAC addresses */
         conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_NONE, 0, 0, 0);
         if (conversation == NULL) {
-            conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_NONE, 0, 0, 0);
+            /* Create new conversation, if no "Ident OK" frame as been dissected yet!
+             * Need to switch dl_src & dl_dst, as current packet is sent by controller and not by device.
+             * All conversations are based on Device MAC as addr1 */
+            conversation = conversation_new(pinfo->num, &pinfo->dl_dst, &pinfo->dl_src, ENDPOINT_NONE, 0, 0, 0);
         }
 
         station_info = (stationInfo*)conversation_get_proto_data(conversation, proto_pn_dcp);
@@ -10721,7 +10730,10 @@ dissect_RecordDataWrite(tvbuff_t *tvb, int offset,
     /* Get current conversation endpoints using MAC addresses */
     conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_NONE, 0, 0, 0);
     if (conversation == NULL) {
-        conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_NONE, 0, 0, 0);
+        /* Create new conversation, if no "Ident OK" frame as been dissected yet!
+        * Need to switch dl_src & dl_dst, as current packet is sent by controller and not by device.
+        * All conversations are based on Device MAC as addr1 */
+        conversation = conversation_new(pinfo->num, &pinfo->dl_dst, &pinfo->dl_src, ENDPOINT_NONE, 0, 0, 0);
     }
 
     station_info = (stationInfo*)conversation_get_proto_data(conversation, proto_pn_dcp);
index f440cc1bc4e6664afb4b0bc083b3c4b2e772463f..4a4145734c9daa08ab7fbff52924ca4726adaf58 100644 (file)
@@ -544,7 +544,14 @@ dissect_PNDCP_Suboption_Device(tvbuff_t *tvb, int offset, packet_info *pinfo,
             /* Create a conversation between the MAC addresses */
             conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_NONE, 0, 0, 0);
             if (conversation == NULL) {
-                conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_NONE, 0, 0, 0);
+                /* Create new conversation, need to switch dl_src & dl_dst if not a response
+                 * All conversations are based on Device MAC as addr1 */
+                if (is_response) {
+                   conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_NONE, 0, 0, 0);
+                }
+                else {
+                   conversation = conversation_new(pinfo->num, &pinfo->dl_dst, &pinfo->dl_src, ENDPOINT_NONE, 0, 0, 0);
+                }
             }
 
             station_info = (stationInfo*)conversation_get_proto_data(conversation, proto_pn_dcp);
@@ -582,7 +589,14 @@ dissect_PNDCP_Suboption_Device(tvbuff_t *tvb, int offset, packet_info *pinfo,
             /* Create a conversation between the MAC addresses */
             conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_NONE, 0, 0, 0);
             if (conversation == NULL) {
-                conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_NONE, 0, 0, 0);
+                /* Create new conversation, need to switch dl_src & dl_dst if not a response
+                 * All conversations are based on Device MAC as addr1 */
+                if (is_response) {
+                   conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_NONE, 0, 0, 0);
+                }
+                else {
+                   conversation = conversation_new(pinfo->num, &pinfo->dl_dst, &pinfo->dl_src, ENDPOINT_NONE, 0, 0, 0);
+                }
             }
 
             station_info = (stationInfo*)conversation_get_proto_data(conversation, proto_pn_dcp);
@@ -606,7 +620,14 @@ dissect_PNDCP_Suboption_Device(tvbuff_t *tvb, int offset, packet_info *pinfo,
             /* Create a conversation between the MAC addresses */
             conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_NONE, 0, 0, 0);
             if (conversation == NULL) {
-                conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_NONE, 0, 0, 0);
+                /* Create new conversation, need to switch dl_src & dl_dst if not a response
+                 * All conversations are based on Device MAC as addr1 */
+                if (is_response) {
+                   conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, ENDPOINT_NONE, 0, 0, 0);
+                }
+                else {
+                   conversation = conversation_new(pinfo->num, &pinfo->dl_dst, &pinfo->dl_src, ENDPOINT_NONE, 0, 0, 0);
+                }
             }
 
             station_info = (stationInfo*)conversation_get_proto_data(conversation, proto_pn_dcp);