You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by hu...@apache.org on 2023/01/31 18:27:36 UTC

[plc4x] 01/02: fix(plc4j/profinet): Updated magic numbers in discovery packets

This is an automated email from the ASF dual-hosted git repository.

hutcheb pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit cb8402fbf8cbf7bfefcde9fec0802538c267d7c5
Author: Ben Hutcheson <be...@gmail.com>
AuthorDate: Tue Jan 31 19:18:55 2023 +0100

    fix(plc4j/profinet): Updated magic numbers in discovery packets
---
 .../plc4x/java/profinet/discovery/ProfinetPlcDiscoverer.java      | 8 +++-----
 .../profinet/src/main/resources/protocols/profinet/profinet.mspec | 3 +--
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/discovery/ProfinetPlcDiscoverer.java b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/discovery/ProfinetPlcDiscoverer.java
index f06d82e7b0..8bba69a7da 100644
--- a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/discovery/ProfinetPlcDiscoverer.java
+++ b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/discovery/ProfinetPlcDiscoverer.java
@@ -308,7 +308,7 @@ public class ProfinetPlcDiscoverer implements PlcDiscoverer {
                                     Collections.singletonList(
                                         new PnDcp_Block_ALLSelector()
                                     )))));
-                    WriteBufferByteBased buffer = new WriteBufferByteBased(34);
+                    WriteBufferByteBased buffer = new WriteBufferByteBased(identificationRequest.getLengthInBytes());
                     try {
                         identificationRequest.serialize(buffer);
                     } catch (SerializationException e) {
@@ -316,15 +316,13 @@ public class ProfinetPlcDiscoverer implements PlcDiscoverer {
                     }
                     Packet packet = null;
                     try {
-                        packet = EthernetPacket.newPacket(buffer.getData(), 0, 34);
+                        packet = EthernetPacket.newPacket(buffer.getBytes(), 0, identificationRequest.getLengthInBytes());
                     } catch (IllegalRawDataException e) {
                         throw new RuntimeException(e);
                     }
                     try {
                         handle.sendPacket(packet);
-                    } catch (PcapNativeException e) {
-                        throw new RuntimeException(e);
-                    } catch (NotOpenException e) {
+                    } catch (PcapNativeException | NotOpenException e) {
                         throw new RuntimeException(e);
                     }
                     return null;
diff --git a/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec b/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
index 09fb0cbf4d..1ba08ea938 100644
--- a/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
+++ b/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
@@ -553,8 +553,7 @@
             [array    byte        deviceVendorValue count 'blockLength-2'             ]
             [padding  uint 8      pad '0x00' 'STATIC_CALL("arrayLength", deviceVendorValue) % 2']
         ]
-        ['DEVICE_PROPERTIES_OPTION','2' PnDcp_Block_DevicePropertiesNameOfStation(uint 16 blockLength)
-            [reserved uint 16     '0x0000'                                            ]
+        ['DEVICE_PROPERTIES_OPTION','2' PnDcp_Block_DevicePropertiesNameOfStation(uint 16 blockLength)                                                      ]
             [array    byte        nameOfStation count 'blockLength-2'                 ]
             [padding  uint 8      pad '0x00' 'STATIC_CALL("arrayLength", nameOfStation) % 2']
         ]