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

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

commit bf77f0d958314681986ed25ff5e134b8ae086f75
Author: Ben Hutcheson <[email protected]>
AuthorDate: Thu Sep 8 10:43:35 2022 -0600

    fix(plc4j(profinet): Add Dummy Advanced Connection Write Request
---
 .../profinet/protocol/ProfinetProtocolLogic.java   | 97 ++++++++++++++++++++--
 .../resources/protocols/profinet/profinet.mspec    | 56 +++++++++++--
 2 files changed, 142 insertions(+), 11 deletions(-)

diff --git 
a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/protocol/ProfinetProtocolLogic.java
 
b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/protocol/ProfinetProtocolLogic.java
index 836732954..8e4e666ab 100644
--- 
a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/protocol/ProfinetProtocolLogic.java
+++ 
b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/protocol/ProfinetProtocolLogic.java
@@ -54,6 +54,16 @@ public class ProfinetProtocolLogic extends 
Plc4xProtocolBase<Ethernet_Frame> {
 
     private ProfinetDriverContext profinetDriverContext;
 
+    private static final Uuid ARUUID;
+
+    static {
+        try {
+            ARUUID = new 
Uuid(Hex.decodeHex("654519352df3b6428f874371217c2b51"));
+        } catch (DecoderException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
     @Override
     public void setContext(ConversationContext<Ethernet_Frame> context) {
         super.setContext(context);
@@ -160,11 +170,23 @@ public class ProfinetProtocolLogic extends 
Plc4xProtocolBase<Ethernet_Frame> {
             } else {
                 throw new PlcException("Unexpected response");
             }
+
+            // Create the packet
+            final DceRpc_Packet profinetAdvancedConnectionWriteRequest = 
createProfinetAdvancedConnectionWriteRequest();
+            // Serialize it to a byte-payload
+            writeBuffer = new 
WriteBufferByteBased(profinetAdvancedConnectionWriteRequest.getLengthInBytes());
+            profinetAdvancedConnectionWriteRequest.serialize(writeBuffer);
+            // Create a udp packet.
+            connectRequestPacket = new DatagramPacket(writeBuffer.getData(), 
writeBuffer.getData().length);
+            connectRequestPacket.setAddress(remoteAddress.getAddress());
+            connectRequestPacket.setPort(remoteAddress.getPort());
+            // Send it.
+
+            udpSocket.send(connectRequestPacket);
+
         } catch (SerializationException | IOException | PlcException | 
ParseException e) {
             logger.error("Error", e);
         }
-
-        //System.out.println(rawSocketChannel);
     }
 
     @Override
@@ -233,14 +255,14 @@ public class ProfinetProtocolLogic extends 
Plc4xProtocolBase<Ethernet_Frame> {
                             // This actually needs to be set to this value and 
not the real port number.
                             0x8892,
                             // It seems that it must be set to this value, or 
it won't work.
-                            "profinetxadriver4933"),
+                            "controller"),
                         new PnIoCm_Block_IoCrReq((short) 1, (short) 0, 
PnIoCm_IoCrType.INPUT_CR,
                             0x0001,
                             0x8892,
                             false, false,
                             false, false, PnIoCm_RtClass.RT_CLASS_2, 40,
                             0xBBF0, 128, 8, 1, 0, 0xffffffff,
-                            3, 3, 0xC000,
+                            50, 50, 0xC000,
                             new 
org.apache.plc4x.java.profinet.readwrite.MacAddress(Hex.decodeHex("000000000000")),
                             Collections.singletonList(
                                 new PnIoCm_IoCrBlockReqApi(
@@ -255,7 +277,7 @@ public class ProfinetProtocolLogic extends 
Plc4xProtocolBase<Ethernet_Frame> {
                             0x0002, 0x8892, false, false,
                             false, false, PnIoCm_RtClass.RT_CLASS_2, 40,
                             0xFFFF, 128, 8, 1, 0, 0xffffffff,
-                            3, 3, 0xC000,
+                            50, 50, 0xC000,
                             new MacAddress(Hex.decodeHex("000000000000")),
                             Collections.singletonList(
                                 new PnIoCm_IoCrBlockReqApi(
@@ -303,6 +325,71 @@ public class ProfinetProtocolLogic extends 
Plc4xProtocolBase<Ethernet_Frame> {
         }
     }
 
+    private DceRpc_Packet createProfinetAdvancedConnectionWriteRequest() 
throws PlcException {
+
+        return new DceRpc_Packet(
+            DceRpc_PacketType.REQUEST, true, false, false,
+            IntegerEncoding.BIG_ENDIAN, CharacterEncoding.ASCII, 
FloatingPointEncoding.IEEE,
+            new DceRpc_ObjectUuid((byte) 0x00, 0x0001, 0x0904, 0x002A),
+            new DceRpc_InterfaceUuid_DeviceInterface(),
+            profinetDriverContext.getDceRpcActivityUuid(),
+            0, 1, DceRpc_Operation.WRITE,
+            new PnIoCm_Packet_Req(16696, 16696, 0, 244,
+                Arrays.asList(
+                    new IODWriteRequestHeader(
+                        (short) 1,
+                        (short) 0,
+                        0,
+                        ARUUID,
+                        0x00000000,
+                        0x0000,
+                        0x0000,
+                        0xe040,
+                        180
+                        ),
+                    new IODWriteRequestHeader(
+                        (short) 1,
+                        (short) 0,
+                        1,
+                        ARUUID,
+                        0x00000000,
+                        0x0000,
+                        0x8000,
+                        0x8071,
+                        12
+                    ),
+                    new PDInterfaceAdjust(
+                        (short) 1,
+                        (short) 0,
+                        MultipleInterfaceModeNameOfDevice.PORT_PROVIDED_BY_LLDP
+                    ),
+                    new IODWriteRequestHeader(
+                        (short) 1,
+                        (short) 0,
+                        2,
+                        ARUUID,
+                        0x00000000,
+                        0x0000,
+                        0x8001,
+                        0x802b,
+                        40
+                    ),
+                    new PDPortDataCheck(
+                        (short) 1,
+                        (short) 0,
+                        0x0000,
+                        0x8001,
+                        new CheckPeers(
+                            (short) 1,
+                            (short) 0,
+                            new PascalString("port-001"),
+                            new PascalString("controller")
+                        )
+                    )
+                ))
+        );
+    }
+
     protected static DceRpc_ActivityUuid generateActivityUuid() {
         UUID number = UUID.randomUUID();
         try {
diff --git 
a/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec 
b/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
index 35bdaf24c..09bfea4a5 100644
--- a/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
+++ b/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
@@ -681,6 +681,34 @@
     [simple        uint 8           blockVersionHigh                    ]
     [simple        uint 8           blockVersionLow                     ]
     [typeSwitch blockType
+        ['IOD_WRITE_REQUEST_HEADER' IODWriteRequestHeader
+            [simple   uint 16                         sequenceNumber           
                              ]
+            [simple   Uuid                            arUuid                   
                              ]
+            [simple   uint 32                         api                      
                              ]
+            [simple   uint 16                         slotNumber               
                              ]
+            [simple   uint 16                         subSlotNumber            
                              ]
+            [const    uint 16                         padField                 
 0x0000                       ]
+            [simple   uint 16                         index                    
                              ]
+            [simple   uint 32                         recordDataLength         
                              ]
+            [padding  uint 8      pad '0x00'          '64 - 6 - 2 - 16 - 4 - 2 
- 2 - 2 - 2 - 4']
+        ]
+        ['PD_INTERFACE_ADJUST' PDInterfaceAdjust
+            [const    uint 16                         padField                 
 0x0000                       ]
+            [const    uint 16                         
multipleInterfaceModeReserved2                  0x0000 ]
+            [const    uint 15                         
multipleInterfaceModeReserved1                  0x0000 ]
+            [simple   MultipleInterfaceModeNameOfDevice 
multipleInterfaceModeNameOfDevice                    ]
+        ]
+        ['PD_PORT_DATA_CHECK' PDPortDataCheck
+            [const    uint 16                         padField                 
 0x0000                       ]
+            [simple   uint 16                         slotNumber               
                              ]
+            [simple   uint 16                         subSlotNumber            
                              ]
+            [simple   PnIoCm_Block                    checkPeers               
                              ]
+        ]
+        ['CHECK_PEERS'  CheckPeers
+            [const    uint 8                          noOfPeers                
 0x01                         ]
+            [simple   PascalString                    peerPortId               
                              ]
+            [simple   PascalString                    peerChassisId            
                              ]
+        ]
         ['AR_BLOCK_REQ' PnIoCm_Block_ArReq
             [simple   PnIoCm_ArType                   arType                   
                              ]
             [simple   Uuid                            arUuid                   
                              ]
@@ -773,13 +801,18 @@
             [array    PnIoCm_ModuleDiffBlockApi apis              count        
 'numberOfApis'      ]
         ]
         ['AR_SERVER_BLOCK' PnIoCm_Block_ArServer
-            //[implicit uint 16                         stationNameLength      
'STR_LEN(cmInitiatorStationName)']
-            //[simple   vstring 'stationNameLength * 8' cmInitiatorStationName 
                                 ]
-            //[padding  byte 0x00                                              
                                 ]
+            [simple   PascalString                    stationName              
                     ]
+            [padding  uint 8      pad '0x00'          '20 - 6 - 
(stationName.stringLength)'              ]
         ]
     ]
 ]
 
+[type PascalString
+    [implicit int 16 sLength          'stringValue.length == 0 ? -1 : 
stringValue.length']
+    [simple vstring 'sLength == -1 ? 0 : sLength * 8' stringValue]
+    [virtual  int 16 stringLength     'stringValue.length == -1 ? 0 : 
stringValue.length']
+]
+
 [type PnIoCm_IoCrBlockReqApi
     [const    uint 32             api              0x00000000             ]
     [implicit uint 16             numIoDataObjects 'COUNT(ioDataObjects)'   ]
@@ -872,15 +905,21 @@
 ]
 
 [enum uint 16 PnIoCm_BlockType
+    ['0x0008' IOD_WRITE_REQUEST_HEADER    ]
     ['0x0101' AR_BLOCK_REQ                ]
-    ['0x8101' AR_BLOCK_RES                ]
     ['0x0102' IO_CR_BLOCK_REQ             ]
-    ['0x8102' IO_CR_BLOCK_RES             ]
     ['0x0103' ALARM_CR_BLOCK_REQ          ]
-    ['0x8103' ALARM_CR_BLOCK_RES          ]
     ['0x0104' EXPECTED_SUBMODULE_BLOCK_REQ]
+    ['0x0110' IOD_CONTROL_REQ             ]
+    ['0x0200' PD_PORT_DATA_CHECK          ]
+    ['0x020a' CHECK_PEERS                 ]
+    ['0x0250' PD_INTERFACE_ADJUST         ]
+    ['0x8101' AR_BLOCK_RES                ]
+    ['0x8102' IO_CR_BLOCK_RES             ]
+    ['0x8103' ALARM_CR_BLOCK_RES          ]
     ['0x8104' MODULE_DIFF_BLOCK           ]
     ['0x8106' AR_SERVER_BLOCK             ]
+    ['0x8110' IOD_CONTROL_RES             ]
 ]
 
 [enum uint 16 PnIoCm_ArType
@@ -917,6 +956,11 @@
     ['0x3' INPUT_AND_OUTPUT_DATA]
 ]
 
+[enum bit MultipleInterfaceModeNameOfDevice
+    ['false' PORT_PROVIDED_BY_LLDP]
+    ['true'  NAME_PROVIDED_BY_LLDP]
+]
+
 [enum uint 16 PnIoCm_DescriptionType
     ['0x0001' INPUT]
 ]

Reply via email to