You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2022/07/31 11:27:47 UTC

[plc4x] branch develop updated: chore(ads): Worked on continuing to implement the discovery and route-management parts.

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

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


The following commit(s) were added to refs/heads/develop by this push:
     new 3cd5c76cc chore(ads): Worked on continuing to implement the discovery and route-management parts.
3cd5c76cc is described below

commit 3cd5c76cc19f2046bbbe508303af5f7f60b17409
Author: christoferdutz <ch...@c-ware.de>
AuthorDate: Sun Jul 31 13:27:37 2022 +0200

    chore(ads): Worked on continuing to implement the discovery and route-management parts.
---
 .../resources/protocols/ads/ads-discovery.mspec    | 177 ++++++++++++++-------
 1 file changed, 117 insertions(+), 60 deletions(-)

diff --git a/protocols/ads/src/main/resources/protocols/ads/ads-discovery.mspec b/protocols/ads/src/main/resources/protocols/ads/ads-discovery.mspec
index c010b50c3..0fd1d4ed7 100644
--- a/protocols/ads/src/main/resources/protocols/ads/ads-discovery.mspec
+++ b/protocols/ads/src/main/resources/protocols/ads/ads-discovery.mspec
@@ -17,85 +17,142 @@
  * under the License.
  */
 
+[type AdsDiscoveryConstants
+    [const          uint 16     adsDiscoveryUdpDefaultPort 58899]
+]
+
 ////////////////////////////////////////////////////////////////
 // AMS/TCP Packet
 ////////////////////////////////////////////////////////////////
+//
+// All discovery requests target the ams port SYSTEM_SERVICE
+//
+// A Discovery Request is usually targeted at the broadcast ip of the current network
+// instead of a real IP address (last segment is "255").
+// The PLCs then respond to that.
+// The Discovery Request generally contains no blocks.
+//
+// A Discovery Response usually contains 3 or 4 blocks.
+// In all cases does it contain:
+// - AdsDiscoveryBlockHostname (Host name of the PLC)
+// - AdsDiscoveryBlockOsData   (Some information on the type and OS)
+// - AdsDiscoveryBlockVersion  (The TwinCat version)
+// Some also send a AdsDiscoveryBlockFingerprint
+//
+// A request for adding or deleting a route usually contains:
+// - AdsDiscoveryBlockRouteName
+// - AdsDiscoveryBlockAmsNetId
+// - AdsDiscoveryBlockUserName
+// - AdsDiscoveryBlockPassword
+// - AdsDiscoveryBlockHostName
+//
+// The responses to adding or deleting a route usually only contain one block,
+// containing the AdsDiscoveryBlockStatus
+
+[type AdsDiscovery byteOrder='LITTLE_ENDIAN'
+    [const    uint 32           header                          0x71146603                 ]
+    [simple   uint 32           requestId                                                  ]
+    [simple   Operation         operation                                                  ]
+    [simple   AmsNetId          amsNetId                                                   ]
+    [simple   AdsPortNumbers    portNumber                                                 ]
+    [implicit uint 32           numBlocks                       'COUNT(blocks)'            ]
+    [array    AdsDiscoveryBlock blocks                          count           'numBlocks']
+]
 
-[discriminatedType AdsDiscovery byteOrder='BIG_ENDIAN'
-    [const      uint 32   header     0x03661471]
-    [reserved   uint 32              '0x00000000']
-    [simple     Operation operation]
-    [reserved   uint 16              '0x0000']
-    [simple     Direction direction]
-    [typeSwitch operation, direction
-        ['DISCOVERY', 'REQUEST' DiscoveryRequest
-            [simple AmsNetId amsNetId]
-            [reserved uint 16 '0x1027']
-            [reserved uint 32 '0x00000000']
+[discriminatedType AdsDiscoveryBlock
+    [discriminator    AdsDiscoveryBlockType    blockType                                   ]
+    [typeSwitch    blockType
+        ['STATUS' *Status
+            [const    uint 16   statusLength   0x0004                                      ]
+            [simple   Status    status                                                     ]
         ]
-        ['DISCOVERY', 'RESPONSE' DiscoveryResponse
-            [simple AmsNetId amsNetId]
-            [reserved uint 16 '0x1027']
-            [reserved uint 16 '0x0400']
-            [reserved uint 24 '0x000005']
-            [simple AmsMagicString name]
+        ['PASSWORD' *Password
+            [simple   AmsString password                                                   ]
         ]
-        ['ROUTE', 'REQUEST' RouteRequest
-            [simple     AmsNetId sender]
-            [reserved   uint 16  '0x1027']
-            [reserved   uint 16  '0x0500']
-            [reserved   uint 24  '0x000C']
-            [simple AmsMagicString routeName ]
-            [reserved   uint 16 '0x0700']
-            [implicit   uint 8 amsSize 'target.lengthInBytes']
-            [const uint 8 targetPrefix 0x00]
-            [simple AmsNetId target]
-            [const uint 8 usernamePrefix 0x0D]
-            [simple AmsMagicString username]
-            [const uint 8 passwordPrefix 0x02]
-            [simple AmsMagicString password]
-            [const uint 8 routePrefix 0x05]
-            [simple AmsMagicString address]
-
+        ['VERSION' *Version
+            [implicit uint 16   versionDataLen 'COUNT(versionData)'                        ]
+            [array    byte      versionData    count                'versionDataLen'       ]
+        ]
+        ['OS_DATA' *OsData
+            [implicit uint 16   osDataLen      'COUNT(osData)'                             ]
+            [array    byte      osData         count                'osDataLen'            ]
         ]
-        ['ROUTE', 'RESPONSE' RouteResponse
-            [simple AmsNetId amsNetId]
-            [reserved uint 16 '0x1027']
-            [reserved uint 16 '0x0100']
-            [reserved uint 32 '0x00000100']
-            [simple   RouteStatus status]
-            [reserved uint 24 '0x000000']
+        ['HOST_NAME' *HostName
+            [simple   AmsString hostName                                                   ]
+        ]
+        ['AMS_NET_ID' *AmsNetId
+            [const    uint 16   amsNetIdLength 0x0006                                      ]
+            [simple   AmsString amsNetId                                                   ]
+        ]
+        ['ROUTE_NAME' *RouteName
+            [simple   AmsString routeName                                                  ]
+        ]
+        ['USER_NAME' *UserName
+            [simple   AmsString userName                                                   ]
+        ]
+        ['FINGERPRINT' *Fingerprint
+            [implicit uint 16   dataLen        'COUNT(data)'                               ]
+            [array    byte      data           count                'dataLen'              ]
         ]
     ]
 ]
 
-[enum uint 8 Operation
-    ['0x01' DISCOVERY]
-    ['0x06' ROUTE    ]
+[enum uint 32 AdsDiscoveryBlockType
+    ['0x0001' STATUS]
+    ['0x0002' PASSWORD]
+    ['0x0003' VERSION]
+    ['0x0004' OS_DATA]
+    ['0x0005' HOST_NAME]
+    ['0x0007' AMS_NET_ID]
+    ['0x000C' ROUTE_NAME]
+    ['0x000D' USER_NAME]
+    ['0x0012' FINGERPRINT]
 ]
 
-[enum uint 8 Direction
-    ['0x00' REQUEST ]
-    ['0x80' RESPONSE]
+[enum uint 32 Operation
+    ['0x00000000' GET_AMS_NET_ID_REQUEST ]
+    ['0x80000000' GET_AMS_NET_ID_RESPONSE]
+    ['0x00000001' DISCOVERY_REQUEST      ]
+    ['0x80000001' DISCOVERY_RESPONSE     ]
+    ['0x00000006' ADD_ROUTE_REQUEST      ]
+    ['0x80000006' ADD_ROUTE_RESPONSE     ]
+    ['0x00000007' DEL_ROUTE_REQUEST      ]
+    ['0x80000007' DEL_ROUTE_RESPONSE     ]
 ]
 
-[enum uint 24 RouteStatus
-    ['0x040000' SUCCESS]
+[enum uint 32 Status
+    ['0x00000000' SUCCESS]
     ['0x000407' FAILURE]
 ]
 
-[type AmsMagicString
-    [implicit uint 16 len 'STR_LEN(text) + 1']
-    [reserved uint 8 '0x00']
-    [simple vstring '8 * (len - 1)' text encoding='"UTF-8"']
-    [reserved uint 8 '0x00']
+[type AmsString
+    [implicit uint 16                 len    'STR_LEN(text) + 1']
+    [simple   vstring '8 * (len - 1)' text   encoding='"UTF-8"' ]
+    [reserved uint 8                  '0x00'                    ]
 ]
 
 [type AmsNetId
-    [simple     uint        8   octet1            ]
-    [simple     uint        8   octet2            ]
-    [simple     uint        8   octet3            ]
-    [simple     uint        8   octet4            ]
-    [simple     uint        8   octet5            ]
-    [simple     uint        8   octet6            ]
+    [simple uint 8 octet1]
+    [simple uint 8 octet2]
+    [simple uint 8 octet3]
+    [simple uint 8 octet4]
+    [simple uint 8 octet5]
+    [simple uint 8 octet6]
+]
+
+// From: https://infosys.beckhoff.com/index.php?content=../content/1031/tcadscommon/html/tcadscommon_identadsdevice.htm&id=
+[enum uint 16 AdsPortNumbers
+    ['100'   LOGGER              ]
+    ['110'   EVENT_LOGGER        ]
+    ['300'   IO                  ]
+    ['301'   ADDITIONAL_TASK_1   ]
+    ['302'   ADDITIONAL_TASK_2   ]
+    ['500'   NC                  ]
+    ['801'   PLC_RUNTIME_SYSTEM_1]
+    ['811'   PLC_RUNTIME_SYSTEM_2]
+    ['821'   PLC_RUNTIME_SYSTEM_3]
+    ['831'   PLC_RUNTIME_SYSTEM_4]
+    ['900'   CAM_SWITCH          ]
+    ['10000' SYSTEM_SERVICE      ]
+    ['14000' SCOPE               ]
 ]