Sfoglia il codice sorgente

Fix cpplint issues

Signed-off-by: Martin Melik Merkumians <martin.melik@gmail.com>
Martin Melik Merkumians 3 settimane fa
parent
commit
f966c176fe
87 ha cambiato i file con 2744 aggiunte e 2765 eliminazioni
  1. 6 0
      .clang-format
  2. 5 1
      .github/workflows/ci.yml
  3. 2 0
      .github/workflows/exhaustive-analysis.yml
  4. 2 1
      .pre-commit-config.yaml
  5. 29 29
      source/src/api/opener_api.h
  6. 89 89
      source/src/cip/appcontype.c
  7. 6 6
      source/src/cip/appcontype.h
  8. 25 26
      source/src/cip/cipassembly.c
  9. 11 11
      source/src/cip/cipclass3connection.c
  10. 6 6
      source/src/cip/cipclass3connection.h
  11. 169 172
      source/src/cip/cipcommon.c
  12. 30 30
      source/src/cip/cipcommon.h
  13. 237 242
      source/src/cip/cipconnectionmanager.c
  14. 126 126
      source/src/cip/cipconnectionmanager.h
  15. 166 166
      source/src/cip/cipconnectionobject.c
  16. 83 85
      source/src/cip/cipconnectionobject.h
  17. 12 12
      source/src/cip/cipdlr.c
  18. 12 12
      source/src/cip/cipelectronickey.c
  19. 12 12
      source/src/cip/cipelectronickey.h
  20. 43 43
      source/src/cip/cipepath.c
  21. 19 19
      source/src/cip/cipepath.h
  22. 92 92
      source/src/cip/cipethernetlink.c
  23. 6 6
      source/src/cip/cipethernetlink.h
  24. 43 47
      source/src/cip/cipidentity.c
  25. 2 2
      source/src/cip/cipidentity.h
  26. 153 153
      source/src/cip/cipioconnection.c
  27. 3 3
      source/src/cip/cipioconnection.h
  28. 44 46
      source/src/cip/cipmessagerouter.c
  29. 42 44
      source/src/cip/cipqos.c
  30. 4 4
      source/src/cip/cipstring.c
  31. 26 28
      source/src/cip/cipstringi.c
  32. 1 1
      source/src/cip/cipstringi.h
  33. 123 123
      source/src/cip/ciptcpipinterface.c
  34. 16 16
      source/src/cip/ciptcpipinterface.h
  35. 25 25
      source/src/cip/ciptypes.h
  36. 1 1
      source/src/core/trace.h
  37. 1 1
      source/src/core/typedefs.h
  38. 147 149
      source/src/enet_encap/cpf.c
  39. 20 20
      source/src/enet_encap/cpf.h
  40. 151 151
      source/src/enet_encap/encap.c
  41. 27 27
      source/src/enet_encap/encap.h
  42. 15 16
      source/src/enet_encap/endianconv.c
  43. 3 3
      source/src/enet_encap/endianconv.h
  44. 2 2
      source/src/ports/MINGW/main.c
  45. 11 11
      source/src/ports/MINGW/networkconfig.c
  46. 2 2
      source/src/ports/MINGW/networkhandler.c
  47. 1 1
      source/src/ports/MINGW/opener_error.c
  48. 25 25
      source/src/ports/MINGW/sample_application/ethlinkcbs.c
  49. 7 8
      source/src/ports/MINGW/sample_application/sampleapplication.c
  50. 10 10
      source/src/ports/POSIX/main.c
  51. 5 5
      source/src/ports/POSIX/networkconfig.c
  52. 3 3
      source/src/ports/POSIX/networkhandler.c
  53. 25 25
      source/src/ports/POSIX/sample_application/ethlinkcbs.c
  54. 9 10
      source/src/ports/POSIX/sample_application/sampleapplication.c
  55. 2 2
      source/src/ports/STM32/networkconfig.c
  56. 1 1
      source/src/ports/STM32/networkhandler.c
  57. 1 1
      source/src/ports/STM32/opener.c
  58. 25 25
      source/src/ports/STM32/sample_application/ethlinkcbs.c
  59. 6 6
      source/src/ports/STM32/sample_application/sampleapplication.c
  60. 2 2
      source/src/ports/WIN32/main.c
  61. 11 11
      source/src/ports/WIN32/networkconfig.c
  62. 1 1
      source/src/ports/WIN32/networkhandler.c
  63. 1 1
      source/src/ports/WIN32/opener_error.c
  64. 25 25
      source/src/ports/WIN32/sample_application/ethlinkcbs.c
  65. 7 8
      source/src/ports/WIN32/sample_application/sampleapplication.c
  66. 191 193
      source/src/ports/generic_networkhandler.c
  67. 1 1
      source/src/ports/generic_networkhandler.h
  68. 1 1
      source/src/ports/nvdata/nvdata.c
  69. 2 2
      source/src/ports/nvdata/nvtcpip.c
  70. 5 5
      source/src/ports/socket_timer.c
  71. 4 4
      source/src/ports/socket_timer.h
  72. 7 7
      source/src/utils/doublylinkedlist.c
  73. 1 1
      source/src/utils/doublylinkedlist.h
  74. 2 1
      source/src/utils/random.c
  75. 1 1
      source/src/utils/random.h
  76. 1 1
      source/src/utils/xorshiftrandom.c
  77. 4 4
      source/tests/callback_mock.cpp
  78. 7 7
      source/tests/cip/cipcommontests.cpp
  79. 101 107
      source/tests/cip/cipconnectionobjecttest.cpp
  80. 2 2
      source/tests/cip/cipelectronickeyformattest.cpp
  81. 4 4
      source/tests/cip/cipelectronickeytest.cpp
  82. 138 138
      source/tests/cip/cipepathtest.cpp
  83. 9 9
      source/tests/cip/cipstringtests.cpp
  84. 28 28
      source/tests/enet_encap/encaptest.cpp
  85. 10 10
      source/tests/enet_encap/endianconvtest.cpp
  86. 3 3
      source/tests/ports/socket_timer_tests.cpp
  87. 5 5
      source/tests/utils/doublylinkedlistTests.cpp

+ 6 - 0
.clang-format

@@ -8,6 +8,9 @@ BasedOnStyle: Google
 # Uncrustify: indent_columns=2
 IndentWidth: 2
 
+# Set continuation indent to match base indent
+ContinuationIndentWidth: 2
+
 # Uncrustify: indent_with_tabs=0
 UseTab: Never
 
@@ -63,6 +66,9 @@ BreakBeforeBraces: Attach
 
 # --- 5. Miscellaneous ---
 
+# Keep opening brace on same line for initializer lists
+Cpp11BracedListStyle: false
+
 # Uncrustify: mod_remove_extra_semicolon=true
 # Note: RemoveSemicolon is not a standard option, clang-format handles this differently
 

+ 5 - 1
.github/workflows/ci.yml

@@ -38,7 +38,11 @@ jobs:
           DISABLE_LINTERS: SPELL_CSPELL
           DISABLE_ERRORS: false
           # Fast standard checks - suppress normalCheckLevelMaxBranches info message
-          C_CPPCHECK_ARGUMENTS: --inline-suppr --suppress=normalCheckLevelMaxBranches
+          C_CPPCHECK_ARGUMENTS: >-
+            --inline-suppr
+            --suppress=normalCheckLevelMaxBranches
+            --suppress=missingIncludeSystem
+            --suppress=missingInclude
           # Enable auto-fixes
           APPLY_FIXES: all
           APPLY_FIXES_EVENT: pull_request

+ 2 - 0
.github/workflows/exhaustive-analysis.yml

@@ -53,6 +53,8 @@ jobs:
             --enable=warning,style,performance,portability
             --std=c99
             --platform=unix64
+            --suppress=missingIncludeSystem
+            --suppress=missingInclude
 
       - name: Archive Exhaustive Reports
         if: always()

+ 2 - 1
.pre-commit-config.yaml

@@ -9,7 +9,7 @@ repos:
       - id: check-toml
 
   - repo: https://github.com/pre-commit/mirrors-clang-format
-    rev: v21.1.6
+    rev: v21.1.8
     hooks:
       - id: clang-format
         types_or: [c, c++, header]
@@ -35,6 +35,7 @@ repos:
           - "--inconclusive"
           - "--force"
           - "--suppress=missingIncludeSystem"
+          - "--suppress=missingInclude"
         types_or: [c, c++, header]
 
   - repo: https://github.com/shellcheck-py/shellcheck-py

+ 29 - 29
source/src/api/opener_api.h

@@ -252,7 +252,7 @@ CipAttributeStruct* GetCipAttribute(const CipInstance* const cip_instance,
                                     const EipUint16 attribute_number);
 
 typedef void (*InitializeCipClass)(
-    CipClass*); /**< Initializer function for CIP class initialization */
+  CipClass*); /**< Initializer function for CIP class initialization */
 
 /** @ingroup CIP_API
  * @brief Allocate memory for new CIP Class and attributes
@@ -309,8 +309,8 @@ CipClass* CreateCipClass(const CipUdint class_code,
  *              0 on error
  */
 CipInstance* AddCipInstances(
-    CipClass* RESTRICT const cip_object_to_add_instances,
-    const CipInstanceNum number_of_instances);
+  CipClass* RESTRICT const cip_object_to_add_instances,
+  const CipInstanceNum number_of_instances);
 
 /** @ingroup CIP_API
  * @brief Create one instance of a given class with a certain instance number
@@ -498,9 +498,9 @@ int DecodeCipByte(CipByte* const data,
                   CipMessageRouterResponse* const message_router_response);
 
 int DecodeCipByteArray(
-    CipByteArray* const data,
-    const CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response);
+  CipByteArray* const data,
+  const CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response);
 
 int DecodeCipWord(CipWord* const data,
                   CipMessageRouterRequest* const message_router_request,
@@ -559,9 +559,9 @@ int DecodeCipString(CipString* const data,
                     CipMessageRouterResponse* const message_router_response);
 
 int DecodeCipShortString(
-    CipShortString* const data,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response);
+  CipShortString* const data,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response);
 
 /** @ingroup CIP_API
  * @brief Create an instance of an assembly object
@@ -596,8 +596,8 @@ typedef struct cip_connection_object CipConnectionObject;
  * @return CIP error code
  */
 typedef CipError (*OpenConnectionFunction)(
-    CipConnectionObject* RESTRICT const connection_object,
-    EipUint16* const extended_error_code);
+  CipConnectionObject* RESTRICT const connection_object,
+  EipUint16* const extended_error_code);
 
 /** @ingroup CIP_API
  * @brief Function prototype for handling the closing of connections
@@ -606,7 +606,7 @@ typedef CipError (*OpenConnectionFunction)(
  * connection
  */
 typedef void (*ConnectionCloseFunction)(
-    CipConnectionObject* RESTRICT connection_object);
+  CipConnectionObject* RESTRICT connection_object);
 
 /** @ingroup CIP_API
  * @brief Function prototype for handling the timeout of connections
@@ -614,7 +614,7 @@ typedef void (*ConnectionCloseFunction)(
  * @param connection_object The connection object which connection timed out
  */
 typedef void (*ConnectionTimeoutFunction)(
-    CipConnectionObject* connection_object);
+  CipConnectionObject* connection_object);
 
 /** @ingroup CIP_API
  * @brief Function prototype for sending data via a connection
@@ -624,7 +624,7 @@ typedef void (*ConnectionTimeoutFunction)(
  * @return EIP stack status
  */
 typedef EipStatus (*ConnectionSendDataFunction)(
-    CipConnectionObject* connection_object);
+  CipConnectionObject* connection_object);
 
 /** @ingroup CIP_API
  * @brief Function prototype for receiving data via a connection
@@ -636,9 +636,9 @@ typedef EipStatus (*ConnectionSendDataFunction)(
  * @return Stack status
  */
 typedef EipStatus (*ConnectionReceiveDataFunction)(
-    CipConnectionObject* connection_object,
-    const EipUint8* data,
-    const EipUint16 data_length);
+  CipConnectionObject* connection_object,
+  const EipUint8* data,
+  const EipUint16 data_length);
 
 /** @ingroup CIP_API
  * @brief Function pointer for timeout checker functions
@@ -674,10 +674,10 @@ EipStatus AddConnectableObject(const CipUdint class_code,
  * this connection
  */
 void ConfigureExclusiveOwnerConnectionPoint(
-    const unsigned int connection_number,
-    const unsigned int output_assembly_id,
-    const unsigned int input_assembly_id,
-    const unsigned int configuration_assembly_id);
+  const unsigned int connection_number,
+  const unsigned int output_assembly_id,
+  const unsigned int input_assembly_id,
+  const unsigned int configuration_assembly_id);
 
 /** @ingroup CIP_API
  * @brief Configures the connection point for an input only connection.
@@ -693,10 +693,10 @@ void ConfigureExclusiveOwnerConnectionPoint(
  * this connection
  */
 void ConfigureInputOnlyConnectionPoint(
-    const unsigned int connection_number,
-    const unsigned int output_assembly_id,
-    const unsigned int input_assembly_id,
-    const unsigned int configuration_assembly_id);
+  const unsigned int connection_number,
+  const unsigned int output_assembly_id,
+  const unsigned int input_assembly_id,
+  const unsigned int configuration_assembly_id);
 
 /** \ingroup CIP_API
  * \brief Configures the connection point for a listen only connection.
@@ -712,10 +712,10 @@ void ConfigureInputOnlyConnectionPoint(
  * this connection
  */
 void ConfigureListenOnlyConnectionPoint(
-    const unsigned int connection_number,
-    const unsigned int output_assembly_id,
-    const unsigned int input_assembly_id,
-    const unsigned int configuration_assembly_id);
+  const unsigned int connection_number,
+  const unsigned int output_assembly_id,
+  const unsigned int input_assembly_id,
+  const unsigned int configuration_assembly_id);
 
 /** @ingroup CIP_API
  * @brief Notify the encapsulation layer that an explicit message has been

+ 89 - 89
source/src/cip/appcontype.c

@@ -21,8 +21,8 @@ typedef struct {
   unsigned int input_assembly;   ///< the T-to-O point for the connection
   unsigned int config_assembly;  ///< the config point for the connection
   CipConnectionObject
-      connection_data;  ///< the connection data, only one connection is allowed
-                        ///< per O-to-T point
+    connection_data;  ///< the connection data, only one connection is allowed
+                      ///< per O-to-T point
 } ExclusiveOwnerConnection;
 
 /** @brief Input Only connection data */
@@ -31,7 +31,7 @@ typedef struct {
   unsigned int input_assembly;   ///< the T-to-O point for the connection
   unsigned int config_assembly;  ///< the config point for the connection
   CipConnectionObject connection_data
-      [OPENER_CIP_NUM_INPUT_ONLY_CONNS_PER_CON_PATH];  ///< the connection data
+    [OPENER_CIP_NUM_INPUT_ONLY_CONNS_PER_CON_PATH];  ///< the connection data
 } InputOnlyConnection;
 
 /** @brief Listen Only connection data */
@@ -40,18 +40,19 @@ typedef struct {
   unsigned int input_assembly;   ///< the T-to-O point for the connection
   unsigned int config_assembly;  ///< the config point for the connection
   CipConnectionObject connection_data
-      [OPENER_CIP_NUM_LISTEN_ONLY_CONNS_PER_CON_PATH];  ///< the connection data
+    [OPENER_CIP_NUM_LISTEN_ONLY_CONNS_PER_CON_PATH];  ///< the connection data
 } ListenOnlyConnection;
 
 ExclusiveOwnerConnection g_exlusive_owner_connections
-    [OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS];  ///< Exclusive Owner connections
+  [OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS];  ///< Exclusive Owner connections
 
 InputOnlyConnection
-    g_input_only_connections[OPENER_CIP_NUM_INPUT_ONLY_CONNS];  ///< Input Only
-                                                                ///< connections
+  g_input_only_connections[OPENER_CIP_NUM_INPUT_ONLY_CONNS];  ///< Input Only
+                                                              ///< connections
 
-ListenOnlyConnection g_listen_only_connections
-    [OPENER_CIP_NUM_LISTEN_ONLY_CONNS];  ///< Listen Only connections
+ListenOnlyConnection
+  g_listen_only_connections[OPENER_CIP_NUM_LISTEN_ONLY_CONNS];  ///< Listen Only
+                                                                ///< connections
 
 /** @brief Takes an ConnectionObject and searches and returns an Exclusive Owner
  * Connection based on the ConnectionObject, if there is non it returns NULL
@@ -63,8 +64,8 @@ ListenOnlyConnection g_listen_only_connections
  * @return The corresponding Exclusive Owner Connection or NULL if there is non
  */
 CipConnectionObject* GetExclusiveOwnerConnection(
-    const CipConnectionObject* const RESTRICT connection_object,
-    EipUint16* const extended_error);
+  const CipConnectionObject* const RESTRICT connection_object,
+  EipUint16* const extended_error);
 
 /** @brief Takes an ConnectionObject and searches and returns an Input Only
  * Connection based on the ConnectionObject, if there is non it returns NULL
@@ -76,8 +77,8 @@ CipConnectionObject* GetExclusiveOwnerConnection(
  * @return The corresponding Exclusive Owner Connection or NULL if there is non
  */
 CipConnectionObject* GetInputOnlyConnection(
-    const CipConnectionObject* const RESTRICT connection_object,
-    EipUint16* const extended_error);
+  const CipConnectionObject* const RESTRICT connection_object,
+  EipUint16* const extended_error);
 
 /** @brief Takes an ConnectionObject and searches and returns an Listen Only
  * Connection based on the ConnectionObject, if there is non it returns NULL
@@ -89,21 +90,21 @@ CipConnectionObject* GetInputOnlyConnection(
  * @return The corresponding Exclusive Owner Connection or NULL if there is non
  */
 CipConnectionObject* GetListenOnlyConnection(
-    const CipConnectionObject* const RESTRICT connection_object,
-    EipUint16* const extended_error);
+  const CipConnectionObject* const RESTRICT connection_object,
+  EipUint16* const extended_error);
 
 void ConfigureExclusiveOwnerConnectionPoint(
-    const unsigned int connection_number,
-    const unsigned int output_assembly,
-    const unsigned int input_assembly,
-    const unsigned int config_assembly) {
+  const unsigned int connection_number,
+  const unsigned int output_assembly,
+  const unsigned int input_assembly,
+  const unsigned int config_assembly) {
   if (OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS > connection_number) {
     g_exlusive_owner_connections[connection_number].output_assembly =
-        output_assembly;
+      output_assembly;
     g_exlusive_owner_connections[connection_number].input_assembly =
-        input_assembly;
+      input_assembly;
     g_exlusive_owner_connections[connection_number].config_assembly =
-        config_assembly;
+      config_assembly;
   }
 }
 
@@ -113,10 +114,10 @@ void ConfigureInputOnlyConnectionPoint(const unsigned int connection_number,
                                        const unsigned int config_assembly) {
   if (OPENER_CIP_NUM_INPUT_ONLY_CONNS > connection_number) {
     g_input_only_connections[connection_number].output_assembly =
-        output_assembly;
+      output_assembly;
     g_input_only_connections[connection_number].input_assembly = input_assembly;
     g_input_only_connections[connection_number].config_assembly =
-        config_assembly;
+      config_assembly;
   }
 }
 
@@ -126,21 +127,21 @@ void ConfigureListenOnlyConnectionPoint(const unsigned int connection_number,
                                         const unsigned int config_assembly) {
   if (OPENER_CIP_NUM_LISTEN_ONLY_CONNS > connection_number) {
     g_listen_only_connections[connection_number].output_assembly =
-        output_assembly;
+      output_assembly;
     g_listen_only_connections[connection_number].input_assembly =
-        input_assembly;
+      input_assembly;
     g_listen_only_connections[connection_number].config_assembly =
-        config_assembly;
+      config_assembly;
   }
 }
 
 CipConnectionObject* GetIoConnectionForConnectionData(
-    CipConnectionObject* const RESTRICT connection_object,
-    EipUint16* const extended_error) {
+  CipConnectionObject* const RESTRICT connection_object,
+  EipUint16* const extended_error) {
   *extended_error = 0;
 
   CipConnectionObject* io_connection =
-      GetExclusiveOwnerConnection(connection_object, extended_error);
+    GetExclusiveOwnerConnection(connection_object, extended_error);
   if (NULL == io_connection) {
     if (kConnectionManagerExtendedStatusCodeSuccess == *extended_error) {
       // we found no connection and don't have an error so try input only next
@@ -151,30 +152,30 @@ CipConnectionObject* GetIoConnectionForConnectionData(
           // we found no connection and don't have an error so try listen only
           // next
           io_connection =
-              GetListenOnlyConnection(connection_object, extended_error);
+            GetListenOnlyConnection(connection_object, extended_error);
           if ((NULL == io_connection) &&
               (kCipErrorSuccess == *extended_error)) {
             // no application connection type was found that suits the given
             // data
             *extended_error =
-                kConnectionManagerExtendedStatusCodeInconsistentApplicationPathCombo;
+              kConnectionManagerExtendedStatusCodeInconsistentApplicationPathCombo;
           } else {
             ConnectionObjectSetInstanceType(
-                connection_object, kConnectionObjectInstanceTypeIOListenOnly);
+              connection_object, kConnectionObjectInstanceTypeIOListenOnly);
             OPENER_TRACE_INFO("IO Listen only connection requested\n");
             // Is listen only connection
           }
         }
       } else {
         ConnectionObjectSetInstanceType(
-            connection_object, kConnectionObjectInstanceTypeIOInputOnly);
+          connection_object, kConnectionObjectInstanceTypeIOInputOnly);
         OPENER_TRACE_INFO("IO Input only connection requested\n");
         // is Input only connection
       }
     }
   } else {
     ConnectionObjectSetInstanceType(
-        connection_object, kConnectionObjectInstanceTypeIOExclusiveOwner);
+      connection_object, kConnectionObjectInstanceTypeIOExclusiveOwner);
     OPENER_TRACE_INFO("IO Exclusive Owner connection requested\n");
     // Is exclusive owner connection
   }
@@ -187,8 +188,8 @@ CipConnectionObject* GetIoConnectionForConnectionData(
 }
 
 CipConnectionObject* GetExclusiveOwnerConnection(
-    const CipConnectionObject* const RESTRICT connection_object,
-    EipUint16* const extended_error) {
+  const CipConnectionObject* const RESTRICT connection_object,
+  EipUint16* const extended_error) {
   for (size_t i = 0; i < OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS; ++i) {
     if ((g_exlusive_owner_connections[i].output_assembly ==
          connection_object->consumed_path.instance_id) &&
@@ -199,29 +200,29 @@ CipConnectionObject* GetExclusiveOwnerConnection(
       // check if on other connection point with the same output assembly is
       // currently connected
       const CipConnectionObject* const exclusive_owner =
-          GetConnectedOutputAssembly(
-              connection_object->produced_path.instance_id);
+        GetConnectedOutputAssembly(
+          connection_object->produced_path.instance_id);
       if (NULL != exclusive_owner) {
         if (kConnectionObjectStateEstablished ==
             ConnectionObjectGetState(exclusive_owner)) {
           *extended_error =
-              kConnectionManagerExtendedStatusCodeErrorOwnershipConflict;
+            kConnectionManagerExtendedStatusCodeErrorOwnershipConflict;
           OPENER_TRACE_INFO("Hit an Ownership conflict in appcontype.c:198\n");
           break;
         }
         if (kConnectionObjectStateTimedOut ==
-                ConnectionObjectGetState(exclusive_owner) &&
+              ConnectionObjectGetState(exclusive_owner) &&
             ConnectionObjectEqualOriginator(connection_object,
                                             exclusive_owner)) {
           g_exlusive_owner_connections[i]
-              .connection_data.connection_close_function(
-                  &(g_exlusive_owner_connections[i].connection_data));
+            .connection_data.connection_close_function(
+              &(g_exlusive_owner_connections[i].connection_data));
           return &(g_exlusive_owner_connections[i].connection_data);
         } else {
           *extended_error =
-              kConnectionManagerExtendedStatusCodeErrorOwnershipConflict;
+            kConnectionManagerExtendedStatusCodeErrorOwnershipConflict;
           OPENER_TRACE_INFO(
-              "Hit an Ownership conflict with timed out connection");
+            "Hit an Ownership conflict with timed out connection");
           break;
         }
       }
@@ -232,39 +233,39 @@ CipConnectionObject* GetExclusiveOwnerConnection(
 }
 
 CipConnectionObject* GetInputOnlyConnection(
-    const CipConnectionObject* const RESTRICT connection_object,
-    EipUint16* const extended_error) {
+  const CipConnectionObject* const RESTRICT connection_object,
+  EipUint16* const extended_error) {
   EipUint16 err = 0;
 
   for (size_t i = 0; i < OPENER_CIP_NUM_INPUT_ONLY_CONNS; ++i) {
     if (g_input_only_connections[i].output_assembly ==
         connection_object->consumed_path
-            .instance_id) {  // we have the same output assembly
+          .instance_id) {  // we have the same output assembly
       if (g_input_only_connections[i].input_assembly !=
           connection_object->produced_path.instance_id) {
         err =
-            kConnectionManagerExtendedStatusCodeInvalidProducingApplicationPath;
+          kConnectionManagerExtendedStatusCodeInvalidProducingApplicationPath;
         continue;
       }
       if (g_input_only_connections[i].config_assembly !=
           connection_object->configuration_path.instance_id) {
         err =
-            kConnectionManagerExtendedStatusCodeInconsistentApplicationPathCombo;
+          kConnectionManagerExtendedStatusCodeInconsistentApplicationPathCombo;
         continue;
       }
 
       for (size_t j = 0; j < OPENER_CIP_NUM_INPUT_ONLY_CONNS_PER_CON_PATH;
            ++j) {
         if (kConnectionObjectStateTimedOut ==
-                ConnectionObjectGetState(
-                    &(g_input_only_connections[i].connection_data[j])) &&
+              ConnectionObjectGetState(
+                &(g_input_only_connections[i].connection_data[j])) &&
             ConnectionObjectEqualOriginator(
-                connection_object,
-                &(g_input_only_connections[i].connection_data[j]))) {
+              connection_object,
+              &(g_input_only_connections[i].connection_data[j]))) {
           g_input_only_connections[i]
-              .connection_data[j]
-              .connection_close_function(
-                  &g_input_only_connections[i].connection_data[j]);
+            .connection_data[j]
+            .connection_close_function(
+              &g_input_only_connections[i].connection_data[j]);
           return &(g_input_only_connections[i].connection_data[j]);
         }
       }
@@ -273,7 +274,7 @@ CipConnectionObject* GetInputOnlyConnection(
            ++j) {
         if (kConnectionObjectStateNonExistent ==
             ConnectionObjectGetState(
-                &(g_input_only_connections[i].connection_data[j]))) {
+              &(g_input_only_connections[i].connection_data[j]))) {
           return &(g_input_only_connections[i].connection_data[j]);
         }
       }
@@ -287,47 +288,47 @@ CipConnectionObject* GetInputOnlyConnection(
 }
 
 CipConnectionObject* GetListenOnlyConnection(
-    const CipConnectionObject* const RESTRICT connection_object,
-    EipUint16* const extended_error) {
+  const CipConnectionObject* const RESTRICT connection_object,
+  EipUint16* const extended_error) {
   EipUint16 err = 0;
 
   for (size_t i = 0; i < OPENER_CIP_NUM_LISTEN_ONLY_CONNS; i++) {
     if (g_listen_only_connections[i].output_assembly ==
         connection_object->consumed_path
-            .instance_id) {  // we have the same output assembly
+          .instance_id) {  // we have the same output assembly
       if (g_listen_only_connections[i].input_assembly !=
           connection_object->produced_path.instance_id) {
         err =
-            kConnectionManagerExtendedStatusCodeInvalidProducingApplicationPath;
+          kConnectionManagerExtendedStatusCodeInvalidProducingApplicationPath;
         continue;
       }
       if (g_listen_only_connections[i].config_assembly !=
           connection_object->configuration_path.instance_id) {
         err =
-            kConnectionManagerExtendedStatusCodeInconsistentApplicationPathCombo;
+          kConnectionManagerExtendedStatusCodeInconsistentApplicationPathCombo;
         continue;
       }
 
       // Here we look for both Point-to-Point and Multicast IO connections
       if (NULL == GetExistingProducerIoConnection(
-                      false, connection_object->produced_path.instance_id)) {
+                    false, connection_object->produced_path.instance_id)) {
         err =
-            kConnectionManagerExtendedStatusCodeNonListenOnlyConnectionNotOpened;
+          kConnectionManagerExtendedStatusCodeNonListenOnlyConnectionNotOpened;
         break;
       }
 
       for (size_t j = 0; j < OPENER_CIP_NUM_LISTEN_ONLY_CONNS_PER_CON_PATH;
            ++j) {
         if (kConnectionObjectStateTimedOut ==
-                ConnectionObjectGetState(
-                    &(g_listen_only_connections[i].connection_data[j])) &&
+              ConnectionObjectGetState(
+                &(g_listen_only_connections[i].connection_data[j])) &&
             ConnectionObjectEqualOriginator(
-                connection_object,
-                &(g_listen_only_connections[i].connection_data[j]))) {
+              connection_object,
+              &(g_listen_only_connections[i].connection_data[j]))) {
           g_listen_only_connections[i]
-              .connection_data[j]
-              .connection_close_function(
-                  &g_listen_only_connections[i].connection_data[j]);
+            .connection_data[j]
+            .connection_close_function(
+              &g_listen_only_connections[i].connection_data[j]);
           return &(g_listen_only_connections[i].connection_data[j]);
         }
       }
@@ -336,7 +337,7 @@ CipConnectionObject* GetListenOnlyConnection(
            j++) {
         if (kConnectionObjectStateNonExistent ==
             ConnectionObjectGetState(
-                &(g_listen_only_connections[i].connection_data[j]))) {
+              &(g_listen_only_connections[i].connection_data[j]))) {
           return &(g_listen_only_connections[i].connection_data[j]);
         }
       }
@@ -350,7 +351,7 @@ CipConnectionObject* GetListenOnlyConnection(
 }
 
 CipConnectionObject* GetExistingProducerIoConnection(
-    const bool multicast_only, const EipUint32 input_point) {
+  const bool multicast_only, const EipUint32 input_point) {
   const DoublyLinkedListNode* node = connection_list.first;
 
   while (NULL != node) {
@@ -360,7 +361,7 @@ CipConnectionObject* GetExistingProducerIoConnection(
         (kEipInvalidSocket !=
          producer_io_connection->socket[kUdpCommuncationDirectionProducing])) {
       ConnectionObjectConnectionType cnxn_type =
-          ConnectionObjectGetTToOConnectionType(producer_io_connection);
+        ConnectionObjectGetTToOConnectionType(producer_io_connection);
       /* we have a connection that produces the same input assembly,
        * and manages the connection.
        */
@@ -378,23 +379,22 @@ CipConnectionObject* GetExistingProducerIoConnection(
 }
 
 CipConnectionObject* GetNextNonControlMasterConnection(
-    const EipUint32 input_point) {
+  const EipUint32 input_point) {
   const DoublyLinkedListNode* node = connection_list.first;
 
   while (NULL != node) {
     CipConnectionObject* next_non_control_master_connection = node->data;
     if (true == ConnectionObjectIsTypeNonLOIOConnection(
-                    next_non_control_master_connection) &&
+                  next_non_control_master_connection) &&
         kConnectionObjectStateEstablished ==
-            ConnectionObjectGetState(next_non_control_master_connection) &&
+          ConnectionObjectGetState(next_non_control_master_connection) &&
         input_point ==
-            next_non_control_master_connection->produced_path.instance_id &&
+          next_non_control_master_connection->produced_path.instance_id &&
         kConnectionObjectConnectionTypeMulticast ==
-            ConnectionObjectGetTToOConnectionType(
-                next_non_control_master_connection) &&
-        (kEipInvalidSocket ==
-         next_non_control_master_connection
-             ->socket[kUdpCommuncationDirectionProducing])) {
+          ConnectionObjectGetTToOConnectionType(
+            next_non_control_master_connection) &&
+        (kEipInvalidSocket == next_non_control_master_connection
+                                ->socket[kUdpCommuncationDirectionProducing])) {
       /* we have a connection that produces the same input assembly,
        * is a multicast producer and does not manage the connection.
        */
@@ -406,8 +406,8 @@ CipConnectionObject* GetNextNonControlMasterConnection(
 }
 
 void CloseAllConnectionsForInputWithSameType(
-    const EipUint32 input_point,
-    const ConnectionObjectInstanceType instance_type) {
+  const EipUint32 input_point,
+  const ConnectionObjectInstanceType instance_type) {
   OPENER_TRACE_INFO("Close all instance type %d only connections\n",
                     instance_type);
   const DoublyLinkedListNode* node = connection_list.first;
@@ -453,9 +453,9 @@ bool ConnectionWithSameConfigPointExists(const EipUint32 config_point) {
 
 void InitializeIoConnectionData(void) {
   memset(
-      g_exlusive_owner_connections,
-      0,
-      OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS * sizeof(ExclusiveOwnerConnection));
+    g_exlusive_owner_connections,
+    0,
+    OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS * sizeof(ExclusiveOwnerConnection));
   memset(g_input_only_connections,
          0,
          OPENER_CIP_NUM_INPUT_ONLY_CONNS * sizeof(InputOnlyConnection));

+ 6 - 6
source/src/cip/appcontype.h

@@ -24,8 +24,8 @@ void InitializeIoConnectionData(void);
  *        - on error: NULL
  */
 CipConnectionObject* GetIoConnectionForConnectionData(
-    CipConnectionObject* const RESTRICT connection_object,
-    EipUint16* const extended_error);
+  CipConnectionObject* const RESTRICT connection_object,
+  EipUint16* const extended_error);
 
 /** @brief Check if there exists already an exclusive owner or listen only
  * connection which produces the input assembly.
@@ -35,7 +35,7 @@ CipConnectionObject* GetIoConnectionForConnectionData(
  *  @return   a pointer to the found connection; NULL if nothing found
  */
 CipConnectionObject* GetExistingProducerIoConnection(
-    const bool multicast_only, const EipUint32 input_point);
+  const bool multicast_only, const EipUint32 input_point);
 
 /** @brief check if there exists an producing multicast exclusive owner or
  * listen only connection that should produce the same input but is not in
@@ -46,7 +46,7 @@ CipConnectionObject* GetExistingProducerIoConnection(
  *      otherwise NULL.
  */
 CipConnectionObject* GetNextNonControlMasterConnection(
-    const EipUint32 input_point);
+  const EipUint32 input_point);
 
 /** @brief Close all connection producing the same input and have the same type
  * (i.e., listen only or input only).
@@ -55,8 +55,8 @@ CipConnectionObject* GetNextNonControlMasterConnection(
  * @param instance_type the connection application type
  */
 void CloseAllConnectionsForInputWithSameType(
-    const EipUint32 input_point,
-    const ConnectionObjectInstanceType instance_type);
+  const EipUint32 input_point,
+  const ConnectionObjectInstanceType instance_type);
 
 /**@ brief close all open connections.
  *

+ 25 - 26
source/src/cip/cipassembly.c

@@ -29,9 +29,9 @@
  *          -1 .. error
  */
 int DecodeCipAssemblyAttribute3(
-    void* const data,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response);
+  void* const data,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response);
 
 static EipStatus AssemblyPreGetCallback(CipInstance* const instance,
                                         CipAttributeStruct* const attribute,
@@ -49,17 +49,17 @@ static EipStatus AssemblyPostSetCallback(CipInstance* const instance,
 CipClass* CreateAssemblyClass(void) {
   /* create the CIP Assembly object with zero instances */
   CipClass* assembly_class = CreateCipClass(
-      kCipAssemblyClassCode,
-      0,          /* # class attributes*/
-      7,          /* # highest class attribute number*/
-      1,          /* # class services*/
-      2,          /* # instance attributes*/
-      4,          /* # highest instance attribute number*/
-      2,          /* # instance services*/
-      0,          /* # instances*/
-      "assembly", /* name */
-      2, /* Revision, according to the CIP spec currently this has to be 2 */
-      NULL); /* # function pointer for initialization*/
+    kCipAssemblyClassCode,
+    0,          /* # class attributes*/
+    7,          /* # highest class attribute number*/
+    1,          /* # class services*/
+    2,          /* # instance attributes*/
+    4,          /* # highest instance attribute number*/
+    2,          /* # instance services*/
+    0,          /* # instances*/
+    "assembly", /* name */
+    2,     /* Revision, according to the CIP spec currently this has to be 2 */
+    NULL); /* # function pointer for initialization*/
   if (NULL != assembly_class) {
     InsertService(assembly_class,
                   kGetAttributeSingle,
@@ -113,11 +113,11 @@ CipInstance* CreateAssemblyObject(const CipInstanceNum instance_id,
   }
 
   CipInstance* const instance = AddCipInstance(
-      assembly_class,
-      instance_id); /* add instances (always succeeds (or asserts))*/
+    assembly_class,
+    instance_id); /* add instances (always succeeds (or asserts))*/
 
   CipByteArray* const assembly_byte_array =
-      (CipByteArray*)CipCalloc(1, sizeof(CipByteArray));
+    (CipByteArray*)CipCalloc(1, sizeof(CipByteArray));
   if (assembly_byte_array == NULL) {
     return NULL; /*TODO remove assembly instance in case of error*/
   }
@@ -152,7 +152,7 @@ EipStatus NotifyAssemblyConnectedDataReceived(CipInstance* const instance,
 
   // copy received data to Attribute 3
   const CipByteArray* const assembly_byte_array =
-      (CipByteArray*)instance->attributes->data;
+    (CipByteArray*)instance->attributes->data;
   if (assembly_byte_array->length != data_length) {
     OPENER_TRACE_ERR("wrong amount of data arrived for assembly object\n");
     // TODO(MartinMelikMerkumians): question should we notify the application
@@ -167,12 +167,12 @@ EipStatus NotifyAssemblyConnectedDataReceived(CipInstance* const instance,
 }
 
 int DecodeCipAssemblyAttribute3(
-    void* const data,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response) {
+  void* const data,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response) {
   CipInstance* const instance =
-      GetCipInstance(GetCipClass(message_router_request->request_path.class_id),
-                     message_router_request->request_path.instance_number);
+    GetCipInstance(GetCipClass(message_router_request->request_path.class_id),
+                   message_router_request->request_path.instance_number);
 
   int number_of_decoded_bytes = -1;
   OPENER_TRACE_INFO(" -> set Assembly attribute byte array\r\n");
@@ -190,9 +190,8 @@ int DecodeCipAssemblyAttribute3(
   }
 
   // data-length is correct
-  memcpy(cip_byte_array->data,
-         message_router_request->data,
-         cip_byte_array->length);
+  memcpy(
+    cip_byte_array->data, message_router_request->data, cip_byte_array->length);
 
   if (AfterAssemblyDataReceived(instance) != kEipStatusOk) {
     /* punt early without updating the status... though I don't know

+ 11 - 11
source/src/cip/cipclass3connection.c

@@ -12,20 +12,20 @@
 
 /**** Global variables ****/
 extern CipConnectionObject
-    explicit_connection_object_pool[OPENER_CIP_NUM_EXPLICIT_CONNS];
+  explicit_connection_object_pool[OPENER_CIP_NUM_EXPLICIT_CONNS];
 
 CipConnectionObject* GetFreeExplicitConnection(void);
 
 void Class3ConnectionTimeoutHandler(CipConnectionObject* connection_object) {
   CheckForTimedOutConnectionsAndCloseTCPConnections(
-      connection_object, CloseSessionBySessionHandle);
+    connection_object, CloseSessionBySessionHandle);
   CloseConnection(connection_object);
 }
 
 /**** Implementation ****/
 CipError EstablishClass3Connection(
-    CipConnectionObject* RESTRICT const connection_object,
-    EipUint16* const extended_error) {
+  CipConnectionObject* RESTRICT const connection_object,
+  EipUint16* const extended_error) {
   CipError cip_error = kCipErrorSuccess;
 
   CipConnectionObject* explicit_connection = GetFreeExplicitConnection();
@@ -33,20 +33,20 @@ CipError EstablishClass3Connection(
   if (NULL == explicit_connection) {
     cip_error = kCipErrorConnectionFailure;
     *extended_error =
-        kConnectionManagerExtendedStatusCodeErrorNoMoreConnectionsAvailable;
+      kConnectionManagerExtendedStatusCodeErrorNoMoreConnectionsAvailable;
   } else {
     ConnectionObjectDeepCopy(explicit_connection, connection_object);
 
     ConnectionObjectGeneralConfiguration(explicit_connection);
 
     ConnectionObjectSetInstanceType(
-        explicit_connection, kConnectionObjectInstanceTypeExplicitMessaging);
+      explicit_connection, kConnectionObjectInstanceTypeExplicitMessaging);
 
     /* set the connection call backs */
     explicit_connection->connection_close_function = CloseConnection;
     /* explicit connection have to be closed on time out*/
     explicit_connection->connection_timeout_function =
-        Class3ConnectionTimeoutHandler;
+      Class3ConnectionTimeoutHandler;
 
     AddNewActiveConnection(explicit_connection);
   }
@@ -74,8 +74,8 @@ void InitializeClass3ConnectionData(void) {
 }
 
 EipStatus CipClass3ConnectionObjectStateEstablishedHandler(
-    CipConnectionObject* RESTRICT const connection_object,
-    ConnectionObjectState new_state) {
+  CipConnectionObject* RESTRICT const connection_object,
+  ConnectionObjectState new_state) {
   switch (new_state) {
     case kConnectionObjectStateNonExistent:
       ConnectionObjectInitializeEmpty(connection_object);
@@ -87,8 +87,8 @@ EipStatus CipClass3ConnectionObjectStateEstablishedHandler(
 }
 
 EipStatus CipClass3ConnectionObjectStateNonExistentHandler(
-    CipConnectionObject* RESTRICT const connection_object,
-    ConnectionObjectState new_state) {
+  CipConnectionObject* RESTRICT const connection_object,
+  ConnectionObjectState new_state) {
   switch (new_state) {
     case kConnectionObjectStateEstablished:
       ConnectionObjectSetState(connection_object, new_state);

+ 6 - 6
source/src/cip/cipclass3connection.h

@@ -33,12 +33,12 @@
 #include "cip/cipconnectionobject.h"
 
 typedef EipStatus (*CipConnectionStateHandler)(
-    CipConnectionObject* RESTRICT const connection_object,
-    ConnectionObjectState new_state);
+  CipConnectionObject* RESTRICT const connection_object,
+  ConnectionObjectState new_state);
 
 EipStatus CipClass3ConnectionObjectStateEstablishedHandler(
-    CipConnectionObject* RESTRICT const connection_object,
-    ConnectionObjectState new_state);
+  CipConnectionObject* RESTRICT const connection_object,
+  ConnectionObjectState new_state);
 
 /** @brief Check if Class3 connection is available and if yes setup all data.
  *
@@ -52,8 +52,8 @@ EipStatus CipClass3ConnectionObjectStateEstablishedHandler(
  *    - On an error the general status code to be put into the response
  */
 CipError EstablishClass3Connection(
-    CipConnectionObject* RESTRICT const connection_object,
-    EipUint16* const extended_error);
+  CipConnectionObject* RESTRICT const connection_object,
+  EipUint16* const extended_error);
 
 /** @brief Initializes the explicit connections mechanism
  *

+ 169 - 172
source/src/cip/cipcommon.c

@@ -107,8 +107,8 @@ EipStatus NotifyClass(const CipClass* RESTRICT const cip_class,
   /* find the instance: if instNr==0, the class is addressed, else find the
    * instance */
   CipInstanceNum instance_number =
-      message_router_request->request_path
-          .instance_number; /* get the instance number */
+    message_router_request->request_path
+      .instance_number; /* get the instance number */
   // look up the instance (note that if instance == 0 this will be the class
   // itself)
   CipInstance* instance = GetCipInstance(cip_class, instance_number);
@@ -118,8 +118,8 @@ EipStatus NotifyClass(const CipClass* RESTRICT const cip_class,
                       instance_number == 0 ? " (class object)" : "");
 
     CipServiceStruct* service =
-        instance->cip_class->services;  // get pointer to array of services
-    if (NULL != service) {              // if services are defined
+      instance->cip_class->services;  // get pointer to array of services
+    if (NULL != service) {            // if services are defined
       for (size_t i = 0; i < instance->cip_class->number_of_services;
            i++) {  // seach the services list
         if (message_router_request->service == service->service_number) {
@@ -150,11 +150,11 @@ EipStatus NotifyClass(const CipClass* RESTRICT const cip_class,
 
   // handle error replies
   message_router_response->size_of_additional_status =
-      0;  // fill in the rest of the reply with not much of anything
+    0;  // fill in the rest of the reply with not much of anything
   InitializeENIPMessage(&message_router_response->message);
   // except the reply code is an echo of the command + the reply flag
   message_router_response->reply_service =
-      (0x80 | message_router_request->service);
+    (0x80 | message_router_request->service);
   return kEipStatusOkSend;
 }
 
@@ -203,7 +203,7 @@ CipInstance* AddCipInstances(CipClass* RESTRICT const cip_class,
           break;
         }
         next_instance =
-            &(*next_instance)->next;  // get next instance in instances chain
+          &(*next_instance)->next;  // get next instance in instances chain
       }
 
       if (!found_free_number) {
@@ -213,26 +213,26 @@ CipInstance* AddCipInstances(CipClass* RESTRICT const cip_class,
     }
 
     CipInstance* current_instance =
-        (CipInstance*)CipCalloc(1, sizeof(CipInstance));
+      (CipInstance*)CipCalloc(1, sizeof(CipInstance));
     OPENER_ASSERT(NULL != current_instance);  // fail if run out of memory
     if (NULL == current_instance) {
       break;
     }
     if (NULL == first_instance) {
       first_instance =
-          current_instance; /* remember the first allocated instance */
+        current_instance; /* remember the first allocated instance */
     }
 
     current_instance->instance_number =
-        instance_number;  // assign the next sequential instance number
+      instance_number;  // assign the next sequential instance number
     current_instance->cip_class =
-        cip_class;  // point each instance to its class
+      cip_class;  // point each instance to its class
 
     // if the class calls for instance attributes
     if (cip_class->number_of_attributes) {
       // then allocate storage for the attribute array
       current_instance->attributes = (CipAttributeStruct*)CipCalloc(
-          cip_class->number_of_attributes, sizeof(CipAttributeStruct));
+        cip_class->number_of_attributes, sizeof(CipAttributeStruct));
       OPENER_ASSERT(NULL !=
                     current_instance->attributes);  // fail if run out of memory
       if (NULL == current_instance->attributes) {
@@ -243,8 +243,8 @@ CipInstance* AddCipInstances(CipClass* RESTRICT const cip_class,
     // link the previous pointer to this new node
     *next_instance = current_instance;
     next_instance =
-        &current_instance
-             ->next;  // update pp to point to the next link of the current node
+      &current_instance
+         ->next;  // update pp to point to the next link of the current node
     // update the total number of instances recorded by the class
     cip_class->number_of_instances += 1;
     // update to the number of the next node
@@ -258,10 +258,10 @@ CipInstance* AddCipInstances(CipClass* RESTRICT const cip_class,
     /* TODO(MartinMelikMerkumians): Free again all attributes and instances
      * allocated so far in this call. */
     OPENER_TRACE_ERR(
-        "ERROR: Allocated only %d instances of requested %d for class %s\n",
-        new_instances,
-        number_of_instances,
-        cip_class->class_name);
+      "ERROR: Allocated only %d instances of requested %d for class %s\n",
+      new_instances,
+      number_of_instances,
+      cip_class->class_name);
     first_instance = NULL;  // failed to allocate all instances / attributes
   }
   return first_instance;
@@ -277,7 +277,7 @@ CipInstance* AddCipInstance(CipClass* RESTRICT const cip_class,
   }
 
   cip_class->max_instance = GetMaxInstanceNumber(
-      cip_class);  // update largest instance number (class Attribute 2)
+    cip_class);  // update largest instance number (class Attribute 2)
   return instance;
 }
 
@@ -293,7 +293,7 @@ CipClass* CreateCipClass(const CipUdint class_code,
                          const EipUint16 revision,
                          InitializeCipClass initializer) {
   OPENER_TRACE_INFO(
-      "creating class '%s' with code: 0x%" PRIX32 "\n", name, class_code);
+    "creating class '%s' with code: 0x%" PRIX32 "\n", name, class_code);
 
   // check if an class with the ClassID already exists should never try to
   // redefine a class
@@ -314,9 +314,9 @@ CipClass* CreateCipClass(const CipUdint class_code,
   cip_class->class_code = class_code;  // the class remembers the class ID
   cip_class->revision   = revision;    // the class remembers the class ID
   cip_class->max_instance =
-      0;  // the largest instance number of a created object in this class
+    0;  // the largest instance number of a created object in this class
   cip_class->number_of_instances =
-      0;  // the number of instances initially zero (more created below)
+    0;  // the number of instances initially zero (more created below)
   cip_class->instances = 0;
   // the class remembers the number of instances of that class
   cip_class->number_of_attributes = number_of_instance_attributes;
@@ -384,14 +384,14 @@ CipClass* CreateCipClass(const CipUdint class_code,
 
   // further initialization of the class object
   cip_class->class_instance.attributes = (CipAttributeStruct*)CipCalloc(
-      meta_class->number_of_attributes, sizeof(CipAttributeStruct));
+    meta_class->number_of_attributes, sizeof(CipAttributeStruct));
   /* TODO(MartinMelikMerkumians) -- check that we didn't run out of memory?*/
 
   meta_class->services = (CipServiceStruct*)CipCalloc(
-      meta_class->number_of_services, sizeof(CipServiceStruct));
+    meta_class->number_of_services, sizeof(CipServiceStruct));
 
   cip_class->services = (CipServiceStruct*)CipCalloc(
-      cip_class->number_of_services, sizeof(CipServiceStruct));
+    cip_class->number_of_services, sizeof(CipServiceStruct));
 
   if (number_of_instances > 0) {
     // TODO(MartinMelikMerkumians) handle return value and clean up if necessary
@@ -425,13 +425,13 @@ CipClass* CreateCipClass(const CipUdint class_code,
                     (void*)&cip_class->max_instance,
                     kGetableSingleAndAll);  // #2 Max instance no.
     InsertAttribute(
-        (CipInstance*)cip_class,
-        3,
-        kCipUint,
-        EncodeCipUint,
-        NULL,
-        (void*)&cip_class->number_of_instances,
-        kGetableSingleAndAll);  // number of instances currently existing
+      (CipInstance*)cip_class,
+      3,
+      kCipUint,
+      EncodeCipUint,
+      NULL,
+      (void*)&cip_class->number_of_instances,
+      kGetableSingleAndAll);  // number of instances currently existing
     InsertAttribute((CipInstance*)cip_class,
                     4,
                     kCipUint,
@@ -464,10 +464,10 @@ CipClass* CreateCipClass(const CipUdint class_code,
       // only if the mask has values add the get_attribute_all service
       if (number_of_class_services > 1) {
         InsertService(
-            meta_class,
-            kGetAttributeAll,
-            &GetAttributeAll,
-            "GetAttributeAll");  // bind instance services to the metaclass
+          meta_class,
+          kGetAttributeAll,
+          &GetAttributeAll,
+          "GetAttributeAll");  // bind instance services to the metaclass
       }
       InsertService(meta_class,
                     kGetAttributeSingle,
@@ -513,11 +513,11 @@ void InsertAttribute(CipInstance* const instance,
       size_t index = CalculateIndex(attribute_number);
 
       cip_class->get_single_bit_mask[index] |=
-          (cip_flags & kGetableSingle) ? 1 << (attribute_number) % 8 : 0;
+        (cip_flags & kGetableSingle) ? 1 << (attribute_number) % 8 : 0;
       cip_class->get_all_bit_mask[index] |=
-          (cip_flags & (kGetableAll | kGetableAllDummy))
-              ? 1 << (attribute_number) % 8
-              : 0;
+        (cip_flags & (kGetableAll | kGetableAllDummy))
+          ? 1 << (attribute_number) % 8
+          : 0;
       cip_class->set_bit_mask[index] |= ((cip_flags & kSetable) ? 1 : 0)
                                         << ((attribute_number) % 8);
       return;
@@ -584,7 +584,7 @@ void InsertGetSetCallback(CipClass* const cip_class,
 CipAttributeStruct* GetCipAttribute(const CipInstance* const instance,
                                     const EipUint16 attribute_number) {
   CipAttributeStruct* attribute =
-      instance->attributes;  // init pointer to array of attributes
+    instance->attributes;  // init pointer to array of attributes
   for (unsigned int i = 0; i < instance->cip_class->number_of_attributes; i++) {
     if (attribute_number == attribute->attribute_number) {
       return attribute;
@@ -597,40 +597,40 @@ CipAttributeStruct* GetCipAttribute(const CipInstance* const instance,
 }
 
 void GenerateGetAttributeSingleHeader(
-    const CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response) {
+  const CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response) {
   InitializeENIPMessage(&message_router_response->message);
   message_router_response->reply_service =
-      (0x80 | message_router_request->service);
+    (0x80 | message_router_request->service);
   message_router_response->general_status = kCipErrorAttributeNotSupported;
   message_router_response->size_of_additional_status = 0;
 }
 
 // TODO(MartinMelikMerkumians) this needs to check for buffer overflow
 EipStatus GetAttributeSingle(
-    CipInstance* RESTRICT const instance,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response,
-    const struct sockaddr* originator_address,
-    const CipSessionHandle encapsulation_session) {
+  CipInstance* RESTRICT const instance,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response,
+  const struct sockaddr* originator_address,
+  const CipSessionHandle encapsulation_session) {
   // Suppress unused parameter compiler warning.
   (void)originator_address;
   (void)encapsulation_session;
 
   // Mask for filtering get-ability of attributes
   CipAttributeStruct* attribute = GetCipAttribute(
-      instance, message_router_request->request_path.attribute_number);
+    instance, message_router_request->request_path.attribute_number);
 
   GenerateGetAttributeSingleHeader(message_router_request,
                                    message_router_response);
 
   EipUint16 attribute_number =
-      message_router_request->request_path.attribute_number;
+    message_router_request->request_path.attribute_number;
 
   if ((NULL != attribute) && (NULL != attribute->data)) {
     uint8_t get_bit_mask =
-        (instance->cip_class
-             ->get_single_bit_mask[CalculateIndex(attribute_number)]);
+      (instance->cip_class
+         ->get_single_bit_mask[CalculateIndex(attribute_number)]);
     if (0 != (get_bit_mask & (1 << (attribute_number % 8)))) {
       // creating a reply message containing the data
       OPENER_TRACE_INFO("getAttribute %d\n",
@@ -641,7 +641,7 @@ EipStatus GetAttributeSingle(
       if ((attribute->attribute_flags & kPreGetFunc) &&
           NULL != instance->cip_class->PreGetCallback) {
         instance->cip_class->PreGetCallback(
-            instance, attribute, message_router_request->service);
+          instance, attribute, message_router_request->service);
       }
 
       OPENER_ASSERT(NULL != attribute);
@@ -653,7 +653,7 @@ EipStatus GetAttributeSingle(
       if ((attribute->attribute_flags & kPostGetFunc) &&
           NULL != instance->cip_class->PostGetCallback) {
         instance->cip_class->PostGetCallback(
-            instance, attribute, message_router_request->service);
+          instance, attribute, message_router_request->service);
       }
     }
   }
@@ -843,7 +843,7 @@ void EncodeCipEPath(const void* const data,
 }
 
 void EncodeCipEthernetLinkPhyisicalAddress(
-    const void* const data, ENIPMessage* const outgoing_message) {
+  const void* const data, ENIPMessage* const outgoing_message) {
   EipUint8* p = (EipUint8*)data;
   memcpy(outgoing_message->current_message_position, p, 6);
   outgoing_message->current_message_position += 6;
@@ -851,33 +851,33 @@ void EncodeCipEthernetLinkPhyisicalAddress(
 }
 
 void GenerateSetAttributeSingleHeader(
-    const CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response) {
+  const CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response) {
   InitializeENIPMessage(&message_router_response->message);
   message_router_response->reply_service =
-      (0x80 | message_router_request->service);
+    (0x80 | message_router_request->service);
   message_router_response->general_status = kCipErrorAttributeNotSupported;
   message_router_response->size_of_additional_status = 0;
 }
 
 EipStatus SetAttributeSingle(
-    CipInstance* RESTRICT const instance,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response,
-    const struct sockaddr* originator_address,
-    const CipSessionHandle encapsulation_session) {
+  CipInstance* RESTRICT const instance,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response,
+  const struct sockaddr* originator_address,
+  const CipSessionHandle encapsulation_session) {
   // Suppress unused parameter compiler warning.
   (void)originator_address;
   (void)encapsulation_session;
 
   CipAttributeStruct* attribute = GetCipAttribute(
-      instance, message_router_request->request_path.attribute_number);
+    instance, message_router_request->request_path.attribute_number);
 
   GenerateSetAttributeSingleHeader(message_router_request,
                                    message_router_response);
 
   EipUint16 attribute_number =
-      message_router_request->request_path.attribute_number;
+    message_router_request->request_path.attribute_number;
 
   // Mask for filtering set-ability
   if ((NULL != attribute) && (NULL != attribute->data)) {
@@ -888,7 +888,7 @@ EipStatus SetAttributeSingle(
                         attribute_number);
     } else {
       uint8_t set_bit_mask =
-          (instance->cip_class->set_bit_mask[CalculateIndex(attribute_number)]);
+        (instance->cip_class->set_bit_mask[CalculateIndex(attribute_number)]);
       if (0 != (set_bit_mask & (1 << (attribute_number % 8)))) {
         OPENER_TRACE_INFO("setAttribute %d\n", attribute_number);
 
@@ -897,21 +897,21 @@ EipStatus SetAttributeSingle(
         if ((attribute->attribute_flags & kPreSetFunc) &&
             NULL != instance->cip_class->PreSetCallback) {
           instance->cip_class->PreSetCallback(
-              instance, attribute, message_router_request->service);
+            instance, attribute, message_router_request->service);
         }
 
         OPENER_ASSERT(NULL != attribute);
 
         // writes data to attribute, sets response status
         attribute->decode(
-            attribute->data, message_router_request, message_router_response);
+          attribute->data, message_router_request, message_router_response);
 
         // Call the PostSetCallback if enabled for this attribute and the class
         // provides one.
         if ((attribute->attribute_flags & (kPostSetFunc | kNvDataFunc)) &&
             NULL != instance->cip_class->PostSetCallback) {
           instance->cip_class->PostSetCallback(
-              instance, attribute, message_router_request->service);
+            instance, attribute, message_router_request->service);
         }
       } else {
         message_router_response->general_status = kCipErrorAttributeNotSetable;
@@ -940,9 +940,9 @@ int DecodeCipByte(CipByte* const data,
 }
 
 int DecodeCipByteArray(
-    CipByteArray* const data,
-    const CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response) {
+  CipByteArray* const data,
+  const CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response) {
   int number_of_decoded_bytes = -1;
   OPENER_TRACE_INFO(" -> set attribute byte array\r\n");
   CipByteArray* cip_byte_array = data;
@@ -959,9 +959,8 @@ int DecodeCipByteArray(
   }
 
   // data-length is correct
-  memcpy(cip_byte_array->data,
-         message_router_request->data,
-         cip_byte_array->length);
+  memcpy(
+    cip_byte_array->data, message_router_request->data, cip_byte_array->length);
   number_of_decoded_bytes = cip_byte_array->length;
 
   message_router_response->general_status = kCipErrorSuccess;
@@ -1086,7 +1085,7 @@ int DecodeCipString(CipString* const data,
   *buffer_address += string->length;
 
   number_of_decoded_bytes =
-      string->length + 2;                // we have a two byte length field
+    string->length + 2;                  // we have a two byte length field
   if (number_of_decoded_bytes & 0x01) {  // we have an odd byte count
     ++(*buffer_address);
     number_of_decoded_bytes++;
@@ -1096,16 +1095,16 @@ int DecodeCipString(CipString* const data,
 }
 
 int DecodeCipShortString(
-    CipShortString* data,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response) {
+  CipShortString* data,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response) {
   int number_of_decoded_bytes  = -1;
   CipShortString* short_string = data;
 
   const CipUsint length = GetUsintFromMessage(&message_router_request->data);
 
-  short_string = SetCipShortStringByData(
-      short_string, length, message_router_request->data);
+  short_string =
+    SetCipShortStringByData(short_string, length, message_router_request->data);
 
   const CipOctet** const buffer_address = &message_router_request->data;
   *buffer_address += short_string->length;
@@ -1141,13 +1140,13 @@ EipStatus GetAttributeAll(CipInstance* instance,
 
   InitializeENIPMessage(&message_router_response->message);
   CipAttributeStruct* attribute =
-      instance->attributes;  // pointer to list of attributes
+    instance->attributes;  // pointer to list of attributes
 
   // Missing header
   if (0 == instance->cip_class->number_of_attributes) {
     // there are no attributes to be sent back
     message_router_response->reply_service =
-        (0x80 | message_router_request->service);
+      (0x80 | message_router_request->service);
     message_router_response->general_status = kCipErrorServiceNotSupported;
     message_router_response->size_of_additional_status = 0;
   } else {
@@ -1158,12 +1157,12 @@ EipStatus GetAttributeAll(CipInstance* instance,
       // for each instance attribute of this class
       EipUint16 attribute_number = attribute->attribute_number;
       if ((instance->cip_class
-               ->get_all_bit_mask[CalculateIndex(attribute_number)]) &
+             ->get_all_bit_mask[CalculateIndex(attribute_number)]) &
           (1 << (attribute_number % 8))) {
         // only return attributes that are flagged as being part of
         // GetAttributeAll
         message_router_request->request_path.attribute_number =
-            attribute_number;
+          attribute_number;
 
         attribute->encode(attribute->data, &message_router_response->message);
       }
@@ -1184,50 +1183,50 @@ EipStatus GetAttributeList(CipInstance* instance,
 
   InitializeENIPMessage(&message_router_response->message);
   message_router_response->reply_service =
-      (0x80 | message_router_request->service);
+    (0x80 | message_router_request->service);
   message_router_response->general_status            = kCipErrorSuccess;
   message_router_response->size_of_additional_status = 0;
 
   CipUint attribute_count_request =
-      GetUintFromMessage(&message_router_request->data);
+    GetUintFromMessage(&message_router_request->data);
 
   if (0 != attribute_count_request) {
     EipUint16 attribute_number    = 0;
     CipAttributeStruct* attribute = NULL;
 
     CipOctet* attribute_count_responst_position =
-        message_router_response->message.current_message_position;
+      message_router_response->message.current_message_position;
 
     MoveMessageNOctets(
-        sizeof(CipInt),
-        &message_router_response
-             ->message);  // move the message pointer to reserve memory
+      sizeof(CipInt),
+      &message_router_response
+         ->message);  // move the message pointer to reserve memory
 
     for (size_t j = 0; j < attribute_count_request; j++) {
       attribute_number = GetUintFromMessage(&message_router_request->data);
       attribute        = GetCipAttribute(instance, attribute_number);
 
       const int_fast64_t needed_message_space =
-          NULL != attribute ? (int_fast64_t)GetCipDataTypeLength(
-                                  attribute->type, attribute->data)
-                            : (int_fast64_t)(2 * sizeof(CipSint));
+        NULL != attribute
+          ? (int_fast64_t)GetCipDataTypeLength(attribute->type, attribute->data)
+          : (int_fast64_t)(2 * sizeof(CipSint));
 
       const int_fast64_t remaining_message_space =
-          (int_fast64_t)PC_OPENER_ETHERNET_BUFFER_SIZE -
-          (int_fast64_t)message_router_response->message.used_message_length -
-          33LL;  // need 33 bytes extra space for the rest of the ENIP message
+        (int_fast64_t)PC_OPENER_ETHERNET_BUFFER_SIZE -
+        (int_fast64_t)message_router_response->message.used_message_length -
+        33LL;  // need 33 bytes extra space for the rest of the ENIP message
       if (needed_message_space > remaining_message_space) {
         message_router_response->message.used_message_length -=
-            2;  // Correct count from Move above
+          2;  // Correct count from Move above
         CipOctet* const save_current_position =
-            message_router_response->message.current_message_position;
+          message_router_response->message.current_message_position;
         message_router_response->message.current_message_position =
-            attribute_count_responst_position;
+          attribute_count_responst_position;
         AddIntToMessage(attribute_count_request,
                         &message_router_response
-                             ->message);  // Add current amount of attributes
+                           ->message);  // Add current amount of attributes
         message_router_response->message.current_message_position =
-            save_current_position;
+          save_current_position;
         // If there was not alreay an attribute list error, resturn partial
         // transfer
         if (message_router_response->general_status !=
@@ -1242,26 +1241,25 @@ EipStatus GetAttributeList(CipInstance* instance,
 
       if (NULL != attribute) {
         uint8_t get_bit_mask =
-            (instance->cip_class
-                 ->get_single_bit_mask[CalculateIndex(attribute_number)]);
+          (instance->cip_class
+             ->get_single_bit_mask[CalculateIndex(attribute_number)]);
         if (0 !=
             (get_bit_mask & (1 << (attribute_number %
                                    8)))) {  // check if attribute is gettable
           AddSintToMessage(
-              kCipErrorSuccess,
-              &message_router_response->message);  // Attribute status
+            kCipErrorSuccess,
+            &message_router_response->message);  // Attribute status
           AddSintToMessage(
-              0, &message_router_response->message);  // Reserved, shall be 0
-          attribute->encode(
-              attribute->data,
-              &message_router_response
-                   ->message);  // write Attribute data to response
+            0, &message_router_response->message);  // Reserved, shall be 0
+          attribute->encode(attribute->data,
+                            &message_router_response
+                               ->message);  // write Attribute data to response
         } else {
           AddSintToMessage(
-              kCipErrorAttributeNotGettable,
-              &message_router_response->message);  // Attribute status
+            kCipErrorAttributeNotGettable,
+            &message_router_response->message);  // Attribute status
           AddSintToMessage(
-              0, &message_router_response->message);  // Reserved, shall be 0
+            0, &message_router_response->message);  // Reserved, shall be 0
           message_router_response->general_status = kCipErrorAttributeListError;
         }
 
@@ -1269,7 +1267,7 @@ EipStatus GetAttributeList(CipInstance* instance,
         AddSintToMessage(kCipErrorAttributeNotSupported,
                          &message_router_response->message);  // status
         AddSintToMessage(
-            0, &message_router_response->message);  // Reserved, shall be 0
+          0, &message_router_response->message);  // Reserved, shall be 0
         message_router_response->general_status = kCipErrorAttributeListError;
       }
     }
@@ -1277,13 +1275,13 @@ EipStatus GetAttributeList(CipInstance* instance,
     // Correct count from Move above
     message_router_response->message.used_message_length -= 2;
     CipOctet* const save_current_position =
-        message_router_response->message.current_message_position;
+      message_router_response->message.current_message_position;
     message_router_response->message.current_message_position =
-        attribute_count_responst_position;
+      attribute_count_responst_position;
     // Add current amount of attributes
     AddIntToMessage(attribute_count_request, &message_router_response->message);
     message_router_response->message.current_message_position =
-        save_current_position;
+      save_current_position;
   } else {
     message_router_response->general_status = kCipErrorAttributeListError;
   }
@@ -1301,19 +1299,19 @@ EipStatus SetAttributeList(CipInstance* instance,
 
   InitializeENIPMessage(&message_router_response->message);
   message_router_response->reply_service =
-      (0x80 | message_router_request->service);
+    (0x80 | message_router_request->service);
   message_router_response->general_status            = kCipErrorSuccess;
   message_router_response->size_of_additional_status = 0;
 
   CipUint attribute_count_request =
-      GetUintFromMessage(&message_router_request->data);
+    GetUintFromMessage(&message_router_request->data);
 
   if (0 != attribute_count_request) {
     EipUint16 attribute_number    = 0;
     CipAttributeStruct* attribute = NULL;
 
     CipOctet* attribute_count_responst_position =
-        message_router_response->message.current_message_position;
+      message_router_response->message.current_message_position;
 
     // move the message pointer to reserve memory
     MoveMessageNOctets(sizeof(CipInt), &message_router_response->message);
@@ -1323,26 +1321,26 @@ EipStatus SetAttributeList(CipInstance* instance,
       attribute        = GetCipAttribute(instance, attribute_number);
 
       const int_fast64_t needed_message_space =
-          NULL != attribute ? (int_fast64_t)GetCipDataTypeLength(
-                                  attribute->type, attribute->data)
-                            : (int_fast64_t)(2 * sizeof(CipSint));
+        NULL != attribute
+          ? (int_fast64_t)GetCipDataTypeLength(attribute->type, attribute->data)
+          : (int_fast64_t)(2 * sizeof(CipSint));
 
       const int_fast64_t remaining_message_space =
-          (int_fast64_t)PC_OPENER_ETHERNET_BUFFER_SIZE -
-          (int_fast64_t)message_router_response->message.used_message_length -
-          33LL;  // need 33 bytes extra space for the rest of the ENIP message
+        (int_fast64_t)PC_OPENER_ETHERNET_BUFFER_SIZE -
+        (int_fast64_t)message_router_response->message.used_message_length -
+        33LL;  // need 33 bytes extra space for the rest of the ENIP message
       if (needed_message_space > remaining_message_space) {
         // Correct count from Move above
         message_router_response->message.used_message_length -= 2;
         CipOctet* const save_current_position =
-            message_router_response->message.current_message_position;
+          message_router_response->message.current_message_position;
         message_router_response->message.current_message_position =
-            attribute_count_responst_position;
+          attribute_count_responst_position;
         // Add current amount of attributes
         AddIntToMessage(attribute_count_request,
                         &message_router_response->message);
         message_router_response->message.current_message_position =
-            save_current_position;
+          save_current_position;
         // If there was not alreay an attribute list error, resturn partial
         // transfer
         if (message_router_response->general_status !=
@@ -1357,8 +1355,7 @@ EipStatus SetAttributeList(CipInstance* instance,
 
       if (NULL != attribute) {
         uint8_t set_bit_mask =
-            (instance->cip_class
-                 ->set_bit_mask[CalculateIndex(attribute_number)]);
+          (instance->cip_class->set_bit_mask[CalculateIndex(attribute_number)]);
         // check if attribute is settable
         if (0 != (set_bit_mask & (1 << (attribute_number % 8)))) {
           // Attribute status
@@ -1367,7 +1364,7 @@ EipStatus SetAttributeList(CipInstance* instance,
           AddSintToMessage(0, &message_router_response->message);
           // write data to attribute
           attribute->decode(
-              attribute->data, message_router_request, message_router_response);
+            attribute->data, message_router_request, message_router_response);
         } else {
           // Attribute status
           AddSintToMessage(kCipErrorAttributeNotSetable,
@@ -1376,12 +1373,12 @@ EipStatus SetAttributeList(CipInstance* instance,
           AddSintToMessage(0, &message_router_response->message);
 
           // move request message pointer
-          size_t attribute_data_length = GetCipDataTypeLength(
-              attribute->type, message_router_request->data);
+          size_t attribute_data_length =
+            GetCipDataTypeLength(attribute->type, message_router_request->data);
           if (0 != attribute_data_length) {
             message_router_request->data += attribute_data_length;
             message_router_response->general_status =
-                kCipErrorAttributeListError;
+              kCipErrorAttributeListError;
           } else {
             message_router_response->general_status = kCipErrorPartialTransfer;
             return kEipStatusOkSend;
@@ -1400,13 +1397,13 @@ EipStatus SetAttributeList(CipInstance* instance,
     // Correct count from Move above
     message_router_response->message.used_message_length -= 2;
     CipOctet* const save_current_position =
-        message_router_response->message.current_message_position;
+      message_router_response->message.current_message_position;
     message_router_response->message.current_message_position =
-        attribute_count_responst_position;
+      attribute_count_responst_position;
     // Add current amount of attributes
     AddIntToMessage(attribute_count_request, &message_router_response->message);
     message_router_response->message.current_message_position =
-        save_current_position;
+      save_current_position;
   } else {
     message_router_response->general_status = kCipErrorAttributeListError;
   }
@@ -1494,50 +1491,50 @@ EipStatus DecodePaddedEPath(CipEpath* epath,
     number_of_decoded_elements++;  // At least one element is decoded
     switch (*message_runner) {
       case SEGMENT_TYPE_LOGICAL_SEGMENT + LOGICAL_SEGMENT_TYPE_CLASS_ID +
-          LOGICAL_SEGMENT_FORMAT_EIGHT_BIT:
+        LOGICAL_SEGMENT_FORMAT_EIGHT_BIT:
         epath->class_id = *(EipUint8*)(message_runner + 1);
         message_runner += 2;
         break;
 
       case SEGMENT_TYPE_LOGICAL_SEGMENT + LOGICAL_SEGMENT_TYPE_CLASS_ID +
-          LOGICAL_SEGMENT_FORMAT_SIXTEEN_BIT:
+        LOGICAL_SEGMENT_FORMAT_SIXTEEN_BIT:
         message_runner += 2;
         epath->class_id = GetUintFromMessage(&(message_runner));
         number_of_decoded_elements++;
         break;
 
       case SEGMENT_TYPE_LOGICAL_SEGMENT + LOGICAL_SEGMENT_TYPE_INSTANCE_ID +
-          LOGICAL_SEGMENT_FORMAT_EIGHT_BIT:
+        LOGICAL_SEGMENT_FORMAT_EIGHT_BIT:
         epath->instance_number = *(EipUint8*)(message_runner + 1);
         message_runner += 2;
         break;
 
       case SEGMENT_TYPE_LOGICAL_SEGMENT + LOGICAL_SEGMENT_TYPE_INSTANCE_ID +
-          LOGICAL_SEGMENT_FORMAT_SIXTEEN_BIT:
+        LOGICAL_SEGMENT_FORMAT_SIXTEEN_BIT:
         message_runner += 2;
         epath->instance_number = GetUintFromMessage(&(message_runner));
         number_of_decoded_elements++;
         break;
 
       case SEGMENT_TYPE_LOGICAL_SEGMENT + LOGICAL_SEGMENT_TYPE_ATTRIBUTE_ID +
-          LOGICAL_SEGMENT_FORMAT_EIGHT_BIT:
+        LOGICAL_SEGMENT_FORMAT_EIGHT_BIT:
         epath->attribute_number = *(EipUint8*)(message_runner + 1);
         message_runner += 2;
         break;
 
       case SEGMENT_TYPE_LOGICAL_SEGMENT + LOGICAL_SEGMENT_TYPE_ATTRIBUTE_ID +
-          LOGICAL_SEGMENT_FORMAT_SIXTEEN_BIT:
+        LOGICAL_SEGMENT_FORMAT_SIXTEEN_BIT:
         message_runner += 2;
         epath->attribute_number = GetUintFromMessage(&(message_runner));
         number_of_decoded_elements++;
         break;
 
       case SEGMENT_TYPE_LOGICAL_SEGMENT + LOGICAL_SEGMENT_TYPE_MEMBER_ID +
-          LOGICAL_SEGMENT_FORMAT_EIGHT_BIT:
+        LOGICAL_SEGMENT_FORMAT_EIGHT_BIT:
         message_runner += 2;
         break;
       case SEGMENT_TYPE_LOGICAL_SEGMENT + LOGICAL_SEGMENT_TYPE_MEMBER_ID +
-          LOGICAL_SEGMENT_FORMAT_SIXTEEN_BIT:
+        LOGICAL_SEGMENT_FORMAT_SIXTEEN_BIT:
         message_runner += 2;
         number_of_decoded_elements++;
         break;
@@ -1555,18 +1552,18 @@ EipStatus DecodePaddedEPath(CipEpath* epath,
 }
 
 EipStatus CipCreateService(
-    CipInstance* RESTRICT const instance,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response,
-    const struct sockaddr* originator_address,
-    const CipSessionHandle encapsulation_session) {
+  CipInstance* RESTRICT const instance,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response,
+  const struct sockaddr* originator_address,
+  const CipSessionHandle encapsulation_session) {
   // Suppress unused parameter compiler warning.
   (void)originator_address;
   (void)encapsulation_session;
 
   InitializeENIPMessage(&message_router_response->message);
   message_router_response->reply_service =
-      (0x80 | message_router_request->service);
+    (0x80 | message_router_request->service);
   message_router_response->general_status            = kCipErrorSuccess;
   message_router_response->size_of_additional_status = 0;
 
@@ -1577,7 +1574,7 @@ EipStatus CipCreateService(
   // Call the PreCreateCallback if the class provides one.
   if (NULL != class->PreCreateCallback) {
     internal_state = class->PreCreateCallback(
-        instance, message_router_request, message_router_response);
+      instance, message_router_request, message_router_response);
   }
 
   if (kEipStatusOk == internal_state) {
@@ -1589,7 +1586,7 @@ EipStatus CipCreateService(
     // Call the PostCreateCallback if the class provides one.
     if (NULL != class->PostCreateCallback) {
       class->PostCreateCallback(
-          new_instance, message_router_request, message_router_response);
+        new_instance, message_router_request, message_router_response);
     }
     OPENER_TRACE_INFO("Instance number %d created\n",
                       new_instance->instance_number);
@@ -1598,11 +1595,11 @@ EipStatus CipCreateService(
 }
 
 EipStatus CipDeleteService(
-    CipInstance* RESTRICT const instance,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response,
-    const struct sockaddr* originator_address,
-    const CipSessionHandle encapsulation_session) {
+  CipInstance* RESTRICT const instance,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response,
+  const struct sockaddr* originator_address,
+  const CipSessionHandle encapsulation_session) {
   // Suppress unused parameter compiler warning.
   (void)originator_address;
   (void)encapsulation_session;
@@ -1611,7 +1608,7 @@ EipStatus CipDeleteService(
   message_router_response->size_of_additional_status = 0;
   InitializeENIPMessage(&message_router_response->message);
   message_router_response->reply_service =
-      (0x80 | message_router_request->service);
+    (0x80 | message_router_request->service);
 
   EipStatus internal_state = kEipStatusOk;
 
@@ -1620,7 +1617,7 @@ EipStatus CipDeleteService(
   // Call the PreDeleteCallback if the class provides one.
   if (NULL != class->PreDeleteCallback) {
     internal_state = class->PreDeleteCallback(
-        instance, message_router_request, message_router_response);
+      instance, message_router_request, message_router_response);
   }
 
   if (kEipStatusOk == internal_state) {
@@ -1647,7 +1644,7 @@ EipStatus CipDeleteService(
     // Call the PostDeleteCallback if the class provides one.
     if (NULL != class->PostDeleteCallback) {
       class->PostDeleteCallback(
-          instance, message_router_request, message_router_response);
+        instance, message_router_request, message_router_response);
     }
 
     CipFree(instance);  // delete instance
@@ -1664,11 +1661,11 @@ EipStatus CipDeleteService(
 }
 
 EipStatus CipResetService(
-    CipInstance* RESTRICT const instance,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response,
-    const struct sockaddr* originator_address,
-    const CipSessionHandle encapsulation_session) {
+  CipInstance* RESTRICT const instance,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response,
+  const struct sockaddr* originator_address,
+  const CipSessionHandle encapsulation_session) {
   // Suppress unused parameter compiler warning.
   (void)originator_address;
   (void)encapsulation_session;
@@ -1677,7 +1674,7 @@ EipStatus CipResetService(
   message_router_response->size_of_additional_status = 0;
   InitializeENIPMessage(&message_router_response->message);
   message_router_response->reply_service =
-      (0x80 | message_router_request->service);
+    (0x80 | message_router_request->service);
 
   EipStatus internal_state = kEipStatusOk;
 
@@ -1686,14 +1683,14 @@ EipStatus CipResetService(
   // Call the PreResetCallback if the class provides one.
   if (NULL != class->PreResetCallback) {
     internal_state = class->PreResetCallback(
-        instance, message_router_request, message_router_response);
+      instance, message_router_request, message_router_response);
   }
 
   if (kEipStatusError != internal_state) {
     // Call the PostResetCallback if the class provides one.
     if (NULL != class->PostResetCallback) {
       class->PostResetCallback(
-          instance, message_router_request, message_router_response);
+        instance, message_router_request, message_router_response);
     }
   }
   return internal_state;

+ 30 - 30
source/src/cip/cipcommon.h

@@ -14,7 +14,7 @@
 #include "core/typedefs.h"
 
 static const EipUint16 kCipUintZero =
-    0; /**< Zero value for returning the UINT standard value */
+  0; /**< Zero value for returning the UINT standard value */
 
 /** @brief Check if requested service present in class/instance and call
  * appropriate service.
@@ -44,8 +44,8 @@ EipStatus NotifyClass(const CipClass* const RESTRICT cip_class,
 CipUint GetMaxInstanceNumber(CipClass* RESTRICT const cip_class);
 
 void GenerateGetAttributeSingleHeader(
-    const CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response);
+  const CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response);
 
 /** @brief Generic implementation of the GetAttributeSingle CIP service
  *
@@ -61,15 +61,15 @@ void GenerateGetAttributeSingleHeader(
  *          -1 .. requested attribute not available
  */
 EipStatus GetAttributeSingle(
-    CipInstance* RESTRICT const instance,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response,
-    const struct sockaddr* originator_address,
-    const CipSessionHandle encapsulation_session);
+  CipInstance* RESTRICT const instance,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response,
+  const struct sockaddr* originator_address,
+  const CipSessionHandle encapsulation_session);
 
 void GenerateSetAttributeSingleHeader(
-    const CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response);
+  const CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response);
 
 /** @brief Generic implementation of the SetAttributeSingle CIP service
  *
@@ -86,11 +86,11 @@ void GenerateSetAttributeSingleHeader(
  *          -1 .. requested attribute not set
  */
 EipStatus SetAttributeSingle(
-    CipInstance* RESTRICT const instance,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response,
-    const struct sockaddr* originator_address,
-    const CipSessionHandle encapsulation_session);
+  CipInstance* RESTRICT const instance,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response,
+  const struct sockaddr* originator_address,
+  const CipSessionHandle encapsulation_session);
 
 /** @brief Generic implementation of the GetAttributeAll CIP service
  *
@@ -175,11 +175,11 @@ EipStatus DecodePaddedEPath(CipEpath* epath,
  *          -1 .. requested instance not created
  */
 EipStatus CipCreateService(
-    CipInstance* RESTRICT const instance,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response,
-    const struct sockaddr* originator_address,
-    const CipSessionHandle encapsulation_session);
+  CipInstance* RESTRICT const instance,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response,
+  const struct sockaddr* originator_address,
+  const CipSessionHandle encapsulation_session);
 
 /** @brief Generic implementation of the CIP Delete service
  *
@@ -196,11 +196,11 @@ EipStatus CipCreateService(
  *          -1 .. requested instance not deleted
  */
 EipStatus CipDeleteService(
-    CipInstance* RESTRICT const instance,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response,
-    const struct sockaddr* originator_address,
-    const CipSessionHandle encapsulation_session);
+  CipInstance* RESTRICT const instance,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response,
+  const struct sockaddr* originator_address,
+  const CipSessionHandle encapsulation_session);
 
 /** @brief Generic implementation of the CIP Reset service
  *
@@ -218,10 +218,10 @@ EipStatus CipDeleteService(
  *          -1 .. requested instance not reseted
  */
 EipStatus CipResetService(
-    CipInstance* RESTRICT const instance,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response,
-    const struct sockaddr* originator_address,
-    const CipSessionHandle encapsulation_session);
+  CipInstance* RESTRICT const instance,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response,
+  const struct sockaddr* originator_address,
+  const CipSessionHandle encapsulation_session);
 
 #endif /* CIP_CIPCOMMON_H_ */

File diff suppressed because it is too large
+ 237 - 242
source/src/cip/cipconnectionmanager.c


+ 126 - 126
source/src/cip/cipconnectionmanager.h

@@ -22,9 +22,9 @@
 
 typedef enum {
   kConnectionManagerGeneralStatusSuccess =
-      0x00U, /**< General Status - Everything is ok */
+    0x00U, /**< General Status - Everything is ok */
   kConnectionManagerGeneralStatusExtendedStatus =
-      0x01U, /**< Indicates that extended status is set */
+    0x01U, /**< Indicates that extended status is set */
   kConnectionManagerGeneralStatusResourceUnavailableForUnconnectedSend = 0x02U,
   kConnectionManagerGeneralStatusPathSegmentErrorInUnconnectedSend     = 0x04U,
   kConnectionManagerGeneralStatusErrorInDataSegment                    = 0x09U,
@@ -37,200 +37,200 @@ typedef enum {
 /** @brief Connection Manager Error codes */
 typedef enum {
   kConnectionManagerExtendedStatusCodeSuccess =
-      0x00U, /**< Obsolete code, should be General Status - Everything is ok */
+    0x00U, /**< Obsolete code, should be General Status - Everything is ok */
   kConnectionManagerExtendedStatusCodeErrorConnectionInUseOrDuplicateForwardOpen =
-      0x0100U,  ///< General Status has to be 0x01, Connection is already in
-                ///< use, or a duplicate Forward Open was received
+    0x0100U,  ///< General Status has to be 0x01, Connection is already in
+              ///< use, or a duplicate Forward Open was received
   kConnectionManagerExtendedStatusCodeErrorTransportClassAndTriggerCombinationNotSupported =
-      0x0103U,  ///< General Status has to be 0x01, A Transport class and
-                ///< trigger combination has been specified, which is not
-                ///< supported by the target application
+    0x0103U,  ///< General Status has to be 0x01, A Transport class and
+              ///< trigger combination has been specified, which is not
+              ///< supported by the target application
   kConnectionManagerExtendedStatusCodeErrorOwnershipConflict =
-      0x0106U,  ///< General Status has to be 0x01, Another connection has
-                ///< already reserved some needed resources */
+    0x0106U,  ///< General Status has to be 0x01, Another connection has
+              ///< already reserved some needed resources */
   kConnectionManagerExtendedStatusCodeErrorConnectionTargetConnectionNotFound =
-      0x0107U,  ///< General Status has to be 0x01, Forward Close error message,
-                ///< if connection to be closed is not found at the target */
+    0x0107U,  ///< General Status has to be 0x01, Forward Close error message,
+              ///< if connection to be closed is not found at the target */
   kConnectionManagerExtendedStatusCodeErrorTargetForConnectionNotConfigured =
-      0x0110U,  ///< General Status has to be 0x01, Target application not
-                ///< configured and connection request does not contain data
-                ///< segment for configuration
+    0x0110U,  ///< General Status has to be 0x01, Target application not
+              ///< configured and connection request does not contain data
+              ///< segment for configuration
   kConnectionManagerExtendedStatusCodeRpiNotSupported =
-      0x0111U,  ///< General Status has
-                ///< to be 0x01, Requested RPI not supported by target device
+    0x0111U,  ///< General Status has
+              ///< to be 0x01, Requested RPI not supported by target device
   kConnectionManagerExtendedStatusCodeErrorRpiValuesNotAcceptable =
-      0x0112U,  ///< General Status has to be 0x01, Requested RPI parameters
-                ///< outside of range, needs 6 16-bit extended status words, see
-                ///< Vol.1 Table 3-5.33
+    0x0112U,  ///< General Status has to be 0x01, Requested RPI parameters
+              ///< outside of range, needs 6 16-bit extended status words, see
+              ///< Vol.1 Table 3-5.33
   kConnectionManagerExtendedStatusCodeErrorNoMoreConnectionsAvailable =
-      0x0113U,  ///< General Status has to be 0x01, No free connection slots
-                ///< available
+    0x0113U,  ///< General Status has to be 0x01, No free connection slots
+              ///< available
   kConnectionManagerExtendedStatusCodeErrorVendorIdOrProductcodeError =
-      0x0114U,  ///< General Status has to be 0x01, The Product Code or Vendor
-                ///< ID in the electronic key logical segment does not match the
-                ///< Product Code or Vendor ID of the device, or if the
-                ///< compatibility bit is set and one or both are zero, or
-                ///< cannot be emulated.
+    0x0114U,  ///< General Status has to be 0x01, The Product Code or Vendor
+              ///< ID in the electronic key logical segment does not match the
+              ///< Product Code or Vendor ID of the device, or if the
+              ///< compatibility bit is set and one or both are zero, or
+              ///< cannot be emulated.
   kConnectionManagerExtendedStatusCodeErrorDeviceTypeError =
-      0x0115U,  ///< General Status has to be 0x01, Device Type specified in the
-                ///< electronic key logical segment does not match the Device
-                ///< Type, or if the compatibility bit is set and Device Type is
-                ///< zero, or cannot be emulated.
+    0x0115U,  ///< General Status has to be 0x01, Device Type specified in the
+              ///< electronic key logical segment does not match the Device
+              ///< Type, or if the compatibility bit is set and Device Type is
+              ///< zero, or cannot be emulated.
   kConnectionManagerExtendedStatusCodeErrorRevisionMismatch =
-      0x0116U,  ///< General Status has to be 0x01, Major and minor revision
-                ///< specified in the electronic key logical segment is not a
-                ///< valid revision of the device, or if the compatibility bit
-                ///< is set and the requested Major Revision and/or Minor
-                ///< Revision is 0 or the device cannot emulate the specified
-                ///< revision.
+    0x0116U,  ///< General Status has to be 0x01, Major and minor revision
+              ///< specified in the electronic key logical segment is not a
+              ///< valid revision of the device, or if the compatibility bit
+              ///< is set and the requested Major Revision and/or Minor
+              ///< Revision is 0 or the device cannot emulate the specified
+              ///< revision.
   kConnectionManagerExtendedStatusCodeNonListenOnlyConnectionNotOpened =
-      0x0119U,  ///< General Status has to be 0x01, listen-only connection
-                ///< cannot be established, if no non-listen only connections
-                ///< are established
+    0x0119U,  ///< General Status has to be 0x01, listen-only connection
+              ///< cannot be established, if no non-listen only connections
+              ///< are established
   kConnectionManagerExtendedStatusCodeTargetObjectOutOfConnections =
-      0x011AU,  ///< Maximum number of connections supported by the instance of
-                ///< the target object exceeded
+    0x011AU,  ///< Maximum number of connections supported by the instance of
+              ///< the target object exceeded
   kConnectionManagerExtendedStatusCodeProductionInhibitTimerGreaterThanRpi =
-      0x011BU,  ///< The Production Inhibit Time is greater than the Target to
-                ///< Originator RPI
+    0x011BU,  ///< The Production Inhibit Time is greater than the Target to
+              ///< Originator RPI
   kConnectionManagerExtendedStatusCodeTransportClassNotSupported =
-      0x011CU,  ///< The transport class requested in the Transport Type/Trigger
-                ///< parameter is not supported.
+    0x011CU,  ///< The transport class requested in the Transport Type/Trigger
+              ///< parameter is not supported.
   kConnectionManagerExtendedStatusCodeProductionTriggerNotSuppoerted =
-      0x011DU,  ///< The production trigger requested in the Transport
-                ///< Type/Trigger parameter is not supported.
+    0x011DU,  ///< The production trigger requested in the Transport
+              ///< Type/Trigger parameter is not supported.
   kConnectionManagerExtendedStatusCodeDirectionNotSupported =
-      0x011EU,  ///< The direction requested in the Transport Type/Trigger
-                ///< parameter is not supported
+    0x011EU,  ///< The direction requested in the Transport Type/Trigger
+              ///< parameter is not supported
   kConnectionManagerExtendedStatusCodeInvalidOToTNetworkConnectionFixVar =
-      0x011FU,  ///< Shall be returned as the result of specifying an O->T fixed
-                ///< / variable flag that is not supported.
+    0x011FU,  ///< Shall be returned as the result of specifying an O->T fixed
+              ///< / variable flag that is not supported.
   kConnectionManagerExtendedStatusCodeInvalidTToONetworkConnectionFixVar =
-      0x0120U,  ///< Shall be returned as the result of specifying an T->O fixed
-                ///< / variable flag that is not supported.
+    0x0120U,  ///< Shall be returned as the result of specifying an T->O fixed
+              ///< / variable flag that is not supported.
   kConnectionManagerExtendedStatusCodeInvalidOToTNetworkConnectionPriority =
-      0x0121U,  ///< Shall be returned as the result of specifying an O->T
-                ///< priority code that is not supported.
+    0x0121U,  ///< Shall be returned as the result of specifying an O->T
+              ///< priority code that is not supported.
   kConnectionManagerExtendedStatusCodeInvalidTToONetworkConnectionPriority =
-      0x0122U,  ///< Shall be returned as the result of specifying an T->O
-                ///< priority code that is not supported.
+    0x0122U,  ///< Shall be returned as the result of specifying an T->O
+              ///< priority code that is not supported.
   kConnectionManagerExtendedStatusCodeErrorInvalidOToTConnectionType =
-      0x0123U,  ///< Shall be returned as the result of specifying an O->T
-                ///< connection type that is not supported
+    0x0123U,  ///< Shall be returned as the result of specifying an O->T
+              ///< connection type that is not supported
   kConnectionManagerExtendedStatusCodeErrorInvalidTToOConnectionType =
-      0x0124U,  ///< Shall be returned as the result of specifying a T->O
-                ///< connection type that is not supported
+    0x0124U,  ///< Shall be returned as the result of specifying a T->O
+              ///< connection type that is not supported
   kConnectionManagerExtendedStatusCodeInvalidOToTNetworkConnectionRedundantOwner =
-      0x0125U,  ///< Shall be returned as the result of specifying an O->T
-                ///< Redundant Owner flag that is not supported.
+    0x0125U,  ///< Shall be returned as the result of specifying an O->T
+              ///< Redundant Owner flag that is not supported.
   kConnectionManagerExtendedStatusCodeInvalidConfigurationSize =
-      0x0126U,  ///< The data segment provided in the Connection_Path parameter
-                ///< did not contain an acceptable number of 16-bit words for
-                ///< the the configuration application path requested. Two
-                ///< additional status words shall follow, the error code plus
-                ///< the max size in words
+    0x0126U,  ///< The data segment provided in the Connection_Path parameter
+              ///< did not contain an acceptable number of 16-bit words for
+              ///< the the configuration application path requested. Two
+              ///< additional status words shall follow, the error code plus
+              ///< the max size in words
   kConnectionManagerExtendedStatusCodeErrorInvalidOToTConnectionSize =
-      0x0127U,  ///< The size of the consuming object declared in the
-                ///< Forward_Open request and available on the target does not
-                ///< match the size declared in the O->T Network Connection
-                ///< Parameter. Two additional status words shall follow, the
-                ///< error code plus the
-                ///<  max size in words
+    0x0127U,  ///< The size of the consuming object declared in the
+              ///< Forward_Open request and available on the target does not
+              ///< match the size declared in the O->T Network Connection
+              ///< Parameter. Two additional status words shall follow, the
+              ///< error code plus the
+              ///<  max size in words
   kConnectionManagerExtendedStatusCodeErrorInvalidTToOConnectionSize =
-      0x0128U,  ///< The size of the consuming object declared in the
-                ///< Forward_Open request and available on the target does not
-                ///< match the size declared in the T->O Network Connection
-                ///< Parameter. Two additional status words shall follow, the
-                ///< error code plus the max size in words
+    0x0128U,  ///< The size of the consuming object declared in the
+              ///< Forward_Open request and available on the target does not
+              ///< match the size declared in the T->O Network Connection
+              ///< Parameter. Two additional status words shall follow, the
+              ///< error code plus the max size in words
   kConnectionManagerExtendedStatusCodeInvalidConfigurationApplicationPath =
-      0x0129U,  ///< Configuration application path specified does not
-                ///< correspond
-                ///<  to a valid configuration application path within the
-                ///<  target
-                ///< configuration application path was required, but not
-                ///< provided
-                ///<  application. This error could also be returned if a
-                ///<  by a connection request.
+    0x0129U,  ///< Configuration application path specified does not
+              ///< correspond
+              ///<  to a valid configuration application path within the
+              ///<  target
+              ///< configuration application path was required, but not
+              ///< provided
+              ///<  application. This error could also be returned if a
+              ///<  by a connection request.
   kConnectionManagerExtendedStatusCodeInvalidConsumingApplicationPath =
-      0x012AU,  ///< Consumed application path specified does not correspond to
-                ///< a valid consumed application path within the target
-                ///< application. This error could also be returned if a
-                ///< consumed application path was required, but not provided by
-                ///< a connection request.
+    0x012AU,  ///< Consumed application path specified does not correspond to
+              ///< a valid consumed application path within the target
+              ///< application. This error could also be returned if a
+              ///< consumed application path was required, but not provided by
+              ///< a connection request.
   kConnectionManagerExtendedStatusCodeInvalidProducingApplicationPath =
-      0x012BU,  ///< Produced application path specified does not correspond to
-                ///< a valid produced application path within the target
-                ///< application. This error could also be returned if a
-                ///< produced application path was required, but not provided by
-                ///< a connection request.
+    0x012BU,  ///< Produced application path specified does not correspond to
+              ///< a valid produced application path within the target
+              ///< application. This error could also be returned if a
+              ///< produced application path was required, but not provided by
+              ///< a connection request.
   kConnectionManagerExtendedStatusCodeConfigurationSymbolDoesNotExist = 0x012CU,
   kConnectionManagerExtendedStatusCodeConsumingSymbolDoesNotExist     = 0x012DU,
   kConnectionManagerExtendedStatusCodeProducingSymbolDoesNotExist     = 0x012EU,
   kConnectionManagerExtendedStatusCodeInconsistentApplicationPathCombo =
-      0x012FU,
+    0x012FU,
   kConnectionManagerExtendedStatusCodeInconsistentConsumeDataFormat = 0x0130U,
   kConnectionManagerExtendedStatusCodeInconsistentProduceDataFormat = 0x0131U,
   kConnectionManagerExtendedStatusCodeNullForwardOpenNotSupported   = 0x0132U,
   kConnectionManagerExtendedStatusCodeConnectionTimeoutMultiplierNotAcceptable =
-      0x0133U,
+    0x0133U,
   kConnectionManagerExtendedStatusCodeMismatchedTToONetworkConnectionFixVar =
-      0x0135U,
+    0x0135U,
   kConnectionManagerExtendedStatusCodeMismatchedTToONetworkConnectionPriority =
-      0x0136U,
+    0x0136U,
   kConnectionManagerExtendedStatusCodeMismatchedTransportClass        = 0x0137U,
   kConnectionManagerExtendedStatusCodeMismatchedTToOProductionTrigger = 0x0138U,
   kConnectionManagerExtendedStatusCodeMismatchedTToOProductionInhibitTimeSegment =
-      0x0139U,
+    0x0139U,
   kConnectionManagerExtendedStatusCodeConnectionTimedOut         = 0x0203U,
   kConnectionManagerExtendedStatusCodeUnconnectedRequestTimedOut = 0x0204U,
   kConnectionManagerExtendedStatusCodeErrorParameterErrorInUnconnectedSendService =
-      0x0205U,
+    0x0205U,
   kConnectionManagerExtendedStatusCodeMessageToLargeForUnconnectedSendService =
-      0x0206U,
+    0x0206U,
   kConnectionManagerExtendedStatusCodeUnconnectedAcknowledgeWithoutReply =
-      0x0207U,
+    0x0207U,
   kConnectionManagerExtendedStatusCodeNoBufferMemoryAvailable = 0x0301U,
   kConnectionManagerExtendedStatusCodeNetworkBandwithNotAvailableForData =
-      0x0302U,
+    0x0302U,
   kConnectionManagerExtendedStatusCodeNoConsumedConnectionIdFilterAvailable =
-      0x0303U,
+    0x0303U,
   kConnectionManagerExtendedStatusCodeNotConfiguredToSendScheduledPriorityData =
-      0x0304U,
+    0x0304U,
   kConnectionManagerExtendedStatusCodeScheduleSignatureMismatch = 0x0305U,
   kConnectionManagerExtendedStatusCodeScheduleSignatureValidationNotPossible =
-      0x0306U,
+    0x0306U,
   kConnectionManagerExtendedStatusCodePortNotAvailable              = 0x0311U,
   kConnectionManagerExtendedStatusCodeLinkAddressNotValid           = 0x0312U,
   kConnectionManagerExtendedStatusCodeErrorInvalidSegmentTypeInPath = 0x0315U,
   kConnectionManagerExtendedStatusCodeForwardCloseServiceConnectionPathMismatch =
-      0x0316U,
+    0x0316U,
   kConnectionManagerExtendedStatusCodeSchedulingNotSpecified        = 0x0317U,
   kConnectionManagerExtendedStatusCodeLinkAddressToSelfInvalid      = 0x0318U,
   kConnectionManagerExtendedStatusCodeSecondaryResourcesUnavailable = 0x0319U,
   kConnectionManagerExtendedStatusCodeRackConnectionAlreadyEstablished =
-      0x031AU,
+    0x031AU,
   kConnectionManagerExtendedStatusCodeModuleConnectionAlreadyEstablished =
-      0x031BU,
+    0x031BU,
   kConnectionManagerExtendedStatusCodeMiscellaneous               = 0x031CU,
   kConnectionManagerExtendedStatusCodeRedundantConnectionMismatch = 0x031DU,
   kConnectionManagerExtendedStatusCodeNoMoreUserConfigurableLinkConsumerResourcesAvailableInTheProducingModule =
-      0x031EU,
+    0x031EU,
   kConnectionManagerExtendedStatusCodeNoUserConfigurableLinkConsumerResourcesConfiguredInTheProducingModule =
-      0x031FU,
+    0x031FU,
   kConnectionManagerExtendedStatusCodeNetworkLinkOffline = 0x0800U,
   kConnectionManagerExtendedStatusCodeNoTargetApplicationDataAvailable =
-      0x0810U,
+    0x0810U,
   kConnectionManagerExtendedStatusCodeNoOriginatorApplicationDataAvailable =
-      0x0811U,
+    0x0811U,
   kConnectionManagerExtendedStatusCodeNodeAddressHasChangedSinceTheNetworkWasScheduled =
-      0x0812U,
+    0x0812U,
   kConnectionManagerExtendedStatusCodeNotConfiguredForOffSubnetMulticast =
-      0x0813U,
+    0x0813U,
   kConnectionManagerExtendedStatusCodeInvalidProduceConsumeDataFormat = 0x0814U,
   kConnectionManagerExtendedStatusWrongCloser =
-      0xFFFFU  ///< Not an official extended error code - used for Forward Close
-               ///< indicating that not the original originator is trying to
-               ///< close the connection
+    0xFFFFU  ///< Not an official extended error code - used for Forward Close
+             ///< indicating that not the original originator is trying to
+             ///< close the connection
 } ConnectionManagerExtendedStatusCode;
 
 /** @brief macros for comparing sequence numbers according to CIP spec vol
@@ -280,7 +280,7 @@ CipConnectionObject* GetConnectedObject(const EipUint32 connection_id);
  *           0 .. connection not present in device
  */
 CipConnectionObject* GetConnectedOutputAssembly(
-    const EipUint32 output_assembly_id);
+  const EipUint32 output_assembly_id);
 
 /** @brief Close the given connection
  *
@@ -315,10 +315,10 @@ void RemoveFromActiveConnections(CipConnectionObject* const connection_object);
 CipUdint GetConnectionId(void);
 
 typedef void (*CloseSessionFunction)(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void CheckForTimedOutConnectionsAndCloseTCPConnections(
-    const CipConnectionObject* const connection_object,
-    CloseSessionFunction CloseSessions);
+  const CipConnectionObject* const connection_object,
+  CloseSessionFunction CloseSessions);
 
 #endif  // CIP_CIPCONNECTIONMANAGER_H_

+ 166 - 166
source/src/cip/cipconnectionobject.c

@@ -56,15 +56,15 @@ DoublyLinkedList connection_list;
 
 /** @brief Array of the available explicit connections */
 CipConnectionObject
-    explicit_connection_object_pool[OPENER_CIP_NUM_EXPLICIT_CONNS];
+  explicit_connection_object_pool[OPENER_CIP_NUM_EXPLICIT_CONNS];
 
 DoublyLinkedListNode* CipConnectionObjectListArrayAllocator() {
   enum {
     kNodesAmount =
-        OPENER_CIP_NUM_EXPLICIT_CONNS + OPENER_CIP_NUM_INPUT_ONLY_CONNS +
-        OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS + OPENER_CIP_NUM_LISTEN_ONLY_CONNS
+      OPENER_CIP_NUM_EXPLICIT_CONNS + OPENER_CIP_NUM_INPUT_ONLY_CONNS +
+      OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS + OPENER_CIP_NUM_LISTEN_ONLY_CONNS
   };
-  static DoublyLinkedListNode nodes[kNodesAmount] = {0};
+  static DoublyLinkedListNode nodes[kNodesAmount] = { 0 };
   for (size_t i = 0; i < kNodesAmount; ++i) {
     if (nodes[i].previous == NULL && nodes[i].next == NULL &&
         nodes[i].data == NULL) {
@@ -89,14 +89,14 @@ void CipConnectionObjectListArrayFree(DoublyLinkedListNode** node) {
 
 /* Private methods declaration */
 uint64_t ConnectionObjectCalculateRegularInactivityWatchdogTimerValue(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void ConnectionObjectSetInitialInactivityWatchdogTimerValue(
-    CipConnectionObject* const connection_object);
+  CipConnectionObject* const connection_object);
 /* End private methods declaration */
 
 void ConnectionObjectInitializeEmpty(
-    CipConnectionObject* const connection_object) {
+  CipConnectionObject* const connection_object) {
   memset(connection_object, 0, sizeof(*connection_object));
   ConnectionObjectSetState(connection_object,
                            kConnectionObjectStateNonExistent);
@@ -113,7 +113,7 @@ CipConnectionObject* CipConnectionObjectCreate(const CipOctet* message) {
 }
 
 void ConnectionObjectInitializeFromMessage(
-    const CipOctet** message, CipConnectionObject* const connection_object) {
+  const CipOctet** message, CipConnectionObject* const connection_object) {
   /* For unconnected send - can be ignored by targets, and is ignored here */
   CipByte priority_timetick = GetByteFromMessage(message);
   CipUsint timeout_ticks    = GetUsintFromMessage(message);
@@ -143,7 +143,7 @@ void ConnectionObjectInitializeFromMessage(
   ConnectionObjectSetState(connection_object,
                            kConnectionObjectStateNonExistent);
   connection_object->sequence_count_producing =
-      0; /* set the sequence count to zero */
+    0; /* set the sequence count to zero */
 
   ConnectionObjectSetConnectionTimeoutMultiplier(connection_object,
                                                  GetUsintFromMessage(message));
@@ -165,10 +165,10 @@ void ConnectionObjectInitializeFromMessage(
 
   if (connection_object->is_large_forward_open == true) {
     ConnectionObjectSetOToTNetworkConnectionParameters(
-        connection_object, GetDwordFromMessage(message));
+      connection_object, GetDwordFromMessage(message));
   } else {
     ConnectionObjectSetOToTNetworkConnectionParameters(
-        connection_object, GetWordFromMessage(message));
+      connection_object, GetWordFromMessage(message));
   }
 
   ConnectionObjectSetTToORequestedPacketInterval(connection_object,
@@ -178,17 +178,17 @@ void ConnectionObjectInitializeFromMessage(
 
   if (connection_object->is_large_forward_open == true) {
     ConnectionObjectSetTToONetworkConnectionParameters(
-        connection_object, GetDwordFromMessage(message));
+      connection_object, GetDwordFromMessage(message));
   } else {
     ConnectionObjectSetTToONetworkConnectionParameters(
-        connection_object, GetWordFromMessage(message));
+      connection_object, GetWordFromMessage(message));
   }
 
   connection_object->transport_class_trigger = GetByteFromMessage(message);
 }
 
 ConnectionObjectState ConnectionObjectGetState(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   ConnectionObjectState new_state = kConnectionObjectStateInvalid;
   switch (connection_object->state) {
     case CIP_CONNECTION_OBJECT_STATE_NON_EXISTENT:
@@ -230,7 +230,7 @@ void ConnectionObjectSetState(CipConnectionObject* const connection_object,
       break;
     case kConnectionObjectStateWaitingForConnectionID:
       connection_object->state =
-          CIP_CONNECTION_OBJECT_STATE_WAITING_FOR_CONNECTION_ID;
+        CIP_CONNECTION_OBJECT_STATE_WAITING_FOR_CONNECTION_ID;
       break;
     case kConnectionObjectStateEstablished:
       connection_object->state = CIP_CONNECTION_OBJECT_STATE_ESTABLISHED;
@@ -251,7 +251,7 @@ void ConnectionObjectSetState(CipConnectionObject* const connection_object,
 }
 
 ConnectionObjectInstanceType ConnectionObjectGetInstanceType(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return connection_object->instance_type;
   //  switch (connection_object->instance_type) {
   //    case CIP_CONNECTION_OBJECT_INSTANCE_TYPE_EXPLICIT_MESSAGING:
@@ -269,13 +269,13 @@ ConnectionObjectInstanceType ConnectionObjectGetInstanceType(
 }
 
 void ConnectionObjectSetInstanceType(
-    CipConnectionObject* const connection_object,
-    const ConnectionObjectInstanceType instance_type) {
+  CipConnectionObject* const connection_object,
+  const ConnectionObjectInstanceType instance_type) {
   connection_object->instance_type = (CipUsint)instance_type;
 }
 
 CipUsint ConnectionObjectGetInstanceTypeForAttribute(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   CipUsint instance_type = kConnectionObjectInstanceTypeInvalid;
   switch (connection_object->instance_type) {
     case kConnectionObjectInstanceTypeExplicitMessaging:
@@ -299,7 +299,7 @@ CipUsint ConnectionObjectGetInstanceTypeForAttribute(
 }
 
 bool ConnectionObjectIsTypeNonLOIOConnection(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   switch (connection_object->instance_type) {
     case kConnectionObjectInstanceTypeIO:
     case kConnectionObjectInstanceTypeIOExclusiveOwner:
@@ -311,7 +311,7 @@ bool ConnectionObjectIsTypeNonLOIOConnection(
 }
 
 bool ConnectionObjectIsTypeIOConnection(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   switch (connection_object->instance_type) {
     case kConnectionObjectInstanceTypeIO:
     case kConnectionObjectInstanceTypeIOExclusiveOwner:
@@ -325,39 +325,39 @@ bool ConnectionObjectIsTypeIOConnection(
 
 ConnectionObjectTransportClassTriggerDirection
 ConnectionObjectGetTransportClassTriggerDirection(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   const CipByte TransportClassTriggerDirectionMask = 0x80;
   return (connection_object->transport_class_trigger &
           TransportClassTriggerDirectionMask) ==
-                 TransportClassTriggerDirectionMask
-             ? kConnectionObjectTransportClassTriggerDirectionServer
-             : kConnectionObjectTransportClassTriggerDirectionClient;
+             TransportClassTriggerDirectionMask
+           ? kConnectionObjectTransportClassTriggerDirectionServer
+           : kConnectionObjectTransportClassTriggerDirectionClient;
 }
 
 ConnectionObjectTransportClassTriggerProductionTrigger
 ConnectionObjectGetTransportClassTriggerProductionTrigger(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   const CipByte kTransportClassTriggerProductionTriggerMask = 0x70;
 
   ConnectionObjectTransportClassTriggerProductionTrigger production_trigger =
-      kConnectionObjectTransportClassTriggerProductionTriggerInvalid;
+    kConnectionObjectTransportClassTriggerProductionTriggerInvalid;
   switch ((connection_object->transport_class_trigger) &
           kTransportClassTriggerProductionTriggerMask) {
     case CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_PRODUCTION_TRIGGER_CYCLIC:
       production_trigger =
-          kConnectionObjectTransportClassTriggerProductionTriggerCyclic;
+        kConnectionObjectTransportClassTriggerProductionTriggerCyclic;
       break;
     case CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_PRODUCTION_TRIGGER_CHANGE_OF_STATE:
       production_trigger =
-          kConnectionObjectTransportClassTriggerProductionTriggerChangeOfState;
+        kConnectionObjectTransportClassTriggerProductionTriggerChangeOfState;
       break;
     case CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_PRODUCTION_TRIGGER_APPLICATION_OBJECT:
       production_trigger =
-          kConnectionObjectTransportClassTriggerProductionTriggerApplicationObject;
+        kConnectionObjectTransportClassTriggerProductionTriggerApplicationObject;
       break;
     default:
       production_trigger =
-          kConnectionObjectTransportClassTriggerProductionTriggerInvalid;
+        kConnectionObjectTransportClassTriggerProductionTriggerInvalid;
       break;
   }
   return production_trigger;
@@ -365,126 +365,126 @@ ConnectionObjectGetTransportClassTriggerProductionTrigger(
 
 ConnectionObjectTransportClassTriggerTransportClass
 ConnectionObjectGetTransportClassTriggerTransportClass(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   const CipByte kTransportClassTriggerTransportClassMask = 0x0F;
 
   ConnectionObjectTransportClassTriggerTransportClass transport_class_trigger =
-      kConnectionObjectTransportClassTriggerTransportClassInvalid;
+    kConnectionObjectTransportClassTriggerTransportClassInvalid;
   switch ((connection_object->transport_class_trigger) &
           kTransportClassTriggerTransportClassMask) {
     case CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_TRANSPORT_CLASS_0:
       transport_class_trigger =
-          kConnectionObjectTransportClassTriggerTransportClass0;
+        kConnectionObjectTransportClassTriggerTransportClass0;
       break;
     case CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_TRANSPORT_CLASS_1:
       transport_class_trigger =
-          kConnectionObjectTransportClassTriggerTransportClass1;
+        kConnectionObjectTransportClassTriggerTransportClass1;
       break;
     case CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_TRANSPORT_CLASS_2:
       transport_class_trigger =
-          kConnectionObjectTransportClassTriggerTransportClass2;
+        kConnectionObjectTransportClassTriggerTransportClass2;
       break;
     case CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_TRANSPORT_CLASS_3:
       transport_class_trigger =
-          kConnectionObjectTransportClassTriggerTransportClass3;
+        kConnectionObjectTransportClassTriggerTransportClass3;
       break;
     default:
       transport_class_trigger =
-          kConnectionObjectTransportClassTriggerTransportClassInvalid;
+        kConnectionObjectTransportClassTriggerTransportClassInvalid;
   }
   return transport_class_trigger;
 }
 
 CipUint ConnectionObjectGetProducedConnectionSize(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return connection_object->produced_connection_size;
 }
 
 void ConnectionObjectSetProducedConnectionSize(
-    CipConnectionObject* const connection_object,
-    const CipUint produced_connection_size) {
+  CipConnectionObject* const connection_object,
+  const CipUint produced_connection_size) {
   connection_object->produced_connection_size = produced_connection_size;
 }
 
 CipUint ConnectionObjectGetConsumedConnectionSize(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return connection_object->consumed_connection_size;
 }
 
 void ConnectionObjectSetConsumedConnectionSize(
-    CipConnectionObject* const connection_object,
-    const CipUint consumed_connection_size) {
+  CipConnectionObject* const connection_object,
+  const CipUint consumed_connection_size) {
   connection_object->consumed_connection_size = consumed_connection_size;
 }
 
 CipUint ConnectionObjectGetExpectedPacketRate(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return connection_object->expected_packet_rate;
 }
 
 CipUint ConnectionObjectGetRequestedPacketInterval(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   CipUdint remainder_to_resolution =
-      (connection_object->t_to_o_requested_packet_interval) %
-      (kOpenerTimerTickInMilliSeconds * 1000UL);
+    (connection_object->t_to_o_requested_packet_interval) %
+    (kOpenerTimerTickInMilliSeconds * 1000UL);
   if (0 == remainder_to_resolution) {
     // Value can be represented in multiples of the timer resolution
     return (CipUint)(connection_object->t_to_o_requested_packet_interval /
                      1000UL);
   } else {
     return (CipUint)(connection_object->t_to_o_requested_packet_interval /
-                         1000UL -
+                       1000UL -
                      remainder_to_resolution / 1000UL);
   }
 }
 
 void ConnectionObjectSetExpectedPacketRate(
-    CipConnectionObject* const connection_object) {
+  CipConnectionObject* const connection_object) {
   CipUdint remainder_to_resolution =
-      (connection_object->t_to_o_requested_packet_interval) %
-      ((CipUdint)kOpenerTimerTickInMilliSeconds * 1000UL);
+    (connection_object->t_to_o_requested_packet_interval) %
+    ((CipUdint)kOpenerTimerTickInMilliSeconds * 1000UL);
   if (0 == remainder_to_resolution) {
     // Value can be represented in multiples of the timer resolution
     connection_object->expected_packet_rate =
-        connection_object->t_to_o_requested_packet_interval / 1000UL;
+      connection_object->t_to_o_requested_packet_interval / 1000UL;
   } else {
     connection_object->expected_packet_rate =
-        connection_object->t_to_o_requested_packet_interval / 1000UL +
-        ((CipUdint)kOpenerTimerTickInMilliSeconds -
-         remainder_to_resolution / 1000UL);
+      connection_object->t_to_o_requested_packet_interval / 1000UL +
+      ((CipUdint)kOpenerTimerTickInMilliSeconds -
+       remainder_to_resolution / 1000UL);
   }
 }
 
 CipUdint ConnectionObjectGetCipProducedConnectionID(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return connection_object->cip_produced_connection_id;
 }
 
 void ConnectionObjectSetCipProducedConnectionID(
-    CipConnectionObject* const connection_object,
-    const CipUdint cip_produced_connection_id) {
+  CipConnectionObject* const connection_object,
+  const CipUdint cip_produced_connection_id) {
   connection_object->cip_produced_connection_id = cip_produced_connection_id;
 }
 
 CipUdint ConnectionObjectGetCipConsumedConnectionID(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return connection_object->cip_consumed_connection_id;
 }
 
 void ConnectionObjectSetCipConsumedConnectionID(
-    CipConnectionObject* const connection_object,
-    const CipUdint cip_consumed_connection_id) {
+  CipConnectionObject* const connection_object,
+  const CipUdint cip_consumed_connection_id) {
   connection_object->cip_consumed_connection_id = cip_consumed_connection_id;
 }
 
 ConnectionObjectWatchdogTimeoutAction ConnectionObjectGetWatchdogTimeoutAction(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   ConnectionObjectWatchdogTimeoutAction timeout_action =
-      kConnectionObjectWatchdogTimeoutActionInvalid;
+    kConnectionObjectWatchdogTimeoutActionInvalid;
   switch (connection_object->watchdog_timeout_action) {
     case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_TRANSITION_TO_TIMED_OUT:
       timeout_action =
-          kConnectionObjectWatchdogTimeoutActionTransitionToTimedOut;
+        kConnectionObjectWatchdogTimeoutActionTransitionToTimedOut;
       break;
     case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_AUTO_DELETE:
       timeout_action = kConnectionObjectWatchdogTimeoutActionAutoDelete;
@@ -503,146 +503,146 @@ ConnectionObjectWatchdogTimeoutAction ConnectionObjectGetWatchdogTimeoutAction(
 }
 
 void ConnectionObjectSetWatchdogTimeoutAction(
-    CipConnectionObject* const connection_object,
-    const CipUsint watchdog_timeout_action) {
+  CipConnectionObject* const connection_object,
+  const CipUsint watchdog_timeout_action) {
   switch (watchdog_timeout_action) {
     case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_TRANSITION_TO_TIMED_OUT:
       connection_object->watchdog_timeout_action =
-          kConnectionObjectWatchdogTimeoutActionTransitionToTimedOut;
+        kConnectionObjectWatchdogTimeoutActionTransitionToTimedOut;
       break;
     case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_AUTO_DELETE:
       connection_object->watchdog_timeout_action =
-          kConnectionObjectWatchdogTimeoutActionAutoDelete;
+        kConnectionObjectWatchdogTimeoutActionAutoDelete;
       break;
     case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_AUTO_RESET:
       connection_object->watchdog_timeout_action =
-          kConnectionObjectWatchdogTimeoutActionAutoReset;
+        kConnectionObjectWatchdogTimeoutActionAutoReset;
       break;
     case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_DEFERRED_DELETE:
       connection_object->watchdog_timeout_action =
-          kConnectionObjectWatchdogTimeoutActionDeferredDelete;
+        kConnectionObjectWatchdogTimeoutActionDeferredDelete;
       break;
     default:
       connection_object->watchdog_timeout_action =
-          kConnectionObjectWatchdogTimeoutActionInvalid;
+        kConnectionObjectWatchdogTimeoutActionInvalid;
       break;
   }
 }
 
 CipUint ConnectionObjectGetProducedConnectionPathLength(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return connection_object->produced_connection_path_length;
 }
 
 void ConnectionObjectSetProducedConnectionPathLength(
-    CipConnectionObject* const connection_object,
-    const CipUint produced_connection_path_length) {
+  CipConnectionObject* const connection_object,
+  const CipUint produced_connection_path_length) {
   connection_object->produced_connection_path_length =
-      produced_connection_path_length;
+    produced_connection_path_length;
 }
 
 CipUint ConnectionObjectGetConsumedConnectionPathLength(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return connection_object->consumed_connection_path_length;
 }
 
 void ConnectionObjectSetConsumedConnectionPathLength(
-    CipConnectionObject* const connection_object,
-    const CipUint consumed_connection_path_length) {
+  CipConnectionObject* const connection_object,
+  const CipUint consumed_connection_path_length) {
   connection_object->consumed_connection_path_length =
-      consumed_connection_path_length;
+    consumed_connection_path_length;
 }
 
 CipUint ConnectionObjectGetProductionInhibitTime(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return connection_object->production_inhibit_time;
 }
 
 void ConnectionObjectSetProductionInhibitTime(
-    CipConnectionObject* const connection_object,
-    const CipUint production_inhibit_time) {
+  CipConnectionObject* const connection_object,
+  const CipUint production_inhibit_time) {
   connection_object->production_inhibit_time = production_inhibit_time;
 }
 
 /*setup the preconsumption timer: max(ConnectionTimeoutMultiplier *
  * ExpectedPacketRate, 10s) */
 void ConnectionObjectSetInitialInactivityWatchdogTimerValue(
-    CipConnectionObject* const connection_object) {
+  CipConnectionObject* const connection_object) {
   const uint64_t kMinimumInitialTimeoutValue = 10000;
   const uint64_t calculated_timeout_value =
-      ConnectionObjectCalculateRegularInactivityWatchdogTimerValue(
-          connection_object);
+    ConnectionObjectCalculateRegularInactivityWatchdogTimerValue(
+      connection_object);
   connection_object->inactivity_watchdog_timer =
-      (calculated_timeout_value > kMinimumInitialTimeoutValue)
-          ? calculated_timeout_value
-          : kMinimumInitialTimeoutValue;
+    (calculated_timeout_value > kMinimumInitialTimeoutValue)
+      ? calculated_timeout_value
+      : kMinimumInitialTimeoutValue;
 }
 
 void ConnectionObjectResetInactivityWatchdogTimerValue(
-    CipConnectionObject* const connection_object) {
+  CipConnectionObject* const connection_object) {
   connection_object->inactivity_watchdog_timer =
-      ConnectionObjectCalculateRegularInactivityWatchdogTimerValue(
-          connection_object);
+    ConnectionObjectCalculateRegularInactivityWatchdogTimerValue(
+      connection_object);
 }
 
 void ConnectionObjectResetLastPackageInactivityTimerValue(
-    CipConnectionObject* const connection_object) {
+  CipConnectionObject* const connection_object) {
   connection_object->last_package_watchdog_timer =
-      ConnectionObjectCalculateRegularInactivityWatchdogTimerValue(
-          connection_object);
+    ConnectionObjectCalculateRegularInactivityWatchdogTimerValue(
+      connection_object);
 }
 
 uint64_t ConnectionObjectCalculateRegularInactivityWatchdogTimerValue(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return (((uint64_t)(connection_object->o_to_t_requested_packet_interval) /
            (uint64_t)1000)
           << (2 + connection_object->connection_timeout_multiplier));
 }
 
 CipUint ConnectionObjectGetConnectionSerialNumber(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return connection_object->connection_serial_number;
 }
 
 void ConnectionObjectSetConnectionSerialNumber(
-    CipConnectionObject* connection_object,
-    const CipUint connection_serial_number) {
+  CipConnectionObject* connection_object,
+  const CipUint connection_serial_number) {
   connection_object->connection_serial_number = connection_serial_number;
 }
 
 CipUint ConnectionObjectGetOriginatorVendorId(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return connection_object->originator_vendor_id;
 }
 
 void ConnectionObjectSetOriginatorVendorId(
-    CipConnectionObject* connection_object, const CipUint vendor_id) {
+  CipConnectionObject* connection_object, const CipUint vendor_id) {
   connection_object->originator_vendor_id = vendor_id;
 }
 
 CipUdint ConnectionObjectGetOriginatorSerialNumber(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return connection_object->originator_serial_number;
 }
 
 void ConnectionObjectSetOriginatorSerialNumber(
-    CipConnectionObject* connection_object, CipUdint originator_serial_number) {
+  CipConnectionObject* connection_object, CipUdint originator_serial_number) {
   connection_object->originator_serial_number = originator_serial_number;
 }
 
 CipUdint ConnectionObjectGetConnectionlNumber(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return connection_object->connection_number;
 }
 
 void ConnectionObjectSetConnectionNumber(
-    CipConnectionObject* connection_object) {
+  CipConnectionObject* connection_object) {
   connection_object->connection_number = GenerateRandomConnectionNumber();
 }
 
 CipUint GenerateRandomConnectionNumber(void) {
   CipUint rand_num =
-      (CipUint)rand();  // TODO(opener): update to random.c functions
+    (CipUint)rand();  // TODO(opener): update to random.c functions
 
   // search for existing connection_numbers
   DoublyLinkedListNode* iterator                = connection_list.first;
@@ -661,53 +661,53 @@ CipUint GenerateRandomConnectionNumber(void) {
 }
 
 CipUsint ConnectionObjectGetConnectionTimeoutMultiplier(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return connection_object->connection_timeout_multiplier;
 }
 
 void ConnectionObjectSetConnectionTimeoutMultiplier(
-    CipConnectionObject* const connection_object,
-    const CipUsint connection_timeout_multiplier) {
+  CipConnectionObject* const connection_object,
+  const CipUsint connection_timeout_multiplier) {
   connection_object->connection_timeout_multiplier =
-      connection_timeout_multiplier;
+    connection_timeout_multiplier;
 }
 
 CipUdint ConnectionObjectGetOToTRequestedPacketInterval(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return connection_object->o_to_t_requested_packet_interval;
 }
 
 void ConnectionObjectSetOToTRequestedPacketInterval(
-    CipConnectionObject* connection_object,
-    const CipUdint requested_packet_interval) {
+  CipConnectionObject* connection_object,
+  const CipUdint requested_packet_interval) {
   connection_object->o_to_t_requested_packet_interval =
-      requested_packet_interval;
+    requested_packet_interval;
 }
 
 CipUdint ConnectionObjectGetTToORequestedPacketInterval(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return connection_object->t_to_o_requested_packet_interval;
 }
 
 void ConnectionObjectSetTToORequestedPacketInterval(
-    CipConnectionObject* connection_object,
-    const CipUdint requested_packet_interval) {
+  CipConnectionObject* connection_object,
+  const CipUdint requested_packet_interval) {
   connection_object->t_to_o_requested_packet_interval =
-      requested_packet_interval;
+    requested_packet_interval;
 }
 
 void ConnectionObjectSetTToONetworkConnectionParameters(
-    CipConnectionObject* connection_object,
-    const CipDword connection_parameters) {
+  CipConnectionObject* connection_object,
+  const CipDword connection_parameters) {
   connection_object->t_to_o_network_connection_parameters =
-      connection_parameters;
+    connection_parameters;
 }
 
 void ConnectionObjectSetOToTNetworkConnectionParameters(
-    CipConnectionObject* connection_object,
-    const CipDword connection_parameters) {
+  CipConnectionObject* connection_object,
+  const CipDword connection_parameters) {
   connection_object->o_to_t_network_connection_parameters =
-      connection_parameters;
+    connection_parameters;
 }
 
 bool ConnectionObjectIsRedundantOwner(const CipDword connection_parameters,
@@ -720,21 +720,21 @@ bool ConnectionObjectIsRedundantOwner(const CipDword connection_parameters,
 }
 
 bool ConnectionObjectIsOToTRedundantOwner(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return ConnectionObjectIsRedundantOwner(
-      connection_object->o_to_t_network_connection_parameters,
-      connection_object->is_large_forward_open);
+    connection_object->o_to_t_network_connection_parameters,
+    connection_object->is_large_forward_open);
 }
 
 bool ConnectionObjectIsTToORedundantOwner(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return ConnectionObjectIsRedundantOwner(
-      connection_object->t_to_o_network_connection_parameters,
-      connection_object->is_large_forward_open);
+    connection_object->t_to_o_network_connection_parameters,
+    connection_object->is_large_forward_open);
 }
 
 ConnectionObjectConnectionType ConnectionObjectGetConnectionType(
-    const CipDword connection_parameters, const CipBool is_lfo) {
+  const CipDword connection_parameters, const CipBool is_lfo) {
   CipUsint connection_type;
   if (is_lfo) {
     connection_type = (connection_parameters & (UINT32_C(3) << 29)) >> 29;
@@ -755,21 +755,21 @@ ConnectionObjectConnectionType ConnectionObjectGetConnectionType(
 }
 
 ConnectionObjectConnectionType ConnectionObjectGetOToTConnectionType(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return ConnectionObjectGetConnectionType(
-      connection_object->o_to_t_network_connection_parameters,
-      connection_object->is_large_forward_open);
+    connection_object->o_to_t_network_connection_parameters,
+    connection_object->is_large_forward_open);
 }
 
 ConnectionObjectConnectionType ConnectionObjectGetTToOConnectionType(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return ConnectionObjectGetConnectionType(
-      connection_object->t_to_o_network_connection_parameters,
-      connection_object->is_large_forward_open);
+    connection_object->t_to_o_network_connection_parameters,
+    connection_object->is_large_forward_open);
 }
 
 ConnectionObjectPriority ConnectionObjectGetPriority(
-    const CipDword connection_parameters, const CipBool is_lfo) {
+  const CipDword connection_parameters, const CipBool is_lfo) {
   CipUsint priority;
   if (is_lfo) {
     priority = (connection_parameters & (UINT32_C(3) << 26)) >> 26;
@@ -800,21 +800,21 @@ ConnectionObjectPriority ConnectionObjectGetPriority(
 }
 
 ConnectionObjectPriority ConnectionObjectGetOToTPriority(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return ConnectionObjectGetPriority(
-      connection_object->o_to_t_network_connection_parameters,
-      connection_object->is_large_forward_open);
+    connection_object->o_to_t_network_connection_parameters,
+    connection_object->is_large_forward_open);
 }
 
 ConnectionObjectPriority ConnectionObjectGetTToOPriority(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return ConnectionObjectGetPriority(
-      connection_object->t_to_o_network_connection_parameters,
-      connection_object->is_large_forward_open);
+    connection_object->t_to_o_network_connection_parameters,
+    connection_object->is_large_forward_open);
 }
 
 ConnectionObjectConnectionSizeType ConnectionObjectGetConnectionSizeType(
-    const CipDword connection_parameters, const CipBool is_lfo) {
+  const CipDword connection_parameters, const CipBool is_lfo) {
   bool connection_size_type;
   if (is_lfo) {
     connection_size_type = (connection_parameters & (UINT32_C(1) << 25));
@@ -830,17 +830,17 @@ ConnectionObjectConnectionSizeType ConnectionObjectGetConnectionSizeType(
 }
 
 ConnectionObjectConnectionSizeType ConnectionObjectGetOToTConnectionSizeType(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return ConnectionObjectGetConnectionSizeType(
-      connection_object->o_to_t_network_connection_parameters,
-      connection_object->is_large_forward_open);
+    connection_object->o_to_t_network_connection_parameters,
+    connection_object->is_large_forward_open);
 }
 
 ConnectionObjectConnectionSizeType ConnectionObjectGetTToOConnectionSizeType(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return ConnectionObjectGetConnectionSizeType(
-      connection_object->t_to_o_network_connection_parameters,
-      connection_object->is_large_forward_open);
+    connection_object->t_to_o_network_connection_parameters,
+    connection_object->is_large_forward_open);
 }
 
 size_t ConnectionObjectGetConnectionSize(const CipDword connection_parameters,
@@ -857,27 +857,27 @@ size_t ConnectionObjectGetConnectionSize(const CipDword connection_parameters,
 }
 
 size_t ConnectionObjectGetOToTConnectionSize(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return ConnectionObjectGetConnectionSize(
-      connection_object->o_to_t_network_connection_parameters,
-      connection_object->is_large_forward_open);
+    connection_object->o_to_t_network_connection_parameters,
+    connection_object->is_large_forward_open);
 }
 
 size_t ConnectionObjectGetTToOConnectionSize(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   return ConnectionObjectGetConnectionSize(
-      connection_object->t_to_o_network_connection_parameters,
-      connection_object->is_large_forward_open);
+    connection_object->t_to_o_network_connection_parameters,
+    connection_object->is_large_forward_open);
 }
 
 void ConnectionObjectDeepCopy(
-    CipConnectionObject* RESTRICT destination,
-    const CipConnectionObject* RESTRICT const source) {
+  CipConnectionObject* RESTRICT destination,
+  const CipConnectionObject* RESTRICT const source) {
   memcpy(destination, source, sizeof(CipConnectionObject));
 }
 
 void ConnectionObjectResetSequenceCounts(
-    CipConnectionObject* const connection_object) {
+  CipConnectionObject* const connection_object) {
   connection_object->eip_level_sequence_count_producing      = 0;
   connection_object->sequence_count_producing                = 0;
   connection_object->eip_level_sequence_count_consuming      = 0;
@@ -886,13 +886,13 @@ void ConnectionObjectResetSequenceCounts(
 }
 
 void ConnectionObjectResetProductionInhibitTimer(
-    CipConnectionObject* const connection_object) {
+  CipConnectionObject* const connection_object) {
   connection_object->production_inhibit_timer =
-      connection_object->production_inhibit_time;
+    connection_object->production_inhibit_time;
 }
 
 void ConnectionObjectGeneralConfiguration(
-    CipConnectionObject* const connection_object) {
+  CipConnectionObject* const connection_object) {
   connection_object->socket[0] = kEipInvalidSocket;
   connection_object->socket[1] = kEipInvalidSocket;
 
@@ -917,7 +917,7 @@ void ConnectionObjectGeneralConfiguration(
   ConnectionObjectResetSequenceCounts(connection_object);
 
   ConnectionObjectSetWatchdogTimeoutAction(
-      connection_object, kConnectionObjectWatchdogTimeoutActionInvalid);
+    connection_object, kConnectionObjectWatchdogTimeoutActionInvalid);
   // Correct value not known at this point
 
   ConnectionObjectResetProductionInhibitTimer(connection_object);
@@ -948,8 +948,8 @@ bool EqualConnectionTriad(const CipConnectionObject* const object1,
 }
 
 bool CipConnectionObjectOriginatorHasSameIP(
-    const CipConnectionObject* const connection_object,
-    const struct sockaddr* const originator_address) {
+  const CipConnectionObject* const connection_object,
+  const struct sockaddr* const originator_address) {
   return ((struct sockaddr_in*)originator_address)->sin_addr.s_addr ==
          connection_object->originator_address.sin_addr.s_addr;
 }

+ 83 - 85
source/src/cip/cipconnectionobject.h

@@ -34,9 +34,9 @@ typedef enum {
 
 typedef enum {
   kConnectionObjectInstanceTypeInvalid =
-      (CipUsint)(~0),  ///< Invalid instance type - shall never occur!
+    (CipUsint)(~0),  ///< Invalid instance type - shall never occur!
   kConnectionObjectInstanceTypeExplicitMessaging =
-      0,  ///< Connection is an explicit messaging connection
+    0,  ///< Connection is an explicit messaging connection
   kConnectionObjectInstanceTypeIO,  ///< Connection is an I/O connection
   kConnectionObjectInstanceTypeIOExclusiveOwner,  ///< Also I/O connection, only
                                                   ///< for easy differentiation
@@ -127,8 +127,8 @@ typedef enum {
 typedef struct cip_connection_object CipConnectionObject;
 
 typedef EipStatus (*CipConnectionStateHandler)(
-    CipConnectionObject* RESTRICT const connection_object,
-    ConnectionObjectState new_state);
+  CipConnectionObject* RESTRICT const connection_object,
+  ConnectionObjectState new_state);
 
 struct cip_connection_object {
   CipUsint state;                   ///< Attribute 1
@@ -136,11 +136,11 @@ struct cip_connection_object {
   CipByte transport_class_trigger;  ///< Attribute 3
   /* Attribute 4-6 only for device net*/
   CipUint
-      produced_connection_size;  ///< Attribute 7 - Limits produced connection
-                                 ///< size - for explicit messaging 0xFFFF
-                                 ///< means no predefined limit
+    produced_connection_size;  ///< Attribute 7 - Limits produced connection
+                               ///< size - for explicit messaging 0xFFFF
+                               ///< means no predefined limit
   CipUint
-      consumed_connection_size;  ///< Attribute 8 - Limits produced connection
+    consumed_connection_size;    ///< Attribute 8 - Limits produced connection
                                  ///< ///< size - for explicit messaging 0xFFFF
                                  ///< ///< means no predefined limit
   CipUint expected_packet_rate;  ///< Attribute 9 - Resolution in Milliseconds
@@ -160,7 +160,7 @@ struct cip_connection_object {
   /* End of CIP attributes */
   /* Start of needed non-object variables */
   CipElectronicKey
-      electronic_key;  // TODO(MartinMelikMerkumians): Check if really needed
+    electronic_key;  // TODO(MartinMelikMerkumians): Check if really needed
 
   CipConnectionPathEpath configuration_path;
 
@@ -244,58 +244,58 @@ CipConnectionObject* CipConnectionObjectCreate(const CipOctet* message);
 void CipConnectionObjectDelete(CipConnectionObject** connection_object);
 
 void ConnectionObjectInitializeEmpty(
-    CipConnectionObject* const connection_object);
+  CipConnectionObject* const connection_object);
 
 void ConnectionObjectInitializeFromMessage(
-    const CipOctet** message, CipConnectionObject* const connection_object);
+  const CipOctet** message, CipConnectionObject* const connection_object);
 
 ConnectionObjectState ConnectionObjectGetState(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void ConnectionObjectSetState(CipConnectionObject* const connection_object,
                               const ConnectionObjectState state);
 
 ConnectionObjectInstanceType ConnectionObjectGetInstanceType(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void ConnectionObjectSetInstanceType(
-    CipConnectionObject* const connection_object,
-    const ConnectionObjectInstanceType instance_type);
+  CipConnectionObject* const connection_object,
+  const ConnectionObjectInstanceType instance_type);
 
 CipUsint ConnectionObjectGetInstanceTypeForAttribute(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 ConnectionObjectTransportClassTriggerDirection
 ConnectionObjectGetTransportClassTriggerDirection(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 ConnectionObjectTransportClassTriggerProductionTrigger
 ConnectionObjectGetTransportClassTriggerProductionTrigger(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 ConnectionObjectTransportClassTriggerTransportClass
 ConnectionObjectGetTransportClassTriggerTransportClass(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 CipUint ConnectionObjectGetProducedConnectionSize(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void ConnectionObjectSetProducedConnectionSize(
-    CipConnectionObject* const connection_object,
-    const CipUint produced_connection_size);
+  CipConnectionObject* const connection_object,
+  const CipUint produced_connection_size);
 
 CipUint ConnectionObjectGetConsumedConnectionSize(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void ConnectionObjectSetConsumedConnectionSize(
-    CipConnectionObject* const connection_object,
-    const CipUint consumed_connection_size);
+  CipConnectionObject* const connection_object,
+  const CipUint consumed_connection_size);
 
 CipUint ConnectionObjectGetExpectedPacketRate(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 CipUint ConnectionObjectGetRequestedPacketInterval(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 /**
  * @brief Sets the expected packet rate according to the rules of the CIP
@@ -309,7 +309,7 @@ CipUint ConnectionObjectGetRequestedPacketInterval(
  * rate is set
  */
 void ConnectionObjectSetExpectedPacketRate(
-    CipConnectionObject* const connection_object);
+  CipConnectionObject* const connection_object);
 
 /** @brief Gets the CIP Produced Connection ID
  *
@@ -319,7 +319,7 @@ void ConnectionObjectSetExpectedPacketRate(
  * @return The CIP Produced Connection ID
  */
 CipUdint ConnectionObjectGetCipProducedConnectionID(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 /** @brief Sets the CIP Produced Connection ID
  *
@@ -329,8 +329,8 @@ CipUdint ConnectionObjectGetCipProducedConnectionID(
  * @param cip_produced_connection_id The CIP Produced Connection ID to set
  */
 void ConnectionObjectSetCipProducedConnectionID(
-    CipConnectionObject* const connection_object,
-    const CipUdint cip_produced_connection_id);
+  CipConnectionObject* const connection_object,
+  const CipUdint cip_produced_connection_id);
 
 /** @brief Get the CIP Consumed Connection ID
  *
@@ -340,7 +340,7 @@ void ConnectionObjectSetCipProducedConnectionID(
  * @return The CIP Consumed Connection ID
  */
 CipUdint ConnectionObjectGetCipConsumedConnectionID(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 /** @brief Sets the CIP Consumed Connection ID
  *
@@ -350,129 +350,127 @@ CipUdint ConnectionObjectGetCipConsumedConnectionID(
  * @param cip_consumed_connection_id The CIP Consumed Connection ID to set
  */
 void ConnectionObjectSetCipConsumedConnectionID(
-    CipConnectionObject* const connection_object,
-    const CipUdint cip_consumed_connection_id);
+  CipConnectionObject* const connection_object,
+  const CipUdint cip_consumed_connection_id);
 
 ConnectionObjectWatchdogTimeoutAction ConnectionObjectGetWatchdogTimeoutAction(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void ConnectionObjectSetWatchdogTimeoutAction(
-    CipConnectionObject* const connection_object,
-    const CipUsint watchdog_timeout_action);
+  CipConnectionObject* const connection_object,
+  const CipUsint watchdog_timeout_action);
 
 CipUint ConnectionObjectGetProducedConnectionPathLength(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void ConnectionObjectSetProducedConnectionPathLength(
-    CipConnectionObject* const connection_object,
-    const CipUint produced_connection_path_length);
+  CipConnectionObject* const connection_object,
+  const CipUint produced_connection_path_length);
 
 CipUint ConnectionObjectGetConsumedConnectionPathLength(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void ConnectionObjectSetConsumedConnectionPathLength(
-    CipConnectionObject* const connection_object,
-    const CipUint consumed_connection_path_length);
+  CipConnectionObject* const connection_object,
+  const CipUint consumed_connection_path_length);
 
 CipUint ConnectionObjectGetProductionInhibitTime(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void ConnectionObjectSetProductionInhibitTime(
-    CipConnectionObject* const connection_object,
-    const CipUint production_inhibit_time);
+  CipConnectionObject* const connection_object,
+  const CipUint production_inhibit_time);
 
 CipUsint ConnectionObjectGetConnectionTimeoutMultiplier(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void ConnectionObjectSetConnectionTimeoutMultiplier(
-    CipConnectionObject* const connection_object,
-    const CipUsint connection_timeout_multiplier);
+  CipConnectionObject* const connection_object,
+  const CipUsint connection_timeout_multiplier);
 
 void ConnectionObjectResetInactivityWatchdogTimerValue(
-    CipConnectionObject* const connection_object);
+  CipConnectionObject* const connection_object);
 
 void ConnectionObjectResetLastPackageInactivityTimerValue(
-    CipConnectionObject* const connection_object);
+  CipConnectionObject* const connection_object);
 
 CipUint ConnectionObjectGetConnectionSerialNumber(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void ConnectionObjectSetConnectionSerialNumber(
-    CipConnectionObject* connection_object,
-    const CipUint connection_serial_number);
+  CipConnectionObject* connection_object,
+  const CipUint connection_serial_number);
 
 CipUint ConnectionObjectGetOriginatorVendorId(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void ConnectionObjectSetOriginatorVendorId(
-    CipConnectionObject* connection_object, const CipUint vendor_id);
+  CipConnectionObject* connection_object, const CipUint vendor_id);
 
 CipUdint ConnectionObjectGetOriginatorSerialNumber(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void ConnectionObjectSetOriginatorSerialNumber(
-    CipConnectionObject* connection_object, CipUdint originator_serial_number);
+  CipConnectionObject* connection_object, CipUdint originator_serial_number);
 
 void ConnectionObjectGetConnectionNumber(CipConnectionObject* connection_object,
                                          const CipUint connection_number);
 
 void ConnectionObjectSetConnectionNumber(
-    CipConnectionObject* connection_object);
+  CipConnectionObject* connection_object);
 
 CipUint GenerateRandomConnectionNumber(void);
 
 CipUdint ConnectionObjectGetOToTRequestedPacketInterval(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void ConnectionObjectSetOToTRequestedPacketInterval(
-    CipConnectionObject* connection_object,
-    const CipUdint requested_packet_interval);
+  CipConnectionObject* connection_object,
+  const CipUdint requested_packet_interval);
 
 bool ConnectionObjectIsOToTRedundantOwner(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 ConnectionObjectConnectionType ConnectionObjectGetOToTConnectionType(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 ConnectionObjectPriority ConnectionObjectGetOToTPriority(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 ConnectionObjectConnectionSizeType ConnectionObjectGetOToTConnectionSizeType(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 size_t ConnectionObjectGetOToTConnectionSize(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 /* T to O */
 CipUdint ConnectionObjectGetTToORequestedPacketInterval(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void ConnectionObjectSetTToORequestedPacketInterval(
-    CipConnectionObject* connection_object,
-    const CipUdint requested_packet_interval);
+  CipConnectionObject* connection_object,
+  const CipUdint requested_packet_interval);
 
 void ConnectionObjectSetTToONetworkConnectionParameters(
-    CipConnectionObject* connection_object,
-    const CipDword connection_parameters);
+  CipConnectionObject* connection_object, const CipDword connection_parameters);
 
 void ConnectionObjectSetOToTNetworkConnectionParameters(
-    CipConnectionObject* connection_object,
-    const CipDword connection_parameters);
+  CipConnectionObject* connection_object, const CipDword connection_parameters);
 
 bool ConnectionObjectIsTToORedundantOwner(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 ConnectionObjectConnectionType ConnectionObjectGetTToOConnectionType(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 ConnectionObjectPriority ConnectionObjectGetTToOPriority(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 ConnectionObjectConnectionSizeType ConnectionObjectGetTToOConnectionSizeType(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 size_t ConnectionObjectGetTToOConnectionSize(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 /** @brief Copy the given connection data from source to destination
  *
@@ -483,7 +481,7 @@ void ConnectionObjectDeepCopy(CipConnectionObject* RESTRICT destination,
                               const CipConnectionObject* RESTRICT const source);
 
 void ConnectionObjectResetProductionInhibitTimer(
-    CipConnectionObject* const connection_object);
+  CipConnectionObject* const connection_object);
 
 /** @brief Generate the ConnectionIDs and set the general configuration
  * parameter in the given connection object.
@@ -492,13 +490,13 @@ void ConnectionObjectResetProductionInhibitTimer(
  * up.
  */
 void ConnectionObjectGeneralConfiguration(
-    CipConnectionObject* const connection_object);
+  CipConnectionObject* const connection_object);
 
 bool ConnectionObjectIsTypeNonLOIOConnection(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 bool ConnectionObjectIsTypeIOConnection(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 bool ConnectionObjectEqualOriginator(const CipConnectionObject* const object1,
                                      const CipConnectionObject* const object2);
@@ -507,7 +505,7 @@ bool EqualConnectionTriad(const CipConnectionObject* const object1,
                           const CipConnectionObject* const object2);
 
 bool CipConnectionObjectOriginatorHasSameIP(
-    const CipConnectionObject* const connection_object,
-    const struct sockaddr* const originator_address);
+  const CipConnectionObject* const connection_object,
+  const struct sockaddr* const originator_address);
 
 #endif  // CIP_CIPCONNECTIONOBJECT_H_

+ 12 - 12
source/src/cip/cipdlr.c

@@ -74,15 +74,15 @@ static const CipUsint s_0x00_default       = 0x00U;
 static const CipUint s_0x0000_default      = 0x0000U;
 static const CipUdint s_0x00000000_default = 0x00000000U;
 
-static const CipNodeAddress s_zero_node = {.device_ip  = 0,
-                                           .device_mac = {
-                                               0,
-                                               0,
-                                               0,
-                                               0,
-                                               0,
-                                               0,
-                                           }};
+static const CipNodeAddress s_zero_node = { .device_ip  = 0,
+                                            .device_mac = {
+                                              0,
+                                              0,
+                                              0,
+                                              0,
+                                              0,
+                                              0,
+                                            } };
 
 /* ********************************************************************
  * global public variables
@@ -99,7 +99,7 @@ static void EncodeCipRingSupervisorConfig(const void* const data,
 
   const size_t kRingSupStructSize = 12u;
   FillNextNMessageOctetsWithValueAndMoveToNextPosition(
-      0, kRingSupStructSize, outgoing_message);
+    0, kRingSupStructSize, outgoing_message);
 }
 
 static void EncodeCipNodeAddress(const void* const data,
@@ -134,9 +134,9 @@ EipStatus CipDlrInit(void) {
 
   /* Add services to the class */
   InsertService(
-      dlr_class, kGetAttributeSingle, GetAttributeSingle, "GetAttributeSingle");
+    dlr_class, kGetAttributeSingle, GetAttributeSingle, "GetAttributeSingle");
   InsertService(
-      dlr_class, kGetAttributeAll, GetAttributeAll, "GetAttributeAll");
+    dlr_class, kGetAttributeAll, GetAttributeAll, "GetAttributeAll");
 
   /* Bind attributes to the instance */
   CipInstance* dlr_instance = GetCipInstance(dlr_class, 1u);

+ 12 - 12
source/src/cip/cipelectronickey.c

@@ -14,7 +14,7 @@ void ElectronicKeySetKeyFormat(CipElectronicKey* const electronic_key,
 }
 
 CipUint ElectronicKeyGetKeyFormat(
-    const CipElectronicKey* const electronic_key) {
+  const CipElectronicKey* const electronic_key) {
   return electronic_key->key_format;
 }
 
@@ -52,44 +52,44 @@ void ElectronicKeyFormat4SetVendorId(ElectronicKeyFormat4* const electronic_key,
 }
 
 CipUint ElectronicKeyFormat4GetVendorId(
-    const ElectronicKeyFormat4* const electronic_key) {
+  const ElectronicKeyFormat4* const electronic_key) {
   return electronic_key->vendor_id;
 }
 
 void ElectronicKeyFormat4SetDeviceType(
-    ElectronicKeyFormat4* const electronic_key, const CipUint device_type) {
+  ElectronicKeyFormat4* const electronic_key, const CipUint device_type) {
   electronic_key->device_type = device_type;
 }
 
 CipUint ElectronicKeyFormat4GetDeviceType(
-    const ElectronicKeyFormat4* const electronic_key) {
+  const ElectronicKeyFormat4* const electronic_key) {
   return electronic_key->device_type;
 }
 
 void ElectronicKeyFormat4SetProductCode(
-    ElectronicKeyFormat4* const electronic_key, const CipUint product_code) {
+  ElectronicKeyFormat4* const electronic_key, const CipUint product_code) {
   electronic_key->product_code = product_code;
 }
 
 CipUint ElectronicKeyFormat4GetProductCode(
-    const ElectronicKeyFormat4* const electronic_key) {
+  const ElectronicKeyFormat4* const electronic_key) {
   return electronic_key->product_code;
 }
 
 void ElectronicKeyFormat4SetMajorRevisionCompatibility(
-    ElectronicKeyFormat4* const electronic_key,
-    const CipByte major_revision_compatibility) {
+  ElectronicKeyFormat4* const electronic_key,
+  const CipByte major_revision_compatibility) {
   electronic_key->major_revision_compatibility = major_revision_compatibility;
 }
 
 CipByte ElectronicKeyFormat4GetMajorRevision(
-    const ElectronicKeyFormat4* const electronic_key) {
+  const ElectronicKeyFormat4* const electronic_key) {
   const CipByte kMajorRevisionMask = 0x7F;
   return (electronic_key->major_revision_compatibility & kMajorRevisionMask);
 }
 
 bool ElectronicKeyFormat4GetMajorRevisionCompatibility(
-    const ElectronicKeyFormat4* const electronic_key) {
+  const ElectronicKeyFormat4* const electronic_key) {
   const CipByte kCompatibilityMask = 0x80;
   if (kCompatibilityMask ==
       (electronic_key->major_revision_compatibility & kCompatibilityMask)) {
@@ -99,11 +99,11 @@ bool ElectronicKeyFormat4GetMajorRevisionCompatibility(
 }
 
 void ElectronicKeyFormat4SetMinorRevision(
-    ElectronicKeyFormat4* const electronic_key, const CipUsint minor_revision) {
+  ElectronicKeyFormat4* const electronic_key, const CipUsint minor_revision) {
   electronic_key->minor_revision = minor_revision;
 }
 
 CipUsint ElectronicKeyFormat4GetMinorRevision(
-    const ElectronicKeyFormat4* const electronic_key) {
+  const ElectronicKeyFormat4* const electronic_key) {
   return electronic_key->minor_revision;
 }

+ 12 - 12
source/src/cip/cipelectronickey.h

@@ -25,7 +25,7 @@ void ElectronicKeySetSegmentType(CipElectronicKey* const electronic_key,
                                  const CipUsint segment_type);
 
 CipUsint ElectronicKeyGetSegmentType(
-    const CipElectronicKey* const electronic_key);
+  const CipElectronicKey* const electronic_key);
 
 void ElectronicKeySetKeyFormat(CipElectronicKey* const electronic_key,
                                const CipUsint key_format);
@@ -72,7 +72,7 @@ void ElectronicKeyFormat4SetVendorId(ElectronicKeyFormat4* const electronic_key,
  *      @return The vendor ID
  */
 CipUint ElectronicKeyFormat4GetVendorId(
-    const ElectronicKeyFormat4* const electronic_key);
+  const ElectronicKeyFormat4* const electronic_key);
 
 /** @brief Sets the device type in the electronic key
  *
@@ -81,7 +81,7 @@ CipUint ElectronicKeyFormat4GetVendorId(
  *electronic key
  */
 void ElectronicKeyFormat4SetDeviceType(
-    ElectronicKeyFormat4* const electronic_key, const CipUint device_type);
+  ElectronicKeyFormat4* const electronic_key, const CipUint device_type);
 
 /** @brief Gets the device type from a format 4 electronic key
  *
@@ -90,7 +90,7 @@ void ElectronicKeyFormat4SetDeviceType(
  *      @return The device type
  */
 CipUint ElectronicKeyFormat4GetDeviceType(
-    const ElectronicKeyFormat4* const electronic_key);
+  const ElectronicKeyFormat4* const electronic_key);
 
 /** @brief Set product code in the electronic key
  *
@@ -98,7 +98,7 @@ CipUint ElectronicKeyFormat4GetDeviceType(
  *      @param product_code The product code to be inserted
  */
 void ElectronicKeyFormat4SetProductCode(
-    ElectronicKeyFormat4* const electronic_key, const CipUint product_code);
+  ElectronicKeyFormat4* const electronic_key, const CipUint product_code);
 
 /** @brief Gets the product code from an format 4 electronic key
  *
@@ -106,7 +106,7 @@ void ElectronicKeyFormat4SetProductCode(
  *      @return The product code
  */
 CipUint ElectronicKeyFormat4GetProductCode(
-    const ElectronicKeyFormat4* const electronic_key);
+  const ElectronicKeyFormat4* const electronic_key);
 
 /** @brief Sets the major revision byte including the compatibility flag
  *
@@ -115,8 +115,8 @@ CipUint ElectronicKeyFormat4GetProductCode(
  *      @param electronic_key The electronic key to be modified
  */
 void ElectronicKeyFormat4SetMajorRevisionCompatibility(
-    ElectronicKeyFormat4* const electronic_key,
-    const CipByte major_revision_compatibility);
+  ElectronicKeyFormat4* const electronic_key,
+  const CipByte major_revision_compatibility);
 
 /** @brief Gets the major revision from an format 4 electronic key
  *
@@ -124,7 +124,7 @@ void ElectronicKeyFormat4SetMajorRevisionCompatibility(
  *      @return The device's major revision
  */
 CipByte ElectronicKeyFormat4GetMajorRevision(
-    const ElectronicKeyFormat4* const electronic_key);
+  const ElectronicKeyFormat4* const electronic_key);
 
 /** @brief Gets the Compatibility flag from the format 4 electronic key
  *
@@ -132,7 +132,7 @@ CipByte ElectronicKeyFormat4GetMajorRevision(
  *      @return True if compatibility bit is set, false if otherwise
  */
 bool ElectronicKeyFormat4GetMajorRevisionCompatibility(
-    const ElectronicKeyFormat4* const electronic_key);
+  const ElectronicKeyFormat4* const electronic_key);
 
 /** @brief Sets the devices minor revision in an format 4 electronic key
  *
@@ -140,7 +140,7 @@ bool ElectronicKeyFormat4GetMajorRevisionCompatibility(
  *      @param electronic_key The electronic key to be modified
  */
 void ElectronicKeyFormat4SetMinorRevision(
-    ElectronicKeyFormat4* const electronic_key, const CipUsint minor_revision);
+  ElectronicKeyFormat4* const electronic_key, const CipUsint minor_revision);
 
 /** @brief Gets the minor revision from an format 4 electronic key
  *
@@ -148,6 +148,6 @@ void ElectronicKeyFormat4SetMinorRevision(
  *      @return The device's minor revision
  */
 CipUsint ElectronicKeyFormat4GetMinorRevision(
-    const ElectronicKeyFormat4* const electronic_key);
+  const ElectronicKeyFormat4* const electronic_key);
 
 #endif  // CIP_CIPELECTRONICKEY_H_

+ 43 - 43
source/src/cip/cipepath.c

@@ -50,7 +50,7 @@ SegmentType GetPathSegmentType(const CipOctet* const cip_path) {
       break;
     default:
       OPENER_TRACE_ERR(
-          "Invalid Segment type in the message! We should never come here!\n");
+        "Invalid Segment type in the message! We should never come here!\n");
       break;
   }
   return result;
@@ -85,7 +85,7 @@ void SetPathSegmentType(SegmentType segment_type,
       break;
     default:
       OPENER_TRACE_ERR(
-          "Invalid Segment type chosen! We should never come here!\n");
+        "Invalid Segment type chosen! We should never come here!\n");
       OPENER_ASSERT(false);
       break;
   }
@@ -93,7 +93,7 @@ void SetPathSegmentType(SegmentType segment_type,
 
 /*** Port Segment ***/
 bool GetPathPortSegmentExtendedLinkAddressSizeBit(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   const unsigned int kExtendedLinkAddressSizeMask = 0x10;
   if (kExtendedLinkAddressSizeMask ==
       (*cip_path & kExtendedLinkAddressSizeMask)) {
@@ -103,7 +103,7 @@ bool GetPathPortSegmentExtendedLinkAddressSizeBit(
 }
 
 unsigned int GetPathPortSegmentPortIdentifier(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   const unsigned int kPortIdentifierMask = 0x0F;
   unsigned int port_identifier           = *cip_path & kPortIdentifierMask;
 
@@ -123,7 +123,7 @@ void SetPathPortSegmentPortIdentifier(const unsigned int port_identifier,
 }
 
 unsigned int GetPathPortSegmentLinkAddressSize(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   /*  OPENER_ASSERT(false ==
      GetPathPortSegmentExtendedLinkAddressSizeBit(cip_path), "Call to non
      existent extended link address size\n"); */
@@ -132,34 +132,34 @@ unsigned int GetPathPortSegmentLinkAddressSize(
 }
 
 unsigned int GetPathPortSegmentExtendedPortNumber(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   /*  OPENER_ASSERT(kPortSegmentExtendedPort ==
      GetPathPortSegmentPortIdentifier(cip_path), "There is no extended port
      available!\n");*/
   OPENER_ASSERT(kPortSegmentExtendedPort ==
                 GetPathPortSegmentPortIdentifier(cip_path));
   const unsigned int kExtendedPortSegmentPosition =
-      GetPathPortSegmentExtendedLinkAddressSizeBit(cip_path) == true ? 2 : 1;
+    GetPathPortSegmentExtendedLinkAddressSizeBit(cip_path) == true ? 2 : 1;
   return cip_path[kExtendedPortSegmentPosition] +
          (cip_path[kExtendedPortSegmentPosition + 1] << 8);
 }
 
 void SetPathPortSegmentExtendedPortIdentifier(
-    const unsigned int extended_port_identifier, CipOctet* const cip_path) {
+  const unsigned int extended_port_identifier, CipOctet* const cip_path) {
   SetPathPortSegmentPortIdentifier(kPortSegmentExtendedPort, cip_path);
   const unsigned int kExtendedPortSegmentPosition =
-      GetPathPortSegmentExtendedLinkAddressSizeBit(cip_path) == true ? 2 : 1;
+    GetPathPortSegmentExtendedLinkAddressSizeBit(cip_path) == true ? 2 : 1;
   cip_path[kExtendedPortSegmentPosition] =
-      (char)(extended_port_identifier & 0x00FF);
+    (char)(extended_port_identifier & 0x00FF);
   cip_path[kExtendedPortSegmentPosition + 1] =
-      (char)((extended_port_identifier & 0xFF00) >> 8);
+    (char)((extended_port_identifier & 0xFF00) >> 8);
 }
 /*** Port Segment ***/
 
 /*** Logical Segment ***/
 
 LogicalSegmentLogicalType GetPathLogicalSegmentLogicalType(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   OPENER_ASSERT(kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path));
   const unsigned int kLogicalTypeMask = 0x1C;
   const unsigned int logical_type     = (*cip_path) & kLogicalTypeMask;
@@ -226,15 +226,15 @@ void SetPathLogicalSegmentLogicalType(LogicalSegmentLogicalType logical_type,
       break;
     default:
       OPENER_TRACE_ERR(
-          "Logical segment/logical type: It is not possible to reach this "
-          "point!\n");
+        "Logical segment/logical type: It is not possible to reach this "
+        "point!\n");
       OPENER_ASSERT(false);
       break;
   }
 }
 
 LogicalSegmentLogicalFormat GetPathLogicalSegmentLogicalFormat(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   OPENER_ASSERT(kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path));
   const unsigned int kLogicalFormatMask = 0x03;
   const unsigned int logical_format     = (*cip_path) & kLogicalFormatMask;
@@ -251,7 +251,7 @@ LogicalSegmentLogicalFormat GetPathLogicalSegmentLogicalFormat(
       break;
     default:
       OPENER_TRACE_ERR(
-          "Logical segment/logical type: Invalid logical type detected!\n");
+        "Logical segment/logical type: Invalid logical type detected!\n");
       break;
   }
   return result;
@@ -273,7 +273,7 @@ void SetPathLogicalSegmentLogicalFormat(LogicalSegmentLogicalFormat format,
       break;
     default:
       OPENER_TRACE_ERR(
-          "Logical segment/logical type: Invalid logical type detected!\n");
+        "Logical segment/logical type: Invalid logical type detected!\n");
       OPENER_ASSERT(false);
       break;
   }
@@ -281,7 +281,7 @@ void SetPathLogicalSegmentLogicalFormat(LogicalSegmentLogicalFormat format,
 
 CipDword CipEpathGetLogicalValue(const EipUint8** message) {
   LogicalSegmentLogicalFormat logical_format =
-      GetPathLogicalSegmentLogicalFormat(*message);
+    GetPathLogicalSegmentLogicalFormat(*message);
   CipDword data = kLogicalSegmentLogicalFormatInvalid;
   (*message) += 1; /* Move to logical value */
   switch (logical_format) {
@@ -298,7 +298,7 @@ CipDword CipEpathGetLogicalValue(const EipUint8** message) {
       break;
     default:
       OPENER_TRACE_ERR(
-          "Logical segment/logical type: Invalid logical value detected!\n");
+        "Logical segment/logical type: Invalid logical value detected!\n");
       break;
   }
   return data;
@@ -310,15 +310,15 @@ void CipEpathSetLogicalValue(const CipDword logical_value,
   switch (logical_format) {
     case kLogicalSegmentLogicalFormatEightBit:
       OPENER_ASSERT(
-          (logical_value <=
-           UINT8_MAX)); /* Sanity check before casting to a smaller integer. */
+        (logical_value <=
+         UINT8_MAX)); /* Sanity check before casting to a smaller integer. */
       AddSintToMessage((EipUint8)logical_value, &message->message);
       break;
     case kLogicalSegmentLogicalFormatSixteenBit:
       MoveMessageNOctets(1, &message->message); /* Needed for padding */
       OPENER_ASSERT(
-          (logical_value <=
-           UINT16_MAX)); /* Sanity check before casting to a smaller integer. */
+        (logical_value <=
+         UINT16_MAX)); /* Sanity check before casting to a smaller integer. */
       AddIntToMessage((EipUint16)logical_value, &message->message);
       break;
     case kLogicalSegmentLogicalFormatThirtyTwoBit:
@@ -332,7 +332,7 @@ void CipEpathSetLogicalValue(const CipDword logical_value,
 }
 
 LogicalSegmentExtendedLogicalType GetPathLogicalSegmentExtendedLogicalType(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   /*  OPENER_ASSERT(LOGICAL_SEGMENT_TYPE_EXTENDED_kLogicalSegmentLogicalTypeExtendedLogicalMessageValue
      == GetPathLogicalSegmentLogicalType(cip_path), "Trying to extract
      non-existent extended logical type") */
@@ -340,7 +340,7 @@ LogicalSegmentExtendedLogicalType GetPathLogicalSegmentExtendedLogicalType(
                 GetPathLogicalSegmentLogicalType(cip_path));
   const unsigned int extended_logical_type = *(cip_path + 1);
   LogicalSegmentExtendedLogicalType result =
-      kLogicalSegmentExtendedLogicalTypeInvalid;
+    kLogicalSegmentExtendedLogicalTypeInvalid;
   switch (extended_logical_type) {
     case LOGICAL_SEGMENT_EXTENDED_TYPE_ARRAY_INDEX:
       result = kLogicalSegmentExtendedLogicalTypeArrayIndex;
@@ -365,14 +365,14 @@ LogicalSegmentExtendedLogicalType GetPathLogicalSegmentExtendedLogicalType(
       break;
     default:
       OPENER_TRACE_ERR(
-          "Logical segment/logical type: Invalid extended type detected!\n");
+        "Logical segment/logical type: Invalid extended type detected!\n");
   }
   return result;
 }
 
 LogicalSegmentSpecialTypeLogicalFormat
 GetPathLogicalSegmentSpecialTypeLogicalType(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   /*  OPENER_ASSERT(kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path),
    * "Not a logical segment!\n") */
   OPENER_ASSERT(kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path));
@@ -382,7 +382,7 @@ GetPathLogicalSegmentSpecialTypeLogicalType(
   const unsigned int logical_format     = (*cip_path) & kLogicalFormatMask;
 
   LogicalSegmentSpecialTypeLogicalFormat result =
-      kLogicalSegmentSpecialTypeLogicalFormatReserved;
+    kLogicalSegmentSpecialTypeLogicalFormatReserved;
   switch (logical_format) {
     case LOGICAL_SEGMENT_SPECIAL_TYPE_FORMAT_ELECTRONIC_KEY:
       result = kLogicalSegmentSpecialTypeLogicalFormatElectronicKey;
@@ -395,7 +395,7 @@ GetPathLogicalSegmentSpecialTypeLogicalType(
 }
 
 ElectronicKeySegmentFormat GetPathLogicalSegmentElectronicKeyFormat(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   /*  OPENER_ASSERT(kLogicalSegmentSpecialTypeLogicalFormatElectronicKey ==
      GetPathLogicalSegmentSpecialTypeLogicalType(cip_path), "Not an electronic
      key!\n") */
@@ -423,7 +423,7 @@ void GetElectronicKeyFormat4FromMessage(const CipOctet** const message,
   ElectronicKeyFormat4SetDeviceType(key, GetUintFromMessage(message));
   ElectronicKeyFormat4SetProductCode(key, GetUintFromMessage(message));
   ElectronicKeyFormat4SetMajorRevisionCompatibility(
-      key, GetByteFromMessage(message));
+    key, GetByteFromMessage(message));
   ElectronicKeyFormat4SetMinorRevision(key, GetUsintFromMessage(message));
 }
 
@@ -437,7 +437,7 @@ void GetElectronicKeyFormat4FromMessage(const CipOctet** const message,
  *  @return The Network Segment subtype of the EPath
  */
 NetworkSegmentSubtype GetPathNetworkSegmentSubtype(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   OPENER_ASSERT(kSegmentTypeNetworkSegment == GetPathSegmentType(cip_path));
   const unsigned int kSubtypeMask = 0x1F;
   const unsigned int subtype      = (*cip_path) & kSubtypeMask;
@@ -476,7 +476,7 @@ NetworkSegmentSubtype GetPathNetworkSegmentSubtype(
  * @return the Production Inhibit Time in milliseconds ranging from 0 to 255
  */
 CipUsint GetPathNetworkSegmentProductionInhibitTimeInMilliseconds(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   /*  OPENER_ASSERT(kSegmentTypeNetworkSegment ==
      GetPathSegmentType(cip_path),"Not a network segment!\n")
      OPENER_ASSERT(kNetworkSegmentSubtypeProductionInhibitTimeInMilliseconds ==
@@ -496,7 +496,7 @@ CipUsint GetPathNetworkSegmentProductionInhibitTimeInMilliseconds(
  * 4294967295
  */
 CipUdint GetPathNetworkSegmentProductionInhibitTimeInMicroseconds(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   /*  OPENER_ASSERT(kSegmentTypeNetworkSegment ==
      GetPathSegmentType(cip_path),"Not a network segment!\n")
      OPENER_ASSERT(kNetworkSegmentSubtypeProductionInhibitTimeInMicroseconds ==
@@ -518,7 +518,7 @@ CipUdint GetPathNetworkSegmentProductionInhibitTimeInMicroseconds(
 /*** Symbolic Segment ***/
 
 SymbolicSegmentFormat GetPathSymbolicSegmentFormat(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   const unsigned int kSymbolicSegmentFormatMask = 0x1F;
   if (SYMBOLIC_SEGMENT_FORMAT_EXTENDED_STRING ==
       (*cip_path & kSymbolicSegmentFormatMask)) {
@@ -528,7 +528,7 @@ SymbolicSegmentFormat GetPathSymbolicSegmentFormat(
 }
 
 unsigned int GetPathSymbolicSegmentASCIIFormatLength(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   const unsigned int kSymbolicSegmentASCIIFormatLength = 0x1F;
   const unsigned int length = *cip_path & kSymbolicSegmentASCIIFormatLength;
   OPENER_ASSERT(0 != length);
@@ -536,10 +536,10 @@ unsigned int GetPathSymbolicSegmentASCIIFormatLength(
 }
 
 SymbolicSegmentExtendedFormat GetPathSymbolicSegmentNumericType(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   const unsigned int kSymbolicSegmentExtendedFormatNumericTypeMask = 0x1F;
   const unsigned int numeric_subtype =
-      *(cip_path + 1) & kSymbolicSegmentExtendedFormatNumericTypeMask;
+    *(cip_path + 1) & kSymbolicSegmentExtendedFormatNumericTypeMask;
   SymbolicSegmentExtendedFormat result = kSymbolicSegmentExtendedFormatReserved;
   switch (numeric_subtype) {
     case SYMBOLIC_SEGMENT_EXTENDED_FORMAT_NUMERIC_USINT_TYPE:
@@ -559,13 +559,13 @@ SymbolicSegmentExtendedFormat GetPathSymbolicSegmentNumericType(
 }
 
 SymbolicSegmentExtendedFormat GetPathSymbolicSegmentExtendedFormat(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   OPENER_ASSERT(kSegmentTypeSymbolicSegment == GetPathSegmentType(cip_path));
   OPENER_ASSERT(kSymbolicSegmentFormatExtendedString ==
                 GetPathSymbolicSegmentFormat(cip_path));
   const unsigned int kSymbolicSegmentExtendedFormatMask = 0xE0;
   const unsigned int extended_type =
-      *(cip_path + 1) & kSymbolicSegmentExtendedFormatMask;
+    *(cip_path + 1) & kSymbolicSegmentExtendedFormatMask;
   SymbolicSegmentExtendedFormat result = kSymbolicSegmentExtendedFormatReserved;
   switch (extended_type) {
     case SYMBOLIC_SEGMENT_EXTENDED_FORMAT_DOUBLE_CHAR:
@@ -589,7 +589,7 @@ SymbolicSegmentExtendedFormat GetPathSymbolicSegmentExtendedFormat(
 /*** Data Segment ***/
 
 DataSegmentSubtype GetPathDataSegmentSubtype(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   const unsigned int kDataSegmentSubtypeMask = 0x1F;
   const unsigned int data_subtype = (*cip_path) & kDataSegmentSubtypeMask;
 
@@ -614,7 +614,7 @@ DataSegmentSubtype GetPathDataSegmentSubtype(
  * @return The amount of 16-bit words of data in the EPath
  */
 CipUsint GetPathDataSegmentSimpleDataWordLength(
-    const unsigned char* const cip_path) {
+  const unsigned char* const cip_path) {
   /*  OPENER_ASSERT(kSegmentTypeDataSegment == GetPathSegmentType(cip_path),"Not
      a data segment!\n"); OPENER_ASSERT(kDataSegmentSubtypeSimpleData ==
      GetPathDataSegmentSubtype(cip_path), "Not a simple data segment!\n") */
@@ -631,9 +631,9 @@ CipUsint GetPathDataSegmentSimpleDataWordLength(
 /* Special purpose functions */
 
 LogicalSegmentLogicalFormat CipEpathGetNeededLogicalFormatForValue(
-    CipDword value) {
+  CipDword value) {
   LogicalSegmentLogicalFormat logical_format =
-      kLogicalSegmentLogicalFormatEightBit;
+    kLogicalSegmentLogicalFormatEightBit;
   if (0xFF < value) {
     logical_format = kLogicalSegmentLogicalFormatSixteenBit;
   }

+ 19 - 19
source/src/cip/cipepath.h

@@ -124,7 +124,7 @@ typedef enum segment_type {
 /** @brief Port Segment flags */
 typedef enum port_segment_type {
   kPortSegmentFlagExtendedLinkAddressSize =
-      0x10 /**< Extended Link Address Size flag, Port segment */
+    0x10 /**< Extended Link Address Size flag, Port segment */
 } PortSegmentFlag;
 
 /** @brief Enum containing values which kind of logical segment is encoded */
@@ -264,7 +264,7 @@ void SetPathSegmentType(SegmentType segment_type,
  * @return True if extended link addres size bit set, false otherwise
  */
 bool GetPathPortSegmentExtendedLinkAddressSizeBit(
-    const unsigned char* const cip_path);
+  const unsigned char* const cip_path);
 
 /** @brief Only to be used on Port Segments. Returns the Port Identifier
  *
@@ -272,7 +272,7 @@ bool GetPathPortSegmentExtendedLinkAddressSizeBit(
  * @return The Port Identifier
  */
 unsigned int GetPathPortSegmentPortIdentifier(
-    const unsigned char* const cip_path);
+  const unsigned char* const cip_path);
 
 /** @brief Sets the Port Identifier form an Port Segment EPath to be sent.
  *
@@ -288,7 +288,7 @@ void SetPathPortSegmentPortIdentifier(const unsigned int port_identifier,
  * @return The Link Address Size
  */
 unsigned int GetPathPortSegmentLinkAddressSize(
-    const unsigned char* const cip_path);
+  const unsigned char* const cip_path);
 
 /** @brief Only to be used on Port Segments with Extended Port Number. Gets the
  * Extended Port Number
@@ -297,7 +297,7 @@ unsigned int GetPathPortSegmentLinkAddressSize(
  * @return The Link Address Size
  */
 unsigned int GetPathPortSegmentExtendedPortNumber(
-    const unsigned char* const cip_path);
+  const unsigned char* const cip_path);
 
 /** @brief Sets the Extended Port Identifier in a EPath Port Segment message
  *
@@ -306,7 +306,7 @@ unsigned int GetPathPortSegmentExtendedPortNumber(
  * @param cip_path The start for the EPatch message
  */
 void SetPathPortSegmentExtendedPortIdentifier(
-    const unsigned int extended_port_identifier, CipOctet* const cip_path);
+  const unsigned int extended_port_identifier, CipOctet* const cip_path);
 
 /** @brief Gets the Logical Type of an EPath Logical Segment message
  *
@@ -314,7 +314,7 @@ void SetPathPortSegmentExtendedPortIdentifier(
  * @return The logical type of the logical segment
  */
 LogicalSegmentLogicalType GetPathLogicalSegmentLogicalType(
-    const unsigned char* const cip_path);
+  const unsigned char* const cip_path);
 
 void SetPathLogicalSegmentLogicalType(LogicalSegmentLogicalType logical_type,
                                       CipOctet* const cip_path);
@@ -325,7 +325,7 @@ void SetPathLogicalSegmentLogicalType(LogicalSegmentLogicalType logical_type,
  * @return The logical format of the logical format
  */
 LogicalSegmentLogicalFormat GetPathLogicalSegmentLogicalFormat(
-    const unsigned char* const cip_path);
+  const unsigned char* const cip_path);
 
 void SetPathLogicalSegmentLogicalFormat(LogicalSegmentLogicalFormat format,
                                         CipOctet* const cip_path);
@@ -342,7 +342,7 @@ void CipEpathSetLogicalValue(const CipDword logical_value,
  * @return The extended logical type of the logical segment
  */
 LogicalSegmentExtendedLogicalType GetPathLogicalSegmentExtendedLogicalType(
-    const unsigned char* const cip_path);
+  const unsigned char* const cip_path);
 
 /** @brief Gets the Special Type Logical Type of a Logical Segment EPath message
  *
@@ -352,7 +352,7 @@ LogicalSegmentExtendedLogicalType GetPathLogicalSegmentExtendedLogicalType(
  */
 LogicalSegmentSpecialTypeLogicalFormat
 GetPathLogicalSegmentSpecialTypeLogicalType(
-    const unsigned char* const cip_path);
+  const unsigned char* const cip_path);
 
 /** @brief Gets the Electronic Key format of a Logical Segment Special Type
  * EPath message
@@ -361,7 +361,7 @@ GetPathLogicalSegmentSpecialTypeLogicalType(
  * @return The Electronic Key Format used in the EPath
  */
 ElectronicKeySegmentFormat GetPathLogicalSegmentElectronicKeyFormat(
-    const unsigned char* const cip_path);
+  const unsigned char* const cip_path);
 
 /** @brief Gets the data for an Electronic Key of format 4 from the EPath
  * message
@@ -379,7 +379,7 @@ void GetElectronicKeyFormat4FromMessage(const CipOctet** const cip_path,
  * @return Network Segment subtype
  */
 NetworkSegmentSubtype GetPathNetworkSegmentSubtype(
-    const unsigned char* const cip_path);
+  const unsigned char* const cip_path);
 
 /** @brief Gets the Production Inhibit Time in Milliseconds
  *
@@ -387,7 +387,7 @@ NetworkSegmentSubtype GetPathNetworkSegmentSubtype(
  * @return The production Inhibit Time in Milliseconds
  */
 CipUsint GetPathNetworkSegmentProductionInhibitTimeInMilliseconds(
-    const unsigned char* const cip_path);
+  const unsigned char* const cip_path);
 
 /** @brief Gets the Production Inhibit Time in Microseconds
  *
@@ -395,7 +395,7 @@ CipUsint GetPathNetworkSegmentProductionInhibitTimeInMilliseconds(
  * @return The production Inhibit Time in Microseconds
  */
 CipUdint GetPathNetworkSegmentProductionInhibitTimeInMicroseconds(
-    const unsigned char* const cip_path);
+  const unsigned char* const cip_path);
 
 /** @brief Gets the Data Segment subtype of a Data Segment EPath message
  *
@@ -403,7 +403,7 @@ CipUdint GetPathNetworkSegmentProductionInhibitTimeInMicroseconds(
  * @return The Data Segment subtype
  */
 DataSegmentSubtype GetPathDataSegmentSubtype(
-    const unsigned char* const cip_path);
+  const unsigned char* const cip_path);
 
 /** @brief Gets the data word length of a Simple Data segment
  *
@@ -411,7 +411,7 @@ DataSegmentSubtype GetPathDataSegmentSubtype(
  * @return The length in words of the Simple Data segment
  */
 CipUsint GetPathDataSegmentSimpleDataWordLength(
-    const unsigned char* const cip_path);
+  const unsigned char* const cip_path);
 
 /** @brief Gets the Symbolic Segment Format of the Symbolic Segment EPath
  * message
@@ -420,7 +420,7 @@ CipUsint GetPathDataSegmentSimpleDataWordLength(
  * @return The Symbolic Segment Format
  */
 SymbolicSegmentFormat GetPathSymbolicSegmentFormat(
-    const unsigned char* const cip_path);
+  const unsigned char* const cip_path);
 
 /** @brief Gets the Numeric subtype of a Symbolic Segment Extended Format EPath
  * message
@@ -429,7 +429,7 @@ SymbolicSegmentFormat GetPathSymbolicSegmentFormat(
  * @return The Numeric Extended Format subtype
  */
 SymbolicSegmentExtendedFormat GetPathSymbolicSegmentNumericType(
-    const unsigned char* const cip_path);
+  const unsigned char* const cip_path);
 
 /** @brief Gets the Extended Format subtype of a Symbolic Segment EPath message
  *
@@ -437,7 +437,7 @@ SymbolicSegmentExtendedFormat GetPathSymbolicSegmentNumericType(
  * @return Symbolic Segment Extended Format
  */
 SymbolicSegmentExtendedFormat GetPathSymbolicSegmentExtendedFormat(
-    const unsigned char* const cip_path);
+  const unsigned char* const cip_path);
 
 /* Special purpose encoding and decoding functions */
 // TODO(MartinMelikMerkumians) currently not fully implemented

+ 92 - 92
source/src/cip/cipethernetlink.c

@@ -78,7 +78,7 @@
 #endif
 
 #if defined(OPENER_ETHLINK_IFACE_CTRL_ENABLE) && \
-    0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
+  0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
 #define IFACE_CTRL_ACCESS_MODE (kSetAndGetAble | kNvDataFunc)
 #else
 #define IFACE_CTRL_ACCESS_MODE kGetableAll
@@ -94,29 +94,29 @@ typedef struct speed_duplex_array_entry {
 
 /* forward declaration of functions to encode certain attribute objects */
 static void EncodeCipEthernetLinkInterfaceCounters(
-    const void* const data, ENIPMessage* const outgoing_message);
+  const void* const data, ENIPMessage* const outgoing_message);
 
 static void EncodeCipEthernetLinkMediaCounters(
-    const void* const data, ENIPMessage* const outgoing_message);
+  const void* const data, ENIPMessage* const outgoing_message);
 
 static void EncodeCipEthernetLinkInterfaceControl(
-    const void* const data, ENIPMessage* const outgoing_message);
+  const void* const data, ENIPMessage* const outgoing_message);
 
 static void EncodeCipEthernetLinkInterfaceCaps(
-    const void* const data, ENIPMessage* const outgoing_message);
+  const void* const data, ENIPMessage* const outgoing_message);
 
 #if defined(OPENER_ETHLINK_CNTRS_ENABLE) && 0 != OPENER_ETHLINK_CNTRS_ENABLE
 /* forward declaration for the GetAndClear service handler function */
 EipStatus GetAndClearEthernetLink(
-    CipInstance* RESTRICT const instance,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response,
-    const struct sockaddr* originator_address,
-    const CipSessionHandle encapsulation_session);
+  CipInstance* RESTRICT const instance,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response,
+  const struct sockaddr* originator_address,
+  const CipSessionHandle encapsulation_session);
 #endif /* ... && 0 != OPENER_ETHLINK_CNTRS_ENABLE */
 
 #if defined(OPENER_ETHLINK_IFACE_CTRL_ENABLE) && \
-    0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
+  0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
 
 /** @brief Modify the attribute values for Attribute6: Interface Control
  *
@@ -127,9 +127,9 @@ EipStatus GetAndClearEthernetLink(
  *          -1 .. error
  */
 int DecodeCipEthernetLinkInterfaceControl(
-    CipEthernetLinkInterfaceControl* const data,
-    const CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response);
+  CipEthernetLinkInterfaceControl* const data,
+  const CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response);
 #endif
 
 /** @brief This is the internal table of possible speed / duplex combinations
@@ -142,34 +142,34 @@ int DecodeCipEthernetLinkInterfaceControl(
  *  CipEthLinkSpeedDpxSelect.
  */
 static const CipEthernetLinkSpeedDuplexArrayEntry speed_duplex_table[] = {
-    {/* Index 0: 10Mbit/s half duplex*/
-     .interface_speed       = 10,
-     .interface_duplex_mode = 0},
-    {/* Index 1: 10Mbit/s full duplex*/
-     .interface_speed       = 10,
-     .interface_duplex_mode = 1},
-    {/* Index 2: 100Mbit/s half duplex*/
-     .interface_speed       = 100,
-     .interface_duplex_mode = 0},
-    {/* Index 3: 100Mbit/s full duplex*/
-     .interface_speed       = 100,
-     .interface_duplex_mode = 1},
-    {/* Index 4: 1000Mbit/s half duplex*/
-     .interface_speed       = 1000,
-     .interface_duplex_mode = 0},
-    {/* Index 5: 1000Mbit/s full duplex*/
-     .interface_speed       = 1000,
-     .interface_duplex_mode = 1},
+  { /* Index 0: 10Mbit/s half duplex*/
+    .interface_speed       = 10,
+    .interface_duplex_mode = 0 },
+  { /* Index 1: 10Mbit/s full duplex*/
+    .interface_speed       = 10,
+    .interface_duplex_mode = 1 },
+  { /* Index 2: 100Mbit/s half duplex*/
+    .interface_speed       = 100,
+    .interface_duplex_mode = 0 },
+  { /* Index 3: 100Mbit/s full duplex*/
+    .interface_speed       = 100,
+    .interface_duplex_mode = 1 },
+  { /* Index 4: 1000Mbit/s half duplex*/
+    .interface_speed       = 1000,
+    .interface_duplex_mode = 0 },
+  { /* Index 5: 1000Mbit/s full duplex*/
+    .interface_speed       = 1000,
+    .interface_duplex_mode = 1 },
 };
 
 #if defined(OPENER_ETHLINK_LABEL_ENABLE) && 0 != OPENER_ETHLINK_LABEL_ENABLE
 static const CipShortString iface_label_table[OPENER_ETHLINK_INSTANCE_CNT] = {
-    {.length = sizeof IFACE_LABEL - 1, .string = (EipByte*)IFACE_LABEL},
+  { .length = sizeof IFACE_LABEL - 1, .string = (EipByte*)IFACE_LABEL },
 #if OPENER_ETHLINK_INSTANCE_CNT > 1
-    {.length = sizeof IFACE_LABEL_1 - 1, .string = (EipByte*)IFACE_LABEL_1},
+  { .length = sizeof IFACE_LABEL_1 - 1, .string = (EipByte*)IFACE_LABEL_1 },
 #endif
 #if OPENER_ETHLINK_INSTANCE_CNT > 2
-    {.length = sizeof IFACE_LABEL_2 - 1, .string = (EipByte*)IFACE_LABEL_2},
+  { .length = sizeof IFACE_LABEL_2 - 1, .string = (EipByte*)IFACE_LABEL_2 },
 #endif
 };
 #endif  // defined(OPENER_ETHLINK_LABEL_ENABLE) &&
@@ -183,12 +183,12 @@ static CipUdint dummy_attribute_udint = 0;
 #endif
 
 #if defined(OPENER_ETHLINK_IFACE_CTRL_ENABLE) && \
-    0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
+  0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
 #else
 /* Constant dummy data for attribute #6 */
 static CipEthernetLinkInterfaceControl s_interface_control = {
-    .control_bits           = 0,
-    .forced_interface_speed = 0,
+  .control_bits           = 0,
+  .forced_interface_speed = 0,
 };
 #endif
 
@@ -197,26 +197,26 @@ CipEthernetLinkObject g_ethernet_link[OPENER_ETHLINK_INSTANCE_CNT];
 
 EipStatus CipEthernetLinkInit(void) {
   CipClass* ethernet_link_class = CreateCipClass(
-      kCipEthernetLinkClassCode,
-      0,
-      /* # class attributes*/
-      7,
-      /* # highest class attribute number*/
-      2,
-      /* # class services*/
-      11,
-      /* # instance attributes*/
-      11,
-      /* # highest instance attribute number*/
-      /* # instance services follow */
-      2 + OPENER_ETHLINK_CNTRS_ENABLE + OPENER_ETHLINK_IFACE_CTRL_ENABLE,
-      OPENER_ETHLINK_INSTANCE_CNT,
-      /* # instances*/
-      "Ethernet Link",
-      /* # class name */
-      4,
-      /* # class revision*/
-      NULL); /* # function pointer for initialization*/
+    kCipEthernetLinkClassCode,
+    0,
+    /* # class attributes*/
+    7,
+    /* # highest class attribute number*/
+    2,
+    /* # class services*/
+    11,
+    /* # instance attributes*/
+    11,
+    /* # highest instance attribute number*/
+    /* # instance services follow */
+    2 + OPENER_ETHLINK_CNTRS_ENABLE + OPENER_ETHLINK_IFACE_CTRL_ENABLE,
+    OPENER_ETHLINK_INSTANCE_CNT,
+    /* # instances*/
+    "Ethernet Link",
+    /* # class name */
+    4,
+    /* # class revision*/
+    NULL); /* # function pointer for initialization*/
 
   /* set attributes to initial values */
   for (size_t idx = 0; idx < OPENER_ETHLINK_INSTANCE_CNT; ++idx) {
@@ -234,11 +234,11 @@ EipStatus CipEthernetLinkInit(void) {
 #endif
     g_ethernet_link[idx].interface_caps.capability_bits = kEthLinkCapAutoNeg;
     g_ethernet_link[idx].interface_caps.speed_duplex_selector =
-        kEthLinkSpeedDpx_100_FD;
+      kEthLinkSpeedDpx_100_FD;
 #if defined(OPENER_ETHLINK_IFACE_CTRL_ENABLE) && \
-    0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
+  0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
     g_ethernet_link[idx].interface_control.control_bits =
-        kEthLinkIfCntrlAutonegotiate;
+      kEthLinkIfCntrlAutonegotiate;
     g_ethernet_link[idx].interface_control.forced_interface_speed = 0U;
 #endif
   }
@@ -261,7 +261,7 @@ EipStatus CipEthernetLinkInit(void) {
                   "GetAndClear");
 #endif
 #if defined(OPENER_ETHLINK_IFACE_CTRL_ENABLE) && \
-    0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
+  0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
     InsertService(ethernet_link_class,
                   kSetAttributeSingle,
                   &SetAttributeSingle,
@@ -271,7 +271,7 @@ EipStatus CipEthernetLinkInit(void) {
     /* bind attributes to the instance */
     for (CipInstanceNum idx = 0; idx < OPENER_ETHLINK_INSTANCE_CNT; ++idx) {
       CipInstance* ethernet_link_instance =
-          GetCipInstance(ethernet_link_class, (CipInstanceNum)(idx + 1));
+        GetCipInstance(ethernet_link_class, (CipInstanceNum)(idx + 1));
 
       InsertAttribute(ethernet_link_instance,
                       1,
@@ -326,7 +326,7 @@ EipStatus CipEthernetLinkInit(void) {
                       kGetableAllDummy);
 #endif /* ... && 0 != OPENER_ETHLINK_CNTRS_ENABLE */
 #if defined(OPENER_ETHLINK_IFACE_CTRL_ENABLE) && \
-    0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
+  0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
       if (2 == idx) {
         /* Interface control of internal switch port is never settable. */
         InsertAttribute(ethernet_link_instance,
@@ -407,7 +407,7 @@ void CipEthernetLinkSetMac(EipUint8* p_physical_address) {
 }
 
 static void EncodeCipEthernetLinkInterfaceCounters(
-    const void* const data, ENIPMessage* const outgoing_message) {
+  const void* const data, ENIPMessage* const outgoing_message) {
   /* Suppress unused parameter compiler warning. */
   (void)data;
 
@@ -422,12 +422,12 @@ static void EncodeCipEthernetLinkInterfaceCounters(
 #else
   /* Encode the default counter value of 0 */
   FillNextNMessageOctetsWithValueAndMoveToNextPosition(
-      0, 11 * sizeof(CipUdint), outgoing_message);
+    0, 11 * sizeof(CipUdint), outgoing_message);
 #endif
 }
 
 static void EncodeCipEthernetLinkMediaCounters(
-    const void* const data, ENIPMessage* const outgoing_message) {
+  const void* const data, ENIPMessage* const outgoing_message) {
   /* Suppress unused parameter compiler warning. */
   (void)data;
 
@@ -442,14 +442,14 @@ static void EncodeCipEthernetLinkMediaCounters(
 #else
   /* Encode the default counter value of 0 */
   FillNextNMessageOctetsWithValueAndMoveToNextPosition(
-      0, 12 * sizeof(CipUdint), outgoing_message);
+    0, 12 * sizeof(CipUdint), outgoing_message);
 #endif
 }
 
 static void EncodeCipEthernetLinkInterfaceControl(
-    const void* const data, ENIPMessage* const outgoing_message) {
+  const void* const data, ENIPMessage* const outgoing_message) {
 #if defined(OPENER_ETHLINK_IFACE_CTRL_ENABLE) && \
-    0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
+  0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
   const CipEthernetLinkInterfaceControl* const interface_control = data;
 #else
   /* Suppress unused parameter compiler warning. */
@@ -463,7 +463,7 @@ static void EncodeCipEthernetLinkInterfaceControl(
 
 #define NELEMENTS(x) ((sizeof(x) / sizeof(x[0])))
 static void EncodeCipEthernetLinkInterfaceCaps(
-    const void* const data, ENIPMessage* const outgoing_message) {
+  const void* const data, ENIPMessage* const outgoing_message) {
   const CipEthernetLinkMetaInterfaceCapability* const interface_caps = data;
   EncodeCipDword(&interface_caps->capability_bits, outgoing_message);
   uint16_t selected = interface_caps->speed_duplex_selector;
@@ -485,22 +485,22 @@ static void EncodeCipEthernetLinkInterfaceCaps(
 
 #if defined(OPENER_ETHLINK_CNTRS_ENABLE) && 0 != OPENER_ETHLINK_CNTRS_ENABLE
 EipStatus GetAndClearEthernetLink(
-    CipInstance* RESTRICT const instance,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response,
-    const struct sockaddr* originator_address,
-    const CipSessionHandle encapsulation_session) {
+  CipInstance* RESTRICT const instance,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response,
+  const struct sockaddr* originator_address,
+  const CipSessionHandle encapsulation_session) {
   CipAttributeStruct* attribute = GetCipAttribute(
-      instance, message_router_request->request_path.attribute_number);
+    instance, message_router_request->request_path.attribute_number);
 
   message_router_response->data_length = 0;
   message_router_response->reply_service =
-      (0x80 | message_router_request->service);
+    (0x80 | message_router_request->service);
   message_router_response->general_status = kCipErrorAttributeNotSupported;
   message_router_response->size_of_additional_status = 0;
 
   EipUint16 attribute_number =
-      message_router_request->request_path.attribute_number;
+    message_router_request->request_path.attribute_number;
 
   if ((NULL != attribute) && (NULL != attribute->data)) {
     OPENER_TRACE_INFO("GetAndClear attribute %" PRIu16 "\n", attribute_number);
@@ -518,7 +518,7 @@ EipStatus GetAndClearEthernetLink(
         break;
       default:
         message_router_response->general_status =
-            kCipErrorServiceNotSupportedForSpecifiedPath;
+          kCipErrorServiceNotSupportedForSpecifiedPath;
         break;
     }
 
@@ -535,18 +535,18 @@ EipStatus GetAndClearEthernetLink(
 #endif /* ... && 0 != OPENER_ETHLINK_CNTRS_ENABLE */
 
 #if defined(OPENER_ETHLINK_IFACE_CTRL_ENABLE) && \
-    0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
+  0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
 static bool IsIfaceControlAllowed(
-    CipInstanceNum instance_id,
-    CipEthernetLinkInterfaceControl const* iface_cntrl) {
+  CipInstanceNum instance_id,
+  CipEthernetLinkInterfaceControl const* iface_cntrl) {
   const CipUsint duplex_mode =
-      (iface_cntrl->control_bits & kEthLinkIfCntrlForceDuplexFD) ? 1 : 0;
+    (iface_cntrl->control_bits & kEthLinkIfCntrlForceDuplexFD) ? 1 : 0;
   for (size_t i = 0; i < NELEMENTS(speed_duplex_table); i++) {
     if (g_ethernet_link[instance_id - 1].interface_caps.speed_duplex_selector &
         (1U << i)) {
       if (duplex_mode == speed_duplex_table[i].interface_duplex_mode &&
           iface_cntrl->forced_interface_speed ==
-              speed_duplex_table[i].interface_speed) {
+            speed_duplex_table[i].interface_speed) {
         return true;
       }
     }
@@ -555,19 +555,19 @@ static bool IsIfaceControlAllowed(
 }
 
 int DecodeCipEthernetLinkInterfaceControl(
-    CipEthernetLinkInterfaceControl* const data,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response) {
+  CipEthernetLinkInterfaceControl* const data,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response) {
   CipInstance* const instance =
-      GetCipInstance(GetCipClass(message_router_request->request_path.class_id),
-                     message_router_request->request_path.instance_number);
+    GetCipInstance(GetCipClass(message_router_request->request_path.class_id),
+                   message_router_request->request_path.instance_number);
 
   int number_of_decoded_bytes = -1;
 
   CipEthernetLinkInterfaceControl if_cntrl;
 
   DecodeCipWord(
-      &if_cntrl.control_bits, message_router_request, message_router_response);
+    &if_cntrl.control_bits, message_router_request, message_router_response);
   DecodeCipUint(&if_cntrl.forced_interface_speed,
                 message_router_request,
                 message_router_response);
@@ -587,7 +587,7 @@ int DecodeCipEthernetLinkInterfaceControl(
         /* Need to check if a supported mode is forced. */
         if (!IsIfaceControlAllowed(instance->instance_number, &if_cntrl)) {
           message_router_response->general_status =
-              kCipErrorInvalidAttributeValue;
+            kCipErrorInvalidAttributeValue;
           return number_of_decoded_bytes;
         }
       }

+ 6 - 6
source/src/cip/cipethernetlink.h

@@ -38,7 +38,7 @@ typedef enum {
   /** For convenience declare the sum of valid bits as the maximum allowed
      value. */
   kEthLinkIfCntrlMaxValid =
-      kEthLinkIfCntrlAutonegotiate + kEthLinkIfCntrlForceDuplexFD,
+    kEthLinkIfCntrlAutonegotiate + kEthLinkIfCntrlForceDuplexFD,
 } CipEthLinkIfaceControl;
 
 /** @brief Provide values for the Interface Type (attribute #7) */
@@ -162,19 +162,19 @@ typedef struct {
                                  ///< link
 #if defined(OPENER_ETHLINK_CNTRS_ENABLE) && 0 != OPENER_ETHLINK_CNTRS_ENABLE
   CipEthernetLinkInterfaceCounters
-      interface_cntrs;  ///< Attribute #4: Interface counters 32-bit wide
+    interface_cntrs;  ///< Attribute #4: Interface counters 32-bit wide
   CipEthernetLinkMediaCounters
-      media_cntrs;  ///< Attribute #5: Media counters 32-bit wide
+    media_cntrs;  ///< Attribute #5: Media counters 32-bit wide
 #endif
 #if defined(OPENER_ETHLINK_IFACE_CTRL_ENABLE) && \
-    0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
+  0 != OPENER_ETHLINK_IFACE_CTRL_ENABLE
   CipEthernetLinkInterfaceControl
-      interface_control;  ///< Attribute #6: control link properties
+    interface_control;  ///< Attribute #6: control link properties
 #endif
   CipUsint interface_type;         ///< Attribute #7: Type of interface
   CipShortString interface_label;  ///< Attribute #10: Interface label
   CipEthernetLinkMetaInterfaceCapability
-      interface_caps;  ///< Attribute #11: Interface capabilities
+    interface_caps;  ///< Attribute #11: Interface capabilities
 } CipEthernetLinkObject;
 
 /* public functions */

+ 43 - 47
source/src/cip/cipidentity.c

@@ -43,58 +43,56 @@
 
 /** @brief Definition of the global Identity Object */
 CipIdentityObject g_identity = {
-    .vendor_id    = OPENER_DEVICE_VENDOR_ID,     // Attribute 1: Vendor ID
-    .device_type  = OPENER_DEVICE_TYPE,          // Attribute 2: Device Type
-    .product_code = OPENER_DEVICE_PRODUCT_CODE,  // Attribute 3: Product Code
-    .revision =
-        {// Attribute 4: Revision / CipUsint Major, CipUsint Minor
-         OPENER_DEVICE_MAJOR_REVISION,
-         OPENER_DEVICE_MINOR_REVISION},
-    .status = 0, /* Attribute 5: Status */
-    .ext_status =
-        kSelftestingUnknown, /* Attribute 5: Extended Device Status field */
-    .serial_number = 0,      /* Attribute 6: Serial Number */
-    /* Attribute 7: Product Name, set by CipIdentityInit() */
+  .vendor_id    = OPENER_DEVICE_VENDOR_ID,     // Attribute 1: Vendor ID
+  .device_type  = OPENER_DEVICE_TYPE,          // Attribute 2: Device Type
+  .product_code = OPENER_DEVICE_PRODUCT_CODE,  // Attribute 3: Product Code
+  // Attribute 4: Revision / CipUsint Major, CipUsint Minor
+  .revision = { OPENER_DEVICE_MAJOR_REVISION, OPENER_DEVICE_MINOR_REVISION },
+  .status   = 0,  // Attribute 5: Status
+  .ext_status =
+    kSelftestingUnknown,  // Attribute 5: Extended Device Status field
+  .serial_number = 0,     // Attribute 6: Serial Number
+  // Attribute 7: Product Name, set by CipIdentityInit()
 };
 
-/* The Doxygen comment is with the function's prototype in opener_api.h. */
+// The Doxygen comment is with the function's prototype in opener_api.h.
 void SetDeviceRevision(EipUint8 major, EipUint8 minor) {
   g_identity.revision.major_revision = major;
   g_identity.revision.minor_revision = minor;
 }
 
-/* The Doxygen comment is with the function's prototype in opener_api.h. */
+// The Doxygen comment is with the function's prototype in opener_api.h.
 void SetDeviceSerialNumber(const EipUint32 serial_number) {
   g_identity.serial_number = serial_number;
 }
 
-/* The Doxygen comment is with the function's prototype in opener_api.h. */
+// The Doxygen comment is with the function's prototype in opener_api.h.
 void SetDeviceType(const EipUint16 type) {
   g_identity.device_type = type;
 }
 
-/* The Doxygen comment is with the function's prototype in opener_api.h. */
+// The Doxygen comment is with the function's prototype in opener_api.h.
 void SetDeviceProductCode(const EipUint16 code) {
   g_identity.product_code = code;
 }
 
-/* The Doxygen comment is with the function's prototype in opener_api.h. */
+// The Doxygen comment is with the function's prototype in opener_api.h.
 void SetDeviceStatus(const CipWord status) {
   g_identity.status     = status;
   g_identity.ext_status = status & kExtStatusMask;
 }
 
-/* The Doxygen comment is with the function's prototype in opener_api.h. */
+// The Doxygen comment is with the function's prototype in opener_api.h.
 void SetDeviceVendorId(CipUint vendor_id) {
   g_identity.vendor_id = vendor_id;
 }
 
-/* The Doxygen comment is with the function's prototype in opener_api.h. */
+// The Doxygen comment is with the function's prototype in opener_api.h.
 CipUint GetDeviceVendorId(void) {
   return g_identity.vendor_id;
 }
 
-/* The Doxygen comment is with the function's prototype in opener_api.h. */
+// The Doxygen comment is with the function's prototype in opener_api.h.
 void SetDeviceProductName(const char* product_name) {
   if (!product_name)
     return;
@@ -102,7 +100,7 @@ void SetDeviceProductName(const char* product_name) {
   SetCipShortStringByCstr(&g_identity.product_name, product_name);
 }
 
-/* The Doxygen comment is with the function's prototype in opener_api.h. */
+// The Doxygen comment is with the function's prototype in opener_api.h.
 CipShortString* GetDeviceProductName(void) {
   return &g_identity.product_name;
 }
@@ -111,8 +109,8 @@ static inline void MergeStatusAndExtStatus(void) {
   CipWord status_flags = g_identity.status & (~kExtStatusMask);
   CipWord ext_status   = g_identity.ext_status & kExtStatusMask;
 
-  /* Any major fault will override the current extended status with kMajorFault.
-     See comment on Major Fault at Vol. 1, Table 5A-2.4. */
+  // Any major fault will override the current extended status with kMajorFault.
+  // See comment on Major Fault at Vol. 1, Table 5A-2.4.
   if (0 !=
       (status_flags & (kMajorRecoverableFault | kMajorUnrecoverableFault))) {
     ext_status = kMajorFault;
@@ -155,7 +153,7 @@ void CipIdentityClearStatusFlags(const CipWord status_flags) {
  *  Status value.
  */
 void CipIdentitySetExtendedDeviceStatus(
-    CipIdentityExtendedStatus extended_status) {
+  CipIdentityExtendedStatus extended_status) {
   OPENER_TRACE_INFO("Setting extended status: %x\n", extended_status);
   g_identity.ext_status = extended_status & kExtStatusMask;
   MergeStatusAndExtStatus();
@@ -168,9 +166,9 @@ void CipIdentitySetExtendedDeviceStatus(
  * @returns Currently always kEipOkSend is returned
  */
 EipStatus IdentityObjectPreResetCallback(
-    CipInstance* RESTRICT const instance,
-    const CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response) {
+  CipInstance* RESTRICT const instance,
+  const CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response) {
   (void)instance;
 
   EipStatus eip_status = kEipStatusOkSend;
@@ -179,7 +177,7 @@ EipStatus IdentityObjectPreResetCallback(
     message_router_response->general_status = kCipErrorTooMuchData;
   } else {
     CipOctet reset_type =
-        0; /* The default type if type parameter was omitted. */
+      0; /* The default type if type parameter was omitted. */
     if (message_router_request->request_data_size == 1) {
       reset_type = message_router_request->data[0];
     }
@@ -265,10 +263,8 @@ void InitializeCipIdentity(CipClass* class) {
                 kGetAttributeAll,
                 &GetAttributeAll,
                 "GetAttributeAll"); /* bind instance services to the metaclass*/
-  InsertService(meta_class,
-                kGetAttributeSingle,
-                &GetAttributeSingle,
-                "GetAttributeSingle");
+  InsertService(
+    meta_class, kGetAttributeSingle, &GetAttributeSingle, "GetAttributeSingle");
 
   // add Callback function pointers
   class->PreResetCallback = &IdentityObjectPreResetCallback;
@@ -283,18 +279,18 @@ void EncodeRevision(const void* const data,
 
 EipStatus CipIdentityInit() {
   CipClass* class = CreateCipClass(
-      kCipIdentityClassCode,
-      0,           // # of non-default class attributes
-      7,           // # highest class attribute number
-      2,           // # of class services
-      7,           // # of instance attributes
-      7,           // # highest instance attribute number
-      5,           // # of instance services
-      1,           // # of instances
-      "identity",  // class name (for debug)
-      1,           // class revision
-      // TODO(MartinMelikMerkumians): change revision to 2 - check
-      &InitializeCipIdentity); /* function pointer for initialization*/
+    kCipIdentityClassCode,
+    0,           // # of non-default class attributes
+    7,           // # highest class attribute number
+    2,           // # of class services
+    7,           // # of instance attributes
+    7,           // # highest instance attribute number
+    5,           // # of instance services
+    1,           // # of instances
+    "identity",  // class name (for debug)
+    1,           // class revision
+    // TODO(MartinMelikMerkumians): change revision to 2 - check
+    &InitializeCipIdentity); /* function pointer for initialization*/
 
   if (class == 0) {
     return kEipStatusError;
@@ -355,13 +351,13 @@ EipStatus CipIdentityInit() {
                   kGetableSingleAndAll);
 
   InsertService(
-      class, kGetAttributeSingle, &GetAttributeSingle, "GetAttributeSingle");
+    class, kGetAttributeSingle, &GetAttributeSingle, "GetAttributeSingle");
   InsertService(class, kGetAttributeAll, &GetAttributeAll, "GetAttributeAll");
   InsertService(class, kReset, &CipResetService, "Reset");
   InsertService(
-      class, kGetAttributeList, &GetAttributeList, "GetAttributeList");
+    class, kGetAttributeList, &GetAttributeList, "GetAttributeList");
   InsertService(
-      class, kSetAttributeList, &SetAttributeList, "SetAttributeList");
+    class, kSetAttributeList, &SetAttributeList, "SetAttributeList");
 
   return kEipStatusOk;
 }

+ 2 - 2
source/src/cip/cipidentity.h

@@ -66,7 +66,7 @@ typedef struct {
   CipUint device_type;   ///< Attribute 2: Device Type
   CipUint product_code;  ///< Attribute 3: Product Code
   CipRevision
-      revision;    ///< Attribute 4: Revision / CipUsint Major, CipUsint Minor
+    revision;      ///< Attribute 4: Revision / CipUsint Major, CipUsint Minor
   CipWord status;  ///< Attribute 5: Status
   CipWord ext_status;  ///< Attribute 5: last set extended status, needed for
                        ///< Status handling
@@ -91,6 +91,6 @@ EipStatus CipIdentityInit(void);
 void CipIdentitySetStatusFlags(const CipWord status_flags);
 void CipIdentityClearStatusFlags(const CipWord status_flags);
 void CipIdentitySetExtendedDeviceStatus(
-    CipIdentityExtendedStatus extended_status);
+  CipIdentityExtendedStatus extended_status);
 
 #endif  // CIP_CIPIDENTITY_H_

+ 153 - 153
source/src/cip/cipioconnection.c

@@ -25,21 +25,21 @@
  * application connection types.
  */
 EipStatus OpenProducingMulticastConnection(
-    CipConnectionObject* connection_object,
-    CipCommonPacketFormatData* common_packet_format_data);
+  CipConnectionObject* connection_object,
+  CipCommonPacketFormatData* common_packet_format_data);
 
 EipStatus OpenMulticastConnection(
-    UdpCommuncationDirection direction,
-    CipConnectionObject* connection_object,
-    CipCommonPacketFormatData* common_packet_format_data);
+  UdpCommuncationDirection direction,
+  CipConnectionObject* connection_object,
+  CipCommonPacketFormatData* common_packet_format_data);
 
 EipStatus OpenConsumingPointToPointConnection(
-    CipConnectionObject* const connection_object,
-    CipCommonPacketFormatData* const common_packet_format_data);
+  CipConnectionObject* const connection_object,
+  CipCommonPacketFormatData* const common_packet_format_data);
 
 CipError OpenProducingPointToPointConnection(
-    CipConnectionObject* connection_object,
-    CipCommonPacketFormatData* common_packet_format_data);
+  CipConnectionObject* connection_object,
+  CipCommonPacketFormatData* common_packet_format_data);
 
 EipUint16 HandleConfigData(CipConnectionObject* connection_object);
 
@@ -100,24 +100,24 @@ bool CipRunIdleHeaderGetT2O(void) {
 }
 
 EipUint16 ProcessProductionInhibitTime(
-    CipConnectionObject* io_connection_object) {
+  CipConnectionObject* io_connection_object) {
   if (kConnectionObjectTransportClassTriggerProductionTriggerCyclic ==
       ConnectionObjectGetTransportClassTriggerProductionTrigger(
-          io_connection_object)) {
+        io_connection_object)) {
     if (256 == ConnectionObjectGetProductionInhibitTime(io_connection_object)) {
       OPENER_TRACE_INFO("No PIT segment available\n");
       /* there was no PIT segment in the connection path; set PIT to one fourth
        * of RPI */
       ConnectionObjectSetProductionInhibitTime(
-          io_connection_object,
-          ConnectionObjectGetTToORequestedPacketInterval(io_connection_object) /
-              4000);
+        io_connection_object,
+        ConnectionObjectGetTToORequestedPacketInterval(io_connection_object) /
+          4000);
     } else {
       /* If a production inhibit time is provided, it needs to be smaller than
        * the Requested Packet Interval */
       if (ConnectionObjectGetProductionInhibitTime(io_connection_object) >
           (ConnectionObjectGetTToORequestedPacketInterval(
-               io_connection_object) /
+             io_connection_object) /
            1000)) {
         /* see section C-1.4.3.3 */
         return kConnectionManagerExtendedStatusCodeProductionInhibitTimerGreaterThanRpi;
@@ -132,17 +132,17 @@ void SetIoConnectionCallbacks(CipConnectionObject* const io_connection_object) {
   io_connection_object->connection_timeout_function = HandleIoConnectionTimeOut;
   io_connection_object->connection_send_data_function = SendConnectedData;
   io_connection_object->connection_receive_data_function =
-      HandleReceivedIoConnectionData;
+    HandleReceivedIoConnectionData;
 }
 
 EipUint16 SetupIoConnectionOriginatorToTargetConnectionPoint(
-    CipConnectionObject* const io_connection_object,
-    CipConnectionObject* const RESTRICT connection_object) {
+  CipConnectionObject* const io_connection_object,
+  CipConnectionObject* const RESTRICT connection_object) {
   CipClass* const assembly_class = GetCipClass(kCipAssemblyClassCode);
   CipInstance* instance          = NULL;
   if (NULL !=
       (instance = GetCipInstance(
-           assembly_class, io_connection_object->consumed_path.instance_id))) {
+         assembly_class, io_connection_object->consumed_path.instance_id))) {
     /* consuming Connection Point is present */
     io_connection_object->consuming_instance              = instance;
     io_connection_object->consumed_connection_path_length = 6;
@@ -152,18 +152,18 @@ EipUint16 SetupIoConnectionOriginatorToTargetConnectionPoint(
        io_connection_object->connection_path.connection_point[
        kConnectionPointConsumer];*/
     io_connection_object->consumed_path.attribute_id_or_connection_point =
-        kAssemblyObjectInstanceAttributeIdData;
+      kAssemblyObjectInstanceAttributeIdData;
     int data_size = ConnectionObjectGetOToTConnectionSize(io_connection_object);
     int diff_size = 0;
 
     /* an assembly object should always have a data attribute. */
     CipAttributeStruct* attribute =
-        GetCipAttribute(instance, kAssemblyObjectInstanceAttributeIdData);
+      GetCipAttribute(instance, kAssemblyObjectInstanceAttributeIdData);
     OPENER_ASSERT(attribute != NULL);
     bool is_heartbeat = (((CipByteArray*)attribute->data)->length == 0);
     if (kConnectionObjectTransportClassTriggerTransportClass1 ==
         ConnectionObjectGetTransportClassTriggerTransportClass(
-            io_connection_object)) {
+          io_connection_object)) {
       /* class 1 connection */
       data_size -= 2; /* remove 16-bit sequence count length */
       diff_size += 2;
@@ -178,7 +178,7 @@ EipUint16 SetupIoConnectionOriginatorToTargetConnectionPoint(
     if (((CipByteArray*)attribute->data)->length != data_size) {
       /*wrong connection size */
       connection_object->correct_originator_to_target_size =
-          ((CipByteArray*)attribute->data)->length + diff_size;
+        ((CipByteArray*)attribute->data)->length + diff_size;
       return kConnectionManagerExtendedStatusCodeErrorInvalidOToTConnectionSize;
     }
   } else {
@@ -188,18 +188,18 @@ EipUint16 SetupIoConnectionOriginatorToTargetConnectionPoint(
 }
 
 EipUint16 SetupIoConnectionTargetToOriginatorConnectionPoint(
-    CipConnectionObject* const io_connection_object,
-    CipConnectionObject* const RESTRICT connection_object) {
+  CipConnectionObject* const io_connection_object,
+  CipConnectionObject* const RESTRICT connection_object) {
   DoublyLinkedListNode* node = connection_list.first;
   while (NULL != node &&
          kConnectionObjectConnectionTypeMulticast ==
-             ConnectionObjectGetTToOConnectionType(io_connection_object)) {
+           ConnectionObjectGetTToOConnectionType(io_connection_object)) {
     CipConnectionObject* iterator = node->data;
     if (io_connection_object->produced_path.instance_id ==
         iterator->produced_path.instance_id) {
       // Check parameters
       if (ConnectionObjectGetTToORequestedPacketInterval(
-              io_connection_object) !=
+            io_connection_object) !=
           ConnectionObjectGetTToORequestedPacketInterval(iterator)) {
         return kConnectionManagerExtendedStatusCodeErrorRpiValuesNotAcceptable;
       }
@@ -213,13 +213,13 @@ EipUint16 SetupIoConnectionTargetToOriginatorConnectionPoint(
       }
 
       if (ConnectionObjectGetTransportClassTriggerTransportClass(
-              io_connection_object) !=
+            io_connection_object) !=
           ConnectionObjectGetTransportClassTriggerTransportClass(iterator)) {
         return kConnectionManagerExtendedStatusCodeMismatchedTransportClass;
       }
 
       if (ConnectionObjectGetTransportClassTriggerProductionTrigger(
-              io_connection_object) !=
+            io_connection_object) !=
           ConnectionObjectGetTransportClassTriggerProductionTrigger(iterator)) {
         return kConnectionManagerExtendedStatusCodeMismatchedTToOProductionTrigger;
       }
@@ -238,20 +238,20 @@ EipUint16 SetupIoConnectionTargetToOriginatorConnectionPoint(
   CipInstance* instance          = NULL;
   if (NULL !=
       (instance = GetCipInstance(
-           assembly_class, io_connection_object->produced_path.instance_id))) {
+         assembly_class, io_connection_object->produced_path.instance_id))) {
     io_connection_object->producing_instance = instance;
     int data_size = ConnectionObjectGetTToOConnectionSize(io_connection_object);
     int diff_size = 0;
     /* an assembly object should always have a data attribute. */
     io_connection_object->produced_path.attribute_id_or_connection_point =
-        kAssemblyObjectInstanceAttributeIdData;
+      kAssemblyObjectInstanceAttributeIdData;
     CipAttributeStruct* attribute =
-        GetCipAttribute(instance, kAssemblyObjectInstanceAttributeIdData);
+      GetCipAttribute(instance, kAssemblyObjectInstanceAttributeIdData);
     OPENER_ASSERT(attribute != NULL);
     bool is_heartbeat = (((CipByteArray*)attribute->data)->length == 0);
     if (kConnectionObjectTransportClassTriggerTransportClass1 ==
         ConnectionObjectGetTransportClassTriggerTransportClass(
-            io_connection_object)) {
+          io_connection_object)) {
       /* class 1 connection */
       data_size -= 2; /* remove 16-bit sequence count length */
       diff_size += 2;
@@ -264,7 +264,7 @@ EipUint16 SetupIoConnectionTargetToOriginatorConnectionPoint(
     if (((CipByteArray*)attribute->data)->length != data_size) {
       /*wrong connection size*/
       connection_object->correct_target_to_originator_size =
-          ((CipByteArray*)attribute->data)->length + diff_size;
+        ((CipByteArray*)attribute->data)->length + diff_size;
       return kConnectionManagerExtendedStatusCodeErrorInvalidTToOConnectionSize;
     }
   } else {
@@ -287,12 +287,12 @@ EipUint16 SetupIoConnectionTargetToOriginatorConnectionPoint(
  *    - On an error the general status code to be put into the response
  */
 CipError EstablishIoConnection(
-    CipConnectionObject* RESTRICT const connection_object,
-    EipUint16* const extended_error) {
+  CipConnectionObject* RESTRICT const connection_object,
+  EipUint16* const extended_error) {
   CipError cip_error = kCipErrorSuccess;
 
   CipConnectionObject* io_connection_object =
-      GetIoConnectionForConnectionData(connection_object, extended_error);
+    GetIoConnectionForConnectionData(connection_object, extended_error);
   if (NULL == io_connection_object) {
     return kCipErrorConnectionFailure;
   }
@@ -308,15 +308,15 @@ CipError EstablishIoConnection(
   ConnectionObjectGeneralConfiguration(io_connection_object);
 
   ConnectionObjectConnectionType originator_to_target_connection_type =
-      ConnectionObjectGetOToTConnectionType(io_connection_object);
+    ConnectionObjectGetOToTConnectionType(io_connection_object);
   ConnectionObjectConnectionType target_to_originator_connection_type =
-      ConnectionObjectGetTToOConnectionType(io_connection_object);
+    ConnectionObjectGetTToOConnectionType(io_connection_object);
 
   /** Already handled by forward open */
   OPENER_ASSERT(!(originator_to_target_connection_type ==
-                      kConnectionObjectConnectionTypeNull &&
+                    kConnectionObjectConnectionTypeNull &&
                   target_to_originator_connection_type ==
-                      kConnectionObjectConnectionTypeNull));
+                    kConnectionObjectConnectionTypeNull));
 
   io_connection_object->consuming_instance              = NULL;
   io_connection_object->consumed_connection_path_length = 0;
@@ -329,7 +329,7 @@ CipError EstablishIoConnection(
   if (originator_to_target_connection_type !=
       kConnectionObjectConnectionTypeNull) { /*setup consumer side*/
     *extended_error = SetupIoConnectionOriginatorToTargetConnectionPoint(
-        io_connection_object, connection_object);
+      io_connection_object, connection_object);
     if (kConnectionManagerExtendedStatusCodeSuccess != *extended_error) {
       return kCipErrorConnectionFailure;
     }
@@ -338,7 +338,7 @@ CipError EstablishIoConnection(
   if (target_to_originator_connection_type !=
       kConnectionObjectConnectionTypeNull) { /*setup producer side*/
     *extended_error = SetupIoConnectionTargetToOriginatorConnectionPoint(
-        io_connection_object, connection_object);
+      io_connection_object, connection_object);
     if (kConnectionManagerExtendedStatusCodeSuccess != *extended_error) {
       return kCipErrorConnectionFailure;
     }
@@ -366,10 +366,10 @@ CipError EstablishIoConnection(
 }
 
 static SocketAddressInfoItem* AllocateSocketAddressInfoItem(
-    CipCommonPacketFormatData* const common_packet_format_data, CipUint type) {
+  CipCommonPacketFormatData* const common_packet_format_data, CipUint type) {
   const int address_info_item_size =
-      sizeof(common_packet_format_data->address_info_item) /
-      sizeof(common_packet_format_data->address_info_item[0]);
+    sizeof(common_packet_format_data->address_info_item) /
+    sizeof(common_packet_format_data->address_info_item[0]);
 
   SocketAddressInfoItem* s = common_packet_format_data->address_info_item;
 
@@ -390,27 +390,27 @@ static SocketAddressInfoItem* AllocateSocketAddressInfoItem(
  * @return kEipStatusOk on success, otherwise kEipStatusError
  */
 EipStatus OpenConsumingPointToPointConnection(
-    CipConnectionObject* const connection_object,
-    CipCommonPacketFormatData* const common_packet_format_data) {
+  CipConnectionObject* const connection_object,
+  CipCommonPacketFormatData* const common_packet_format_data) {
   SocketAddressInfoItem* sock_addr_info = AllocateSocketAddressInfoItem(
-      common_packet_format_data, kCipItemIdSocketAddressInfoOriginatorToTarget);
+    common_packet_format_data, kCipItemIdSocketAddressInfoOriginatorToTarget);
 
   if (NULL == sock_addr_info) {
     OPENER_TRACE_ERR(
-        "OpenConsumingPointToPointConnection: could not allocate "
-        "socket address info.\n");
+      "OpenConsumingPointToPointConnection: could not allocate "
+      "socket address info.\n");
     return kEipStatusError;
   }
 
-  struct sockaddr_in addr = {.sin_family      = AF_INET,
-                             .sin_addr.s_addr = INADDR_ANY,
-                             .sin_port        = htons(kOpenerEipIoUdpPort)};
+  struct sockaddr_in addr = { .sin_family      = AF_INET,
+                              .sin_addr.s_addr = INADDR_ANY,
+                              .sin_port        = htons(kOpenerEipIoUdpPort) };
 
   CipUsint qos_for_socket = ConnectionObjectGetTToOPriority(connection_object);
   int error               = SetQos(qos_for_socket);
   if (error != 0) {
     OPENER_TRACE_ERR(
-        "cannot set QoS for UDP socket in OpenPointToPointConnection\n");
+      "cannot set QoS for UDP socket in OpenPointToPointConnection\n");
     return kEipStatusError;
   }
   /* store the address of the originator for packet scanning */
@@ -419,7 +419,7 @@ EipStatus OpenConsumingPointToPointConnection(
   connection_object->originator_address.sin_port = htons(kOpenerEipIoUdpPort);
 
   connection_object->socket[kUdpCommuncationDirectionConsuming] =
-      g_network_status.udp_io_messaging;
+    g_network_status.udp_io_messaging;
 
   sock_addr_info->length   = 16;
   sock_addr_info->type_id  = kCipItemIdSocketAddressInfoOriginatorToTarget;
@@ -433,8 +433,8 @@ EipStatus OpenConsumingPointToPointConnection(
 }
 
 CipError OpenProducingPointToPointConnection(
-    CipConnectionObject* connection_object,
-    CipCommonPacketFormatData* common_packet_format_data) {
+  CipConnectionObject* connection_object,
+  CipCommonPacketFormatData* common_packet_format_data) {
   /* the default port to be used if no port information is part of the forward
    * open request */
   in_port_t port = htons(kOpenerEipIoUdpPort);
@@ -457,31 +457,31 @@ CipError OpenProducingPointToPointConnection(
   int error               = SetQos(qos_for_socket);
   if (error != 0) {
     OPENER_TRACE_ERR(
-        "cannot set QoS for UDP socket in OpenPointToPointConnection\n");
+      "cannot set QoS for UDP socket in OpenPointToPointConnection\n");
     return kEipStatusError;
   }
 
   connection_object->socket[kUdpCommuncationDirectionProducing] =
-      g_network_status.udp_io_messaging;
+    g_network_status.udp_io_messaging;
 
   return kCipErrorSuccess;
 }
 
 EipStatus OpenProducingMulticastConnection(
-    CipConnectionObject* connection_object,
-    CipCommonPacketFormatData* common_packet_format_data) {
+  CipConnectionObject* connection_object,
+  CipCommonPacketFormatData* common_packet_format_data) {
   /* Here we look for existing multi-cast IO connections only. */
   CipConnectionObject* existing_connection_object =
-      GetExistingProducerIoConnection(
-          true, connection_object->produced_path.instance_id);
+    GetExistingProducerIoConnection(
+      true, connection_object->produced_path.instance_id);
 
   SocketAddressInfoItem* sock_addr_info = AllocateSocketAddressInfoItem(
-      common_packet_format_data, kCipItemIdSocketAddressInfoTargetToOriginator);
+    common_packet_format_data, kCipItemIdSocketAddressInfoTargetToOriginator);
 
   if (NULL == sock_addr_info) {
     OPENER_TRACE_ERR(
-        "OpenProducingMulticastConnection: could not allocate "
-        "socket address info.\n");
+      "OpenProducingMulticastConnection: could not allocate "
+      "socket address info.\n");
     return kEipStatusError;
   }
 
@@ -501,7 +501,7 @@ EipStatus OpenProducingMulticastConnection(
   } else {
     // we need to inform our originator on the correct connection id
     connection_object->cip_produced_connection_id =
-        existing_connection_object->cip_produced_connection_id;
+      existing_connection_object->cip_produced_connection_id;
   }
 
   // we have a connection reuse the data and the socket
@@ -512,12 +512,12 @@ EipStatus OpenProducingMulticastConnection(
      * especially in the case of time outs.
      */
     connection_object->socket[kUdpCommuncationDirectionProducing] =
-        existing_connection_object->socket[kUdpCommuncationDirectionProducing];
+      existing_connection_object->socket[kUdpCommuncationDirectionProducing];
     existing_connection_object->socket[kUdpCommuncationDirectionProducing] =
-        kEipInvalidSocket;
+      kEipInvalidSocket;
   } else { /* this connection will not produce the data */
     connection_object->socket[kUdpCommuncationDirectionProducing] =
-        kEipInvalidSocket;
+      kEipInvalidSocket;
   }
 
   sock_addr_info->length = 16;
@@ -525,7 +525,7 @@ EipStatus OpenProducingMulticastConnection(
   connection_object->remote_address.sin_family = AF_INET;
   connection_object->remote_address.sin_port = sock_addr_info->sin_port = port;
   connection_object->remote_address.sin_addr.s_addr = sock_addr_info->sin_addr =
-      g_tcpip.mcast_config.starting_multicast_address;
+    g_tcpip.mcast_config.starting_multicast_address;
   memset(sock_addr_info->nasin_zero, 0, 8);
   sock_addr_info->sin_family = htons(AF_INET);
 
@@ -540,9 +540,9 @@ EipStatus OpenProducingMulticastConnection(
  * @return kEipStatusOk on success, otherwise kEipStatusError
  */
 EipStatus OpenMulticastConnection(
-    UdpCommuncationDirection direction,
-    CipConnectionObject* connection_object,
-    CipCommonPacketFormatData* common_packet_format_data) {
+  UdpCommuncationDirection direction,
+  CipConnectionObject* connection_object,
+  CipCommonPacketFormatData* common_packet_format_data) {
   int j = -1;
 
   int address_info_item_which_contains_o_to_t = -1;
@@ -580,12 +580,12 @@ EipStatus OpenMulticastConnection(
 
   if (-1 == j) {
     OPENER_TRACE_ERR(
-        "no suitable addr info item available / O->T: %d, T->O: %d, Selector: "
-        "%d, direction: %d\n",
-        address_info_item_which_contains_o_to_t,
-        address_info_item_which_contains_t_to_o,
-        j,
-        direction);
+      "no suitable addr info item available / O->T: %d, T->O: %d, Selector: "
+      "%d, direction: %d\n",
+      address_info_item_which_contains_o_to_t,
+      address_info_item_which_contains_t_to_o,
+      j,
+      direction);
     return kEipStatusError;
   }
 
@@ -595,9 +595,9 @@ EipStatus OpenMulticastConnection(
      * address */
     common_packet_format_data->address_info_item[j].sin_family = htons(AF_INET);
     common_packet_format_data->address_info_item[j].sin_port =
-        htons(kOpenerEipIoUdpPort);
+      htons(kOpenerEipIoUdpPort);
     common_packet_format_data->address_info_item[j].sin_addr =
-        g_tcpip.mcast_config.starting_multicast_address;
+      g_tcpip.mcast_config.starting_multicast_address;
     memset(common_packet_format_data->address_info_item[j].nasin_zero, 0, 8);
     common_packet_format_data->address_info_item[j].length = 16;
   }
@@ -605,24 +605,24 @@ EipStatus OpenMulticastConnection(
   if (htons(AF_INET) !=
       common_packet_format_data->address_info_item[j].sin_family) {
     OPENER_TRACE_ERR(
-        "Sockaddr Info Item with wrong sin family value received\n");
+      "Sockaddr Info Item with wrong sin family value received\n");
     return kEipStatusError;
   }
 
   /* allocate an unused sockaddr struct to use */
-  struct sockaddr_in socket_address = {0};
+  struct sockaddr_in socket_address = { 0 };
   socket_address.sin_family =
-      ntohs(common_packet_format_data->address_info_item[j].sin_family);
+    ntohs(common_packet_format_data->address_info_item[j].sin_family);
   socket_address.sin_addr.s_addr =
-      common_packet_format_data->address_info_item[j].sin_addr;
+    common_packet_format_data->address_info_item[j].sin_addr;
   socket_address.sin_port =
-      common_packet_format_data->address_info_item[j].sin_port;
+    common_packet_format_data->address_info_item[j].sin_port;
 
   CipUsint qos_for_socket = ConnectionObjectGetTToOPriority(connection_object);
   int error               = SetQos(qos_for_socket);
   if (error != 0) {
     OPENER_TRACE_ERR(
-        "cannot set QoS for UDP socket in OpenMulticastConnection\n");
+      "cannot set QoS for UDP socket in OpenMulticastConnection\n");
     return kEipStatusError;
   }
   if (direction == kUdpCommuncationDirectionProducing) {
@@ -635,11 +635,11 @@ EipStatus OpenMulticastConnection(
     /* store the originators address */
     socket_address.sin_addr.s_addr = GetPeerAddress();
     common_packet_format_data->address_info_item[j].type_id =
-        kCipItemIdSocketAddressInfoOriginatorToTarget;
+      kCipItemIdSocketAddressInfoOriginatorToTarget;
     connection_object->originator_address = socket_address;
   } else {
     common_packet_format_data->address_info_item[j].type_id =
-        kCipItemIdSocketAddressInfoTargetToOriginator;
+      kCipItemIdSocketAddressInfoTargetToOriginator;
     connection_object->remote_address = socket_address;
   }
 
@@ -650,12 +650,12 @@ EipUint16 HandleConfigData(CipConnectionObject* connection_object) {
   CipClass* const assembly_class      = GetCipClass(kCipAssemblyClassCode);
   EipUint16 connection_manager_status = 0;
   CipInstance* config_instance        = GetCipInstance(
-      assembly_class, connection_object->configuration_path.instance_id);
+    assembly_class, connection_object->configuration_path.instance_id);
 
   if (0 != g_config_data_length) {
     OPENER_ASSERT(NULL != config_instance);
     if (ConnectionWithSameConfigPointExists(
-            connection_object->configuration_path.instance_id)) {
+          connection_object->configuration_path.instance_id)) {
       /* there is a connected connection with the same config point
        * we have to have the same data as already present in the config point*/
       CipAttributeStruct* attribute_three = GetCipAttribute(config_instance, 3);
@@ -664,18 +664,18 @@ EipUint16 HandleConfigData(CipConnectionObject* connection_object) {
       OPENER_ASSERT(NULL != attribute_three_data);
       if (attribute_three_data->length != g_config_data_length) {
         connection_manager_status =
-            kConnectionManagerExtendedStatusCodeErrorOwnershipConflict;
+          kConnectionManagerExtendedStatusCodeErrorOwnershipConflict;
         OPENER_TRACE_INFO(
-            "Hit an Ownership conflict in cipioconnection.c occurrence 1");
+          "Hit an Ownership conflict in cipioconnection.c occurrence 1");
       } else {
         /*FIXME check if this is correct */
         if (memcmp(attribute_three_data->data,
                    g_config_data_buffer,
                    g_config_data_length)) {
           connection_manager_status =
-              kConnectionManagerExtendedStatusCodeErrorOwnershipConflict;
+            kConnectionManagerExtendedStatusCodeErrorOwnershipConflict;
           OPENER_TRACE_INFO(
-              "Hit an Ownership conflict in cipioconnection.c occurrence 2");
+            "Hit an Ownership conflict in cipioconnection.c occurrence 2");
         }
       }
     } else {
@@ -683,10 +683,10 @@ EipUint16 HandleConfigData(CipConnectionObject* connection_object) {
          design this can be done rather efficiently */
       if (kEipStatusOk !=
           NotifyAssemblyConnectedDataReceived(
-              config_instance, g_config_data_buffer, g_config_data_length)) {
+            config_instance, g_config_data_buffer, g_config_data_length)) {
         OPENER_TRACE_WARN("Configuration data was invalid\n");
         connection_manager_status =
-            kConnectionManagerExtendedStatusCodeInvalidConfigurationApplicationPath;
+          kConnectionManagerExtendedStatusCodeInvalidConfigurationApplicationPath;
       }
     }
   }
@@ -701,26 +701,26 @@ static int transfer_master_connection(CipConnectionObject* connection_object) {
   CipConnectionObject* active;
 
   active = GetNextNonControlMasterConnection(
-      connection_object->produced_path.instance_id);
+    connection_object->produced_path.instance_id);
   if (!active) {
     return 1;
   }
 
   OPENER_TRACE_INFO("Transferring socket ownership\n");
   active->socket[kUdpCommuncationDirectionProducing] =
-      connection_object->socket[kUdpCommuncationDirectionProducing];
+    connection_object->socket[kUdpCommuncationDirectionProducing];
   connection_object->socket[kUdpCommuncationDirectionProducing] =
-      kEipInvalidSocket;
+    kEipInvalidSocket;
 
   memcpy(&(active->remote_address),
          &(connection_object->remote_address),
          sizeof(active->remote_address));
   active->eip_level_sequence_count_producing =
-      connection_object->eip_level_sequence_count_producing;
+    connection_object->eip_level_sequence_count_producing;
   active->sequence_count_producing =
-      connection_object->sequence_count_producing;
+    connection_object->sequence_count_producing;
   active->transmission_trigger_timer =
-      connection_object->transmission_trigger_timer;
+    connection_object->transmission_trigger_timer;
 
   return 0;
 }
@@ -728,9 +728,9 @@ static int transfer_master_connection(CipConnectionObject* connection_object) {
 /* Always sync any changes with HandleIoConnectionTimeout() */
 void CloseIoConnection(CipConnectionObject* RESTRICT connection_object) {
   ConnectionObjectInstanceType instance_type =
-      ConnectionObjectGetInstanceType(connection_object);
+    ConnectionObjectGetInstanceType(connection_object);
   ConnectionObjectConnectionType conn_type =
-      ConnectionObjectGetTToOConnectionType(connection_object);
+    ConnectionObjectGetTToOConnectionType(connection_object);
 
   CheckIoConnectionEvent(connection_object->consumed_path.instance_id,
                          connection_object->produced_path.instance_id,
@@ -742,32 +742,32 @@ void CloseIoConnection(CipConnectionObject* RESTRICT connection_object) {
       kConnectionObjectInstanceTypeIOInputOnly == instance_type) {
     if (kConnectionObjectConnectionTypeMulticast == conn_type &&
         kEipInvalidSocket !=
-            connection_object->socket[kUdpCommuncationDirectionProducing]) {
+          connection_object->socket[kUdpCommuncationDirectionProducing]) {
       OPENER_TRACE_INFO(
-          "Exclusive Owner or Input Only connection closed - Instance type: "
-          "%d\n",
-          instance_type);
+        "Exclusive Owner or Input Only connection closed - Instance type: "
+        "%d\n",
+        instance_type);
 
       if (transfer_master_connection(connection_object)) {
         /* No transfer, this was the last master connection, close all
          * listen only connections listening on the port */
         CloseAllConnectionsForInputWithSameType(
-            connection_object->produced_path.instance_id,
-            kConnectionObjectInstanceTypeIOListenOnly);
+          connection_object->produced_path.instance_id,
+          kConnectionObjectInstanceTypeIOListenOnly);
       }
     }
   }
 
   CloseCommunicationChannelsAndRemoveFromActiveConnectionsList(
-      connection_object);
+    connection_object);
 }
 
 /* Always sync any changes with CloseIoConnection() */
 void HandleIoConnectionTimeOut(CipConnectionObject* connection_object) {
   ConnectionObjectInstanceType instance_type =
-      ConnectionObjectGetInstanceType(connection_object);
+    ConnectionObjectGetInstanceType(connection_object);
   ConnectionObjectConnectionType conn_type =
-      ConnectionObjectGetTToOConnectionType(connection_object);
+    ConnectionObjectGetTToOConnectionType(connection_object);
   int handover = 0;
 
   CheckIoConnectionEvent(connection_object->consumed_path.instance_id,
@@ -778,26 +778,26 @@ void HandleIoConnectionTimeOut(CipConnectionObject* connection_object) {
   if (connection_object->last_package_watchdog_timer ==
       connection_object->inactivity_watchdog_timer) {
     CheckForTimedOutConnectionsAndCloseTCPConnections(
-        connection_object, CloseEncapsulationSessionBySockAddr);
+      connection_object, CloseEncapsulationSessionBySockAddr);
   }
 
   if (kConnectionObjectInstanceTypeIOExclusiveOwner == instance_type ||
       kConnectionObjectInstanceTypeIOInputOnly == instance_type) {
     if (kConnectionObjectConnectionTypeMulticast == conn_type &&
         kEipInvalidSocket !=
-            connection_object->socket[kUdpCommuncationDirectionProducing]) {
+          connection_object->socket[kUdpCommuncationDirectionProducing]) {
       OPENER_TRACE_INFO(
-          "Exclusive Owner or Input Only connection timed out - Instance type: "
-          "%d\n",
-          instance_type);
+        "Exclusive Owner or Input Only connection timed out - Instance type: "
+        "%d\n",
+        instance_type);
       /* we are the controlling input only connection find a new controller*/
 
       if (transfer_master_connection(connection_object)) {
         /* No transfer, this was the last master connection, close all
          * listen only connections listening on the port */
         CloseAllConnectionsForInputWithSameType(
-            connection_object->produced_path.instance_id,
-            kConnectionObjectInstanceTypeIOListenOnly);
+          connection_object->produced_path.instance_id,
+          kConnectionObjectInstanceTypeIOListenOnly);
       } else {
         handover = 1;
       }
@@ -807,11 +807,11 @@ void HandleIoConnectionTimeOut(CipConnectionObject* connection_object) {
   if (kConnectionObjectInstanceTypeIOExclusiveOwner == instance_type &&
       !handover) {
     CloseAllConnectionsForInputWithSameType(
-        connection_object->produced_path.instance_id,
-        kConnectionObjectInstanceTypeIOInputOnly);
+      connection_object->produced_path.instance_id,
+      kConnectionObjectInstanceTypeIOInputOnly);
     CloseAllConnectionsForInputWithSameType(
-        connection_object->produced_path.instance_id,
-        kConnectionObjectInstanceTypeIOListenOnly);
+      connection_object->produced_path.instance_id,
+      kConnectionObjectInstanceTypeIOListenOnly);
   }
 
   ConnectionObjectSetState(connection_object, kConnectionObjectStateTimedOut);
@@ -823,7 +823,7 @@ EipStatus SendConnectedData(CipConnectionObject* connection_object) {
    * opening and just change the variable data items e.g., sequence number */
 
   CipCommonPacketFormatData* common_packet_format_data =
-      &g_common_packet_format_data_item;
+    &g_common_packet_format_data_item;
   /* TODO(MartinMelikMerkumians) think on adding a CPF data item to the
    * S_CIP_ConnectionObject in order to remove the code here or even better
    * allocate memory in the connection object for storing the message to send
@@ -835,25 +835,25 @@ EipStatus SendConnectedData(CipConnectionObject* connection_object) {
   common_packet_format_data->item_count = 2;
   if (kConnectionObjectTransportClassTriggerTransportClass0 !=
       ConnectionObjectGetTransportClassTriggerTransportClass(
-          connection_object)) {
+        connection_object)) {
     // use Sequenced Address Items if not Connection Class 0
     common_packet_format_data->address_item.type_id =
-        kCipItemIdSequencedAddressItem;
+      kCipItemIdSequencedAddressItem;
     common_packet_format_data->address_item.length = 8;
     common_packet_format_data->address_item.data.sequence_number =
-        connection_object->eip_level_sequence_count_producing;
+      connection_object->eip_level_sequence_count_producing;
   } else {
     common_packet_format_data->address_item.type_id =
-        kCipItemIdConnectionAddress;
+      kCipItemIdConnectionAddress;
     common_packet_format_data->address_item.length = 4;
   }
   common_packet_format_data->address_item.data.connection_identifier =
-      connection_object->cip_produced_connection_id;
+    connection_object->cip_produced_connection_id;
 
   common_packet_format_data->data_item.type_id = kCipItemIdConnectedDataItem;
 
   CipByteArray* producing_instance_attributes =
-      (CipByteArray*)connection_object->producing_instance->attributes->data;
+    (CipByteArray*)connection_object->producing_instance->attributes->data;
   common_packet_format_data->data_item.length = 0;
 
   // notify the application that data will be sent immediately after the call
@@ -872,7 +872,7 @@ EipStatus SendConnectedData(CipConnectionObject* connection_object) {
 
   MoveMessageNOctets(-2, &outgoing_message);
   common_packet_format_data->data_item.length =
-      producing_instance_attributes->length;
+    producing_instance_attributes->length;
 
   bool is_heartbeat = (common_packet_format_data->data_item.length == 0);
   if (s_produce_run_idle && !is_heartbeat) {
@@ -881,7 +881,7 @@ EipStatus SendConnectedData(CipConnectionObject* connection_object) {
 
   if (kConnectionObjectTransportClassTriggerTransportClass1 ==
       ConnectionObjectGetTransportClassTriggerTransportClass(
-          connection_object)) {
+        connection_object)) {
     common_packet_format_data->data_item.length += 2;
     AddIntToMessage(common_packet_format_data->data_item.length,
                     &outgoing_message);
@@ -901,7 +901,7 @@ EipStatus SendConnectedData(CipConnectionObject* connection_object) {
          producing_instance_attributes->length);
 
   outgoing_message.current_message_position +=
-      producing_instance_attributes->length;
+    producing_instance_attributes->length;
   outgoing_message.used_message_length += producing_instance_attributes->length;
 
   return SendUdpData(&connection_object->remote_address, &outgoing_message);
@@ -915,7 +915,7 @@ EipStatus HandleReceivedIoConnectionData(CipConnectionObject* connection_object,
   /* check class 1 sequence number*/
   if (kConnectionObjectTransportClassTriggerTransportClass1 ==
       ConnectionObjectGetTransportClassTriggerTransportClass(
-          connection_object)) {
+        connection_object)) {
     EipUint16 sequence_buffer = GetUintFromMessage(&(data));
     if (SEQ_LEQ16(sequence_buffer,
                   connection_object->sequence_count_consuming)) {
@@ -936,7 +936,7 @@ EipStatus HandleReceivedIoConnectionData(CipConnectionObject* connection_object,
         CipIdentitySetExtendedDeviceStatus(kAtLeastOneIoConnectionInRunMode);
       } else {
         CipIdentitySetExtendedDeviceStatus(
-            kAtLeastOneIoConnectionEstablishedAllInIdleMode);
+          kAtLeastOneIoConnectionEstablishedAllInIdleMode);
       }
       if (g_run_idle_state != nRunIdleBuf) {
         RunIdleChanged(nRunIdleBuf);
@@ -949,9 +949,9 @@ EipStatus HandleReceivedIoConnectionData(CipConnectionObject* connection_object,
     }
 
     if (NotifyAssemblyConnectedDataReceived(
-            connection_object->consuming_instance,
-            (EipUint8* const)data,
-            data_length) != 0) {
+          connection_object->consuming_instance,
+          (EipUint8* const)data,
+          data_length) != 0) {
       return kEipStatusError;
     }
   }
@@ -965,13 +965,13 @@ CipError OpenCommunicationChannels(CipConnectionObject* connection_object) {
   /*get pointer to the CPF data, currently we have just one global instance of
    * the struct. This may change in the future*/
   CipCommonPacketFormatData* common_packet_format_data =
-      &g_common_packet_format_data_item;
+    &g_common_packet_format_data_item;
 
   ConnectionObjectConnectionType originator_to_target_connection_type =
-      ConnectionObjectGetOToTConnectionType(connection_object);
+    ConnectionObjectGetOToTConnectionType(connection_object);
 
   ConnectionObjectConnectionType target_to_originator_connection_type =
-      ConnectionObjectGetTToOConnectionType(connection_object);
+    ConnectionObjectGetTToOConnectionType(connection_object);
 
   /* open a connection "point to point" or "multicast" based on the
    * ConnectionParameter */
@@ -988,7 +988,7 @@ CipError OpenCommunicationChannels(CipConnectionObject* connection_object) {
              kConnectionObjectConnectionTypePointToPoint) {
     // Point to Point consuming
     if (OpenConsumingPointToPointConnection(
-            connection_object, common_packet_format_data) == kEipStatusError) {
+          connection_object, common_packet_format_data) == kEipStatusError) {
       OPENER_TRACE_ERR("error in PointToPoint consuming connection\n");
       return kCipErrorConnectionFailure;
     }
@@ -998,7 +998,7 @@ CipError OpenCommunicationChannels(CipConnectionObject* connection_object) {
       kConnectionObjectConnectionTypeMulticast) {
     // Multicast producing
     if (OpenProducingMulticastConnection(
-            connection_object, common_packet_format_data) == kEipStatusError) {
+          connection_object, common_packet_format_data) == kEipStatusError) {
       OPENER_TRACE_ERR("error in OpenMulticast Connection\n");
       return kCipErrorConnectionFailure;
     }
@@ -1006,7 +1006,7 @@ CipError OpenCommunicationChannels(CipConnectionObject* connection_object) {
              kConnectionObjectConnectionTypePointToPoint) {
     // Point to Point producing
     if (OpenProducingPointToPointConnection(
-            connection_object, common_packet_format_data) != kCipErrorSuccess) {
+          connection_object, common_packet_format_data) != kCipErrorSuccess) {
       OPENER_TRACE_ERR("error in PointToPoint producing connection\n");
       return kCipErrorConnectionFailure;
     }
@@ -1015,22 +1015,22 @@ CipError OpenCommunicationChannels(CipConnectionObject* connection_object) {
 }
 
 void CloseCommunicationChannelsAndRemoveFromActiveConnectionsList(
-    CipConnectionObject* connection_object) {
+  CipConnectionObject* connection_object) {
   if (kEipInvalidSocket !=
       connection_object->socket[kUdpCommuncationDirectionConsuming]) {
     CloseUdpSocket(
-        connection_object->socket[kUdpCommuncationDirectionConsuming]);
+      connection_object->socket[kUdpCommuncationDirectionConsuming]);
   }
 
   if (kEipInvalidSocket !=
       connection_object->socket[kUdpCommuncationDirectionProducing]) {
     CloseUdpSocket(
-        connection_object->socket[kUdpCommuncationDirectionProducing]);
+      connection_object->socket[kUdpCommuncationDirectionProducing]);
   }
 
   RemoveFromActiveConnections(connection_object);
   ConnectionObjectInitializeEmpty(connection_object);
   OPENER_TRACE_INFO(
-      "cipioconnection: "
-      "CloseCommunicationChannelsAndRemoveFromActiveConnectionsList\n");
+    "cipioconnection: "
+    "CloseCommunicationChannelsAndRemoveFromActiveConnectionsList\n");
 }

+ 3 - 3
source/src/cip/cipioconnection.h

@@ -56,8 +56,8 @@
  *    - On an error the general status code to be put into the response
  */
 CipError EstablishIoConnection(
-    CipConnectionObject* RESTRICT const connection_object,
-    EipUint16* const extended_error);
+  CipConnectionObject* RESTRICT const connection_object,
+  EipUint16* const extended_error);
 
 /** @brief Take the data given in the connection object structure and open the
  * necessary communication channels
@@ -76,7 +76,7 @@ CipError OpenCommunicationChannels(CipConnectionObject* connection_object);
  * @param connection_object pointer to the connection object data
  */
 void CloseCommunicationChannelsAndRemoveFromActiveConnectionsList(
-    CipConnectionObject* connection_object);
+  CipConnectionObject* connection_object);
 
 extern EipUint8* g_config_data_buffer;
 extern unsigned int g_config_data_length;

+ 44 - 46
source/src/cip/cipmessagerouter.c

@@ -47,9 +47,9 @@ EipStatus RegisterCipClass(CipClass* cip_class);
  * @return kEipStatusOk on success. otherwise kEipStatusError
  */
 CipError CreateMessageRouterRequestStructure(
-    const EipUint8* data,
-    EipInt16 data_length,
-    CipMessageRouterRequest* message_router_request);
+  const EipUint8* data,
+  EipInt16 data_length,
+  CipMessageRouterRequest* message_router_request);
 
 void InitializeCipMessageRouterClass(CipClass* cip_class) {
   CipClass* meta_class = cip_class->class_instance.cip_class;
@@ -108,25 +108,23 @@ void InitializeCipMessageRouterClass(CipClass* cip_class) {
                 kGetAttributeAll,
                 &GetAttributeAll,
                 "GetAttributeAll"); /* bind instance services to the metaclass*/
-  InsertService(meta_class,
-                kGetAttributeSingle,
-                &GetAttributeSingle,
-                "GetAttributeSingle");
+  InsertService(
+    meta_class, kGetAttributeSingle, &GetAttributeSingle, "GetAttributeSingle");
 }
 
 EipStatus CipMessageRouterInit() {
   CipClass* message_router = CreateCipClass(
-      kCipMessageRouterClassCode,        // class code
-      7,                                 // # of class attributes
-      7,                                 // # highest class attribute number
-      2,                                 // # of class services
-      0,                                 // # of instance attributes
-      0,                                 // # highest instance attribute number
-      1,                                 // # of instance services
-      1,                                 // # of instances
-      "message router",                  // class name
-      1,                                 // # class revision
-      InitializeCipMessageRouterClass);  // function pointer for initialization
+    kCipMessageRouterClassCode,        // class code
+    7,                                 // # of class attributes
+    7,                                 // # highest class attribute number
+    2,                                 // # of class services
+    0,                                 // # of instance attributes
+    0,                                 // # highest instance attribute number
+    1,                                 // # of instance services
+    1,                                 // # of instances
+    "message router",                  // class name
+    1,                                 // # class revision
+    InitializeCipMessageRouterClass);  // function pointer for initialization
   if (NULL == message_router) {
     return kEipStatusError;
   }
@@ -148,7 +146,7 @@ EipStatus CipMessageRouterInit() {
  */
 CipMessageRouterObject* GetRegisteredObject(EipUint32 class_id) {
   CipMessageRouterObject* object =
-      g_first_object; /* get pointer to head of class registration list */
+    g_first_object; /* get pointer to head of class registration list */
 
   while (NULL != object) {
     // for each entry in list
@@ -163,7 +161,7 @@ CipMessageRouterObject* GetRegisteredObject(EipUint32 class_id) {
 
 CipClass* GetCipClass(const CipUdint class_code) {
   CipMessageRouterObject* message_router_object =
-      GetRegisteredObject(class_code);
+    GetRegisteredObject(class_code);
 
   if (message_router_object) {
     return message_router_object->cip_class;
@@ -198,7 +196,7 @@ EipStatus RegisterCipClass(CipClass* cip_class) {
   }
   // create a new node at the end of the list
   *message_router_object =
-      (CipMessageRouterObject*)CipCalloc(1, sizeof(CipMessageRouterObject));
+    (CipMessageRouterObject*)CipCalloc(1, sizeof(CipMessageRouterObject));
   if (*message_router_object == 0) {
     return kEipStatusError; /* check for memory error*/
   }
@@ -219,32 +217,32 @@ EipStatus NotifyMessageRouter(EipUint8* data,
   OPENER_TRACE_INFO("NotifyMessageRouter: routing unconnected message\n");
   if (kCipErrorSuccess !=
       (status = CreateMessageRouterRequestStructure(
-           data,
-           data_length,
-           &g_message_router_request))) { /* error from create MR structure*/
+         data,
+         data_length,
+         &g_message_router_request))) { /* error from create MR structure*/
     OPENER_TRACE_ERR(
-        "NotifyMessageRouter: error from createMRRequeststructure\n");
+      "NotifyMessageRouter: error from createMRRequeststructure\n");
     message_router_response->general_status            = status;
     message_router_response->size_of_additional_status = 0;
     message_router_response->reserved                  = 0;
     message_router_response->reply_service =
-        (0x80 | g_message_router_request.service);
+      (0x80 | g_message_router_request.service);
   } else {
     /* forward request to appropriate Object if it is registered*/
     CipMessageRouterObject* registered_object =
-        GetRegisteredObject(g_message_router_request.request_path.class_id);
+      GetRegisteredObject(g_message_router_request.request_path.class_id);
     if (registered_object == 0) {
       OPENER_TRACE_ERR(
-          "NotifyMessageRouter: sending CIP_ERROR_OBJECT_DOES_NOT_EXIST reply, "
-          "class id 0x%x is not registered\n",
-          (unsigned)g_message_router_request.request_path.class_id);
+        "NotifyMessageRouter: sending CIP_ERROR_OBJECT_DOES_NOT_EXIST reply, "
+        "class id 0x%x is not registered\n",
+        (unsigned)g_message_router_request.request_path.class_id);
       // according to the test tool this should be the correct error flag
       // instead of CIP_ERROR_OBJECT_DOES_NOT_EXIST;
       message_router_response->general_status = kCipErrorPathDestinationUnknown;
       message_router_response->size_of_additional_status = 0;
       message_router_response->reserved                  = 0;
       message_router_response->reply_service =
-          (0x80 | g_message_router_request.service);
+        (0x80 | g_message_router_request.service);
     } else {
       /* call notify function from Object with ClassID
          (gMRRequest.RequestPath.ClassID) object will or will not make an reply
@@ -252,8 +250,8 @@ EipStatus NotifyMessageRouter(EipUint8* data,
       message_router_response->reserved = 0;
       OPENER_ASSERT(NULL != registered_object->cip_class);
       OPENER_TRACE_INFO(
-          "NotifyMessageRouter: calling notify function of class '%s'\n",
-          registered_object->cip_class->class_name);
+        "NotifyMessageRouter: calling notify function of class '%s'\n",
+        registered_object->cip_class->class_name);
       eip_status = NotifyClass(registered_object->cip_class,
                                &g_message_router_request,
                                message_router_response,
@@ -263,16 +261,16 @@ EipStatus NotifyMessageRouter(EipUint8* data,
 #ifdef OPENER_TRACE_ENABLED
       if (eip_status == kEipStatusError) {
         OPENER_TRACE_ERR(
-            "notifyMR: notify function of class '%s' returned an error\n",
-            registered_object->cip_class->class_name);
+          "notifyMR: notify function of class '%s' returned an error\n",
+          registered_object->cip_class->class_name);
       } else if (eip_status == kEipStatusOk) {
         OPENER_TRACE_INFO(
-            "notifyMR: notify function of class '%s' returned no reply\n",
-            registered_object->cip_class->class_name);
+          "notifyMR: notify function of class '%s' returned no reply\n",
+          registered_object->cip_class->class_name);
       } else {
         OPENER_TRACE_INFO(
-            "notifyMR: notify function of class '%s' returned a reply\n",
-            registered_object->cip_class->class_name);
+          "notifyMR: notify function of class '%s' returned a reply\n",
+          registered_object->cip_class->class_name);
       }
 #endif
     }
@@ -281,16 +279,16 @@ EipStatus NotifyMessageRouter(EipUint8* data,
 }
 
 CipError CreateMessageRouterRequestStructure(
-    const EipUint8* data,
-    EipInt16 data_length,
-    CipMessageRouterRequest* message_router_request) {
+  const EipUint8* data,
+  EipInt16 data_length,
+  CipMessageRouterRequest* message_router_request) {
   message_router_request->service = *data;
   data++;
   data_length--;
 
   size_t number_of_decoded_bytes;
   const EipStatus path_result = DecodePaddedEPath(
-      &(message_router_request->request_path), &data, &number_of_decoded_bytes);
+    &(message_router_request->request_path), &data, &number_of_decoded_bytes);
   if (path_result != kEipStatusOk) {
     return kCipErrorPathSegmentError;
   }
@@ -300,14 +298,14 @@ CipError CreateMessageRouterRequestStructure(
   } else {
     message_router_request->data = data;
     message_router_request->request_data_size =
-        data_length - number_of_decoded_bytes;
+      data_length - number_of_decoded_bytes;
     return kCipErrorSuccess;
   }
 }
 
 void DeleteAllClasses(void) {
   CipMessageRouterObject* message_router_object =
-      g_first_object; /* get pointer to head of class registration list */
+    g_first_object; /* get pointer to head of class registration list */
   CipMessageRouterObject* message_router_object_to_delete = NULL;
   CipInstance* instance                                   = NULL;
   CipInstance* instance_to_delete                         = NULL;
@@ -330,7 +328,7 @@ void DeleteAllClasses(void) {
 
     // free meta class data
     CipClass* meta_class =
-        message_router_object_to_delete->cip_class->class_instance.cip_class;
+      message_router_object_to_delete->cip_class->class_instance.cip_class;
     CipFree(meta_class->class_name);
     CipFree(meta_class->services);
     CipFree(meta_class->get_single_bit_mask);

+ 42 - 44
source/src/cip/cipqos.c

@@ -27,14 +27,14 @@
  *
  *  The global instance of the QoS object
  */
-CipQosObject g_qos = {.q_frames_enable   = false,
-                      .dscp.event        = DEFAULT_DSCP_EVENT,
-                      .dscp.general      = DEFAULT_DSCP_GENERAL,
-                      .dscp.urgent       = DEFAULT_DSCP_URGENT,
-                      .dscp.scheduled    = DEFAULT_DSCP_SCHEDULED,
-                      .dscp.high         = DEFAULT_DSCP_HIGH,
-                      .dscp.low          = DEFAULT_DSCP_LOW,
-                      .dscp.explicit_msg = DEFAULT_DSCP_EXPLICIT};
+CipQosObject g_qos = { .q_frames_enable   = false,
+                       .dscp.event        = DEFAULT_DSCP_EVENT,
+                       .dscp.general      = DEFAULT_DSCP_GENERAL,
+                       .dscp.urgent       = DEFAULT_DSCP_URGENT,
+                       .dscp.scheduled    = DEFAULT_DSCP_SCHEDULED,
+                       .dscp.high         = DEFAULT_DSCP_HIGH,
+                       .dscp.low          = DEFAULT_DSCP_LOW,
+                       .dscp.explicit_msg = DEFAULT_DSCP_EXPLICIT };
 
 /** @brief Active set of DSCP data inherits its data from the QoS object on
  * boot-up
@@ -43,13 +43,14 @@ CipQosObject g_qos = {.q_frames_enable   = false,
  * should come into effect only after a restart. Values are initialized with the
  * default values. Changes are activated via the Identity Reset function
  */
-static CipQosDscpValues s_active_dscp = {.event        = DEFAULT_DSCP_EVENT,
-                                         .general      = DEFAULT_DSCP_GENERAL,
-                                         .urgent       = DEFAULT_DSCP_URGENT,
-                                         .scheduled    = DEFAULT_DSCP_SCHEDULED,
-                                         .high         = DEFAULT_DSCP_HIGH,
-                                         .low          = DEFAULT_DSCP_LOW,
-                                         .explicit_msg = DEFAULT_DSCP_EXPLICIT};
+static CipQosDscpValues s_active_dscp = { .event     = DEFAULT_DSCP_EVENT,
+                                          .general   = DEFAULT_DSCP_GENERAL,
+                                          .urgent    = DEFAULT_DSCP_URGENT,
+                                          .scheduled = DEFAULT_DSCP_SCHEDULED,
+                                          .high      = DEFAULT_DSCP_HIGH,
+                                          .low       = DEFAULT_DSCP_LOW,
+                                          .explicit_msg =
+                                            DEFAULT_DSCP_EXPLICIT };
 
 /************** Functions ****************************************/
 
@@ -67,9 +68,9 @@ static CipQosDscpValues s_active_dscp = {.event        = DEFAULT_DSCP_EVENT,
  *          -1 .. error
  */
 int DecodeCipQoSAttribute(
-    void* const data,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response) {
+  void* const data,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response) {
   const EipUint8** const cip_message = &(message_router_request->data);
 
   int number_of_decoded_bytes = -1;
@@ -120,17 +121,17 @@ EipStatus CipQoSInit() {
   CipClass* qos_class = NULL;
 
   if ((qos_class =
-           CreateCipClass(kCipQoSClassCode,
-                          7,  // # class attributes
-                          7,  // # highest class attribute number
-                          2,  // # class services
-                          8,  // # instance attributes
-                          8,  // # highest instance attribute number
-                          2,  // # instance services
-                          1,  // # instances
-                          "Quality of Service",
-                          1,      // # class revision
-                          NULL))  // # function pointer for initialization
+         CreateCipClass(kCipQoSClassCode,
+                        7,  // # class attributes
+                        7,  // # highest class attribute number
+                        2,  // # class services
+                        8,  // # instance attributes
+                        8,  // # highest instance attribute number
+                        2,  // # instance services
+                        1,  // # instances
+                        "Quality of Service",
+                        1,      // # class revision
+                        NULL))  // # function pointer for initialization
       == 0) {
     return kEipStatusError;
   }
@@ -195,14 +196,10 @@ EipStatus CipQoSInit() {
                   (void*)&g_qos.dscp.explicit_msg,
                   kGetableSingle | kSetable | kNvDataFunc);
 
-  InsertService(qos_class,
-                kGetAttributeSingle,
-                &GetAttributeSingle,
-                "GetAttributeSingle");
-  InsertService(qos_class,
-                kSetAttributeSingle,
-                &SetAttributeSingle,
-                "SetAttributeSingle");
+  InsertService(
+    qos_class, kGetAttributeSingle, &GetAttributeSingle, "GetAttributeSingle");
+  InsertService(
+    qos_class, kSetAttributeSingle, &SetAttributeSingle, "SetAttributeSingle");
 
   return kEipStatusOk;
 }
@@ -213,13 +210,14 @@ void CipQosUpdateUsedSetQosValues(void) {
 
 void CipQosResetAttributesToDefaultValues(void) {
   static const CipQosDscpValues kDefaultValues = {
-      .event        = DEFAULT_DSCP_EVENT,
-      .general      = DEFAULT_DSCP_GENERAL,
-      .urgent       = DEFAULT_DSCP_URGENT,
-      .scheduled    = DEFAULT_DSCP_SCHEDULED,
-      .high         = DEFAULT_DSCP_HIGH,
-      .low          = DEFAULT_DSCP_LOW,
-      .explicit_msg = DEFAULT_DSCP_EXPLICIT};
+    .event        = DEFAULT_DSCP_EVENT,
+    .general      = DEFAULT_DSCP_GENERAL,
+    .urgent       = DEFAULT_DSCP_URGENT,
+    .scheduled    = DEFAULT_DSCP_SCHEDULED,
+    .high         = DEFAULT_DSCP_HIGH,
+    .low          = DEFAULT_DSCP_LOW,
+    .explicit_msg = DEFAULT_DSCP_EXPLICIT
+  };
   g_qos.q_frames_enable = false;
   g_qos.dscp            = kDefaultValues;
 }

+ 4 - 4
source/src/cip/cipstring.c

@@ -63,7 +63,7 @@ CipStringN* SetCipStringNByData(CipStringN* const cip_string,
     cip_string->length = str_len;
     cip_string->size   = size;
     cip_string->string =
-        CipCalloc(cip_string->length, cip_string->size * sizeof(CipOctet));
+      CipCalloc(cip_string->length, cip_string->size * sizeof(CipOctet));
     if (NULL == cip_string->string) {
       result             = NULL;
       cip_string->length = 0;
@@ -144,7 +144,7 @@ CipString2* SetCipString2ByData(CipString2* const cip_string,
 CipString2* SetCipString2ByCstr(CipString2* const cip_string,
                                 const char* const string) {
   return SetCipString2ByData(
-      cip_string, (CipUint)strlen(string) / 2, (const CipOctet*)string);
+    cip_string, (CipUint)strlen(string) / 2, (const CipOctet*)string);
 }
 
 CipString* ClearCipString(CipString* const cip_string) {
@@ -192,7 +192,7 @@ CipString* SetCipStringByData(CipString* const cip_string,
 CipString* SetCipStringByCstr(CipString* const cip_string,
                               const char* const string) {
   return SetCipStringByData(
-      cip_string, (CipUint)strlen(string), (const CipOctet*)string);
+    cip_string, (CipUint)strlen(string), (const CipOctet*)string);
 }
 
 CipShortString* ClearCipShortString(CipShortString* const cip_string) {
@@ -265,7 +265,7 @@ CipShortString* SetCipShortStringByData(CipShortString* const cip_string,
 CipShortString* SetCipShortStringByCstr(CipShortString* const cip_string,
                                         const char* const string) {
   return SetCipShortStringByData(
-      cip_string, (CipUsint)strlen(string), (const CipOctet*)string);
+    cip_string, (CipUsint)strlen(string), (const CipOctet*)string);
 }
 
 /* Ensures buf is NUL terminated, provided initial validation is successful */

+ 26 - 28
source/src/cip/cipstringi.c

@@ -22,19 +22,19 @@ void CipStringIDelete(CipStringI* const string) {
     switch (string->array_of_string_i_structs[i].char_string_struct) {
       case kCipShortString:
         ClearCipShortString(
-            (CipShortString*)&string->array_of_string_i_structs[i].string);
+          (CipShortString*)&string->array_of_string_i_structs[i].string);
         break;
       case kCipString:
         ClearCipString(
-            (CipString*)&string->array_of_string_i_structs[i].string);
+          (CipString*)&string->array_of_string_i_structs[i].string);
         break;
       case kCipString2:
         ClearCipString2(
-            (CipString2*)&string->array_of_string_i_structs[i].string);
+          (CipString2*)&string->array_of_string_i_structs[i].string);
         break;
       case kCipStringN:
         ClearCipStringN(
-            (CipStringN*)&string->array_of_string_i_structs[i].string);
+          (CipStringN*)&string->array_of_string_i_structs[i].string);
         break;
       default:
         OPENER_TRACE_ERR("CIP File: No valid String type received!\n");
@@ -125,7 +125,7 @@ void CipStringIDeepCopyInternalString(CipStringIStruct* const to,
       toString->length       = fromString->length;
       toString->size         = fromString->size;
       toString->string =
-          CipCalloc(toString->length, toString->size * sizeof(CipOctet));
+        CipCalloc(toString->length, toString->size * sizeof(CipOctet));
       memcpy(toString->string,
              fromString->string,
              toString->size * sizeof(CipOctet) * toString->length);
@@ -138,7 +138,7 @@ void CipStringIDeepCopyInternalString(CipStringIStruct* const to,
 void CipStringICopy(CipStringI* const to, const CipStringI* const from) {
   to->number_of_strings = from->number_of_strings;
   to->array_of_string_i_structs =
-      CipCalloc(to->number_of_strings, sizeof(CipStringIStruct));
+    CipCalloc(to->number_of_strings, sizeof(CipStringIStruct));
   for (size_t i = 0; i < to->number_of_strings; ++i) {
     CipStringIStruct* const toStruct   = to->array_of_string_i_structs + i;
     CipStringIStruct* const fromStruct = from->array_of_string_i_structs + i;
@@ -153,56 +153,54 @@ void CipStringICopy(CipStringI* const to, const CipStringI* const from) {
 }
 
 void CipStringIDecodeFromMessage(
-    CipStringI* data_to,
-    CipMessageRouterRequest* const message_router_request) {
+  CipStringI* data_to, CipMessageRouterRequest* const message_router_request) {
   CipStringI* target_stringI = data_to;
 
   target_stringI->number_of_strings =
-      GetUsintFromMessage(&message_router_request->data);
+    GetUsintFromMessage(&message_router_request->data);
 
   target_stringI->array_of_string_i_structs =
-      CipCalloc(target_stringI->number_of_strings, sizeof(CipStringIStruct));
+    CipCalloc(target_stringI->number_of_strings, sizeof(CipStringIStruct));
 
   for (size_t i = 0; i < target_stringI->number_of_strings; ++i) {
     target_stringI->array_of_string_i_structs[i].language_char_1 =
-        GetUsintFromMessage(&message_router_request->data);
+      GetUsintFromMessage(&message_router_request->data);
     target_stringI->array_of_string_i_structs[i].language_char_2 =
-        GetUsintFromMessage(&message_router_request->data);
+      GetUsintFromMessage(&message_router_request->data);
     target_stringI->array_of_string_i_structs[i].language_char_3 =
-        GetUsintFromMessage(&message_router_request->data);
+      GetUsintFromMessage(&message_router_request->data);
     target_stringI->array_of_string_i_structs[i].char_string_struct =
-        GetUsintFromMessage(&message_router_request->data);
+      GetUsintFromMessage(&message_router_request->data);
     target_stringI->array_of_string_i_structs[i].character_set =
-        GetUintFromMessage(&message_router_request->data);
+      GetUintFromMessage(&message_router_request->data);
 
     switch (target_stringI->array_of_string_i_structs[i].char_string_struct) {
       case kCipShortString: {
         target_stringI->array_of_string_i_structs[i].string =
-            CipCalloc(1, sizeof(CipShortString));
+          CipCalloc(1, sizeof(CipShortString));
         CipShortString* short_string =
-            (CipShortString*)(target_stringI->array_of_string_i_structs[i]
-                                  .string);
+          (CipShortString*)(target_stringI->array_of_string_i_structs[i]
+                              .string);
         CipUsint length = GetUsintFromMessage(&message_router_request->data);
         SetCipShortStringByData(
-            short_string, length, message_router_request->data);
+          short_string, length, message_router_request->data);
         message_router_request->data += length;
       } break;
       case kCipString: {
         target_stringI->array_of_string_i_structs[i].string =
-            CipCalloc(1, sizeof(CipString));
+          CipCalloc(1, sizeof(CipString));
         CipString* const string =
-            (CipString* const)target_stringI->array_of_string_i_structs[i]
-                .string;
+          (CipString* const)target_stringI->array_of_string_i_structs[i].string;
         CipUint length = GetUintFromMessage(&message_router_request->data);
         SetCipStringByData(string, length, message_router_request->data);
         message_router_request->data += length;
       } break;
       case kCipString2: {
         target_stringI->array_of_string_i_structs[i].string =
-            CipCalloc(1, sizeof(CipString2));
+          CipCalloc(1, sizeof(CipString2));
         CipString2* const string =
-            (CipString2* const)target_stringI->array_of_string_i_structs[i]
-                .string;
+          (CipString2* const)target_stringI->array_of_string_i_structs[i]
+            .string;
         CipUint length = GetUintFromMessage(&message_router_request->data);
         SetCipString2ByData(string, length, message_router_request->data);
         message_router_request->data += length * 2 * sizeof(CipOctet);
@@ -212,10 +210,10 @@ void CipStringIDecodeFromMessage(
         CipUint length = GetUintFromMessage(&message_router_request->data);
 
         target_stringI->array_of_string_i_structs[i].string =
-            CipCalloc(1, sizeof(CipStringN));
+          CipCalloc(1, sizeof(CipStringN));
         CipStringN* const string =
-            (CipStringN* const)target_stringI->array_of_string_i_structs[i]
-                .string;
+          (CipStringN* const)target_stringI->array_of_string_i_structs[i]
+            .string;
         SetCipStringNByData(string, length, size, message_router_request->data);
         message_router_request->data += length * size;
       } break;

+ 1 - 1
source/src/cip/cipstringi.h

@@ -16,7 +16,7 @@ bool CipStringIsAnyStringEmpty(const CipStringI* const string);
 void CipStringICopy(CipStringI* const to, const CipStringI* const from);
 
 void CipStringIDecodeFromMessage(
-    CipStringI* data_to, CipMessageRouterRequest* const message_router_request);
+  CipStringI* data_to, CipMessageRouterRequest* const message_router_request);
 
 bool CipStringICompare(const CipStringI* const stringI_1,
                        const CipStringI* const stringI_2);

+ 123 - 123
source/src/cip/ciptcpipinterface.c

@@ -36,7 +36,7 @@
  *   - CFG_CAPS is the matching initial value for .config_capability
  */
 #if defined(OPENER_TCPIP_IFACE_CFG_SETTABLE) && \
-    0 != OPENER_TCPIP_IFACE_CFG_SETTABLE
+  0 != OPENER_TCPIP_IFACE_CFG_SETTABLE
 #define IFACE_CFG_SET_MODE kSetable
 #define CFG_CAPS \
   (CFG_CAPS_DHCP_CLIENT | CFG_CAPS_CFG_SETTABLE | CFG_CAPS_CFG_CHG_NEEDS_RESET)
@@ -45,73 +45,67 @@
 #define CFG_CAPS (CFG_CAPS_DHCP_CLIENT)
 #endif
 
-/** definition of TCP/IP object instance 1 data */
+// definition of TCP/IP object instance 1 data
 CipTcpIpObject g_tcpip = {
-    .status = 0x01, /* attribute #1 TCP status with 1 we indicate that we got a
-                       valid configuration from DHCP, BOOTP or NV data */
-    .config_capability = CFG_CAPS, /* attribute #2 config_capability */
+    .status = 0x01,  // attribute #1 TCP status with 1 we indicate that we got
+                     // a valid configuration from DHCP, BOOTP or NV data
+    .config_capability = CFG_CAPS,  // attribute #2 config_capability
     .config_control =
-        0x02, /* attribute #3 config_control: 0x02 means that the device shall
-                 obtain its interface configuration values via DHCP. */
+        0x02,  // attribute #3 config_control: 0x02 means that the device shall
+               // obtain its interface configuration values via DHCP.
 #if 2 != OPENER_ETHLINK_INSTANCE_CNT
-    /* For the details where the physical_link_object path should point to,
-     * depending on the # of Ethernet Link objects refer to Vol. 2, Section
-     * 5-4.3.2.4 "Physical Link Object". */
-    .physical_link_object =
-        {
-            /* attribute #4 physical link object */
-            2,                           /* PathSize in 16 Bit chunks */
-            CIP_ETHERNETLINK_CLASS_CODE, /* Class Code */
-            OPENER_ETHLINK_INSTANCE_CNT, /* Instance # */
-            0 /* Attribute # (not used as this is the EPATH to the EthernetLink
-                 object)*/
-        },
+    // For the details where the physical_link_object path should point to,
+    // depending on the # of Ethernet Link objects refer to Vol. 2, Section
+    // 5-4.3.2.4 "Physical Link Object".
+
+    // attribute #4 physical link object
+    .physical_link_object = {2,  // PathSize in 16 Bit chunks
+                             CIP_ETHERNETLINK_CLASS_CODE,  // Class Code
+                             OPENER_ETHLINK_INSTANCE_CNT,  // Instance #
+                             // Attribute # (not used as this is the EPATH to
+                             // the EthernetLink object)
+                             0},
 #else
-    .physical_link_object =
-        {
-            /* attribute #4 physical link object */
-            0, /* PathSize in 16 Bit chunks */
-            0, /* Class Code */
-            0, /* Instance # */
-            0  /* Attribute # */
-        },
+    // attribute #4 physical link object
+    .physical_link_object = {
+      0,  // PathSize in 16 Bit chunks
+      0,  // Class Code
+      0,  // Instance #
+      0   // Attribute #
+    },
 #endif /* #if OPENER_ETHLINK_INSTANCE_CNT != 2 */
-    .interface_configuration =
-        {   /* attribute #5 interface_configuration */
-         0, /* IP address */
-         0, /* NetworkMask */
-         0, /* Gateway */
-         0, /* NameServer */
-         0, /* NameServer2 */
-         {
-             /* DomainName */
-             0,
-             NULL,
-         }},
-    .hostname =
-        {/* attribute #6 hostname */
-         0,
-         NULL},
-    .mcast_ttl_value = 1, /* attribute #8 mcast TTL value */
-    .mcast_config =
-        {
-            /* attribute #9 multicast configuration */
-            0, /* use the default allocation algorithm */
-            0, /* reserved */
-            1, /* we currently use only one multicast address */
-            0  /* the multicast address will be allocated on IP address
-                  configuration */
-        },
+    // attribute #5 interface_configuration
+    .interface_configuration = {
+      0,  // IP address
+      0,  // NetworkMask
+      0,  // Gateway
+      0,  // NameServer
+      0,  // NameServer2
+      // DomainName
+      { 0,
+        NULL,
+      }
+    },
+    // attribute #6 hostname
+    .hostname        = {0, NULL},
+    .mcast_ttl_value = 1,  // attribute #8 mcast TTL value
+    // attribute #9 multicast configuration
+    .mcast_config = {
+      0,  // use the default allocation algorithm
+      0,  // reserved
+      1,  // we currently use only one multicast address
+      0   // the multicast address will be allocated on IP address
+          // configuration
+    },
     .select_acd = false,
-    .encapsulation_inactivity_timeout =
-        120 /* attribute #13 encapsulation_inactivity_timeout, use a default
-               value of 120 */
-};
+    // attribute #13 encapsulation_inactivity_timeout, use a default
+    // value of 120 seconds
+    .encapsulation_inactivity_timeout = 120};
 
 /************** Static Functions *********************************/
 
 #if defined(OPENER_TCPIP_IFACE_CFG_SETTABLE) && \
-    0 != OPENER_TCPIP_IFACE_CFG_SETTABLE
+  0 != OPENER_TCPIP_IFACE_CFG_SETTABLE
 /** Check for pb being an alphanumerical character
  *
  * Is slow but avoids issues with the locale if we're NOT in the 'C' locale.
@@ -306,7 +300,7 @@ static bool IsIOConnectionActive(void) {
     CipConnectionObject* connection = node->data;
     if (ConnectionObjectIsTypeIOConnection(connection) &&
         kConnectionObjectStateTimedOut !=
-            ConnectionObjectGetState(connection)) {
+          ConnectionObjectGetState(connection)) {
       /* An IO connection is present but is only considered active
        *  if it is NOT in timeout state. */
       return true;
@@ -316,19 +310,19 @@ static bool IsIOConnectionActive(void) {
 
   return false;
 }
-#endif /* defined (OPENER_TCPIP_IFACE_CFG_SETTABLE) && 0 != \
-          OPENER_TCPIP_IFACE_CFG_SETTABLE*/
+#endif  // defined (OPENER_TCPIP_IFACE_CFG_SETTABLE) &&
+        // 0 != OPENER_TCPIP_IFACE_CFG_SETTABLE
 
-static CipUsint dummy_data_field =
-    0; /**< dummy data fiel to provide non-null data pointers for attributes
-          without data fields */
+/// dummy data field to provide non-null data pointers for attributes without
+/// data fields
+static CipUsint dummy_data_field = 0;
 
 /************** Functions ****************************************/
 
 void EncodeCipTcpIpInterfaceConfiguration(const void* const data,
                                           ENIPMessage* const outgoing_message) {
   CipTcpIpInterfaceConfiguration* tcp_ip_network_interface_configuration =
-      (CipTcpIpInterfaceConfiguration*)data;
+    (CipTcpIpInterfaceConfiguration*)data;
   AddDintToMessage(ntohl(tcp_ip_network_interface_configuration->ip_address),
                    outgoing_message);
   AddDintToMessage(ntohl(tcp_ip_network_interface_configuration->network_mask),
@@ -355,7 +349,7 @@ void EncodeCipTcpIpMulticastConfiguration(const void* const data,
                 outgoing_message);
 
   CipUdint multicast_address =
-      ntohl(g_tcpip.mcast_config.starting_multicast_address);
+    ntohl(g_tcpip.mcast_config.starting_multicast_address);
 
   EncodeCipUdint(&multicast_address, outgoing_message);
 }
@@ -374,22 +368,22 @@ void EncodeCipLastConflictDetected(const void* const data,
   (void)data;
 
   const size_t kAttribute11Size =
-      sizeof(CipUsint) + 6 * sizeof(CipUsint) + 28 * sizeof(CipUsint);
+    sizeof(CipUsint) + 6 * sizeof(CipUsint) + 28 * sizeof(CipUsint);
   OPENER_ASSERT(kAttribute11Size == 35);
   FillNextNMessageOctetsWithValueAndMoveToNextPosition(
-      0, kAttribute11Size, outgoing_message);
+    0, kAttribute11Size, outgoing_message);
 }
 
 int DecodeTcpIpInterfaceConfigurationControl(/* Attribute 3 */
                                              void* const data,
                                              CipMessageRouterRequest* const
-                                                 message_router_request,
+                                               message_router_request,
                                              CipMessageRouterResponse* const
-                                                 message_router_response) {
+                                               message_router_response) {
   int number_of_decoded_bytes = -1;
 
   CipDword configuration_control_received =
-      GetDintFromMessage(&(message_router_request->data));
+    GetDintFromMessage(&(message_router_request->data));
   if ((configuration_control_received & kTcpipCfgCtrlMethodMask) >= 0x03 ||
       (configuration_control_received & ~kTcpipCfgCtrlMethodMask)) {
     message_router_response->general_status = kCipErrorInvalidAttributeValue;
@@ -397,7 +391,7 @@ int DecodeTcpIpInterfaceConfigurationControl(/* Attribute 3 */
   } else {
     /* Set reserved bits to zero on reception. */
     configuration_control_received &=
-        (kTcpipCfgCtrlMethodMask | kTcpipCfgCtrlDnsEnable);
+      (kTcpipCfgCtrlMethodMask | kTcpipCfgCtrlDnsEnable);
 
     *(CipDword*)data                        = configuration_control_received;
     number_of_decoded_bytes                 = 4;
@@ -408,15 +402,15 @@ int DecodeTcpIpInterfaceConfigurationControl(/* Attribute 3 */
 }
 
 #if defined(OPENER_TCPIP_IFACE_CFG_SETTABLE) && \
-    0 != OPENER_TCPIP_IFACE_CFG_SETTABLE
+  0 != OPENER_TCPIP_IFACE_CFG_SETTABLE
 
 int DecodeCipTcpIpInterfaceConfiguration(/* Attribute 5 */
                                          CipTcpIpInterfaceConfiguration* const
-                                             data,  // kCipUdintUdintUdintUdintUdintString
+                                           data,  // kCipUdintUdintUdintUdintUdintString
                                          CipMessageRouterRequest* const
-                                             message_router_request,
+                                           message_router_request,
                                          CipMessageRouterResponse* const
-                                             message_router_response) {
+                                           message_router_response) {
   int number_of_decoded_bytes = -1;
 
   CipTcpIpInterfaceConfiguration if_cfg;
@@ -444,18 +438,18 @@ int DecodeCipTcpIpInterfaceConfiguration(/* Attribute 5 */
   if_cfg.name_server_2 = htonl(tmp_ip);
 
   CipUint domain_name_length =
-      GetUintFromMessage(&(message_router_request->data));
+    GetUintFromMessage(&(message_router_request->data));
   if (domain_name_length >
       48) { /* see Vol. 2, Table 5-4.3 Instance Attributes */
     message_router_response->general_status = kCipErrorTooMuchData;
     return number_of_decoded_bytes;
   }
   SetCipStringByData(
-      &if_cfg.domain_name, domain_name_length, message_router_request->data);
+    &if_cfg.domain_name, domain_name_length, message_router_request->data);
   domain_name_length =
-      (domain_name_length + 1) & (~0x0001u); /* Align for possible pad byte */
+    (domain_name_length + 1) & (~0x0001u); /* Align for possible pad byte */
   OPENER_TRACE_INFO(
-      "Domain: ds %hu '%s'\n", domain_name_length, if_cfg.domain_name.string);
+    "Domain: ds %hu '%s'\n", domain_name_length, if_cfg.domain_name.string);
 
   if (!IsValidNetworkConfig(&if_cfg) ||
       (domain_name_length > 0 && !IsValidDomain(if_cfg.domain_name.string))) {
@@ -476,24 +470,24 @@ int DecodeCipTcpIpInterfaceConfiguration(/* Attribute 5 */
 int DecodeCipTcpIpInterfaceHostName(/* Attribute 6 */
                                     CipString* const data,
                                     CipMessageRouterRequest* const
-                                        message_router_request,
+                                      message_router_request,
                                     CipMessageRouterResponse* const
-                                        message_router_response) {
+                                      message_router_response) {
   int number_of_decoded_bytes = -1;
 
-  CipString tmp_host_name = {.length = 0u, .string = NULL};
+  CipString tmp_host_name = { .length = 0u, .string = NULL };
   CipUint host_name_length =
-      GetUintFromMessage(&(message_router_request->data));
+    GetUintFromMessage(&(message_router_request->data));
   if (host_name_length > 64) { /* see RFC 1123 on more details */
     message_router_response->general_status = kCipErrorTooMuchData;
     return number_of_decoded_bytes;
   }
   SetCipStringByData(
-      &tmp_host_name, host_name_length, message_router_request->data);
+    &tmp_host_name, host_name_length, message_router_request->data);
   host_name_length =
-      (host_name_length + 1) & (~0x0001u); /* Align for possible pad byte */
+    (host_name_length + 1) & (~0x0001u); /* Align for possible pad byte */
   OPENER_TRACE_INFO(
-      "Host Name: ds %hu '%s'\n", host_name_length, tmp_host_name.string);
+    "Host Name: ds %hu '%s'\n", host_name_length, tmp_host_name.string);
 
   if (!IsValidNameLabel(tmp_host_name.string)) {
     message_router_response->general_status = kCipErrorInvalidAttributeValue;
@@ -509,21 +503,28 @@ int DecodeCipTcpIpInterfaceHostName(/* Attribute 6 */
   return number_of_decoded_bytes;
 }
 
-#endif /* defined (OPENER_TCPIP_IFACE_CFG_SETTABLE) && 0 != \
-          OPENER_TCPIP_IFACE_CFG_SETTABLE*/
-
-int DecodeCipTcpIpInterfaceEncapsulationInactivityTimeout(/* Attribute 13 */
-                                                          void* const data,
-                                                          CipMessageRouterRequest* const
-                                                              message_router_request,
-                                                          CipMessageRouterResponse* const
-                                                              message_router_response) {
+#endif  // defined (OPENER_TCPIP_IFACE_CFG_SETTABLE) && 0 !=
+        // OPENER_TCPIP_IFACE_CFG_SETTABLE*/
+
+/** @brief Decodes Attribute 13 from a request and sets the inactivity timeout
+ *      value if valid.
+ * @param data Pointer to the attribute data where to store the decoded value.
+ * @param message_router_request Pointer to the message router request
+ *      containing the data to decode.
+ * @param message_router_response Pointer to the message router response
+ *      to set the general status in.
+ * @return Number of decoded bytes or -1 on error.
+ */
+int DecodeCipTcpIpInterfaceEncapsulationInactivityTimeout(
+  void* const data,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response) {
   int number_of_decoded_bytes = -1;
 
   CipUint inactivity_timeout_received =
-      GetUintFromMessage(&(message_router_request->data));
+    GetUintFromMessage(&(message_router_request->data));
 
-  if (inactivity_timeout_received > 3600) {
+  if (inactivity_timeout_received > 3600U) {
     message_router_response->general_status = kCipErrorInvalidAttributeValue;
   } else {
     *(CipUint*)data                         = inactivity_timeout_received;
@@ -538,24 +539,23 @@ EipStatus CipTcpIpInterfaceInit() {
   CipClass* tcp_ip_class = NULL;
 
   if ((tcp_ip_class =
-           CreateCipClass(kCipTcpIpInterfaceClassCode, /* class code */
-                          0,                           /* # class attributes */
-                          7,  /* # highest class attribute number */
-                          2,  /* # class services */
-                          13, /* # instance attributes */
-                          13, /* # highest instance attribute number */
-                          3,  /* # instance services */
-                          1,  /* # instances */
-                          "TCP/IP interface",
-                          4,   /* # class revision */
-                          NULL /* # function pointer for initialization */
-                          )) == 0) {
+         CreateCipClass(kCipTcpIpInterfaceClassCode,  // class code
+                        0,                            // # class attributes
+                        7,   // # highest class attribute number
+                        2,   // # class services
+                        13,  // # instance attributes
+                        13,  // # highest instance attribute number
+                        3,   // # instance services
+                        1,   // # instances
+                        "TCP/IP interface",
+                        4,      // # class revision
+                        NULL))  // # function pointer for initialization
+      == 0) {
     return kEipStatusError;
   }
 
-  CipInstance* instance = GetCipInstance(
-      tcp_ip_class,
-      1); /* bind attributes to the instance #1 that was created above */
+  // bind attributes to the instance #1 that was created above
+  CipInstance* instance = GetCipInstance(tcp_ip_class, 1);
 
   InsertAttribute(instance,
                   1,
@@ -587,7 +587,7 @@ EipStatus CipTcpIpInterfaceInit() {
                   kGetableSingleAndAll);
 
 #if defined(OPENER_TCPIP_IFACE_CFG_SETTABLE) && \
-    0 != OPENER_TCPIP_IFACE_CFG_SETTABLE
+  0 != OPENER_TCPIP_IFACE_CFG_SETTABLE
   InsertAttribute(instance,
                   5,
                   kCipUdintUdintUdintUdintUdintString,
@@ -619,8 +619,8 @@ EipStatus CipTcpIpInterfaceInit() {
                   &g_tcpip.hostname,
                   kGetableSingleAndAll | kNvDataFunc | IFACE_CFG_SET_MODE);
 
-#endif /* defined (OPENER_TCPIP_IFACE_CFG_SETTABLE) && 0 != \
-          OPENER_TCPIP_IFACE_CFG_SETTABLE*/
+#endif  // defined (OPENER_TCPIP_IFACE_CFG_SETTABLE) && 0 !=
+        // OPENER_TCPIP_IFACE_CFG_SETTABLE*/
 
   InsertAttribute(instance,
                   7,
@@ -678,7 +678,7 @@ EipStatus CipTcpIpInterfaceInit() {
                 "GetAttributeSingle");
 
   InsertService(
-      tcp_ip_class, kGetAttributeAll, &GetAttributeAll, "GetAttributeAll");
+    tcp_ip_class, kGetAttributeAll, &GetAttributeAll, "GetAttributeAll");
 
   InsertService(tcp_ip_class,
                 kSetAttributeSingle,
@@ -689,7 +689,7 @@ EipStatus CipTcpIpInterfaceInit() {
 }
 
 void ShutdownTcpIpInterface(void) {
-  /*Only free the resources if they are initialized */
+  // Only free the resources if they are initialized
   if (NULL != g_tcpip.hostname.string) {
     CipFree(g_tcpip.hostname.string);
     g_tcpip.hostname.string = NULL;
@@ -708,18 +708,18 @@ void ShutdownTcpIpInterface(void) {
  *  section 3-5.3 "Multicast Address Allocation for EtherNet/IP"
  */
 void CipTcpIpCalculateMulticastIp(CipTcpIpObject* const tcpip) {
-  /* Multicast base address according to spec: 239.192.1.0 */
-  static const CipUdint cip_mcast_base_addr = 0xEFC00100;
+  // Multicast base address according to spec: 239.192.1.0
+  static const CipUdint cip_mcast_base_addr = 0xEFC00100UL;
 
-  /* Calculate the CIP multicast address. The multicast address is calculated,
-   * not input */
+  // Calculate the CIP multicast address. The multicast address is calculated,
+  // not input
   CipUdint host_id = ntohl(tcpip->interface_configuration.ip_address) &
                      ~ntohl(tcpip->interface_configuration.network_mask);
   host_id -= 1;
   host_id &= 0x3ff;
 
   tcpip->mcast_config.starting_multicast_address =
-      htonl(cip_mcast_base_addr + (host_id << 5));
+    htonl(cip_mcast_base_addr + (host_id << 5));
 }
 
 EipUint16 GetEncapsulationInactivityTimeout(CipInstance* instance) {

+ 16 - 16
source/src/cip/ciptcpipinterface.h

@@ -32,15 +32,15 @@ static const CipDword kTcpipStatusAcdFault = 0x80U;
 
 /* Declare constants for config_control attribute (#3) */
 static const CipDword kTcpipCfgCtrlStaticIp =
-    0x00U;  ///< IP configuration method is manual IP assignment
+  0x00U;  ///< IP configuration method is manual IP assignment
 static const CipDword kTcpipCfgCtrlBootp =
-    0x01U;  ///< IP configuration method is BOOTP
+  0x01U;  ///< IP configuration method is BOOTP
 static const CipDword kTcpipCfgCtrlDhcp =
-    0x02U;  ///< IP configuration method is DHCP
+  0x02U;  ///< IP configuration method is DHCP
 static const CipDword kTcpipCfgCtrlMethodMask =
-    0x0FU;  ///< bit mask for the method field
+  0x0FU;  ///< bit mask for the method field
 static const CipDword kTcpipCfgCtrlDnsEnable =
-    0x10U;  ///< enables DNS resolution on originator devices
+  0x10U;  ///< enables DNS resolution on originator devices
 
 /** @brief Multicast Configuration struct, called Mcast config
  *
@@ -53,9 +53,9 @@ typedef struct multicast_address_configuration {
   CipUint number_of_allocated_multicast_addresses;  ///< Number of IP multicast
                                                     ///< addresses allocated
   CipUdint
-      starting_multicast_address;  ///< Starting multicast address from which
-                                   ///< Num Mcast addresses are allocated Mcast
-                                   ///< addresses are allocated
+    starting_multicast_address;  ///< Starting multicast address from which
+                                 ///< Num Mcast addresses are allocated Mcast
+                                 ///< addresses are allocated
 } MulticastAddressConfiguration;
 
 /// @brief Declaration of the TCP/IP object's structure type
@@ -67,18 +67,18 @@ typedef struct {
   CipEpath physical_link_object;  ///< attribute #4 references the Ethernet Link
                                   ///< object for this  interface
   CipTcpIpInterfaceConfiguration
-      interface_configuration;  ///< attribute #5 IP, network mask, gateway,
-                                ///< name server 1 & 2, domain name
-  CipString hostname;           ///< #6 host name
-  CipUsint mcast_ttl_value;     ///< #8 the time to live value to be used for
-                                ///< multi-cast connections
+    interface_configuration;  ///< attribute #5 IP, network mask, gateway,
+                              ///< name server 1 & 2, domain name
+  CipString hostname;         ///< #6 host name
+  CipUsint mcast_ttl_value;   ///< #8 the time to live value to be used for
+                              ///< multi-cast connections
 
   MulticastAddressConfiguration
-      mcast_config;    ///< #9 The multicast configuration for this device
+    mcast_config;      ///< #9 The multicast configuration for this device
   CipBool select_acd;  ///< attribute #10 - Is ACD enabled?
   CipUint
-      encapsulation_inactivity_timeout;  /// #13 Number of seconds of inactivity
-                                         /// before TCP connection is closed
+    encapsulation_inactivity_timeout;  /// #13 Number of seconds of inactivity
+                                       /// before TCP connection is closed
 } CipTcpIpObject;
 
 /* global public variables */

+ 25 - 25
source/src/cip/ciptypes.h

@@ -37,9 +37,9 @@ typedef enum cip_data_types {
   kCipLword       = 0xD4,  ///< 64-bit bit string
   kCipString2     = 0xD5,  ///< Character string, 2 byte per character
   kCipFtime =
-      0xD6,  ///< Duration in micro-seconds, high resolution; range of DINT
+    0xD6,  ///< Duration in micro-seconds, high resolution; range of DINT
   kCipLtime =
-      0xD7,  ///< Duration in micro-seconds, high resolution, range of LINT
+    0xD7,  ///< Duration in micro-seconds, high resolution, range of LINT
   kCipItime       = 0xD8,  ///< Duration in milli-seconds, short; range of INT
   kCipStringN     = 0xD9,  ///< Character string, N byte per character
   kCipShortString = 0xDA,  ///< Character string, 1 byte per character, 1 byte
@@ -52,8 +52,8 @@ typedef enum cip_data_types {
   /* TODO: Check these codes */
   kCipUsintUsint = 0xA0,  ///< Used for CIP Identity attribute 4 Revision
   kCipUdintUdintUdintUdintUdintString =
-      0xA1,  ///< TCP/IP attribute 5 - IP address, subnet mask, gateway, IP name
-             ///< server 1, IP name server 2, domain name
+    0xA1,  ///< TCP/IP attribute 5 - IP address, subnet mask, gateway, IP name
+           ///< server 1, IP name server 2, domain name
   kCip6Usint     = 0xA2,  ///< Struct for MAC Address (six USINTs)
   kCipMemberList = 0xA3,  ///< self-defined code for Member List
   kCipByteArray  = 0xA4,  ///< seld-defined code for Byte Array
@@ -231,9 +231,9 @@ typedef struct {
   EipUint8 path_size;  ///< Path size in 16 bit words (path_size * 16 bit)
   EipUint16 class_id;  ///< Class ID of the linked object
   CipInstanceNum
-      instance_number;  ///< Requested Instance Number of the linked object
+    instance_number;  ///< Requested Instance Number of the linked object
   EipUint16
-      attribute_number;  ///< Requested Attribute Number of the linked object
+    attribute_number;  ///< Requested Attribute Number of the linked object
 } CipEpath;
 
 typedef enum connection_point_type {
@@ -283,28 +283,28 @@ typedef struct enip_message ENIPMessage;
  */
 typedef struct {
   CipUsint
-      reply_service;  ///< Reply service code, the requested service code 0x80
+    reply_service;    ///< Reply service code, the requested service code 0x80
   CipOctet reserved;  ///< Reserved; Shall be zero
   CipUsint general_status;  ///< One of the General Status codes listed in CIP
                             ///< Specification Volume 1, Appendix B
   CipUsint size_of_additional_status;  ///< Number of additional 16 bit words in
                                        ///< Additional Status Array
   EipUint16 additional_status
-      [MAX_SIZE_OF_ADD_STATUS];  ///< Array of 16 bit words; Additional status;
-                                 ///< If SizeOfAdditionalStatus is 0. there is
-                                 ///< no Additional Status
-  ENIPMessage message;           ///< The constructed message
+    [MAX_SIZE_OF_ADD_STATUS];  ///< Array of 16 bit words; Additional status;
+                               ///< If SizeOfAdditionalStatus is 0. there is
+                               ///< no Additional Status
+  ENIPMessage message;         ///< The constructed message
 } CipMessageRouterResponse;
 
 /** @brief self-describing data encoding for CIP types */
 typedef void (*CipAttributeEncodeInMessage)(
-    const void* const data, ENIPMessage* const outgoing_message);
+  const void* const data, ENIPMessage* const outgoing_message);
 
 /** @brief self-describing data decoding for CIP types */
 typedef int (*CipAttributeDecodeFromMessage)(
-    void* const data,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response);
+  void* const data,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response);
 
 /** @brief Structure to describe a single CIP attribute of an object
  */
@@ -325,12 +325,12 @@ typedef struct {
  */
 typedef struct cip_instance {
   CipInstanceNum
-      instance_number;  ///< this instance's number (unique within the class)
+    instance_number;  ///< this instance's number (unique within the class)
   CipAttributeStruct* attributes;  ///< pointer to an array of attributes which
                                    ///< is unique to this instance
   struct cip_class* cip_class;     ///< class the instance belongs to
   struct cip_instance*
-      next;  ///< next instance, all instances of a class live in a linked list
+    next;  ///< next instance, all instances of a class live in a linked list
   void* data;  ///< pointer to instance data struct
 } CipInstance;
 
@@ -365,9 +365,9 @@ typedef EipStatus (*CipGetSetCallback)(CipInstance* const instance,
  *  @return           status of kEipStatusOk or kEipStatusError on failure
  */
 typedef EipStatus (*CipCallback)(
-    CipInstance* const instance,
-    const CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response);
+  CipInstance* const instance,
+  const CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response);
 
 /** @brief Type definition of CipClass that is a subclass of CipInstance */
 typedef struct cip_class {
@@ -439,11 +439,11 @@ typedef struct cip_class {
  *   should be sent
  */
 typedef EipStatus (*CipServiceFunction)(
-    CipInstance* const instance,
-    CipMessageRouterRequest* const message_router_request,
-    CipMessageRouterResponse* const message_router_response,
-    const struct sockaddr* originator_address,
-    const CipSessionHandle encapsulation_session);
+  CipInstance* const instance,
+  CipMessageRouterRequest* const message_router_request,
+  CipMessageRouterResponse* const message_router_response,
+  const struct sockaddr* originator_address,
+  const CipSessionHandle encapsulation_session);
 
 /** @brief Service descriptor. These are stored in an array */
 typedef struct cip_service_struct {

+ 1 - 1
source/src/core/trace.h

@@ -33,7 +33,7 @@
 #ifndef OPENER_TRACE_LEVEL
 #ifdef WIN32
 #pragma message( \
-    "OPENER_TRACE_LEVEL was not defined setting it to OPENER_TRACE_LEVEL_ERROR")
+  "OPENER_TRACE_LEVEL was not defined setting it to OPENER_TRACE_LEVEL_ERROR")
 #else
 #warning OPENER_TRACE_LEVEL was not defined setting it to OPENER_TRACE_LEVEL_ERROR
 #endif

+ 1 - 1
source/src/core/typedefs.h

@@ -41,7 +41,7 @@ typedef uint8_t EipBool8;   /**< bool data types */
 /** @brief Data types as defined in the CIP Specification Vol 1 Appendix C
  */
 typedef uint8_t
-    CipOctet;            /**< 8 bit value that indicates particular data type */
+  CipOctet;              /**< 8 bit value that indicates particular data type */
 typedef uint8_t CipBool; /**< Boolean data type */
 typedef uint8_t CipByte; /**< 8-bit bit string */
 typedef uint16_t CipWord;  /**< 16-bit bit string */

+ 147 - 149
source/src/enet_encap/cpf.c

@@ -18,9 +18,9 @@
 #include "trace.h"
 
 const size_t kItemCountFieldSize =
-    2; /**< The size of the item count field in the message */
+  2; /**< The size of the item count field in the message */
 const size_t KItemDataTypeIdFieldLength =
-    2; /**< The size of the item count field in the message */
+  2; /**< The size of the item count field in the message */
 
 /** @brief Size, in bytes, of the encoded sequenced address item data field.
  *
@@ -29,27 +29,27 @@ const size_t KItemDataTypeIdFieldLength =
 const EipUint16 kSequencedAddressItemLength = 8;
 
 CipCommonPacketFormatData
-    g_common_packet_format_data_item; /**< CPF global data items */
+  g_common_packet_format_data_item; /**< CPF global data items */
 
 static void InitializeMessageRouterResponse(
-    CipMessageRouterResponse* const message_router_response) {
+  CipMessageRouterResponse* const message_router_response) {
   memset(message_router_response, 0, sizeof(*message_router_response));
   InitializeENIPMessage(&message_router_response->message);
 }
 
 EipStatus NotifyCommonPacketFormat(
-    const EncapsulationData* const received_data,
-    const struct sockaddr* const originator_address,
-    ENIPMessage* const outgoing_message) {
+  const EncapsulationData* const received_data,
+  const struct sockaddr* const originator_address,
+  ENIPMessage* const outgoing_message) {
   EipStatus return_value = kEipStatusError;
   CipMessageRouterResponse message_router_response;
   InitializeMessageRouterResponse(&message_router_response);
 
   if (kEipStatusError ==
       (return_value = CreateCommonPacketFormatStructure(
-           received_data->current_communication_buffer_position,
-           received_data->data_length,
-           &g_common_packet_format_data_item))) {
+         received_data->current_communication_buffer_position,
+         received_data->data_length,
+         &g_common_packet_format_data_item))) {
     OPENER_TRACE_ERR("notifyCPF: error from createCPFstructure\n");
   } else {
     return_value = kEipStatusOkSend; /* In cases of errors we normally need to
@@ -61,27 +61,27 @@ EipStatus NotifyCommonPacketFormat(
     {                          /* found null address item*/
       if (g_common_packet_format_data_item.data_item.type_id ==
           kCipItemIdUnconnectedDataItem) { /* unconnected data item received*/
-        return_value = NotifyMessageRouter(
-            g_common_packet_format_data_item.data_item.data,
-            g_common_packet_format_data_item.data_item.length,
-            &message_router_response,
-            originator_address,
-            received_data->session_handle);
+        return_value =
+          NotifyMessageRouter(g_common_packet_format_data_item.data_item.data,
+                              g_common_packet_format_data_item.data_item.length,
+                              &message_router_response,
+                              originator_address,
+                              received_data->session_handle);
         if (return_value != kEipStatusError) {
           SkipEncapsulationHeader(outgoing_message);
           /* TODO: Here we get the status. What to do? kEipStatusError from
            * AssembleLinearMessage(). Its not clear how to transport this error
            * information to the requester. */
           EipStatus status =
-              AssembleLinearMessage(&message_router_response,
-                                    &g_common_packet_format_data_item,
-                                    outgoing_message);
+            AssembleLinearMessage(&message_router_response,
+                                  &g_common_packet_format_data_item,
+                                  outgoing_message);
           (void)status; /* Suppress unused variable warning. */
 
           /* Save pointer and move to start for Encapusulation Header */
           CipOctet* buffer = outgoing_message->current_message_position;
           outgoing_message->current_message_position =
-              outgoing_message->message_buffer;
+            outgoing_message->message_buffer;
           GenerateEncapsulationHeader(received_data,
                                       outgoing_message->used_message_length,
                                       received_data->session_handle,
@@ -94,8 +94,8 @@ EipStatus NotifyCommonPacketFormat(
       } else {
         /* wrong data item detected*/
         OPENER_TRACE_ERR(
-            "notifyCPF: got something besides the expected "
-            "CIP_ITEM_ID_UNCONNECTEDMESSAGE\n");
+          "notifyCPF: got something besides the expected "
+          "CIP_ITEM_ID_UNCONNECTEDMESSAGE\n");
         GenerateEncapsulationHeader(received_data,
                                     0,
                                     received_data->session_handle,
@@ -105,7 +105,7 @@ EipStatus NotifyCommonPacketFormat(
       }
     } else {
       OPENER_TRACE_ERR(
-          "notifyCPF: got something besides the expected CIP_ITEM_ID_NULL\n");
+        "notifyCPF: got something besides the expected CIP_ITEM_ID_NULL\n");
       GenerateEncapsulationHeader(received_data,
                                   0,
                                   received_data->session_handle,
@@ -118,13 +118,13 @@ EipStatus NotifyCommonPacketFormat(
 }
 
 EipStatus NotifyConnectedCommonPacketFormat(
-    const EncapsulationData* const received_data,
-    const struct sockaddr* const originator_address,
-    ENIPMessage* const outgoing_message) {
+  const EncapsulationData* const received_data,
+  const struct sockaddr* const originator_address,
+  ENIPMessage* const outgoing_message) {
   EipStatus return_value = CreateCommonPacketFormatStructure(
-      received_data->current_communication_buffer_position,
-      received_data->data_length,
-      &g_common_packet_format_data_item);
+    received_data->current_communication_buffer_position,
+    received_data->data_length,
+    &g_common_packet_format_data_item);
 
   if (kEipStatusError == return_value) {
     OPENER_TRACE_ERR("notifyConnectedCPF: error from createCPFstructure\n");
@@ -137,8 +137,8 @@ EipStatus NotifyConnectedCommonPacketFormat(
                                         should not be here*/
     {                                /* ConnectedAddressItem item */
       CipConnectionObject* connection_object =
-          GetConnectedObject(g_common_packet_format_data_item.address_item.data
-                                 .connection_identifier);
+        GetConnectedObject(g_common_packet_format_data_item.address_item.data
+                             .connection_identifier);
       if (NULL != connection_object) {
         /* reset the watchdog timer */
         ConnectionObjectResetInactivityWatchdogTimerValue(connection_object);
@@ -148,23 +148,22 @@ EipStatus NotifyConnectedCommonPacketFormat(
             kCipItemIdConnectedDataItem) { /* connected data item received*/
           EipUint8* buffer = g_common_packet_format_data_item.data_item.data;
           g_common_packet_format_data_item.address_item.data.sequence_number =
-              GetUintFromMessage((const EipUint8** const)&buffer);
+            GetUintFromMessage((const EipUint8** const)&buffer);
           OPENER_TRACE_INFO(
-              "Class 3 sequence number: %d, last sequence number: %d\n",
-              g_common_packet_format_data_item.address_item.data
-                  .sequence_number,
-              connection_object->sequence_count_consuming);
+            "Class 3 sequence number: %d, last sequence number: %d\n",
+            g_common_packet_format_data_item.address_item.data.sequence_number,
+            connection_object->sequence_count_consuming);
           if (connection_object->sequence_count_consuming ==
               g_common_packet_format_data_item.address_item.data
-                  .sequence_number) {
+                .sequence_number) {
             memcpy(outgoing_message,
                    &(connection_object->last_reply_sent),
                    sizeof(ENIPMessage));
             outgoing_message->current_message_position =
-                outgoing_message->message_buffer;
+              outgoing_message->message_buffer;
             /* Regenerate encapsulation header for new message */
             outgoing_message->used_message_length -=
-                ENCAPSULATION_HEADER_LENGTH;
+              ENCAPSULATION_HEADER_LENGTH;
             GenerateEncapsulationHeader(received_data,
                                         outgoing_message->used_message_length,
                                         received_data->session_handle,
@@ -175,37 +174,36 @@ EipStatus NotifyConnectedCommonPacketFormat(
             return kEipStatusOkSend;
           }
           connection_object->sequence_count_consuming =
-              g_common_packet_format_data_item.address_item.data
-                  .sequence_number;
+            g_common_packet_format_data_item.address_item.data.sequence_number;
 
           ConnectionObjectResetInactivityWatchdogTimerValue(connection_object);
 
           CipMessageRouterResponse message_router_response;
           InitializeMessageRouterResponse(&message_router_response);
           return_value = NotifyMessageRouter(
-              buffer,
-              g_common_packet_format_data_item.data_item.length - 2,
-              &message_router_response,
-              originator_address,
-              received_data->session_handle);
+            buffer,
+            g_common_packet_format_data_item.data_item.length - 2,
+            &message_router_response,
+            originator_address,
+            received_data->session_handle);
 
           if (return_value != kEipStatusError) {
             g_common_packet_format_data_item.address_item.data
-                .connection_identifier =
-                connection_object->cip_produced_connection_id;
+              .connection_identifier =
+              connection_object->cip_produced_connection_id;
             SkipEncapsulationHeader(outgoing_message);
             /* TODO: Here we get the status. What to do? kEipStatusError from
              * AssembleLinearMessage(). Its not clear how to transport this
              * error information to the requester. */
             EipStatus status =
-                AssembleLinearMessage(&message_router_response,
-                                      &g_common_packet_format_data_item,
-                                      outgoing_message);
+              AssembleLinearMessage(&message_router_response,
+                                    &g_common_packet_format_data_item,
+                                    outgoing_message);
             (void)status; /* Suppress unused variable warning. */
 
             CipOctet* pos = outgoing_message->current_message_position;
             outgoing_message->current_message_position =
-                outgoing_message->message_buffer;
+              outgoing_message->message_buffer;
             GenerateEncapsulationHeader(received_data,
                                         outgoing_message->used_message_length,
                                         received_data->session_handle,
@@ -220,25 +218,25 @@ EipStatus NotifyConnectedCommonPacketFormat(
         } else {
           /* wrong data item detected*/
           OPENER_TRACE_ERR(
-              "notifyConnectedCPF: got something besides the expected "
-              "CIP_ITEM_ID_UNCONNECTEDMESSAGE\n");
+            "notifyConnectedCPF: got something besides the expected "
+            "CIP_ITEM_ID_UNCONNECTEDMESSAGE\n");
         }
       } else {
         OPENER_TRACE_ERR(
-            "notifyConnectedCPF: connection with given ID could not be "
-            "found\n");
+          "notifyConnectedCPF: connection with given ID could not be "
+          "found\n");
       }
     } else {
       OPENER_TRACE_ERR(
-          "notifyConnectedCPF: got something besides the expected "
-          "CIP_ITEM_ID_NULL\n");
+        "notifyConnectedCPF: got something besides the expected "
+        "CIP_ITEM_ID_NULL\n");
     }
   }
   // return outgoing_message->used_message_length;
   return (
-      0 != outgoing_message->used_message_length
-          ? kEipStatusOkSend
-          : kEipStatusOk); /* TODO: What would the right EipStatus to return? */
+    0 != outgoing_message->used_message_length
+      ? kEipStatusOkSend
+      : kEipStatusOk); /* TODO: What would the right EipStatus to return? */
 }
 
 /**
@@ -251,9 +249,9 @@ EipStatus NotifyConnectedCommonPacketFormat(
  *             kEipStatusError .. error
  */
 EipStatus CreateCommonPacketFormatStructure(
-    const EipUint8* data,
-    size_t data_length,
-    CipCommonPacketFormatData* common_packet_format_data) {
+  const EipUint8* data,
+  size_t data_length,
+  CipCommonPacketFormatData* common_packet_format_data) {
   common_packet_format_data->address_info_item[0].type_id = 0;
   common_packet_format_data->address_info_item[1].type_id = 0;
 
@@ -269,12 +267,12 @@ EipStatus CreateCommonPacketFormatStructure(
     length_count += 4;
     if (common_packet_format_data->address_item.length >= 4) {
       common_packet_format_data->address_item.data.connection_identifier =
-          GetUdintFromMessage(&data);
+        GetUdintFromMessage(&data);
       length_count += 4;
     }
     if (common_packet_format_data->address_item.length == 8) {
       common_packet_format_data->address_item.data.sequence_number =
-          GetUdintFromMessage(&data);
+        GetUdintFromMessage(&data);
       length_count += 4;
     }
   }
@@ -292,29 +290,29 @@ EipStatus CreateCommonPacketFormatStructure(
 
     /* Data type per CIP Volume 2, Edition 1.4, Table 2-6.1. */
     CipUint address_item_count =
-        (CipUint)(common_packet_format_data->item_count - 2U);
+      (CipUint)(common_packet_format_data->item_count - 2U);
 
     for (size_t j = 0; j < (address_item_count > 2 ? 2 : address_item_count);
          j++) /* TODO there needs to be a limit check here???*/
     {
       common_packet_format_data->address_info_item[j].type_id =
-          GetIntFromMessage(&data);
+        GetIntFromMessage(&data);
       OPENER_TRACE_INFO(
-          "Sockaddr type id: %x\n",
-          common_packet_format_data->address_info_item[j].type_id);
+        "Sockaddr type id: %x\n",
+        common_packet_format_data->address_info_item[j].type_id);
       length_count += 2;
       if ((common_packet_format_data->address_info_item[j].type_id ==
            kCipItemIdSocketAddressInfoOriginatorToTarget) ||
           (common_packet_format_data->address_info_item[j].type_id ==
            kCipItemIdSocketAddressInfoTargetToOriginator)) {
         common_packet_format_data->address_info_item[j].length =
-            GetIntFromMessage(&data);
+          GetIntFromMessage(&data);
         common_packet_format_data->address_info_item[j].sin_family =
-            GetIntFromMessage(&data);
+          GetIntFromMessage(&data);
         common_packet_format_data->address_info_item[j].sin_port =
-            GetIntFromMessage(&data);
+          GetIntFromMessage(&data);
         common_packet_format_data->address_info_item[j].sin_addr =
-            GetUdintFromMessage(&data);
+          GetUdintFromMessage(&data);
         for (size_t i = 0; i < 8; i++) {
           common_packet_format_data->address_info_item[j].nasin_zero[i] = *data;
           data++;
@@ -322,7 +320,7 @@ EipStatus CreateCommonPacketFormatStructure(
         length_count += 18;
       } else { /* no sockaddr item found */
         common_packet_format_data->address_info_item[j].type_id =
-            0; /* mark as not set */
+          0; /* mark as not set */
         data -= 2;
       }
     }
@@ -339,8 +337,8 @@ EipStatus CreateCommonPacketFormatStructure(
     return kEipStatusOk;
   } else {
     OPENER_TRACE_WARN(
-        "something is wrong with the length in Message Router @ "
-        "CreateCommonPacketFormatStructure\n");
+      "something is wrong with the length in Message Router @ "
+      "CreateCommonPacketFormatStructure\n");
     if (common_packet_format_data->item_count > 2) {
       /* there is an optional packet in data stream which is not sockaddr item
        */
@@ -368,15 +366,15 @@ void EncodeNullAddressItem(ENIPMessage* const outgoing_message) {
  * @param outgoing_message The outgoing message object
  */
 void EncodeConnectedAddressItem(
-    const CipCommonPacketFormatData* const common_packet_format_data_item,
-    ENIPMessage* const outgoing_message) {
+  const CipCommonPacketFormatData* const common_packet_format_data_item,
+  ENIPMessage* const outgoing_message) {
   /* connected data item -> address length set to 4 and copy
    * ConnectionIdentifier */
   AddIntToMessage(kCipItemIdConnectionAddress, outgoing_message);
   AddIntToMessage(4, outgoing_message);
   AddDintToMessage(
-      common_packet_format_data_item->address_item.data.connection_identifier,
-      outgoing_message);
+    common_packet_format_data_item->address_item.data.connection_identifier,
+    outgoing_message);
 }
 
 /**
@@ -387,18 +385,18 @@ void EncodeConnectedAddressItem(
  * @param outgoing_message The outgoing message object
  */
 void EncodeSequencedAddressItem(
-    const CipCommonPacketFormatData* const common_packet_format_data_item,
-    ENIPMessage* const outgoing_message) {
+  const CipCommonPacketFormatData* const common_packet_format_data_item,
+  ENIPMessage* const outgoing_message) {
   /* sequenced address item -> address length set to 8 and copy
    * ConnectionIdentifier and SequenceNumber */
   AddIntToMessage(kCipItemIdSequencedAddressItem, outgoing_message);
   AddIntToMessage(kSequencedAddressItemLength, outgoing_message);
   AddDintToMessage(
-      common_packet_format_data_item->address_item.data.connection_identifier,
-      outgoing_message);
+    common_packet_format_data_item->address_item.data.connection_identifier,
+    outgoing_message);
   AddDintToMessage(
-      common_packet_format_data_item->address_item.data.sequence_number,
-      outgoing_message);
+    common_packet_format_data_item->address_item.data.sequence_number,
+    outgoing_message);
 }
 
 /**
@@ -409,8 +407,8 @@ void EncodeSequencedAddressItem(
  * @param outgoing_message The outgoing message object
  */
 void EncodeItemCount(
-    const CipCommonPacketFormatData* const common_packet_format_data_item,
-    ENIPMessage* const outgoing_message) {
+  const CipCommonPacketFormatData* const common_packet_format_data_item,
+  ENIPMessage* const outgoing_message) {
   AddIntToMessage(common_packet_format_data_item->item_count,
                   outgoing_message); /* item count */
 }
@@ -423,8 +421,8 @@ void EncodeItemCount(
  * @param outgoing_message The outgoing message object
  */
 void EncodeDataItemType(
-    const CipCommonPacketFormatData* const common_packet_format_data_item,
-    ENIPMessage* const outgoing_message) {
+  const CipCommonPacketFormatData* const common_packet_format_data_item,
+  ENIPMessage* const outgoing_message) {
   AddIntToMessage(common_packet_format_data_item->data_item.type_id,
                   outgoing_message);
 }
@@ -437,8 +435,8 @@ void EncodeDataItemType(
  * @param outgoing_message The outgoing message object
  */
 void EncodeDataItemLength(
-    const CipCommonPacketFormatData* const common_packet_format_data_item,
-    ENIPMessage* const outgoing_message) {
+  const CipCommonPacketFormatData* const common_packet_format_data_item,
+  ENIPMessage* const outgoing_message) {
   AddIntToMessage(common_packet_format_data_item->data_item.length,
                   outgoing_message);
 }
@@ -451,15 +449,15 @@ void EncodeDataItemLength(
  * @param outgoing_message The outgoing message object
  */
 void EncodeDataItemData(
-    const CipCommonPacketFormatData* const common_packet_format_data_item,
-    ENIPMessage* const outgoing_message) {
+  const CipCommonPacketFormatData* const common_packet_format_data_item,
+  ENIPMessage* const outgoing_message) {
   memcpy(outgoing_message->current_message_position,
          common_packet_format_data_item->data_item.data,
          common_packet_format_data_item->data_item.length);
   outgoing_message->current_message_position +=
-      common_packet_format_data_item->data_item.length;
+    common_packet_format_data_item->data_item.length;
   outgoing_message->used_message_length +=
-      common_packet_format_data_item->data_item.length;
+    common_packet_format_data_item->data_item.length;
 }
 
 /**
@@ -471,13 +469,13 @@ void EncodeDataItemData(
  */
 
 void EncodeConnectedDataItemLength(
-    const CipMessageRouterResponse* const message_router_response,
-    ENIPMessage* const outgoing_message) {
+  const CipMessageRouterResponse* const message_router_response,
+  ENIPMessage* const outgoing_message) {
   AddIntToMessage(
-      (EipUint16)(message_router_response->message.used_message_length + 4 +
-                  2 /* TODO: Magic numbers */
-                  + (2 * message_router_response->size_of_additional_status)),
-      outgoing_message);
+    (EipUint16)(message_router_response->message.used_message_length + 4 +
+                2 /* TODO: Magic numbers */
+                + (2 * message_router_response->size_of_additional_status)),
+    outgoing_message);
 }
 
 /**
@@ -487,10 +485,10 @@ void EncodeConnectedDataItemLength(
  * @param outgoing_message The outgoing message object
  */
 void EncodeSequenceNumber(
-    const CipCommonPacketFormatData* const common_packet_format_data_item,
-    ENIPMessage* const outgoing_message) {
+  const CipCommonPacketFormatData* const common_packet_format_data_item,
+  ENIPMessage* const outgoing_message) {
   AddIntToMessage((EipUint16)common_packet_format_data_item->address_item.data
-                      .sequence_number,
+                    .sequence_number,
                   outgoing_message);
 }
 
@@ -502,8 +500,8 @@ void EncodeSequenceNumber(
  * @param outgoing_message The outgoing message object
  */
 void EncodeReplyService(
-    const CipMessageRouterResponse* const message_router_response,
-    ENIPMessage* const outgoing_message) {
+  const CipMessageRouterResponse* const message_router_response,
+  ENIPMessage* const outgoing_message) {
   AddSintToMessage(message_router_response->reply_service, outgoing_message);
 }
 
@@ -514,8 +512,8 @@ void EncodeReplyService(
  * @param outgoing_message The outgoing message object
  */
 void EncodeReservedFieldOfLengthByte(
-    const CipMessageRouterResponse* const message_router_response,
-    ENIPMessage* const outgoing_message) {
+  const CipMessageRouterResponse* const message_router_response,
+  ENIPMessage* const outgoing_message) {
   AddSintToMessage(message_router_response->reserved, outgoing_message);
 }
 
@@ -526,8 +524,8 @@ void EncodeReservedFieldOfLengthByte(
  * @param outgoing_message The outgoing message object
  */
 void EncodeGeneralStatus(
-    const CipMessageRouterResponse* const message_router_response,
-    ENIPMessage* const outgoing_message) {
+  const CipMessageRouterResponse* const message_router_response,
+  ENIPMessage* const outgoing_message) {
   AddSintToMessage(message_router_response->general_status, outgoing_message);
 }
 
@@ -539,8 +537,8 @@ void EncodeGeneralStatus(
  */
 
 void EncodeExtendedStatusLength(
-    const CipMessageRouterResponse* const message_router_response,
-    ENIPMessage* const outgoing_message) {
+  const CipMessageRouterResponse* const message_router_response,
+  ENIPMessage* const outgoing_message) {
   AddSintToMessage(message_router_response->size_of_additional_status,
                    outgoing_message);
 }
@@ -552,8 +550,8 @@ void EncodeExtendedStatusLength(
  * @param outgoing_message The outgoing message object
  */
 void EncodeExtendedStatusDataItems(
-    const CipMessageRouterResponse* const message_router_response,
-    ENIPMessage* const outgoing_message) {
+  const CipMessageRouterResponse* const message_router_response,
+  ENIPMessage* const outgoing_message) {
   for (size_t i = 0; i < message_router_response->size_of_additional_status &&
                      i < MAX_SIZE_OF_ADD_STATUS;
        i++) {
@@ -574,8 +572,8 @@ void EncodeExtendedStatusDataItems(
  */
 
 void EncodeExtendedStatus(
-    const CipMessageRouterResponse* const message_router_response,
-    ENIPMessage* const outgoing_message) {
+  const CipMessageRouterResponse* const message_router_response,
+  ENIPMessage* const outgoing_message) {
   EncodeExtendedStatusLength(message_router_response, outgoing_message);
   EncodeExtendedStatusDataItems(message_router_response, outgoing_message);
 }
@@ -588,13 +586,13 @@ void EncodeExtendedStatus(
  *
  */
 void EncodeUnconnectedDataItemLength(
-    const CipMessageRouterResponse* const message_router_response,
-    ENIPMessage* const outgoing_message) {
+  const CipMessageRouterResponse* const message_router_response,
+  ENIPMessage* const outgoing_message) {
   AddIntToMessage(
-      (EipUint16)(message_router_response->message.used_message_length +
-                  4 /* TODO: Magic number */
-                  + (2 * message_router_response->size_of_additional_status)),
-      outgoing_message);
+    (EipUint16)(message_router_response->message.used_message_length +
+                4 /* TODO: Magic number */
+                + (2 * message_router_response->size_of_additional_status)),
+    outgoing_message);
 }
 
 /**
@@ -604,16 +602,16 @@ void EncodeUnconnectedDataItemLength(
  * @param outgoing_message The outgoing message object
  */
 void EncodeMessageRouterResponseData(
-    const CipMessageRouterResponse* const message_router_response,
-    ENIPMessage* const outgoing_message) {
+  const CipMessageRouterResponse* const message_router_response,
+  ENIPMessage* const outgoing_message) {
   memcpy(outgoing_message->current_message_position,
          message_router_response->message.message_buffer,
          message_router_response->message.used_message_length);
 
   outgoing_message->current_message_position +=
-      message_router_response->message.used_message_length;
+    message_router_response->message.used_message_length;
   outgoing_message->used_message_length +=
-      message_router_response->message.used_message_length;
+    message_router_response->message.used_message_length;
 }
 
 /**
@@ -625,13 +623,13 @@ void EncodeMessageRouterResponseData(
  * @param outgoing_message The outgoing message object
  */
 void EncodeSockaddrInfoItemTypeId(
-    int item_type,
-    const CipCommonPacketFormatData* const common_packet_format_data_item,
-    ENIPMessage* const outgoing_message) {
+  int item_type,
+  const CipCommonPacketFormatData* const common_packet_format_data_item,
+  ENIPMessage* const outgoing_message) {
   OPENER_ASSERT(item_type == 0 || item_type == 1);
   AddIntToMessage(
-      common_packet_format_data_item->address_info_item[item_type].type_id,
-      outgoing_message);
+    common_packet_format_data_item->address_info_item[item_type].type_id,
+    outgoing_message);
 }
 
 /**
@@ -643,18 +641,18 @@ void EncodeSockaddrInfoItemTypeId(
  * @param outgoing_message The outgoing message object
  */
 void EncodeSockaddrInfoLength(
-    int item_type,
-    const CipCommonPacketFormatData* const common_packet_format_data_item,
-    ENIPMessage* const outgoing_message) {
+  int item_type,
+  const CipCommonPacketFormatData* const common_packet_format_data_item,
+  ENIPMessage* const outgoing_message) {
   AddIntToMessage(
-      common_packet_format_data_item->address_info_item[item_type].length,
-      outgoing_message);
+    common_packet_format_data_item->address_info_item[item_type].length,
+    outgoing_message);
 }
 
 EipStatus AssembleLinearMessage(
-    const CipMessageRouterResponse* const message_router_response,
-    const CipCommonPacketFormatData* const common_packet_format_data_item,
-    ENIPMessage* const outgoing_message) {
+  const CipMessageRouterResponse* const message_router_response,
+  const CipCommonPacketFormatData* const common_packet_format_data_item,
+  ENIPMessage* const outgoing_message) {
   if (message_router_response) {
     /* add Interface Handle and Timeout = 0 -> only for SendRRData and
      * SendUnitData necessary */
@@ -734,18 +732,18 @@ EipStatus AssembleLinearMessage(
       if (common_packet_format_data_item->address_info_item[j].type_id ==
           type) {
         EncodeSockaddrInfoItemTypeId(
-            j, common_packet_format_data_item, outgoing_message);
+          j, common_packet_format_data_item, outgoing_message);
 
         EncodeSockaddrInfoLength(
-            j, common_packet_format_data_item, outgoing_message);
+          j, common_packet_format_data_item, outgoing_message);
 
         EncapsulateIpAddress(
-            common_packet_format_data_item->address_info_item[j].sin_port,
-            common_packet_format_data_item->address_info_item[j].sin_addr,
-            outgoing_message);
+          common_packet_format_data_item->address_info_item[j].sin_port,
+          common_packet_format_data_item->address_info_item[j].sin_addr,
+          outgoing_message);
 
         FillNextNMessageOctetsWithValueAndMoveToNextPosition(
-            0, 8, outgoing_message);
+          0, 8, outgoing_message);
         break;
       }
     }
@@ -754,7 +752,7 @@ EipStatus AssembleLinearMessage(
 }
 
 void AssembleIOMessage(
-    const CipCommonPacketFormatData* const common_packet_format_data_item,
-    ENIPMessage* const outgoing_message) {
+  const CipCommonPacketFormatData* const common_packet_format_data_item,
+  ENIPMessage* const outgoing_message) {
   AssembleLinearMessage(0, common_packet_format_data_item, outgoing_message);
 }

+ 20 - 20
source/src/enet_encap/cpf.h

@@ -27,17 +27,17 @@ typedef enum {
                                      encapsulation routing is not needed. */
   kCipItemIdListIdentityResponse = 0x000C,
   kCipItemIdConnectionAddress =
-      0x00A1, /**< Type: Address; Connection-based, used for connected messages,
-                 see Vol.2, p.42 */
+    0x00A1, /**< Type: Address; Connection-based, used for connected messages,
+               see Vol.2, p.42 */
   kCipItemIdConnectedDataItem =
-      0x00B1, /**< Type: Data; Connected data item, see Vol.2, p.43 */
+    0x00B1, /**< Type: Data; Connected data item, see Vol.2, p.43 */
   kCipItemIdUnconnectedDataItem =
-      0x00B2, /**< Type: Data; Unconnected message */
+    0x00B2, /**< Type: Data; Unconnected message */
   kCipItemIdListServiceResponse = 0x0100,
   kCipItemIdSocketAddressInfoOriginatorToTarget =
-      0x8000, /**< Type: Data; Sockaddr info item originator to target */
+    0x8000, /**< Type: Data; Sockaddr info item originator to target */
   kCipItemIdSocketAddressInfoTargetToOriginator =
-      0x8001, /**< Type: Data; Sockaddr info item target to originator */
+    0x8001, /**< Type: Data; Sockaddr info item target to originator */
   kCipItemIdSequencedAddressItem = 0x8002 /**< Sequenced Address item */
 } CipItemId;
 
@@ -97,9 +97,9 @@ typedef struct {
  * status
  */
 EipStatus NotifyCommonPacketFormat(
-    const EncapsulationData* const received_data,
-    const struct sockaddr* const originator_address,
-    ENIPMessage* const outgoing_message);
+  const EncapsulationData* const received_data,
+  const struct sockaddr* const originator_address,
+  ENIPMessage* const outgoing_message);
 
 /** @ingroup ENCAP
  * Parse the CPF data from a received connected explicit message, check
@@ -114,9 +114,9 @@ EipStatus NotifyCommonPacketFormat(
  * status
  */
 EipStatus NotifyConnectedCommonPacketFormat(
-    const EncapsulationData* const received_data,
-    const struct sockaddr* const originator_address,
-    ENIPMessage* const outgoing_message);
+  const EncapsulationData* const received_data,
+  const struct sockaddr* const originator_address,
+  ENIPMessage* const outgoing_message);
 
 /** @ingroup ENCAP
  *  Create CPF structure out of the received data.
@@ -128,9 +128,9 @@ EipStatus NotifyConnectedCommonPacketFormat(
  *             EIP_ERROR .. error
  */
 EipStatus CreateCommonPacketFormatStructure(
-    const EipUint8* data,
-    size_t data_length,
-    CipCommonPacketFormatData* common_packet_format_data);
+  const EipUint8* data,
+  size_t data_length,
+  CipCommonPacketFormatData* common_packet_format_data);
 
 /** @ingroup ENCAP
  * Copy data from CPFDataItem into linear memory in message for transmission
@@ -142,8 +142,8 @@ EipStatus CreateCommonPacketFormatStructure(
  *     kEipStatusError .. error
  */
 void AssembleIOMessage(
-    const CipCommonPacketFormatData* const common_packet_format_data_item,
-    ENIPMessage* const message);
+  const CipCommonPacketFormatData* const common_packet_format_data_item,
+  ENIPMessage* const message);
 
 /** @ingroup ENCAP
  * @brief Copy data from message_router_response struct and
@@ -159,9 +159,9 @@ void AssembleIOMessage(
  *         kEipStatusError .. error
  */
 EipStatus AssembleLinearMessage(
-    const CipMessageRouterResponse* const message_router_response,
-    const CipCommonPacketFormatData* const common_packet_format_data_item,
-    ENIPMessage* const outgoing_message);
+  const CipMessageRouterResponse* const message_router_response,
+  const CipCommonPacketFormatData* const common_packet_format_data_item,
+  ENIPMessage* const outgoing_message);
 
 /** @ingroup ENCAP
  * @brief Data storage for the any CPF data

+ 151 - 151
source/src/enet_encap/encap.c

@@ -25,19 +25,19 @@
 
 /* IP address data taken from TCPIPInterfaceObject*/
 const EipUint16 kSupportedProtocolVersion =
-    1; /**< Supported Encapsulation protocol version */
+  1; /**< Supported Encapsulation protocol version */
 
 const CipUdint kEncapsulationHeaderOptionsFlag =
-    0x00; /**< Mask of which options are supported as of the current CIP specs
-             no other option value as 0 should be supported.*/
+  0x00; /**< Mask of which options are supported as of the current CIP specs
+           no other option value as 0 should be supported.*/
 
 const int kEncapsulationHeaderSessionHandlePosition =
-    4; /**< the position of the session handle within the encapsulation header*/
+  4; /**< the position of the session handle within the encapsulation header*/
 
 const EipUint16 kListIdentityDefaultDelayTime =
-    2000; /**< Default delay time for List Identity response */
+  2000; /**< Default delay time for List Identity response */
 const EipUint16 kListIdentityMinimumDelayTime =
-    500; /**< Minimum delay time for List Identity response */
+  500; /**< Minimum delay time for List Identity response */
 
 typedef enum {
   kSessionStatusInvalid = -1,
@@ -45,21 +45,21 @@ typedef enum {
 } SessionStatus;
 
 const int kSenderContextSize =
-    8; /**< size of sender context in encapsulation header*/
+  8; /**< size of sender context in encapsulation header*/
 
 /** @brief definition of known encapsulation commands */
 typedef enum {
   kEncapsulationCommandNoOperation = 0x0000, /**< only allowed for TCP */
   kEncapsulationCommandListServices =
-      0x0004, /**< allowed for both UDP and TCP */
+    0x0004, /**< allowed for both UDP and TCP */
   kEncapsulationCommandListIdentity =
-      0x0063, /**< allowed for both UDP and TCP */
+    0x0063, /**< allowed for both UDP and TCP */
   kEncapsulationCommandListInterfaces =
-      0x0064, /**< optional, allowed for both UDP and TCP */
+    0x0064, /**< optional, allowed for both UDP and TCP */
   kEncapsulationCommandRegisterSession   = 0x0065, /**< only allowed for TCP */
   kEncapsulationCommandUnregisterSession = 0x0066, /**< only allowed for TCP */
   kEncapsulationCommandSendRequestReplyData =
-      0x006F,                                /**< only allowed for TCP */
+    0x006F,                                  /**< only allowed for TCP */
   kEncapsulationCommandSendUnitData = 0x0070 /**< only allowed for TCP */
 } EncapsulationCommand;
 
@@ -88,39 +88,39 @@ EncapsulationServiceInformation g_service_information;
 int g_registered_sessions[OPENER_NUMBER_OF_SUPPORTED_SESSIONS];
 
 DelayedEncapsulationMessage g_delayed_encapsulation_messages
-    [ENCAP_NUMBER_OF_SUPPORTED_DELAYED_ENCAP_MESSAGES];
+  [ENCAP_NUMBER_OF_SUPPORTED_DELAYED_ENCAP_MESSAGES];
 
 /*** private functions ***/
 void HandleReceivedListIdentityCommandTcp(
-    const EncapsulationData* const receive_data,
-    ENIPMessage* const outgoing_message);
+  const EncapsulationData* const receive_data,
+  ENIPMessage* const outgoing_message);
 
 void HandleReceivedListIdentityCommandUdp(
-    const int socket,
-    const struct sockaddr_in* const from_address,
-    const EncapsulationData* const receive_data);
+  const int socket,
+  const struct sockaddr_in* const from_address,
+  const EncapsulationData* const receive_data);
 
 EipStatus HandleReceivedUnregisterSessionCommand(
-    const EncapsulationData* const receive_data,
-    ENIPMessage* const outgoing_message);
+  const EncapsulationData* const receive_data,
+  ENIPMessage* const outgoing_message);
 
 EipStatus HandleReceivedSendUnitDataCommand(
-    const EncapsulationData* const receive_data,
-    const struct sockaddr* const originator_address,
-    ENIPMessage* const outgoing_message);
+  const EncapsulationData* const receive_data,
+  const struct sockaddr* const originator_address,
+  ENIPMessage* const outgoing_message);
 
 EipStatus HandleReceivedInvalidCommand(
-    const EncapsulationData* const receive_data,
-    ENIPMessage* const outgoing_message);
+  const EncapsulationData* const receive_data,
+  ENIPMessage* const outgoing_message);
 
 int GetFreeSessionIndex(void);
 
 SessionStatus CheckRegisteredSessions(
-    const EncapsulationData* const receive_data);
+  const EncapsulationData* const receive_data);
 
 void DetermineDelayTime(
-    const EipByte* buffer_start,
-    DelayedEncapsulationMessage* const delayed_message_buffer);
+  const EipByte* buffer_start,
+  DelayedEncapsulationMessage* const delayed_message_buffer);
 
 /*   @brief Initializes session list and interface information. */
 void EncapsulationInit(void) {
@@ -146,7 +146,7 @@ void EncapsulationInit(void) {
   g_service_information.length    = sizeof(g_service_information);
   g_service_information.encapsulation_protocol_version = 1;
   g_service_information.capability_flags =
-      kCapabilityFlagsCipTcp | kCapabilityFlagsCipUdpClass0or1;
+    kCapabilityFlagsCipTcp | kCapabilityFlagsCipUdpClass0or1;
   snprintf((char*)g_service_information.name_of_service,
            sizeof(g_service_information.name_of_service),
            "Communications");
@@ -160,18 +160,18 @@ EipStatus HandleReceivedExplictTcpData(int socket,
                                        ENIPMessage* const outgoing_message) {
   OPENER_TRACE_INFO("Handles data for TCP socket: %d\n", socket);
   EipStatus return_value               = kEipStatusOk;
-  EncapsulationData encapsulation_data = {0};
+  EncapsulationData encapsulation_data = { 0 };
   /* eat the encapsulation header*/
   /* the structure contains a pointer to the encapsulated data*/
   /* returns how many bytes are left after the encapsulated data*/
   const int remaining_bytes =
-      CreateEncapsulationStructure(buffer, length, &encapsulation_data);
+    CreateEncapsulationStructure(buffer, length, &encapsulation_data);
 
   if (remaining_bytes >= 0) {
     *number_of_remaining_bytes = remaining_bytes;
   } else {
     OPENER_TRACE_ERR(
-        "Fragmented packet detected! Fragmented packets are not supported!\n");
+      "Fragmented packet detected! Fragmented packets are not supported!\n");
     *number_of_remaining_bytes = 0;
     return kEipStatusError;
   }
@@ -215,30 +215,30 @@ EipStatus HandleReceivedExplictTcpData(int socket,
         case (kEncapsulationCommandRegisterSession):
           OPENER_TRACE_INFO("Register session\n");
           HandleReceivedRegisterSessionCommand(
-              socket, &encapsulation_data, outgoing_message);
+            socket, &encapsulation_data, outgoing_message);
           break;
 
         case (kEncapsulationCommandUnregisterSession):
           OPENER_TRACE_INFO("unregister session\n");
           return_value = HandleReceivedUnregisterSessionCommand(
-              &encapsulation_data, outgoing_message);
+            &encapsulation_data, outgoing_message);
           break;
 
         case (kEncapsulationCommandSendRequestReplyData):
           OPENER_TRACE_INFO("Send Request/Reply Data\n");
           return_value = HandleReceivedSendRequestResponseDataCommand(
-              &encapsulation_data, originator_address, outgoing_message);
+            &encapsulation_data, originator_address, outgoing_message);
           break;
 
         case (kEncapsulationCommandSendUnitData):
           OPENER_TRACE_INFO("Send Unit Data\n");
           return_value = HandleReceivedSendUnitDataCommand(
-              &encapsulation_data, originator_address, outgoing_message);
+            &encapsulation_data, originator_address, outgoing_message);
           break;
 
         default:
-          return_value = HandleReceivedInvalidCommand(&encapsulation_data,
-                                                      outgoing_message);
+          return_value =
+            HandleReceivedInvalidCommand(&encapsulation_data, outgoing_message);
           break;
       }
     }
@@ -255,18 +255,18 @@ EipStatus HandleReceivedExplictUdpData(const int socket,
                                        bool unicast,
                                        ENIPMessage* const outgoing_message) {
   EipStatus return_value               = kEipStatusOk;
-  EncapsulationData encapsulation_data = {0};
+  EncapsulationData encapsulation_data = { 0 };
   /* eat the encapsulation header*/
   /* the structure contains a pointer to the encapsulated data*/
   /* returns how many bytes are left after the encapsulated data*/
   const int remaining_bytes =
-      CreateEncapsulationStructure(buffer, buffer_length, &encapsulation_data);
+    CreateEncapsulationStructure(buffer, buffer_length, &encapsulation_data);
 
   if (remaining_bytes >= 0) {
     *number_of_remaining_bytes = remaining_bytes;
   } else {
     OPENER_TRACE_ERR(
-        "Fragmented packet detected! Fragmented packets are not supported!\n");
+      "Fragmented packet detected! Fragmented packets are not supported!\n");
     *number_of_remaining_bytes = 0;
     return kEipStatusError;
   }
@@ -296,7 +296,7 @@ EipStatus HandleReceivedExplictUdpData(const int socket,
                                                  outgoing_message);
           } else {
             HandleReceivedListIdentityCommandUdp(
-                socket, from_address, &encapsulation_data);
+              socket, from_address, &encapsulation_data);
             /* as the response has to be delayed do not send it now */
             return_value = kEipStatusOk;
           }
@@ -332,11 +332,11 @@ void SkipEncapsulationHeader(ENIPMessage* const outgoing_message) {
 }
 
 void GenerateEncapsulationHeader(
-    const EncapsulationData* const receive_data,
-    const size_t command_specific_data_length,
-    const CipSessionHandle session_handle,
-    const EncapsulationProtocolErrorCode encapsulation_protocol_status,
-    ENIPMessage* const outgoing_message) {
+  const EncapsulationData* const receive_data,
+  const size_t command_specific_data_length,
+  const CipSessionHandle session_handle,
+  const EncapsulationProtocolErrorCode encapsulation_protocol_status,
+  ENIPMessage* const outgoing_message) {
   AddIntToMessage(receive_data->command_code, outgoing_message);
   AddIntToMessage(command_specific_data_length, outgoing_message);
   AddDintToMessage(session_handle, outgoing_message);  // Session handle
@@ -354,11 +354,11 @@ void GenerateEncapsulationHeader(
  *  @param outgoing_message The outgoing ENIP message
  */
 void HandleReceivedListServicesCommand(
-    const EncapsulationData* const receive_data,
-    ENIPMessage* const outgoing_message) {
+  const EncapsulationData* const receive_data,
+  ENIPMessage* const outgoing_message) {
   /* Create encapsulation header */
   const size_t kListServicesCommandSpecificDataLength =
-      sizeof(CipUint) + sizeof(g_service_information);
+    sizeof(CipUint) + sizeof(g_service_information);
   GenerateEncapsulationHeader(receive_data,
                               kListServicesCommandSpecificDataLength,
                               0,
@@ -379,14 +379,14 @@ void HandleReceivedListServicesCommand(
          g_service_information.name_of_service,
          sizeof(g_service_information.name_of_service));
   outgoing_message->current_message_position +=
-      sizeof(g_service_information.name_of_service);
+    sizeof(g_service_information.name_of_service);
   outgoing_message->used_message_length +=
-      sizeof(g_service_information.name_of_service);
+    sizeof(g_service_information.name_of_service);
 }
 
 void HandleReceivedListInterfacesCommand(
-    const EncapsulationData* const receive_data,
-    ENIPMessage* const outgoing_message) {
+  const EncapsulationData* const receive_data,
+  ENIPMessage* const outgoing_message) {
   /* Encapsulation header */
   const size_t kListInterfacesCommandSpecificDataLength = sizeof(CipUint);
 
@@ -398,20 +398,20 @@ void HandleReceivedListInterfacesCommand(
                               outgoing_message);
   /* Command specific data */
   AddIntToMessage(
-      0x0000,
-      outgoing_message); /* Set Item Count to 0: no Target Items follow. */
+    0x0000,
+    outgoing_message); /* Set Item Count to 0: no Target Items follow. */
 }
 
 void HandleReceivedListIdentityCommandTcp(
-    const EncapsulationData* const receive_data,
-    ENIPMessage* const outgoing_message) {
+  const EncapsulationData* const receive_data,
+  ENIPMessage* const outgoing_message) {
   EncapsulateListIdentityResponseMessage(receive_data, outgoing_message);
 }
 
 void HandleReceivedListIdentityCommandUdp(
-    const int socket,
-    const struct sockaddr_in* const from_address,
-    const EncapsulationData* const receive_data) {
+  const int socket,
+  const struct sockaddr_in* const from_address,
+  const EncapsulationData* const receive_data) {
   DelayedEncapsulationMessage* delayed_message_buffer = NULL;
   ENIPMessage* p_outgoing_message                     = NULL;
 
@@ -483,11 +483,11 @@ void EncodeListIdentityCipIdentityItem(ENIPMessage* const outgoing_message) {
 }
 
 void EncapsulateListIdentityResponseMessage(
-    const EncapsulationData* const receive_data,
-    ENIPMessage* const outgoing_message) {
+  const EncapsulationData* const receive_data,
+  ENIPMessage* const outgoing_message) {
   const CipUint kEncapsulationCommandListIdentityLength =
-      ListIdentityGetCipIdentityItemLength() + sizeof(CipUint) +
-      sizeof(CipUint) + sizeof(CipUint); /* Last element is item count */
+    ListIdentityGetCipIdentityItemLength() + sizeof(CipUint) + sizeof(CipUint) +
+    sizeof(CipUint); /* Last element is item count */
 
   GenerateEncapsulationHeader(receive_data,
                               kEncapsulationCommandListIdentityLength,
@@ -501,11 +501,11 @@ void EncapsulateListIdentityResponseMessage(
 }
 
 void DetermineDelayTime(
-    const EipByte* buffer_start,
-    DelayedEncapsulationMessage* const delayed_message_buffer) {
+  const EipByte* buffer_start,
+  DelayedEncapsulationMessage* const delayed_message_buffer) {
   buffer_start += 12; /* start of the sender context */
   EipUint16 maximum_delay_time =
-      GetUintFromMessage((const EipUint8** const)&buffer_start);
+    GetUintFromMessage((const EipUint8** const)&buffer_start);
 
   if (0 == maximum_delay_time) {
     maximum_delay_time = kListIdentityDefaultDelayTime;
@@ -519,13 +519,13 @@ void DetermineDelayTime(
 }
 
 void EncapsulateRegisterSessionCommandResponseMessage(
-    const EncapsulationData* const receive_data,
-    const CipSessionHandle session_handle,
-    const EncapsulationProtocolErrorCode encapsulation_protocol_status,
-    ENIPMessage* const outgoing_message) {
+  const EncapsulationData* const receive_data,
+  const CipSessionHandle session_handle,
+  const EncapsulationProtocolErrorCode encapsulation_protocol_status,
+  ENIPMessage* const outgoing_message) {
   /* Encapsulation header */
   const size_t kListInterfacesCommandSpecificDataLength =
-      sizeof(CipUint) + sizeof(CipUint);
+    sizeof(CipUint) + sizeof(CipUint);
   assert(kListInterfacesCommandSpecificDataLength == 4);
   GenerateEncapsulationHeader(receive_data,
                               kListInterfacesCommandSpecificDataLength,
@@ -544,20 +544,20 @@ void EncapsulateRegisterSessionCommandResponseMessage(
  * @param receive_data Pointer to received data with request/response.
  */
 void HandleReceivedRegisterSessionCommand(
-    int socket,
-    const EncapsulationData* const receive_data,
-    ENIPMessage* const outgoing_message) {
+  int socket,
+  const EncapsulationData* const receive_data,
+  ENIPMessage* const outgoing_message) {
   int session_index               = 0;
   CipSessionHandle session_handle = 0;
   EncapsulationProtocolErrorCode encapsulation_protocol_status =
-      kEncapsulationProtocolSuccess;
+    kEncapsulationProtocolSuccess;
 
   EipUint16 protocol_version =
-      GetUintFromMessage((const EipUint8** const)&receive_data
-                             ->current_communication_buffer_position);
+    GetUintFromMessage((const EipUint8** const)&receive_data
+                         ->current_communication_buffer_position);
   EipUint16 option_flag =
-      GetUintFromMessage((const EipUint8** const)&receive_data
-                             ->current_communication_buffer_position);
+    GetUintFromMessage((const EipUint8** const)&receive_data
+                         ->current_communication_buffer_position);
 
   /* check if requested protocol version is supported and the register session
    * option flag is zero*/
@@ -569,10 +569,10 @@ void HandleReceivedRegisterSessionCommand(
       if (g_registered_sessions[i] == socket) {
         /* the socket has already registered a session this is not allowed*/
         OPENER_TRACE_INFO(
-            "Error: A session is already registered at socket %d\n", socket);
+          "Error: A session is already registered at socket %d\n", socket);
         session_handle =
-            i + 1; /*return the already assigned session back, the cip spec is
-                      not clear about this needs to be tested*/
+          i + 1; /*return the already assigned session back, the cip spec is
+                    not clear about this needs to be tested*/
         encapsulation_protocol_status = kEncapsulationProtocolInvalidCommand;
         session_index                 = kSessionStatusInvalid;
         break;
@@ -585,14 +585,14 @@ void HandleReceivedRegisterSessionCommand(
           session_index) /* no more sessions available */
       {
         encapsulation_protocol_status =
-            kEncapsulationProtocolInsufficientMemory;
+          kEncapsulationProtocolInsufficientMemory;
       } else { /* successful session registered */
         SocketTimer* socket_timer = SocketTimerArrayGetEmptySocketTimer(
-            g_timestamps, OPENER_NUMBER_OF_SUPPORTED_SESSIONS);
+          g_timestamps, OPENER_NUMBER_OF_SUPPORTED_SESSIONS);
         SocketTimerSetSocket(socket_timer, socket);
         SocketTimerSetLastUpdate(socket_timer, g_actual_time);
         g_registered_sessions[session_index] =
-            socket; /* store associated socket */
+          socket; /* store associated socket */
         session_handle                = (CipSessionHandle)(session_index + 1);
         encapsulation_protocol_status = kEncapsulationProtocolSuccess;
       }
@@ -602,10 +602,10 @@ void HandleReceivedRegisterSessionCommand(
   }
 
   EncapsulateRegisterSessionCommandResponseMessage(
-      receive_data,
-      session_handle,
-      encapsulation_protocol_status,
-      outgoing_message);
+    receive_data,
+    session_handle,
+    encapsulation_protocol_status,
+    outgoing_message);
 }
 
 /** @brief Unregister encapsulation session
@@ -617,8 +617,8 @@ void HandleReceivedRegisterSessionCommand(
  * Close all corresponding TCP connections and delete session handle.
  */
 EipStatus HandleReceivedUnregisterSessionCommand(
-    const EncapsulationData* const receive_data,
-    ENIPMessage* const outgoing_message) {
+  const EncapsulationData* const receive_data,
+  ENIPMessage* const outgoing_message) {
   OPENER_TRACE_INFO("encap.c: Unregister Session Command\n");
   if ((0 < receive_data->session_handle) &&
       (receive_data->session_handle <= OPENER_NUMBER_OF_SUPPORTED_SESSIONS)) {
@@ -646,35 +646,35 @@ EipStatus HandleReceivedUnregisterSessionCommand(
  *  @param outgoing_message The outgoing ENIP message
  */
 EipStatus HandleReceivedSendUnitDataCommand(
-    const EncapsulationData* const receive_data,
-    const struct sockaddr* const originator_address,
-    ENIPMessage* const outgoing_message) {
+  const EncapsulationData* const receive_data,
+  const struct sockaddr* const originator_address,
+  ENIPMessage* const outgoing_message) {
   EipStatus return_value = kEipStatusOkSend;
   /*EipStatus*/ return_value =
-      kEipStatusOk; /* TODO: Shouldn't this be kEipStatusOk cause we must not
-                       send any response if data_length < 6? */
+    kEipStatusOk; /* TODO: Shouldn't this be kEipStatusOk cause we must not
+                     send any response if data_length < 6? */
 
   if (receive_data->data_length >= 6) {
     /* Command specific data UDINT .. Interface Handle, UINT .. Timeout, CPF
      * packets */
     /* don't use the data yet */
     GetDintFromMessage(
-        (const EipUint8** const)&receive_data
-            ->current_communication_buffer_position); /* skip over null
-                                                         interface handle*/
+      (const EipUint8** const)&receive_data
+        ->current_communication_buffer_position); /* skip over null
+                                                     interface handle*/
     GetIntFromMessage(
-        (const EipUint8** const)&receive_data
-            ->current_communication_buffer_position); /* skip over unused
-                                                         timeout value*/
+      (const EipUint8** const)&receive_data
+        ->current_communication_buffer_position); /* skip over unused
+                                                     timeout value*/
     ((EncapsulationData* const)receive_data)->data_length -=
-        6; /* the rest is in CPF format*/
+      6; /* the rest is in CPF format*/
 
     if (kSessionStatusValid ==
         CheckRegisteredSessions(
-            receive_data)) /* see if the EIP session is registered*/
+          receive_data)) /* see if the EIP session is registered*/
     {
       return_value = NotifyConnectedCommonPacketFormat(
-          receive_data, originator_address, outgoing_message);
+        receive_data, originator_address, outgoing_message);
     } else { /* received a package with non registered session handle */
       InitializeENIPMessage(outgoing_message);
       GenerateEncapsulationHeader(receive_data,
@@ -683,8 +683,8 @@ EipStatus HandleReceivedSendUnitDataCommand(
                                   kEncapsulationProtocolInvalidSessionHandle,
                                   outgoing_message);
       return_value =
-          kEipStatusOkSend; /* TODO: Needs to be here if line with first TODO of
-                               this function is adjusted. */
+        kEipStatusOkSend; /* TODO: Needs to be here if line with first TODO of
+                             this function is adjusted. */
     }
   }
   return return_value;
@@ -699,35 +699,35 @@ EipStatus HandleReceivedSendUnitDataCommand(
  *                      kEipStatusError .. error
  */
 EipStatus HandleReceivedSendRequestResponseDataCommand(
-    const EncapsulationData* const receive_data,
-    const struct sockaddr* const originator_address,
-    ENIPMessage* const outgoing_message) {
+  const EncapsulationData* const receive_data,
+  const struct sockaddr* const originator_address,
+  ENIPMessage* const outgoing_message) {
   EipStatus return_value = kEipStatusOkSend;
   /* EipStatus*/ return_value =
-      kEipStatusOk; /* TODO: Shouldn't this be kEipStatusOk cause we must not
-                       send any response if data_length < 6? */
+    kEipStatusOk; /* TODO: Shouldn't this be kEipStatusOk cause we must not
+                     send any response if data_length < 6? */
 
   if (receive_data->data_length >= 6) {
     /* Command specific data UDINT .. Interface Handle, UINT .. Timeout, CPF
      * packets */
     /* don't use the data yet */
     GetDintFromMessage(
-        (const EipUint8** const)&receive_data
-            ->current_communication_buffer_position); /* skip over null
-                                                         interface handle*/
+      (const EipUint8** const)&receive_data
+        ->current_communication_buffer_position); /* skip over null
+                                                     interface handle*/
     GetIntFromMessage(
-        (const EipUint8** const)&receive_data
-            ->current_communication_buffer_position); /* skip over unused
-                                                         timeout value*/
+      (const EipUint8** const)&receive_data
+        ->current_communication_buffer_position); /* skip over unused
+                                                     timeout value*/
     ((EncapsulationData* const)receive_data)->data_length -=
-        6; /* the rest is in CPF format*/
+      6; /* the rest is in CPF format*/
 
     if (kSessionStatusValid ==
         CheckRegisteredSessions(
-            receive_data)) /* see if the EIP session is registered*/
+          receive_data)) /* see if the EIP session is registered*/
     {
       return_value = NotifyCommonPacketFormat(
-          receive_data, originator_address, outgoing_message);
+        receive_data, originator_address, outgoing_message);
     } else { /* received a package with non registered session handle */
       InitializeENIPMessage(outgoing_message);
       GenerateEncapsulationHeader(receive_data,
@@ -736,16 +736,16 @@ EipStatus HandleReceivedSendRequestResponseDataCommand(
                                   kEncapsulationProtocolInvalidSessionHandle,
                                   outgoing_message);
       return_value =
-          kEipStatusOkSend; /* TODO: Needs to be here if line with first TODO of
-                               this function is adjusted. */
+        kEipStatusOkSend; /* TODO: Needs to be here if line with first TODO of
+                             this function is adjusted. */
     }
   }
   return return_value;
 }
 
 EipStatus HandleReceivedInvalidCommand(
-    const EncapsulationData* const receive_data,
-    ENIPMessage* const outgoing_message) {
+  const EncapsulationData* const receive_data,
+  ENIPMessage* const outgoing_message) {
   /* Encapsulation header */
   GenerateEncapsulationHeader(receive_data,
                               0,
@@ -781,9 +781,9 @@ int GetFreeSessionIndex(void) {
  *                      <0 .. only fragment of data portion received
  */
 int_fast32_t CreateEncapsulationStructure(
-    const EipUint8* receive_buffer,
-    size_t receive_buffer_length,
-    EncapsulationData* const encapsulation_data) {
+  const EipUint8* receive_buffer,
+  size_t receive_buffer_length,
+  EncapsulationData* const encapsulation_data) {
   encapsulation_data->communication_buffer_start = (EipUint8*)receive_buffer;
   encapsulation_data->command_code   = GetUintFromMessage(&receive_buffer);
   encapsulation_data->data_length    = GetUintFromMessage(&receive_buffer);
@@ -791,11 +791,11 @@ int_fast32_t CreateEncapsulationStructure(
   encapsulation_data->status         = GetUdintFromMessage(&receive_buffer);
 
   memcpy(
-      encapsulation_data->sender_context, receive_buffer, kSenderContextSize);
+    encapsulation_data->sender_context, receive_buffer, kSenderContextSize);
   receive_buffer += kSenderContextSize;
   encapsulation_data->options = GetUdintFromMessage(&receive_buffer);
   encapsulation_data->current_communication_buffer_position =
-      (EipUint8*)receive_buffer;
+    (EipUint8*)receive_buffer;
 
   /* Ensure buffer length fits in an int32 before casting in the return
    * expression. */
@@ -812,7 +812,7 @@ int_fast32_t CreateEncapsulationStructure(
  * received
  */
 SessionStatus CheckRegisteredSessions(
-    const EncapsulationData* const receive_data) {
+  const EncapsulationData* const receive_data) {
   /* Skip the check when fuzzing
    in order to increase our code coverage
    we are simply bypassing all the session checks
@@ -832,10 +832,10 @@ SessionStatus CheckRegisteredSessions(
 }
 
 void CloseSessionBySessionHandle(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   OPENER_TRACE_INFO("encap.c: Close session by handle\n");
   CipSessionHandle session_handle =
-      connection_object->associated_encapsulation_session;
+    connection_object->associated_encapsulation_session;
   CloseTcpSocket(g_registered_sessions[session_handle - 1]);
   g_registered_sessions[session_handle - 1] = kEipInvalidSocket;
   OPENER_TRACE_INFO("encap.c: Close session by handle done\n");
@@ -884,14 +884,14 @@ void ManageEncapsulationMessages(const MilliSeconds elapsed_time) {
       if (0 >= g_delayed_encapsulation_messages[i].time_out) {
         /* If delay is reached or passed, send the UDP message */
         sendto(
-            g_delayed_encapsulation_messages[i].socket,
-            (char*)g_delayed_encapsulation_messages[i]
-                .outgoing_message.message_buffer,
-            g_delayed_encapsulation_messages[i]
-                .outgoing_message.used_message_length,
-            0,
-            (struct sockaddr*)&(g_delayed_encapsulation_messages[i].receiver),
-            sizeof(struct sockaddr));
+          g_delayed_encapsulation_messages[i].socket,
+          (char*)g_delayed_encapsulation_messages[i]
+            .outgoing_message.message_buffer,
+          g_delayed_encapsulation_messages[i]
+            .outgoing_message.used_message_length,
+          0,
+          (struct sockaddr*)&(g_delayed_encapsulation_messages[i].receiver),
+          sizeof(struct sockaddr));
         g_delayed_encapsulation_messages[i].socket = kEipInvalidSocket;
       }
     }
@@ -899,10 +899,10 @@ void ManageEncapsulationMessages(const MilliSeconds elapsed_time) {
 }
 
 void CloseEncapsulationSessionBySockAddr(
-    const CipConnectionObject* const connection_object) {
+  const CipConnectionObject* const connection_object) {
   for (size_t i = 0; i < OPENER_NUMBER_OF_SUPPORTED_SESSIONS; ++i) {
     if (kEipInvalidSocket != g_registered_sessions[i]) {
-      struct sockaddr_in encapsulation_session_addr = {0};
+      struct sockaddr_in encapsulation_session_addr = { 0 };
       socklen_t addrlength = sizeof(encapsulation_session_addr);
       if (getpeername(g_registered_sessions[i],
                       (struct sockaddr*)&encapsulation_session_addr,
@@ -910,9 +910,9 @@ void CloseEncapsulationSessionBySockAddr(
         int error_code      = GetSocketErrorNumber();
         char* error_message = GetErrorMessage(error_code);
         OPENER_TRACE_ERR(
-            "encap.c: error on getting peer name on closing session: %d - %s\n",
-            error_code,
-            error_message);
+          "encap.c: error on getting peer name on closing session: %d - %s\n",
+          error_code,
+          error_message);
         FreeErrorMessage(error_message);
       }
       if (encapsulation_session_addr.sin_addr.s_addr ==
@@ -933,15 +933,15 @@ CipSessionHandle GetSessionFromSocket(const int socket_handle) {
 }
 
 void CloseClass3ConnectionBasedOnSession(
-    CipSessionHandle encapsulation_session_handle) {
+  CipSessionHandle encapsulation_session_handle) {
   DoublyLinkedListNode* node = connection_list.first;
   while (NULL != node) {
     CipConnectionObject* connection_object = node->data;
     if (kConnectionObjectTransportClassTriggerTransportClass3 ==
-            ConnectionObjectGetTransportClassTriggerTransportClass(
-                connection_object) &&
+          ConnectionObjectGetTransportClassTriggerTransportClass(
+            connection_object) &&
         connection_object->associated_encapsulation_session ==
-            encapsulation_session_handle) {
+          encapsulation_session_handle) {
       connection_object->connection_close_function(connection_object);
     }
     node = node->next;

+ 27 - 27
source/src/enet_encap/encap.h

@@ -43,14 +43,14 @@ typedef struct encapsulation_data {
   CipSessionHandle session_handle;
   CipUdint status;
   CipOctet
-      sender_context[8]; /**< length of 8, according to the specification */
+    sender_context[8]; /**< length of 8, according to the specification */
   CipUdint options;
   const EipUint8* communication_buffer_start; /**< Pointer to the communication
                                                  buffer used for this message */
   const EipUint8*
-      current_communication_buffer_position; /**< The current position in the
-                                                communication buffer during the
-                                                decoding process */
+    current_communication_buffer_position; /**< The current position in the
+                                              communication buffer during the
+                                              decoding process */
 } EncapsulationData;
 
 typedef struct encapsulation_service_information {
@@ -90,52 +90,52 @@ CipSessionHandle GetSessionFromSocket(const int socket_handle);
 void RemoveSession(const int socket);
 
 void CloseSessionBySessionHandle(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void CloseEncapsulationSessionBySockAddr(
-    const CipConnectionObject* const connection_object);
+  const CipConnectionObject* const connection_object);
 
 void CloseClass3ConnectionBasedOnSession(
-    CipSessionHandle encapsulation_session_handle);
+  CipSessionHandle encapsulation_session_handle);
 
 /* No reason to use this functions outside the encapsulation layer, they are
  * here for testing */
 typedef struct enip_message ENIPMessage;
 
 void EncapsulateListIdentityResponseMessage(
-    const EncapsulationData* const receive_data,
-    ENIPMessage* const outgoing_message);
+  const EncapsulationData* const receive_data,
+  ENIPMessage* const outgoing_message);
 
 int_fast32_t CreateEncapsulationStructure(
-    const EipUint8* receive_buffer,
-    size_t receive_buffer_length,
-    EncapsulationData* const encapsulation_data);
+  const EipUint8* receive_buffer,
+  size_t receive_buffer_length,
+  EncapsulationData* const encapsulation_data);
 
 void SkipEncapsulationHeader(ENIPMessage* const outgoing_message);
 
 void GenerateEncapsulationHeader(
-    const EncapsulationData* const receive_data,
-    const size_t command_specific_data_length,
-    const CipSessionHandle session_handle,
-    const EncapsulationProtocolErrorCode encapsulation_protocol_status,
-    ENIPMessage* const outgoing_message);
+  const EncapsulationData* const receive_data,
+  const size_t command_specific_data_length,
+  const CipSessionHandle session_handle,
+  const EncapsulationProtocolErrorCode encapsulation_protocol_status,
+  ENIPMessage* const outgoing_message);
 
 void HandleReceivedListServicesCommand(
-    const EncapsulationData* const receive_data,
-    ENIPMessage* const outgoing_message);
+  const EncapsulationData* const receive_data,
+  ENIPMessage* const outgoing_message);
 
 void HandleReceivedListInterfacesCommand(
-    const EncapsulationData* const receive_data,
-    ENIPMessage* const outgoing_message);
+  const EncapsulationData* const receive_data,
+  ENIPMessage* const outgoing_message);
 
 void HandleReceivedRegisterSessionCommand(
-    int socket,
-    const EncapsulationData* const receive_data,
-    ENIPMessage* const outgoing_message);
+  int socket,
+  const EncapsulationData* const receive_data,
+  ENIPMessage* const outgoing_message);
 
 EipStatus HandleReceivedSendRequestResponseDataCommand(
-    const EncapsulationData* const receive_data,
-    const struct sockaddr* const originator_address,
-    ENIPMessage* const outgoing_message);
+  const EncapsulationData* const receive_data,
+  const struct sockaddr* const originator_address,
+  ENIPMessage* const outgoing_message);
 
 #endif /* OPENER_ENCAP_H_ */

+ 15 - 16
source/src/enet_encap/endianconv.c

@@ -99,7 +99,7 @@ CipDint GetDintFromMessage(const EipUint8** const buffer) {
 CipUdint GetUdintFromMessage(const CipOctet** const buffer_address) {
   const CipOctet* buffer = *buffer_address;
   CipUdint data =
-      buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24;
+    buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24;
   *buffer_address += 4;
   return data;
 }
@@ -107,7 +107,7 @@ CipUdint GetUdintFromMessage(const CipOctet** const buffer_address) {
 CipUdint GetDwordFromMessage(const CipOctet** const buffer_address) {
   const CipOctet* buffer = *buffer_address;
   CipDword data =
-      buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24;
+    buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24;
   *buffer_address += 4;
   return data;
 }
@@ -163,14 +163,14 @@ void AddDintToMessage(const EipUint32 data,
 EipUint64 GetLintFromMessage(const EipUint8** const buffer) {
   const EipUint8* buffer_address = *buffer;
   EipUint64 data =
-      ((((EipUint64)buffer_address[0]) << 56) & 0xFF00000000000000LL) +
-      ((((EipUint64)buffer_address[1]) << 48) & 0x00FF000000000000LL) +
-      ((((EipUint64)buffer_address[2]) << 40) & 0x0000FF0000000000LL) +
-      ((((EipUint64)buffer_address[3]) << 32) & 0x000000FF00000000LL) +
-      ((((EipUint64)buffer_address[4]) << 24) & 0x00000000FF000000) +
-      ((((EipUint64)buffer_address[5]) << 16) & 0x0000000000FF0000) +
-      ((((EipUint64)buffer_address[6]) << 8) & 0x000000000000FF00) +
-      (((EipUint64)buffer_address[7]) & 0x00000000000000FF);
+    ((((EipUint64)buffer_address[0]) << 56) & 0xFF00000000000000LL) +
+    ((((EipUint64)buffer_address[1]) << 48) & 0x00FF000000000000LL) +
+    ((((EipUint64)buffer_address[2]) << 40) & 0x0000FF0000000000LL) +
+    ((((EipUint64)buffer_address[3]) << 32) & 0x000000FF00000000LL) +
+    ((((EipUint64)buffer_address[4]) << 24) & 0x00000000FF000000) +
+    ((((EipUint64)buffer_address[5]) << 16) & 0x0000000000FF0000) +
+    ((((EipUint64)buffer_address[6]) << 8) & 0x000000000000FF00) +
+    (((EipUint64)buffer_address[7]) & 0x00000000000000FF);
   *buffer += 8;
   return data;
 }
@@ -261,15 +261,14 @@ void MoveMessageNOctets(const int amount_of_bytes_moved,
 void FillNextNMessageOctetsWith(CipOctet value,
                                 unsigned int amount_of_bytes_written,
                                 ENIPMessage* const outgoing_message) {
-  memset(outgoing_message->current_message_position,
-         value,
-         amount_of_bytes_written);
+  memset(
+    outgoing_message->current_message_position, value, amount_of_bytes_written);
 }
 
 void FillNextNMessageOctetsWithValueAndMoveToNextPosition(
-    CipOctet value,
-    unsigned int amount_of_filled_bytes,
-    ENIPMessage* const outgoing_message) {
+  CipOctet value,
+  unsigned int amount_of_filled_bytes,
+  ENIPMessage* const outgoing_message) {
   FillNextNMessageOctetsWith(value, amount_of_filled_bytes, outgoing_message);
   MoveMessageNOctets(amount_of_filled_bytes, outgoing_message);
 }

+ 3 - 3
source/src/enet_encap/endianconv.h

@@ -138,8 +138,8 @@ void FillNextNMessageOctetsWith(CipOctet value,
                                 ENIPMessage* const outgoing_message);
 
 void FillNextNMessageOctetsWithValueAndMoveToNextPosition(
-    CipOctet value,
-    unsigned int amount_of_filled_bytes,
-    ENIPMessage* const outgoing_message);
+  CipOctet value,
+  unsigned int amount_of_filled_bytes,
+  ENIPMessage* const outgoing_message);
 
 #endif /* OPENER_ENDIANCONV_H_ */

+ 2 - 2
source/src/ports/MINGW/main.c

@@ -98,7 +98,7 @@ int main(int argc, char* arg[]) {
    */
   if (kEipStatusError == NvdataLoad()) {
     OPENER_TRACE_WARN(
-        "Loading of some NV data failed. Maybe the first start?\n");
+      "Loading of some NV data failed. Maybe the first start?\n");
   }
 
   /* Bring up network interface or start DHCP client ... */
@@ -118,7 +118,7 @@ int main(int argc, char* arg[]) {
 
   /* Next actions depend on the set network configuration method. */
   CipDword network_config_method =
-      g_tcpip.config_control & kTcpipCfgCtrlMethodMask;
+    g_tcpip.config_control & kTcpipCfgCtrlMethodMask;
   if (kTcpipCfgCtrlStaticIp == network_config_method) {
     OPENER_TRACE_INFO("Static network configuration done\n");
   }

+ 11 - 11
source/src/ports/MINGW/networkconfig.c

@@ -161,11 +161,11 @@ EipStatus RetrieveAdapterAddressesTable(ULONG flags,
     p_addr_table = (PIP_ADAPTER_ADDRESSES)MALLOC(outBufLen);
     if (NULL == p_addr_table) {
       OPENER_TRACE_ERR(
-          "Memory allocation failed for IP_ADAPTER_ADDRESSES struct\n");
+        "Memory allocation failed for IP_ADAPTER_ADDRESSES struct\n");
       return kEipStatusError;
     }
     ret_val =
-        GetAdaptersAddresses(AF_INET, flags, NULL, p_addr_table, &outBufLen);
+      GetAdaptersAddresses(AF_INET, flags, NULL, p_addr_table, &outBufLen);
 
     if (ERROR_BUFFER_OVERFLOW == ret_val) {
       FREE(p_addr_table);
@@ -334,7 +334,7 @@ EipStatus IfaceGetConfiguration(const char* iface,
        */
       {
         PIP_ADAPTER_UNICAST_ADDRESS pUnicast =
-            p_addr_entry->FirstUnicastAddress;
+          p_addr_entry->FirstUnicastAddress;
         if (NULL != pUnicast) {
           local_cfg.ip_address = GetIpFromSocketAddress(&pUnicast->Address);
         }
@@ -343,30 +343,30 @@ EipStatus IfaceGetConfiguration(const char* iface,
         PIP_ADAPTER_PREFIX pPrefix = p_addr_entry->FirstPrefix;
         if (NULL != pPrefix) {
           local_cfg.network_mask =
-              htonl(0xffffffff << (32U - pPrefix->PrefixLength));
+            htonl(0xffffffff << (32U - pPrefix->PrefixLength));
         }
       }
       {
         PIP_ADAPTER_GATEWAY_ADDRESS pGateway =
-            p_addr_entry->FirstGatewayAddress;
+          p_addr_entry->FirstGatewayAddress;
         if (NULL != pGateway) {
           local_cfg.gateway = GetIpFromSocketAddress(&pGateway->Address);
         }
       }
       {
         IP_ADAPTER_DNS_SERVER_ADDRESS* pDnServer =
-            p_addr_entry->FirstDnsServerAddress;
+          p_addr_entry->FirstDnsServerAddress;
         if (NULL != pDnServer) {
           local_cfg.name_server = GetIpFromSocketAddress(&pDnServer->Address);
           pDnServer             = pDnServer->Next;
           if (NULL != pDnServer) {
             local_cfg.name_server_2 =
-                GetIpFromSocketAddress(&pDnServer->Address);
+              GetIpFromSocketAddress(&pDnServer->Address);
           }
         }
       }
       DWORD ret_val =
-          WideToCipString(p_addr_entry->DnsSuffix, &local_cfg.domain_name);
+        WideToCipString(p_addr_entry->DnsSuffix, &local_cfg.domain_name);
       if (NO_ERROR != ret_val) {
         char* error_message = GetErrorMessage(ret_val);
         OPENER_TRACE_ERR("WideToCipString(DnsSuffix) failed with error: %" PRIDW
@@ -425,8 +425,8 @@ EipStatus IfaceWaitForIp(const char* const iface,
           pmib_ipaddr_table = MALLOC(addr_table_sz);
           if (NULL == pmib_ipaddr_table) {
             OPENER_TRACE_ERR(
-                "Memory allocation failed for "
-                "MIB_IPADDRTABLE struct\n");
+              "Memory allocation failed for "
+              "MIB_IPADDRTABLE struct\n");
             return kEipStatusError;
           }
         }
@@ -459,7 +459,7 @@ EipStatus IfaceWaitForIp(const char* const iface,
              (0 == SleepEx(WAIT_CYCLE_MS, FALSE)));
 
     OPENER_TRACE_INFO(
-        "IP=%08" PRIx32 ", timeout=%d\n", (uint32_t)ntohl(ipaddr), timeout);
+      "IP=%08" PRIx32 ", timeout=%d\n", (uint32_t)ntohl(ipaddr), timeout);
     if (pmib_ipaddr_table) {
       FREE(pmib_ipaddr_table);
     }

+ 2 - 2
source/src/ports/MINGW/networkhandler.c

@@ -39,7 +39,7 @@ EipStatus NetworkHandlerInitializePlatform(void) {
 
 void ShutdownSocketPlatform(int socket_handle) {
 #warning \
-    "Untested. Is a shutdown() needed under Windows like for the POSIX port?"
+  "Untested. Is a shutdown() needed under Windows like for the POSIX port?"
 }
 
 void CloseSocketPlatform(int socket_handle) {
@@ -57,5 +57,5 @@ int SetQosOnSocket(int socket, CipUsint qos_value) {
    *  in the IP header, must be shifted left 2 bits. */
   DWORD set_tos = qos_value << 2;
   return setsockopt(
-      socket, IPPROTO_IP, IP_TOS, (char*)&set_tos, sizeof(set_tos));
+    socket, IPPROTO_IP, IP_TOS, (char*)&set_tos, sizeof(set_tos));
 }

+ 1 - 1
source/src/ports/MINGW/opener_error.c

@@ -22,7 +22,7 @@ int GetSocketErrorNumber(void) {
 char* GetErrorMessage(int error_number) {
   char* error_message = NULL;
   FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
-                     FORMAT_MESSAGE_IGNORE_INSERTS,
+                   FORMAT_MESSAGE_IGNORE_INSERTS,
                  NULL,
                  error_number,
                  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),

+ 25 - 25
source/src/ports/MINGW/sample_application/ethlinkcbs.c

@@ -68,36 +68,36 @@ EipStatus EthLnkPreGetCallback(CipInstance* const instance,
   switch (attr_no) {
     case 4: {
       CipEthernetLinkInterfaceCounters* p_iface_cntrs =
-          &g_ethernet_link[idx].interface_cntrs;
+        &g_ethernet_link[idx].interface_cntrs;
 
       ++iface_calls[idx]; /* Count successful calls */
       p_iface_cntrs->ul.in_octets =
-          MAKE_CNTR(inst_no, attr_no, 0, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 0, iface_calls[idx]);
       p_iface_cntrs->ul.in_ucast =
-          MAKE_CNTR(inst_no, attr_no, 1, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 1, iface_calls[idx]);
       p_iface_cntrs->ul.in_nucast =
-          MAKE_CNTR(inst_no, attr_no, 2, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 2, iface_calls[idx]);
       p_iface_cntrs->ul.in_discards =
-          MAKE_CNTR(inst_no, attr_no, 3, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 3, iface_calls[idx]);
       p_iface_cntrs->ul.in_errors =
-          MAKE_CNTR(inst_no, attr_no, 4, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 4, iface_calls[idx]);
       p_iface_cntrs->ul.in_unknown_protos =
-          MAKE_CNTR(inst_no, attr_no, 5, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 5, iface_calls[idx]);
       p_iface_cntrs->ul.out_octets =
-          MAKE_CNTR(inst_no, attr_no, 6, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 6, iface_calls[idx]);
       p_iface_cntrs->ul.out_ucast =
-          MAKE_CNTR(inst_no, attr_no, 7, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 7, iface_calls[idx]);
       p_iface_cntrs->ul.out_nucast =
-          MAKE_CNTR(inst_no, attr_no, 8, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 8, iface_calls[idx]);
       p_iface_cntrs->ul.out_discards =
-          MAKE_CNTR(inst_no, attr_no, 9, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 9, iface_calls[idx]);
       p_iface_cntrs->ul.out_errors =
-          MAKE_CNTR(inst_no, attr_no, 10, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 10, iface_calls[idx]);
       break;
     }
     case 5: {
       CipEthernetLinkMediaCounters* p_media_cntrs =
-          &g_ethernet_link[idx].media_cntrs;
+        &g_ethernet_link[idx].media_cntrs;
 
       ++media_calls[idx]; /* Count successful calls */
       /* The 1 != mediaCalls[idx] is a concession to the conformance test tool
@@ -106,29 +106,29 @@ EipStatus EthLnkPreGetCallback(CipInstance* const instance,
        */
       if (1 != media_calls[idx]) {
         p_media_cntrs->ul.align_errs =
-            MAKE_CNTR(inst_no, attr_no, 0, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 0, media_calls[idx]);
         p_media_cntrs->ul.fcs_errs =
-            MAKE_CNTR(inst_no, attr_no, 1, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 1, media_calls[idx]);
         p_media_cntrs->ul.single_coll =
-            MAKE_CNTR(inst_no, attr_no, 2, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 2, media_calls[idx]);
         p_media_cntrs->ul.multi_coll =
-            MAKE_CNTR(inst_no, attr_no, 3, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 3, media_calls[idx]);
         p_media_cntrs->ul.sqe_test_errs =
-            MAKE_CNTR(inst_no, attr_no, 4, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 4, media_calls[idx]);
         p_media_cntrs->ul.def_trans =
-            MAKE_CNTR(inst_no, attr_no, 5, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 5, media_calls[idx]);
         p_media_cntrs->ul.late_coll =
-            MAKE_CNTR(inst_no, attr_no, 6, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 6, media_calls[idx]);
         p_media_cntrs->ul.exc_coll =
-            MAKE_CNTR(inst_no, attr_no, 7, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 7, media_calls[idx]);
         p_media_cntrs->ul.mac_tx_errs =
-            MAKE_CNTR(inst_no, attr_no, 8, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 8, media_calls[idx]);
         p_media_cntrs->ul.crs_errs =
-            MAKE_CNTR(inst_no, attr_no, 9, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 9, media_calls[idx]);
         p_media_cntrs->ul.frame_too_long =
-            MAKE_CNTR(inst_no, attr_no, 10, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 10, media_calls[idx]);
         p_media_cntrs->ul.mac_rx_errs =
-            MAKE_CNTR(inst_no, attr_no, 11, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 11, media_calls[idx]);
       }
       break;
     }

+ 7 - 8
source/src/ports/MINGW/sample_application/sampleapplication.c

@@ -71,19 +71,18 @@ EipStatus ApplicationInitialization(void) {
                                     DEMO_APP_INPUT_ASSEMBLY_NUM,
                                     DEMO_APP_CONFIG_ASSEMBLY_NUM);
   ConfigureListenOnlyConnectionPoint(
-      0,
-      DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM,
-      DEMO_APP_INPUT_ASSEMBLY_NUM,
-      DEMO_APP_CONFIG_ASSEMBLY_NUM);
+    0,
+    DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM,
+    DEMO_APP_INPUT_ASSEMBLY_NUM,
+    DEMO_APP_CONFIG_ASSEMBLY_NUM);
 
   /* For NV data support connect callback functions for each object class with
    *  NV data.
    */
   InsertGetSetCallback(
-      GetCipClass(kCipQoSClassCode), NvQosSetCallback, kNvDataFunc);
-  InsertGetSetCallback(GetCipClass(kCipTcpIpInterfaceClassCode),
-                       NvTcpipSetCallback,
-                       kNvDataFunc);
+    GetCipClass(kCipQoSClassCode), NvQosSetCallback, kNvDataFunc);
+  InsertGetSetCallback(
+    GetCipClass(kCipTcpIpInterfaceClassCode), NvTcpipSetCallback, kNvDataFunc);
 
 #if defined(OPENER_ETHLINK_CNTRS_ENABLE) && 0 != OPENER_ETHLINK_CNTRS_ENABLE
   /* For the Ethernet Interface & Media Counters connect a PreGetCallback and

+ 10 - 10
source/src/ports/POSIX/main.c

@@ -120,7 +120,7 @@ int main(int argc, char* arg[]) {
    */
   if (kEipStatusError == NvdataLoad()) {
     OPENER_TRACE_WARN(
-        "Loading of some NV data failed. Maybe the first start?\n");
+      "Loading of some NV data failed. Maybe the first start?\n");
   }
 
   /* Bring up network interface or start DHCP client ... */
@@ -139,7 +139,7 @@ int main(int argc, char* arg[]) {
 
   /* Next actions depend on the set network configuration method. */
   CipDword network_config_method =
-      g_tcpip.config_control & kTcpipCfgCtrlMethodMask;
+    g_tcpip.config_control & kTcpipCfgCtrlMethodMask;
   if (kTcpipCfgCtrlStaticIp == network_config_method) {
     OPENER_TRACE_INFO("Static network configuration done\n");
   }
@@ -149,14 +149,14 @@ int main(int argc, char* arg[]) {
      * here for IP present (DHCP done) or abort through g_end_stack. */
     eip_status = IfaceWaitForIp(arg[1], -1, &g_end_stack);
     OPENER_TRACE_INFO(
-        "DHCP wait for interface: eip_status %d, g_end_stack=%d\n",
-        eip_status,
-        g_end_stack);
+      "DHCP wait for interface: eip_status %d, g_end_stack=%d\n",
+      eip_status,
+      g_end_stack);
     if (kEipStatusOk == eip_status && 0 == g_end_stack) {
       /* Read IP configuration received via DHCP from interface and store in
        *  the TCP/IP object.*/
       eip_status =
-          IfaceGetConfiguration(arg[1], &g_tcpip.interface_configuration);
+        IfaceGetConfiguration(arg[1], &g_tcpip.interface_configuration);
       if (eip_status < 0) {
         OPENER_TRACE_WARN("Problems getting interface configuration\n");
       }
@@ -269,10 +269,10 @@ static void* executeEventLoop(void* pthread_arg) {
 
 #ifdef FUZZING_AFL
 static void fuzzHandlePacketFlow(void) {
-  int socket_fd = 0;                      // Fake socket fd
-  uint8_t buff[512];                      // Input buffer
-  struct sockaddr_in from_address = {0};  // Fake socket address
-  int remaining_bytes             = 0;    // Fake reamining bytes
+  int socket_fd = 0;                        // Fake socket fd
+  uint8_t buff[512];                        // Input buffer
+  struct sockaddr_in from_address = { 0 };  // Fake socket address
+  int remaining_bytes             = 0;      // Fake reamining bytes
   ENIPMessage outgoing_message;
 
   /* AFL persistent mode */

+ 5 - 5
source/src/ports/POSIX/networkconfig.c

@@ -50,7 +50,7 @@ EipStatus IfaceGetMacAddress(const char* iface,
 }
 
 static EipStatus GetIpAndNetmaskFromInterface(
-    const char* iface, CipTcpIpInterfaceConfiguration* iface_cfg) {
+  const char* iface, CipTcpIpInterfaceConfiguration* iface_cfg) {
   struct ifreq ifr;
   size_t if_name_len = strlen(iface);
   if (if_name_len < sizeof(ifr.ifr_name)) {
@@ -89,7 +89,7 @@ static EipStatus GetIpAndNetmaskFromInterface(
 }
 
 static EipStatus GetGatewayFromRoute(
-    const char* iface, CipTcpIpInterfaceConfiguration* iface_cfg) {
+  const char* iface, CipTcpIpInterfaceConfiguration* iface_cfg) {
   static const char route_location[] = "/proc/net/route";
 
   FILE* file_handle = fopen(route_location, "r");
@@ -150,7 +150,7 @@ static EipStatus GetGatewayFromRoute(
 }
 
 static EipStatus GetDnsInfoFromResolvConf(
-    CipTcpIpInterfaceConfiguration* iface_cfg) {
+  CipTcpIpInterfaceConfiguration* iface_cfg) {
   static const char resolv_conf_file[] = "/etc/resolv.conf";
   FILE* file_handle                    = fopen(resolv_conf_file, "r");
   char* file_buffer                    = NULL;
@@ -234,7 +234,7 @@ static EipStatus GetDnsInfoFromResolvConf(
 }
 
 static int nanosleep_simple32(uint32_t sleep_ns) {
-  struct timespec tsv = {0, (long)sleep_ns};
+  struct timespec tsv = { 0, (long)sleep_ns };
   struct timespec trem;
   int rc;
 
@@ -257,7 +257,7 @@ EipStatus IfaceGetConfiguration(const char* iface,
   status = GetIpAndNetmaskFromInterface(iface, &local_cfg);
   if (kEipStatusOk == status) {
     (void)nanosleep_simple32(
-        300000000u); /* sleep 300ms to let route "settle" */
+      300000000u); /* sleep 300ms to let route "settle" */
     status = GetGatewayFromRoute(iface, &local_cfg);
     if (kEipStatusOk == status) {
       status = GetDnsInfoFromResolvConf(&local_cfg);

+ 3 - 3
source/src/ports/POSIX/networkhandler.c

@@ -20,12 +20,12 @@
 #include "trace.h"
 
 MicroSeconds GetMicroSeconds(void) {
-  struct timespec now = {.tv_nsec = 0, .tv_sec = 0};
+  struct timespec now = { .tv_nsec = 0, .tv_sec = 0 };
 
   int error = clock_gettime(CLOCK_MONOTONIC, &now);
   OPENER_ASSERT(-1 != error);
   MicroSeconds micro_seconds =
-      (MicroSeconds)now.tv_nsec / 1000ULL + now.tv_sec * 1000000ULL;
+    (MicroSeconds)now.tv_nsec / 1000ULL + now.tv_sec * 1000000ULL;
   return micro_seconds;
 }
 
@@ -56,7 +56,7 @@ void CloseSocketPlatform(int socket_handle) {
 
 int SetSocketToNonBlocking(int socket_handle) {
   return fcntl(
-      socket_handle, F_SETFL, fcntl(socket_handle, F_GETFL, 0) | O_NONBLOCK);
+    socket_handle, F_SETFL, fcntl(socket_handle, F_GETFL, 0) | O_NONBLOCK);
 }
 
 int SetQosOnSocket(const int socket, CipUsint qos_value) {

+ 25 - 25
source/src/ports/POSIX/sample_application/ethlinkcbs.c

@@ -68,36 +68,36 @@ EipStatus EthLnkPreGetCallback(CipInstance* const instance,
   switch (attr_no) {
     case 4: {
       CipEthernetLinkInterfaceCounters* p_iface_cntrs =
-          &g_ethernet_link[idx].interface_cntrs;
+        &g_ethernet_link[idx].interface_cntrs;
 
       ++iface_calls[idx]; /* Count successful calls */
       p_iface_cntrs->ul.in_octets =
-          MAKE_CNTR(inst_no, attr_no, 0, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 0, iface_calls[idx]);
       p_iface_cntrs->ul.in_ucast =
-          MAKE_CNTR(inst_no, attr_no, 1, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 1, iface_calls[idx]);
       p_iface_cntrs->ul.in_nucast =
-          MAKE_CNTR(inst_no, attr_no, 2, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 2, iface_calls[idx]);
       p_iface_cntrs->ul.in_discards =
-          MAKE_CNTR(inst_no, attr_no, 3, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 3, iface_calls[idx]);
       p_iface_cntrs->ul.in_errors =
-          MAKE_CNTR(inst_no, attr_no, 4, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 4, iface_calls[idx]);
       p_iface_cntrs->ul.in_unknown_protos =
-          MAKE_CNTR(inst_no, attr_no, 5, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 5, iface_calls[idx]);
       p_iface_cntrs->ul.out_octets =
-          MAKE_CNTR(inst_no, attr_no, 6, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 6, iface_calls[idx]);
       p_iface_cntrs->ul.out_ucast =
-          MAKE_CNTR(inst_no, attr_no, 7, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 7, iface_calls[idx]);
       p_iface_cntrs->ul.out_nucast =
-          MAKE_CNTR(inst_no, attr_no, 8, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 8, iface_calls[idx]);
       p_iface_cntrs->ul.out_discards =
-          MAKE_CNTR(inst_no, attr_no, 9, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 9, iface_calls[idx]);
       p_iface_cntrs->ul.out_errors =
-          MAKE_CNTR(inst_no, attr_no, 10, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 10, iface_calls[idx]);
       break;
     }
     case 5: {
       CipEthernetLinkMediaCounters* p_media_cntrs =
-          &g_ethernet_link[idx].media_cntrs;
+        &g_ethernet_link[idx].media_cntrs;
 
       ++media_calls[idx]; /* Count successful calls */
       /* The 1 != mediaCalls[idx] is a concession to the conformance test tool
@@ -106,29 +106,29 @@ EipStatus EthLnkPreGetCallback(CipInstance* const instance,
        */
       if (1 != media_calls[idx]) {
         p_media_cntrs->ul.align_errs =
-            MAKE_CNTR(inst_no, attr_no, 0, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 0, media_calls[idx]);
         p_media_cntrs->ul.fcs_errs =
-            MAKE_CNTR(inst_no, attr_no, 1, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 1, media_calls[idx]);
         p_media_cntrs->ul.single_coll =
-            MAKE_CNTR(inst_no, attr_no, 2, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 2, media_calls[idx]);
         p_media_cntrs->ul.multi_coll =
-            MAKE_CNTR(inst_no, attr_no, 3, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 3, media_calls[idx]);
         p_media_cntrs->ul.sqe_test_errs =
-            MAKE_CNTR(inst_no, attr_no, 4, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 4, media_calls[idx]);
         p_media_cntrs->ul.def_trans =
-            MAKE_CNTR(inst_no, attr_no, 5, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 5, media_calls[idx]);
         p_media_cntrs->ul.late_coll =
-            MAKE_CNTR(inst_no, attr_no, 6, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 6, media_calls[idx]);
         p_media_cntrs->ul.exc_coll =
-            MAKE_CNTR(inst_no, attr_no, 7, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 7, media_calls[idx]);
         p_media_cntrs->ul.mac_tx_errs =
-            MAKE_CNTR(inst_no, attr_no, 8, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 8, media_calls[idx]);
         p_media_cntrs->ul.crs_errs =
-            MAKE_CNTR(inst_no, attr_no, 9, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 9, media_calls[idx]);
         p_media_cntrs->ul.frame_too_long =
-            MAKE_CNTR(inst_no, attr_no, 10, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 10, media_calls[idx]);
         p_media_cntrs->ul.mac_rx_errs =
-            MAKE_CNTR(inst_no, attr_no, 11, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 11, media_calls[idx]);
       }
       break;
     }

+ 9 - 10
source/src/ports/POSIX/sample_application/sampleapplication.c

@@ -74,19 +74,18 @@ EipStatus ApplicationInitialization(void) {
                                     DEMO_APP_INPUT_ASSEMBLY_NUM,
                                     DEMO_APP_CONFIG_ASSEMBLY_NUM);
   ConfigureListenOnlyConnectionPoint(
-      0,
-      DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM,
-      DEMO_APP_INPUT_ASSEMBLY_NUM,
-      DEMO_APP_CONFIG_ASSEMBLY_NUM);
+    0,
+    DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM,
+    DEMO_APP_INPUT_ASSEMBLY_NUM,
+    DEMO_APP_CONFIG_ASSEMBLY_NUM);
 
   /* For NV data support connect callback functions for each object class with
    *  NV data.
    */
   InsertGetSetCallback(
-      GetCipClass(kCipQoSClassCode), NvQosSetCallback, kNvDataFunc);
-  InsertGetSetCallback(GetCipClass(kCipTcpIpInterfaceClassCode),
-                       NvTcpipSetCallback,
-                       kNvDataFunc);
+    GetCipClass(kCipQoSClassCode), NvQosSetCallback, kNvDataFunc);
+  InsertGetSetCallback(
+    GetCipClass(kCipTcpIpInterfaceClassCode), NvTcpipSetCallback, kNvDataFunc);
 
 #if defined(OPENER_ETHLINK_CNTRS_ENABLE) && 0 != OPENER_ETHLINK_CNTRS_ENABLE
   /* For the Ethernet Interface & Media Counters connect a PreGetCallback and
@@ -158,7 +157,7 @@ EipStatus AfterAssemblyDataReceived(CipInstance* instance) {
       break;
     default:
       OPENER_TRACE_INFO(
-          "Unknown assembly instance ind AfterAssemblyDataReceived");
+        "Unknown assembly instance ind AfterAssemblyDataReceived");
       break;
   }
   return status;
@@ -208,7 +207,7 @@ void RunIdleChanged(EipUint32 run_idle_value) {
     CipIdentitySetExtendedDeviceStatus(kAtLeastOneIoConnectionInRunMode);
   } else {
     CipIdentitySetExtendedDeviceStatus(
-        kAtLeastOneIoConnectionEstablishedAllInIdleMode);
+      kAtLeastOneIoConnectionEstablishedAllInIdleMode);
   }
   (void)run_idle_value;
 }

+ 2 - 2
source/src/ports/STM32/networkconfig.c

@@ -25,7 +25,7 @@ EipStatus IfaceGetMacAddress(TcpIpInterface* iface,
 }
 
 static EipStatus GetIpAndNetmaskFromInterface(
-    TcpIpInterface* iface, CipTcpIpInterfaceConfiguration* iface_cfg) {
+  TcpIpInterface* iface, CipTcpIpInterfaceConfiguration* iface_cfg) {
   iface_cfg->ip_address   = iface->ip_addr.addr;
   iface_cfg->network_mask = iface->netmask.addr;
 
@@ -33,7 +33,7 @@ static EipStatus GetIpAndNetmaskFromInterface(
 }
 
 static EipStatus GetGatewayFromRoute(
-    TcpIpInterface* iface, CipTcpIpInterfaceConfiguration* iface_cfg) {
+  TcpIpInterface* iface, CipTcpIpInterfaceConfiguration* iface_cfg) {
   iface_cfg->gateway = iface->gw.addr;
 
   return kEipStatusOk;

+ 1 - 1
source/src/ports/STM32/networkhandler.c

@@ -38,7 +38,7 @@ void CloseSocketPlatform(int socket_handle) {
 
 int SetSocketToNonBlocking(int socket_handle) {
   return fcntl(
-      socket_handle, F_SETFL, fcntl(socket_handle, F_GETFL, 0) | O_NONBLOCK);
+    socket_handle, F_SETFL, fcntl(socket_handle, F_GETFL, 0) | O_NONBLOCK);
 }
 
 int SetQosOnSocket(const int socket, CipUsint qos_value) {

+ 1 - 1
source/src/ports/STM32/opener.c

@@ -69,7 +69,7 @@ void opener_init(struct netif* netif) {
   }
   if ((g_end_stack == 0) && (eip_status == kEipStatusOk)) {
     osThreadDef(
-        OpENer, opener_thread, OPENER_THREAD_PRIO, 0, OPENER_STACK_SIZE);
+      OpENer, opener_thread, OPENER_THREAD_PRIO, 0, OPENER_STACK_SIZE);
     osThreadCreate(osThread(OpENer), netif);
     OPENER_TRACE_INFO("OpENer: opener_thread started, free heap size: %d\n",
                       xPortGetFreeHeapSize());

+ 25 - 25
source/src/ports/STM32/sample_application/ethlinkcbs.c

@@ -68,36 +68,36 @@ EipStatus EthLnkPreGetCallback(CipInstance* const instance,
   switch (attr_no) {
     case 4: {
       CipEthernetLinkInterfaceCounters* p_iface_cntrs =
-          &g_ethernet_link[idx].interface_cntrs;
+        &g_ethernet_link[idx].interface_cntrs;
 
       ++iface_calls[idx]; /* Count successful calls */
       p_iface_cntrs->ul.in_octets =
-          MAKE_CNTR(inst_no, attr_no, 0, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 0, iface_calls[idx]);
       p_iface_cntrs->ul.in_ucast =
-          MAKE_CNTR(inst_no, attr_no, 1, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 1, iface_calls[idx]);
       p_iface_cntrs->ul.in_nucast =
-          MAKE_CNTR(inst_no, attr_no, 2, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 2, iface_calls[idx]);
       p_iface_cntrs->ul.in_discards =
-          MAKE_CNTR(inst_no, attr_no, 3, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 3, iface_calls[idx]);
       p_iface_cntrs->ul.in_errors =
-          MAKE_CNTR(inst_no, attr_no, 4, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 4, iface_calls[idx]);
       p_iface_cntrs->ul.in_unknown_protos =
-          MAKE_CNTR(inst_no, attr_no, 5, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 5, iface_calls[idx]);
       p_iface_cntrs->ul.out_octets =
-          MAKE_CNTR(inst_no, attr_no, 6, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 6, iface_calls[idx]);
       p_iface_cntrs->ul.out_ucast =
-          MAKE_CNTR(inst_no, attr_no, 7, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 7, iface_calls[idx]);
       p_iface_cntrs->ul.out_nucast =
-          MAKE_CNTR(inst_no, attr_no, 8, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 8, iface_calls[idx]);
       p_iface_cntrs->ul.out_discards =
-          MAKE_CNTR(inst_no, attr_no, 9, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 9, iface_calls[idx]);
       p_iface_cntrs->ul.out_errors =
-          MAKE_CNTR(inst_no, attr_no, 10, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 10, iface_calls[idx]);
       break;
     }
     case 5: {
       CipEthernetLinkMediaCounters* p_media_cntrs =
-          &g_ethernet_link[idx].media_cntrs;
+        &g_ethernet_link[idx].media_cntrs;
 
       ++media_calls[idx]; /* Count successful calls */
       /* The 1 != mediaCalls[idx] is a concession to the conformance test tool
@@ -106,29 +106,29 @@ EipStatus EthLnkPreGetCallback(CipInstance* const instance,
        */
       if (1 != media_calls[idx]) {
         p_media_cntrs->ul.align_errs =
-            MAKE_CNTR(inst_no, attr_no, 0, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 0, media_calls[idx]);
         p_media_cntrs->ul.fcs_errs =
-            MAKE_CNTR(inst_no, attr_no, 1, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 1, media_calls[idx]);
         p_media_cntrs->ul.single_coll =
-            MAKE_CNTR(inst_no, attr_no, 2, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 2, media_calls[idx]);
         p_media_cntrs->ul.multi_coll =
-            MAKE_CNTR(inst_no, attr_no, 3, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 3, media_calls[idx]);
         p_media_cntrs->ul.sqe_test_errs =
-            MAKE_CNTR(inst_no, attr_no, 4, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 4, media_calls[idx]);
         p_media_cntrs->ul.def_trans =
-            MAKE_CNTR(inst_no, attr_no, 5, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 5, media_calls[idx]);
         p_media_cntrs->ul.late_coll =
-            MAKE_CNTR(inst_no, attr_no, 6, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 6, media_calls[idx]);
         p_media_cntrs->ul.exc_coll =
-            MAKE_CNTR(inst_no, attr_no, 7, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 7, media_calls[idx]);
         p_media_cntrs->ul.mac_tx_errs =
-            MAKE_CNTR(inst_no, attr_no, 8, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 8, media_calls[idx]);
         p_media_cntrs->ul.crs_errs =
-            MAKE_CNTR(inst_no, attr_no, 9, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 9, media_calls[idx]);
         p_media_cntrs->ul.frame_too_long =
-            MAKE_CNTR(inst_no, attr_no, 10, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 10, media_calls[idx]);
         p_media_cntrs->ul.mac_rx_errs =
-            MAKE_CNTR(inst_no, attr_no, 11, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 11, media_calls[idx]);
       }
       break;
     }

+ 6 - 6
source/src/ports/STM32/sample_application/sampleapplication.c

@@ -69,10 +69,10 @@ EipStatus ApplicationInitialization(void) {
                                     DEMO_APP_INPUT_ASSEMBLY_NUM,
                                     DEMO_APP_CONFIG_ASSEMBLY_NUM);
   ConfigureListenOnlyConnectionPoint(
-      0,
-      DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM,
-      DEMO_APP_INPUT_ASSEMBLY_NUM,
-      DEMO_APP_CONFIG_ASSEMBLY_NUM);
+    0,
+    DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM,
+    DEMO_APP_INPUT_ASSEMBLY_NUM,
+    DEMO_APP_CONFIG_ASSEMBLY_NUM);
 
 #if defined(OPENER_ETHLINK_CNTRS_ENABLE) && 0 != OPENER_ETHLINK_CNTRS_ENABLE
   /* For the Ethernet Interface & Media Counters connect a PreGetCallback and
@@ -144,7 +144,7 @@ EipStatus AfterAssemblyDataReceived(CipInstance* instance) {
       break;
     default:
       OPENER_TRACE_INFO(
-          "Unknown assembly instance ind AfterAssemblyDataReceived");
+        "Unknown assembly instance ind AfterAssemblyDataReceived");
       break;
   }
   return status;
@@ -194,7 +194,7 @@ void RunIdleChanged(EipUint32 run_idle_value) {
     CipIdentitySetExtendedDeviceStatus(kAtLeastOneIoConnectionInRunMode);
   } else {
     CipIdentitySetExtendedDeviceStatus(
-        kAtLeastOneIoConnectionEstablishedAllInIdleMode);
+      kAtLeastOneIoConnectionEstablishedAllInIdleMode);
   }
   (void)run_idle_value;
 }

+ 2 - 2
source/src/ports/WIN32/main.c

@@ -98,7 +98,7 @@ int main(int argc, char* arg[]) {
    */
   if (kEipStatusError == NvdataLoad()) {
     OPENER_TRACE_WARN(
-        "Loading of some NV data failed. Maybe the first start?\n");
+      "Loading of some NV data failed. Maybe the first start?\n");
   }
 
   /* Bring up network interface or start DHCP client ... */
@@ -118,7 +118,7 @@ int main(int argc, char* arg[]) {
 
   /* Next actions depend on the set network configuration method. */
   CipDword network_config_method =
-      g_tcpip.config_control & kTcpipCfgCtrlMethodMask;
+    g_tcpip.config_control & kTcpipCfgCtrlMethodMask;
   if (kTcpipCfgCtrlStaticIp == network_config_method) {
     OPENER_TRACE_INFO("Static network configuration done\n");
   }

+ 11 - 11
source/src/ports/WIN32/networkconfig.c

@@ -161,11 +161,11 @@ EipStatus RetrieveAdapterAddressesTable(ULONG flags,
     p_addr_table = (PIP_ADAPTER_ADDRESSES)MALLOC(outBufLen);
     if (NULL == p_addr_table) {
       OPENER_TRACE_ERR(
-          "Memory allocation failed for IP_ADAPTER_ADDRESSES struct\n");
+        "Memory allocation failed for IP_ADAPTER_ADDRESSES struct\n");
       return kEipStatusError;
     }
     ret_val =
-        GetAdaptersAddresses(AF_INET, flags, NULL, p_addr_table, &outBufLen);
+      GetAdaptersAddresses(AF_INET, flags, NULL, p_addr_table, &outBufLen);
 
     if (ERROR_BUFFER_OVERFLOW == ret_val) {
       FREE(p_addr_table);
@@ -335,7 +335,7 @@ EipStatus IfaceGetConfiguration(const char* iface,
        */
       {
         PIP_ADAPTER_UNICAST_ADDRESS pUnicast =
-            p_addr_entry->FirstUnicastAddress;
+          p_addr_entry->FirstUnicastAddress;
         if (NULL != pUnicast) {
           local_cfg.ip_address = GetIpFromSocketAddress(&pUnicast->Address);
         }
@@ -344,30 +344,30 @@ EipStatus IfaceGetConfiguration(const char* iface,
         PIP_ADAPTER_PREFIX pPrefix = p_addr_entry->FirstPrefix;
         if (NULL != pPrefix) {
           local_cfg.network_mask =
-              htonl(0xffffffff << (32U - pPrefix->PrefixLength));
+            htonl(0xffffffff << (32U - pPrefix->PrefixLength));
         }
       }
       {
         PIP_ADAPTER_GATEWAY_ADDRESS pGateway =
-            p_addr_entry->FirstGatewayAddress;
+          p_addr_entry->FirstGatewayAddress;
         if (NULL != pGateway) {
           local_cfg.gateway = GetIpFromSocketAddress(&pGateway->Address);
         }
       }
       {
         IP_ADAPTER_DNS_SERVER_ADDRESS* pDnServer =
-            p_addr_entry->FirstDnsServerAddress;
+          p_addr_entry->FirstDnsServerAddress;
         if (NULL != pDnServer) {
           local_cfg.name_server = GetIpFromSocketAddress(&pDnServer->Address);
           pDnServer             = pDnServer->Next;
           if (NULL != pDnServer) {
             local_cfg.name_server_2 =
-                GetIpFromSocketAddress(&pDnServer->Address);
+              GetIpFromSocketAddress(&pDnServer->Address);
           }
         }
       }
       DWORD ret_val =
-          WideToCipString(p_addr_entry->DnsSuffix, &local_cfg.domain_name);
+        WideToCipString(p_addr_entry->DnsSuffix, &local_cfg.domain_name);
       if (NO_ERROR != ret_val) {
         char* error_message = GetErrorMessage(ret_val);
         OPENER_TRACE_ERR("WideToCipString(DnsSuffix) failed with error: %" PRIDW
@@ -426,8 +426,8 @@ EipStatus IfaceWaitForIp(const char* const iface,
           pmib_ipaddr_table = MALLOC(addr_table_sz);
           if (NULL == pmib_ipaddr_table) {
             OPENER_TRACE_ERR(
-                "Memory allocation failed for "
-                "MIB_IPADDRTABLE struct\n");
+              "Memory allocation failed for "
+              "MIB_IPADDRTABLE struct\n");
             return kEipStatusError;
           }
         }
@@ -460,7 +460,7 @@ EipStatus IfaceWaitForIp(const char* const iface,
              (0 == SleepEx(WAIT_CYCLE_MS, FALSE)));
 
     OPENER_TRACE_INFO(
-        "IP=%08" PRIx32 ", timeout=%d\n", (uint32_t)ntohl(ipaddr), timeout);
+      "IP=%08" PRIx32 ", timeout=%d\n", (uint32_t)ntohl(ipaddr), timeout);
     if (pmib_ipaddr_table) {
       FREE(pmib_ipaddr_table);
     }

+ 1 - 1
source/src/ports/WIN32/networkhandler.c

@@ -41,7 +41,7 @@ void ShutdownSocketPlatform(int socket_handle) {
   (void)socket_handle;
 
 #pragma message( \
-    "Untested. Is a shutdown() needed under Windows like for the POSIX port?")
+  "Untested. Is a shutdown() needed under Windows like for the POSIX port?")
 }
 
 void CloseSocketPlatform(int socket_handle) {

+ 1 - 1
source/src/ports/WIN32/opener_error.c

@@ -22,7 +22,7 @@ int GetSocketErrorNumber(void) {
 char* GetErrorMessage(int error_number) {
   char* error_message = NULL;
   FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
-                     FORMAT_MESSAGE_IGNORE_INSERTS,
+                   FORMAT_MESSAGE_IGNORE_INSERTS,
                  NULL,
                  error_number,
                  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),

+ 25 - 25
source/src/ports/WIN32/sample_application/ethlinkcbs.c

@@ -68,36 +68,36 @@ EipStatus EthLnkPreGetCallback(CipInstance* const instance,
   switch (attr_no) {
     case 4: {
       CipEthernetLinkInterfaceCounters* p_iface_cntrs =
-          &g_ethernet_link[idx].interface_cntrs;
+        &g_ethernet_link[idx].interface_cntrs;
 
       ++iface_calls[idx]; /* Count successful calls */
       p_iface_cntrs->ul.in_octets =
-          MAKE_CNTR(inst_no, attr_no, 0, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 0, iface_calls[idx]);
       p_iface_cntrs->ul.in_ucast =
-          MAKE_CNTR(inst_no, attr_no, 1, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 1, iface_calls[idx]);
       p_iface_cntrs->ul.in_nucast =
-          MAKE_CNTR(inst_no, attr_no, 2, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 2, iface_calls[idx]);
       p_iface_cntrs->ul.in_discards =
-          MAKE_CNTR(inst_no, attr_no, 3, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 3, iface_calls[idx]);
       p_iface_cntrs->ul.in_errors =
-          MAKE_CNTR(inst_no, attr_no, 4, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 4, iface_calls[idx]);
       p_iface_cntrs->ul.in_unknown_protos =
-          MAKE_CNTR(inst_no, attr_no, 5, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 5, iface_calls[idx]);
       p_iface_cntrs->ul.out_octets =
-          MAKE_CNTR(inst_no, attr_no, 6, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 6, iface_calls[idx]);
       p_iface_cntrs->ul.out_ucast =
-          MAKE_CNTR(inst_no, attr_no, 7, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 7, iface_calls[idx]);
       p_iface_cntrs->ul.out_nucast =
-          MAKE_CNTR(inst_no, attr_no, 8, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 8, iface_calls[idx]);
       p_iface_cntrs->ul.out_discards =
-          MAKE_CNTR(inst_no, attr_no, 9, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 9, iface_calls[idx]);
       p_iface_cntrs->ul.out_errors =
-          MAKE_CNTR(inst_no, attr_no, 10, iface_calls[idx]);
+        MAKE_CNTR(inst_no, attr_no, 10, iface_calls[idx]);
       break;
     }
     case 5: {
       CipEthernetLinkMediaCounters* p_media_cntrs =
-          &g_ethernet_link[idx].media_cntrs;
+        &g_ethernet_link[idx].media_cntrs;
 
       ++media_calls[idx]; /* Count successful calls */
       /* The 1 != mediaCalls[idx] is a concession to the conformance test tool
@@ -106,29 +106,29 @@ EipStatus EthLnkPreGetCallback(CipInstance* const instance,
        */
       if (1 != media_calls[idx]) {
         p_media_cntrs->ul.align_errs =
-            MAKE_CNTR(inst_no, attr_no, 0, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 0, media_calls[idx]);
         p_media_cntrs->ul.fcs_errs =
-            MAKE_CNTR(inst_no, attr_no, 1, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 1, media_calls[idx]);
         p_media_cntrs->ul.single_coll =
-            MAKE_CNTR(inst_no, attr_no, 2, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 2, media_calls[idx]);
         p_media_cntrs->ul.multi_coll =
-            MAKE_CNTR(inst_no, attr_no, 3, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 3, media_calls[idx]);
         p_media_cntrs->ul.sqe_test_errs =
-            MAKE_CNTR(inst_no, attr_no, 4, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 4, media_calls[idx]);
         p_media_cntrs->ul.def_trans =
-            MAKE_CNTR(inst_no, attr_no, 5, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 5, media_calls[idx]);
         p_media_cntrs->ul.late_coll =
-            MAKE_CNTR(inst_no, attr_no, 6, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 6, media_calls[idx]);
         p_media_cntrs->ul.exc_coll =
-            MAKE_CNTR(inst_no, attr_no, 7, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 7, media_calls[idx]);
         p_media_cntrs->ul.mac_tx_errs =
-            MAKE_CNTR(inst_no, attr_no, 8, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 8, media_calls[idx]);
         p_media_cntrs->ul.crs_errs =
-            MAKE_CNTR(inst_no, attr_no, 9, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 9, media_calls[idx]);
         p_media_cntrs->ul.frame_too_long =
-            MAKE_CNTR(inst_no, attr_no, 10, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 10, media_calls[idx]);
         p_media_cntrs->ul.mac_rx_errs =
-            MAKE_CNTR(inst_no, attr_no, 11, media_calls[idx]);
+          MAKE_CNTR(inst_no, attr_no, 11, media_calls[idx]);
       }
       break;
     }

+ 7 - 8
source/src/ports/WIN32/sample_application/sampleapplication.c

@@ -71,19 +71,18 @@ EipStatus ApplicationInitialization(void) {
                                     DEMO_APP_INPUT_ASSEMBLY_NUM,
                                     DEMO_APP_CONFIG_ASSEMBLY_NUM);
   ConfigureListenOnlyConnectionPoint(
-      0,
-      DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM,
-      DEMO_APP_INPUT_ASSEMBLY_NUM,
-      DEMO_APP_CONFIG_ASSEMBLY_NUM);
+    0,
+    DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM,
+    DEMO_APP_INPUT_ASSEMBLY_NUM,
+    DEMO_APP_CONFIG_ASSEMBLY_NUM);
 
   /* For NV data support connect callback functions for each object class with
    *  NV data.
    */
   InsertGetSetCallback(
-      GetCipClass(kCipQoSClassCode), NvQosSetCallback, kNvDataFunc);
-  InsertGetSetCallback(GetCipClass(kCipTcpIpInterfaceClassCode),
-                       NvTcpipSetCallback,
-                       kNvDataFunc);
+    GetCipClass(kCipQoSClassCode), NvQosSetCallback, kNvDataFunc);
+  InsertGetSetCallback(
+    GetCipClass(kCipTcpIpInterfaceClassCode), NvTcpipSetCallback, kNvDataFunc);
 
 #if defined(OPENER_ETHLINK_CNTRS_ENABLE) && 0 != OPENER_ETHLINK_CNTRS_ENABLE
   /* For the Ethernet Interface & Media Counters connect a PreGetCallback and

+ 191 - 193
source/src/ports/generic_networkhandler.c

@@ -34,7 +34,7 @@
 
 /* ----- Windows size_t PRI macros ------------- */
 #if defined(__MINGW32__) || \
-    defined(STM32) /* This is a Mingw compiler or STM32 target (GCC) */
+  defined(STM32) /* This is a Mingw compiler or STM32 target (GCC) */
 #define PRIuSZT PRIuPTR
 #define PRIxSZT PRIxPTR
 #else
@@ -149,19 +149,19 @@ EipStatus NetworkHandlerInitialize(void) {
 
   /* create a new TCP socket */
   if ((g_network_status.tcp_listener =
-           socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
+         socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
     int error_code      = GetSocketErrorNumber();
     char* error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-        "networkhandler tcp_listener: error allocating socket, %d - %s\n",
-        error_code,
-        error_message);
+      "networkhandler tcp_listener: error allocating socket, %d - %s\n",
+      error_code,
+      error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
 
   int set_socket_option_value =
-      1;  // Represents true for used set socket options
+    1;  // Represents true for used set socket options
   /* Activates address reuse */
   if (setsockopt(g_network_status.tcp_listener,
                  SOL_SOCKET,
@@ -169,42 +169,42 @@ EipStatus NetworkHandlerInitialize(void) {
                  (char*)&set_socket_option_value,
                  sizeof(set_socket_option_value)) == -1) {
     OPENER_TRACE_ERR(
-        "networkhandler tcp_listener: error setting socket option "
-        "SO_REUSEADDR\n");
+      "networkhandler tcp_listener: error setting socket option "
+      "SO_REUSEADDR\n");
     return kEipStatusError;
   }
 
   if (SetSocketToNonBlocking(g_network_status.tcp_listener) < 0) {
     OPENER_TRACE_ERR(
-        "networkhandler tcp_listener: error setting socket to non-blocking on "
-        "new socket\n");
+      "networkhandler tcp_listener: error setting socket to non-blocking on "
+      "new socket\n");
     return kEipStatusError;
   }
 
   /* create a new UDP socket */
   if ((g_network_status.udp_global_broadcast_listener =
-           socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == kEipInvalidSocket) {
+         socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == kEipInvalidSocket) {
     int error_code      = GetSocketErrorNumber();
     char* error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-        "networkhandler udp_global_broadcast_listener: error allocating "
-        "socket, %d - %s\n",
-        error_code,
-        error_message);
+      "networkhandler udp_global_broadcast_listener: error allocating "
+      "socket, %d - %s\n",
+      error_code,
+      error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
 
   /* create a new UDP socket */
   if ((g_network_status.udp_unicast_listener =
-           socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == kEipInvalidSocket) {
+         socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == kEipInvalidSocket) {
     int error_code      = GetSocketErrorNumber();
     char* error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-        "networkhandler udp_unicast_listener: error allocating socket, %d - "
-        "%s\n",
-        error_code,
-        error_message);
+      "networkhandler udp_unicast_listener: error allocating socket, %d - "
+      "%s\n",
+      error_code,
+      error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
@@ -217,16 +217,16 @@ EipStatus NetworkHandlerInitialize(void) {
                  (char*)&set_socket_option_value,
                  sizeof(set_socket_option_value)) == -1) {
     OPENER_TRACE_ERR(
-        "networkhandler udp_global_broadcast_listener: error setting socket "
-        "option SO_REUSEADDR\n");
+      "networkhandler udp_global_broadcast_listener: error setting socket "
+      "option SO_REUSEADDR\n");
     return kEipStatusError;
   }
 
   if (SetSocketToNonBlocking(g_network_status.udp_global_broadcast_listener) <
       0) {
     OPENER_TRACE_ERR(
-        "networkhandler udp_global_broadcast_listener: error setting socket to "
-        "non-blocking on new socket\n");
+      "networkhandler udp_global_broadcast_listener: error setting socket to "
+      "non-blocking on new socket\n");
     return kEipStatusError;
   }
 
@@ -238,22 +238,22 @@ EipStatus NetworkHandlerInitialize(void) {
                  (char*)&set_socket_option_value,
                  sizeof(set_socket_option_value)) == -1) {
     OPENER_TRACE_ERR(
-        "networkhandler udp_unicast_listener: error setting socket option "
-        "SO_REUSEADDR\n");
+      "networkhandler udp_unicast_listener: error setting socket option "
+      "SO_REUSEADDR\n");
     return kEipStatusError;
   }
 
   if (SetSocketToNonBlocking(g_network_status.udp_unicast_listener) < 0) {
     OPENER_TRACE_ERR(
-        "networkhandler udp_unicast_listener: error setting socket to "
-        "non-blocking\n");
+      "networkhandler udp_unicast_listener: error setting socket to "
+      "non-blocking\n");
     return kEipStatusError;
   }
 
-  struct sockaddr_in my_address = {
-      .sin_family      = AF_INET,
-      .sin_port        = htons(kOpenerEthernetPort),
-      .sin_addr.s_addr = g_network_status.ip_address};
+  struct sockaddr_in my_address = { .sin_family = AF_INET,
+                                    .sin_port   = htons(kOpenerEthernetPort),
+                                    .sin_addr.s_addr =
+                                      g_network_status.ip_address };
 
   /* bind the new socket to port 0xAF12 (CIP) */
   if ((bind(g_network_status.tcp_listener,
@@ -262,9 +262,9 @@ EipStatus NetworkHandlerInitialize(void) {
     int error_code      = GetSocketErrorNumber();
     char* error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-        "networkhandler tcp_listener: error with TCP bind: %d - %s\n",
-        error_code,
-        error_message);
+      "networkhandler tcp_listener: error with TCP bind: %d - %s\n",
+      error_code,
+      error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
@@ -275,32 +275,33 @@ EipStatus NetworkHandlerInitialize(void) {
     int error_code      = GetSocketErrorNumber();
     char* error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-        "networkhandler udp_unicast_listener: error with UDP bind: %d - %s\n",
-        error_code,
-        error_message);
+      "networkhandler udp_unicast_listener: error with UDP bind: %d - %s\n",
+      error_code,
+      error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
 
   /* have QoS DSCP explicit appear on UDP responses to unicast messages */
   if (SetQosOnSocket(
-          g_network_status.udp_unicast_listener,
-          CipQosGetDscpPriority(kConnectionObjectPriorityExplicit)) != 0) {
+        g_network_status.udp_unicast_listener,
+        CipQosGetDscpPriority(kConnectionObjectPriorityExplicit)) != 0) {
     int error_code      = GetSocketErrorNumber();
     char* error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-        "networkhandler udp_unicast_listener: error set QoS %d: %d - %s\n",
-        g_network_status.udp_unicast_listener,
-        error_code,
-        error_message);
+      "networkhandler udp_unicast_listener: error set QoS %d: %d - %s\n",
+      g_network_status.udp_unicast_listener,
+      error_code,
+      error_message);
     FreeErrorMessage(error_message);
     /* print message but don't abort by intent */
   }
 
-  struct sockaddr_in global_broadcast_address = {
-      .sin_family      = AF_INET,
-      .sin_port        = htons(kOpenerEthernetPort),
-      .sin_addr.s_addr = htonl(INADDR_ANY)};
+  struct sockaddr_in global_broadcast_address = { .sin_family = AF_INET,
+                                                  .sin_port =
+                                                    htons(kOpenerEthernetPort),
+                                                  .sin_addr.s_addr =
+                                                    htonl(INADDR_ANY) };
 
   /* enable the UDP socket to receive broadcast messages */
   set_socket_option_value = 1;
@@ -312,10 +313,10 @@ EipStatus NetworkHandlerInitialize(void) {
     int error_code      = GetSocketErrorNumber();
     char* error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-        "networkhandler udp_global_broadcast_listener: error with setting "
-        "broadcast receive: %d - %s\n",
-        error_code,
-        error_message);
+      "networkhandler udp_global_broadcast_listener: error with setting "
+      "broadcast receive: %d - %s\n",
+      error_code,
+      error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
@@ -326,26 +327,26 @@ EipStatus NetworkHandlerInitialize(void) {
     int error_code      = GetSocketErrorNumber();
     char* error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-        "networkhandler udp_global_broadcast_listener: error with UDP bind: %d "
-        "- %s\n",
-        error_code,
-        error_message);
+      "networkhandler udp_global_broadcast_listener: error with UDP bind: %d "
+      "- %s\n",
+      error_code,
+      error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
 
   /* have QoS DSCP explicit appear on UDP responses to broadcast messages */
   if (SetQosOnSocket(
-          g_network_status.udp_global_broadcast_listener,
-          CipQosGetDscpPriority(kConnectionObjectPriorityExplicit)) != 0) {
+        g_network_status.udp_global_broadcast_listener,
+        CipQosGetDscpPriority(kConnectionObjectPriorityExplicit)) != 0) {
     int error_code      = GetSocketErrorNumber();
     char* error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-        "networkhandler udp_global_broadcast_listener: error set QoS %d: %d - "
-        "%s\n",
-        g_network_status.udp_global_broadcast_listener,
-        error_code,
-        error_message);
+      "networkhandler udp_global_broadcast_listener: error set QoS %d: %d - "
+      "%s\n",
+      g_network_status.udp_global_broadcast_listener,
+      error_code,
+      error_message);
     FreeErrorMessage(error_message);
     /* print message but don't abort by intent */
   }
@@ -354,8 +355,8 @@ EipStatus NetworkHandlerInitialize(void) {
    * A newly accept()ed TCP socket inherits the setting from this socket.
    */
   if (SetQosOnSocket(
-          g_network_status.tcp_listener,
-          CipQosGetDscpPriority(kConnectionObjectPriorityExplicit)) != 0) {
+        g_network_status.tcp_listener,
+        CipQosGetDscpPriority(kConnectionObjectPriorityExplicit)) != 0) {
     int error_code      = GetSocketErrorNumber();
     char* error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR("networkhandler tcp_listener: error set QoS %d: %d - %s\n",
@@ -371,9 +372,9 @@ EipStatus NetworkHandlerInitialize(void) {
     int error_code      = GetSocketErrorNumber();
     char* error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-        "networkhandler tcp_listener: error with listen: %d - %s\n",
-        error_code,
-        error_message);
+      "networkhandler tcp_listener: error with listen: %d - %s\n",
+      error_code,
+      error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
@@ -385,10 +386,10 @@ EipStatus NetworkHandlerInitialize(void) {
 
   /* keep track of the biggest file descriptor */
   highest_socket_handle =
-      GetMaxSocket(g_network_status.tcp_listener,
-                   g_network_status.udp_global_broadcast_listener,
-                   0,
-                   g_network_status.udp_unicast_listener);
+    GetMaxSocket(g_network_status.tcp_listener,
+                 g_network_status.udp_global_broadcast_listener,
+                 0,
+                 g_network_status.udp_unicast_listener);
 
   g_last_time = GetMilliSeconds(); /* initialize time keeping */
   g_network_status.elapsed_time = 0;
@@ -411,9 +412,9 @@ void CloseTcpSocket(int socket_handle) {
 void RemoveSocketTimerFromList(const int socket_handle) {
   SocketTimer* socket_timer = NULL;
   while (
-      NULL !=
-      (socket_timer = SocketTimerArrayGetSocketTimer(
-           g_timestamps, OPENER_NUMBER_OF_SUPPORTED_SESSIONS, socket_handle))) {
+    NULL !=
+    (socket_timer = SocketTimerArrayGetSocketTimer(
+       g_timestamps, OPENER_NUMBER_OF_SUPPORTED_SESSIONS, socket_handle))) {
     SocketTimerClear(socket_timer);
   }
 }
@@ -452,7 +453,7 @@ void CheckAndHandleTcpListenerSocket(void) {
                       new_socket);
 
     SocketTimer* socket_timer = SocketTimerArrayGetEmptySocketTimer(
-        g_timestamps, OPENER_NUMBER_OF_SUPPORTED_SESSIONS);
+      g_timestamps, OPENER_NUMBER_OF_SUPPORTED_SESSIONS);
 
     //    OPENER_TRACE_INFO("Current time stamp: %ld\n", g_actual_time);
     //    for(size_t i = 0; i < OPENER_NUMBER_OF_SUPPORTED_SESSIONS; i++) {
@@ -480,13 +481,13 @@ EipStatus NetworkHandlerProcessCyclic(void) {
 
   g_time_value.tv_sec = 0;
   g_time_value.tv_usec =
-      (g_network_status.elapsed_time < kOpenerTimerTickInMilliSeconds
-           ? kOpenerTimerTickInMilliSeconds - g_network_status.elapsed_time
-           : 0) *
-      1000; /* 10 ms */
+    (g_network_status.elapsed_time < kOpenerTimerTickInMilliSeconds
+       ? kOpenerTimerTickInMilliSeconds - g_network_status.elapsed_time
+       : 0) *
+    1000; /* 10 ms */
 
   int ready_socket =
-      select(highest_socket_handle + 1, &read_socket, 0, 0, &g_time_value);
+    select(highest_socket_handle + 1, &read_socket, 0, 0, &g_time_value);
 
   if (ready_socket == kEipInvalidSocket) {
     if (EINTR == errno) /* we have somehow been interrupted. The default
@@ -565,15 +566,15 @@ EipStatus NetworkHandlerFinish(void) {
 void CheckAndHandleUdpGlobalBroadcastSocket(void) {
   /* see if this is an unsolicited inbound UDP message */
   if (true == CheckSocketSet(g_network_status.udp_global_broadcast_listener)) {
-    struct sockaddr_in from_address = {0};
+    struct sockaddr_in from_address = { 0 };
     socklen_t from_address_length   = sizeof(from_address);
 
     OPENER_TRACE_STATE(
-        "networkhandler: unsolicited UDP message on EIP global broadcast "
-        "socket\n");
+      "networkhandler: unsolicited UDP message on EIP global broadcast "
+      "socket\n");
 
     /* Handle UDP broadcast messages */
-    CipOctet incoming_message[PC_OPENER_ETHERNET_BUFFER_SIZE] = {0};
+    CipOctet incoming_message[PC_OPENER_ETHERNET_BUFFER_SIZE] = { 0 };
     int received_size = recvfrom(g_network_status.udp_global_broadcast_listener,
                                  NWBUF_CAST incoming_message,
                                  sizeof(incoming_message),
@@ -585,10 +586,10 @@ void CheckAndHandleUdpGlobalBroadcastSocket(void) {
       int error_code      = GetSocketErrorNumber();
       char* error_message = GetErrorMessage(error_code);
       OPENER_TRACE_ERR(
-          "networkhandler: error on recvfrom UDP global broadcast port: %d - "
-          "%s\n",
-          error_code,
-          error_message);
+        "networkhandler: error on recvfrom UDP global broadcast port: %d - "
+        "%s\n",
+        error_code,
+        error_message);
       FreeErrorMessage(error_message);
       return;
     }
@@ -599,16 +600,16 @@ void CheckAndHandleUdpGlobalBroadcastSocket(void) {
     int remaining_bytes            = 0;
     ENIPMessage outgoing_message;
     InitializeENIPMessage(&outgoing_message);
-    EipStatus need_to_send = HandleReceivedExplictUdpData(
-        g_network_status.udp_unicast_listener,
-        /* sending from unicast port, due to strange behavior of the broadcast
-           port */
-        &from_address,
-        receive_buffer,
-        received_size,
-        &remaining_bytes,
-        false,
-        &outgoing_message);
+    EipStatus need_to_send =
+      HandleReceivedExplictUdpData(g_network_status.udp_unicast_listener,
+                                   /* sending from unicast port, due to strange
+                                      behavior of the broadcast port */
+                                   &from_address,
+                                   receive_buffer,
+                                   received_size,
+                                   &remaining_bytes,
+                                   false,
+                                   &outgoing_message);
 
     receive_buffer += received_size - remaining_bytes;
     received_size = remaining_bytes;
@@ -618,16 +619,15 @@ void CheckAndHandleUdpGlobalBroadcastSocket(void) {
 
       /* if the active socket matches a registered UDP callback, handle a UDP
        * packet */
-      if (sendto(g_network_status
-                     .udp_unicast_listener, /* sending from unicast port, due to
-                                               strange behavior of the broadcast
-                                               port */
-                 (char*)outgoing_message.message_buffer,
-                 outgoing_message.used_message_length,
-                 0,
-                 (struct sockaddr*)&from_address,
-                 sizeof(from_address)) !=
-          outgoing_message.used_message_length) {
+      if (sendto(
+            g_network_status.udp_unicast_listener, /* sending from unicast port,
+                                                      due to strange behavior of
+                                                      the broadcast port */
+            (char*)outgoing_message.message_buffer,
+            outgoing_message.used_message_length,
+            0,
+            (struct sockaddr*)&from_address,
+            sizeof(from_address)) != outgoing_message.used_message_length) {
         OPENER_TRACE_INFO("networkhandler: UDP response was not fully sent\n");
       }
     }
@@ -641,14 +641,14 @@ void CheckAndHandleUdpGlobalBroadcastSocket(void) {
 void CheckAndHandleUdpUnicastSocket(void) {
   /* see if this is an unsolicited inbound UDP message */
   if (true == CheckSocketSet(g_network_status.udp_unicast_listener)) {
-    struct sockaddr_in from_address = {0};
+    struct sockaddr_in from_address = { 0 };
     socklen_t from_address_length   = sizeof(from_address);
 
     OPENER_TRACE_STATE(
-        "networkhandler: unsolicited UDP message on EIP unicast socket\n");
+      "networkhandler: unsolicited UDP message on EIP unicast socket\n");
 
     /* Handle UDP broadcast messages */
-    CipOctet incoming_message[PC_OPENER_ETHERNET_BUFFER_SIZE] = {0};
+    CipOctet incoming_message[PC_OPENER_ETHERNET_BUFFER_SIZE] = { 0 };
     int received_size = recvfrom(g_network_status.udp_unicast_listener,
                                  NWBUF_CAST incoming_message,
                                  sizeof(incoming_message),
@@ -660,9 +660,9 @@ void CheckAndHandleUdpUnicastSocket(void) {
       int error_code      = GetSocketErrorNumber();
       char* error_message = GetErrorMessage(error_code);
       OPENER_TRACE_ERR(
-          "networkhandler: error on recvfrom UDP unicast port: %d - %s\n",
-          error_code,
-          error_message);
+        "networkhandler: error on recvfrom UDP unicast port: %d - %s\n",
+        error_code,
+        error_message);
       FreeErrorMessage(error_message);
       return;
     }
@@ -674,13 +674,13 @@ void CheckAndHandleUdpUnicastSocket(void) {
     ENIPMessage outgoing_message;
     InitializeENIPMessage(&outgoing_message);
     EipStatus need_to_send =
-        HandleReceivedExplictUdpData(g_network_status.udp_unicast_listener,
-                                     &from_address,
-                                     receive_buffer,
-                                     received_size,
-                                     &remaining_bytes,
-                                     true,
-                                     &outgoing_message);
+      HandleReceivedExplictUdpData(g_network_status.udp_unicast_listener,
+                                   &from_address,
+                                   receive_buffer,
+                                   received_size,
+                                   &remaining_bytes,
+                                   true,
+                                   &outgoing_message);
 
     receive_buffer += received_size - remaining_bytes;
     received_size = remaining_bytes;
@@ -698,7 +698,7 @@ void CheckAndHandleUdpUnicastSocket(void) {
                  sizeof(from_address)) !=
           outgoing_message.used_message_length) {
         OPENER_TRACE_INFO(
-            "networkhandler: UDP unicast response was not fully sent\n");
+          "networkhandler: UDP unicast response was not fully sent\n");
       }
     }
     if (remaining_bytes > 0) {
@@ -713,9 +713,9 @@ EipStatus SendUdpData(const struct sockaddr_in* const address,
 #if defined(OPENER_TRACE_ENABLED)
   static char ip_str[INET_ADDRSTRLEN];
   OPENER_TRACE_INFO(
-      "UDP packet to be sent to: %s:%d\n",
-      inet_ntop(AF_INET, &address->sin_addr, ip_str, sizeof ip_str),
-      ntohs(address->sin_port));
+    "UDP packet to be sent to: %s:%d\n",
+    inet_ntop(AF_INET, &address->sin_addr, ip_str, sizeof ip_str),
+    ntohs(address->sin_port));
 #endif
 
   int sent_length = sendto(g_network_status.udp_io_messaging,
@@ -728,19 +728,19 @@ EipStatus SendUdpData(const struct sockaddr_in* const address,
     int error_code      = GetSocketErrorNumber();
     char* error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-        "networkhandler: error with sendto in SendUDPData: %d - %s\n",
-        error_code,
-        error_message);
+      "networkhandler: error with sendto in SendUDPData: %d - %s\n",
+      error_code,
+      error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
 
   if (sent_length != outgoing_message->used_message_length) {
     OPENER_TRACE_WARN(
-        "data length sent_length mismatch; probably not all data was sent in "
-        "SendUdpData, sent %d of %d\n",
-        sent_length,
-        outgoing_message->used_message_length);
+      "data length sent_length mismatch; probably not all data was sent in "
+      "SendUdpData, sent %d of %d\n",
+      sent_length,
+      outgoing_message->used_message_length);
     return kEipStatusError;
   }
 
@@ -760,19 +760,19 @@ EipStatus HandleDataOnTcpSocket(int socket) {
 
   /*Check how many data is here -- read the first four bytes from the connection
    */
-  CipOctet incoming_message[PC_OPENER_ETHERNET_BUFFER_SIZE] = {0};
+  CipOctet incoming_message[PC_OPENER_ETHERNET_BUFFER_SIZE] = { 0 };
 
   long number_of_read_bytes =
-      recv(socket,
-           NWBUF_CAST incoming_message,
-           4,
-           0); /*TODO we may have to set the socket to a non blocking socket */
+    recv(socket,
+         NWBUF_CAST incoming_message,
+         4,
+         0); /*TODO we may have to set the socket to a non blocking socket */
 
   SocketTimer* const socket_timer = SocketTimerArrayGetSocketTimer(
-      g_timestamps, OPENER_NUMBER_OF_SUPPORTED_SESSIONS, socket);
+    g_timestamps, OPENER_NUMBER_OF_SUPPORTED_SESSIONS, socket);
   if (number_of_read_bytes == 0) {
     OPENER_TRACE_ERR(
-        "networkhandler: socket: %d - connection closed by client.\n", socket);
+      "networkhandler: socket: %d - connection closed by client.\n", socket);
     RemoveSocketTimerFromList(socket);
     RemoveSession(socket);
     return kEipStatusError;
@@ -784,13 +784,13 @@ EipStatus HandleDataOnTcpSocket(int socket) {
     }
     char* error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-        "networkhandler: error on recv: %d - %s\n", error_code, error_message);
+      "networkhandler: error on recv: %d - %s\n", error_code, error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
 
   const EipUint8* read_buffer =
-      &incoming_message[2]; /* at this place EIP stores the data length */
+    &incoming_message[2]; /* at this place EIP stores the data length */
   size_t data_size = GetUintFromMessage(&read_buffer) +
                      ENCAPSULATION_HEADER_LENGTH -
                      4; /* -4 is for the 4 bytes we have already read*/
@@ -798,15 +798,15 @@ EipStatus HandleDataOnTcpSocket(int socket) {
   if ((PC_OPENER_ETHERNET_BUFFER_SIZE - 4) <
       data_size) { /*TODO can this be handled in a better way?*/
     OPENER_TRACE_ERR(
-        "too large packet received will be ignored, will drop the data\n");
+      "too large packet received will be ignored, will drop the data\n");
     /* Currently we will drop the whole packet */
 
     do {
       OPENER_TRACE_INFO(
-          "Entering consumption loop, remaining data to receive: %ld\n",
-          data_sent);
+        "Entering consumption loop, remaining data to receive: %ld\n",
+        data_sent);
       number_of_read_bytes =
-          recv(socket, NWBUF_CAST & incoming_message[0], data_sent, 0);
+        recv(socket, NWBUF_CAST & incoming_message[0], data_sent, 0);
 
       if (number_of_read_bytes ==
           0) /* got error or connection closed by client */
@@ -814,11 +814,11 @@ EipStatus HandleDataOnTcpSocket(int socket) {
         int error_code      = GetSocketErrorNumber();
         char* error_message = GetErrorMessage(error_code);
         OPENER_TRACE_ERR(
-            "networkhandler: socket: %d - connection closed by client: %d - "
-            "%s\n",
-            socket,
-            error_code,
-            error_message);
+          "networkhandler: socket: %d - connection closed by client: %d - "
+          "%s\n",
+          socket,
+          error_code,
+          error_message);
         FreeErrorMessage(error_message);
         RemoveSocketTimerFromList(socket);
         return kEipStatusError;
@@ -845,17 +845,17 @@ EipStatus HandleDataOnTcpSocket(int socket) {
   }
 
   number_of_read_bytes =
-      recv(socket, NWBUF_CAST & incoming_message[4], data_size, 0);
+    recv(socket, NWBUF_CAST & incoming_message[4], data_size, 0);
 
   if (0 == number_of_read_bytes) /* got error or connection closed by client */
   {
     int error_code      = GetSocketErrorNumber();
     char* error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-        "networkhandler: socket: %d - connection closed by client: %d - %s\n",
-        socket,
-        error_code,
-        error_message);
+      "networkhandler: socket: %d - connection closed by client: %d - %s\n",
+      socket,
+      error_code,
+      error_message);
     FreeErrorMessage(error_message);
     RemoveSocketTimerFromList(socket);
     RemoveSession(socket);
@@ -868,7 +868,7 @@ EipStatus HandleDataOnTcpSocket(int socket) {
       return kEipStatusOk;
     }
     OPENER_TRACE_ERR(
-        "networkhandler: error on recv: %d - %s\n", error_code, error_message);
+      "networkhandler: error on recv: %d - %s\n", error_code, error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
@@ -909,8 +909,8 @@ EipStatus HandleDataOnTcpSocket(int socket) {
 
     if (remaining_bytes != 0) {
       OPENER_TRACE_WARN(
-          "Warning: received packet was to long: %d Bytes left!\n",
-          remaining_bytes);
+        "Warning: received packet was to long: %d Bytes left!\n",
+        remaining_bytes);
     }
 
     if (need_to_send > 0) {
@@ -963,8 +963,8 @@ int CreateUdpSocket(void) {
 
   if (SetSocketToNonBlocking(g_network_status.udp_io_messaging) < 0) {
     OPENER_TRACE_ERR(
-        "networkhandler udp_io_messaging: error setting socket to non-blocking "
-        "on new socket\n");
+      "networkhandler udp_io_messaging: error setting socket to non-blocking "
+      "on new socket\n");
     CloseUdpSocket(g_network_status.udp_io_messaging);
     OPENER_ASSERT(false); /* This should never happen! */
     return kEipInvalidSocket;
@@ -980,16 +980,16 @@ int CreateUdpSocket(void) {
                  (char*)&option_value,
                  sizeof(option_value)) < 0) {
     OPENER_TRACE_ERR(
-        "error setting socket option SO_REUSEADDR on %s UDP socket\n");
+      "error setting socket option SO_REUSEADDR on %s UDP socket\n");
     CloseUdpSocket(g_network_status.udp_io_messaging);
     return kEipInvalidSocket;
   }
 
   /* The bind on UDP sockets is necessary as the ENIP spec wants the source port
    * to be specified to 2222 */
-  struct sockaddr_in source_addr = {.sin_family      = AF_INET,
-                                    .sin_addr.s_addr = htonl(INADDR_ANY),
-                                    .sin_port = htons(kOpenerEipIoUdpPort)};
+  struct sockaddr_in source_addr = { .sin_family      = AF_INET,
+                                     .sin_addr.s_addr = htonl(INADDR_ANY),
+                                     .sin_port = htons(kOpenerEipIoUdpPort) };
 
   if (bind(g_network_status.udp_io_messaging,
            (struct sockaddr*)&source_addr,
@@ -1046,17 +1046,17 @@ int SetSocketOptionsMulticastProduce(void) {
       int error_code      = GetSocketErrorNumber();
       char* error_message = GetErrorMessage(error_code);
       OPENER_TRACE_ERR(
-          "networkhandler: could not set the TTL to: %d, error: %d - %s\n",
-          g_tcpip.mcast_ttl_value,
-          error_code,
-          error_message);
+        "networkhandler: could not set the TTL to: %d, error: %d - %s\n",
+        g_tcpip.mcast_ttl_value,
+        error_code,
+        error_message);
       FreeErrorMessage(error_message);
       return error_code;
     }
   }
   /* Need to specify the interface for outgoing multicast packets on a
      device with multiple interfaces. */
-  struct in_addr my_addr = {.s_addr = g_network_status.ip_address};
+  struct in_addr my_addr = { .s_addr = g_network_status.ip_address };
   if (setsockopt(g_network_status.udp_io_messaging,
                  IPPROTO_IP,
                  IP_MULTICAST_IF,
@@ -1065,10 +1065,10 @@ int SetSocketOptionsMulticastProduce(void) {
     int error_code      = GetSocketErrorNumber();
     char* error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-        "networkhandler: could not set the multicast interface, error: %d "
-        "- %s\n",
-        error_code,
-        error_message);
+      "networkhandler: could not set the multicast interface, error: %d "
+      "- %s\n",
+      error_code,
+      error_message);
     FreeErrorMessage(error_message);
     return error_code;
   }
@@ -1107,16 +1107,15 @@ void CheckAndHandleConsumingUdpSocket(void) {
     iterator = iterator->next; /* do this at the beginning as the close function
                                   may can make the entry invalid */
 
-    if ((kEipInvalidSocket !=
-         current_connection_object
-             ->socket[kUdpCommuncationDirectionConsuming]) &&
+    if ((kEipInvalidSocket != current_connection_object
+                                ->socket[kUdpCommuncationDirectionConsuming]) &&
         (true ==
          CheckSocketSet(current_connection_object
-                            ->socket[kUdpCommuncationDirectionConsuming]))) {
+                          ->socket[kUdpCommuncationDirectionConsuming]))) {
       OPENER_TRACE_INFO("Processing UDP consuming message\n");
-      struct sockaddr_in from_address = {0};
+      struct sockaddr_in from_address = { 0 };
       socklen_t from_address_length   = sizeof(from_address);
-      CipOctet incoming_message[PC_OPENER_ETHERNET_BUFFER_SIZE] = {0};
+      CipOctet incoming_message[PC_OPENER_ETHERNET_BUFFER_SIZE] = { 0 };
 
       int received_size = recvfrom(g_network_status.udp_io_messaging,
                                    NWBUF_CAST incoming_message,
@@ -1128,15 +1127,14 @@ void CheckAndHandleConsumingUdpSocket(void) {
         int error_code      = GetSocketErrorNumber();
         char* error_message = GetErrorMessage(error_code);
         OPENER_TRACE_ERR(
-            "networkhandler: socket: %d - connection closed by client: %d - "
-            "%s\n",
-            current_connection_object
-                ->socket[kUdpCommuncationDirectionConsuming],
-            error_code,
-            error_message);
+          "networkhandler: socket: %d - connection closed by client: %d - "
+          "%s\n",
+          current_connection_object->socket[kUdpCommuncationDirectionConsuming],
+          error_code,
+          error_message);
         FreeErrorMessage(error_message);
         current_connection_object->connection_close_function(
-            current_connection_object);
+          current_connection_object);
         continue;
       }
 
@@ -1151,12 +1149,12 @@ void CheckAndHandleConsumingUdpSocket(void) {
                          error_message);
         FreeErrorMessage(error_message);
         current_connection_object->connection_close_function(
-            current_connection_object);
+          current_connection_object);
         continue;
       }
 
       HandleReceivedConnectedData(
-          incoming_message, received_size, &from_address);
+        incoming_message, received_size, &from_address);
     }
   }
 }
@@ -1192,19 +1190,19 @@ void CheckEncapsulationInactivity(int socket_handle) {
       g_tcpip.encapsulation_inactivity_timeout) {  //*< Encapsulation inactivity
                                                    // timeout is enabled
     SocketTimer* socket_timer = SocketTimerArrayGetSocketTimer(
-        g_timestamps, OPENER_NUMBER_OF_SUPPORTED_SESSIONS, socket_handle);
+      g_timestamps, OPENER_NUMBER_OF_SUPPORTED_SESSIONS, socket_handle);
 
     //    OPENER_TRACE_INFO("Check socket %d - socket timer: %p\n",
     //                      socket_handle,
     //                      socket_timer);
     if (NULL != socket_timer) {
       MilliSeconds diff_milliseconds =
-          g_actual_time - SocketTimerGetLastUpdate(socket_timer);
+        g_actual_time - SocketTimerGetLastUpdate(socket_timer);
 
       if (diff_milliseconds >=
           (MilliSeconds)(1000UL * g_tcpip.encapsulation_inactivity_timeout)) {
         CipSessionHandle encapsulation_session_handle =
-            GetSessionFromSocket(socket_handle);
+          GetSessionFromSocket(socket_handle);
 
         CloseClass3ConnectionBasedOnSession(encapsulation_session_handle);
 
@@ -1219,7 +1217,7 @@ void RegisterTimeoutChecker(TimeoutCheckerFunction timeout_checker_function) {
   for (size_t i = 0; i < OPENER_TIMEOUT_CHECKER_ARRAY_SIZE; i++) {
     if (NULL == timeout_checker_array[i]) {  // find empty array element
       timeout_checker_array[i] =
-          timeout_checker_function;  // add function pointer to array
+        timeout_checker_function;  // add function pointer to array
       break;
     }
   }

+ 1 - 1
source/src/ports/generic_networkhandler.h

@@ -78,7 +78,7 @@ typedef struct {
 } NetworkStatus;
 
 extern NetworkStatus
-    g_network_status; /**< Global variable holding the current network status */
+  g_network_status; /**< Global variable holding the current network status */
 
 /** @brief The platform independent part of network handler initialization
  * routine

+ 1 - 1
source/src/ports/nvdata/nvdata.c

@@ -39,7 +39,7 @@ EipStatus NvdataLoad(void) {
   EipStatus eip_status = NvQosLoad(&g_qos);
   if (kEipStatusError != eip_status) {
     eip_status =
-        (kEipStatusError == NvQosStore(&g_qos)) ? kEipStatusError : eip_status;
+      (kEipStatusError == NvQosStore(&g_qos)) ? kEipStatusError : eip_status;
   }
 
   return eip_status;

+ 2 - 2
source/src/ports/nvdata/nvtcpip.c

@@ -34,7 +34,7 @@ int NvTcpipLoad(CipTcpIpObject* p_tcp_ip) {
   if (NULL != p_file) {
     /* Read input data */
     OPENER_TRACE_ERR(
-        "ERROR: Loading of TCP/IP object's NV data not implemented yet\n");
+      "ERROR: Loading of TCP/IP object's NV data not implemented yet\n");
     /* TODO: Implement load */
     eip_status = kEipStatusError;
     /* If all NV attributes were read copy them attribute by attribute
@@ -62,7 +62,7 @@ EipStatus NvTcpipStore(const CipTcpIpObject* p_tcp_ip) {
   if (NULL != p_file) {
     /* Print output data */
     OPENER_TRACE_ERR(
-        "ERROR: Storing of TCP/IP object's NV data not implemented yet\n");
+      "ERROR: Storing of TCP/IP object's NV data not implemented yet\n");
     /* TODO: Implement store */
     EipStatus eip_status = kEipStatusError;
 

+ 5 - 5
source/src/ports/socket_timer.c

@@ -38,9 +38,9 @@ void SocketTimerArrayInitialize(SocketTimer* const array_of_socket_timers,
 }
 
 SocketTimer* SocketTimerArrayGetSocketTimer(
-    SocketTimer* const array_of_socket_timers,
-    const size_t array_length,
-    const int socket) {
+  SocketTimer* const array_of_socket_timers,
+  const size_t array_length,
+  const int socket) {
   for (size_t i = 0; i < array_length; ++i) {
     if (socket == array_of_socket_timers[i].socket) {
       return &array_of_socket_timers[i];
@@ -50,7 +50,7 @@ SocketTimer* SocketTimerArrayGetSocketTimer(
 }
 
 SocketTimer* SocketTimerArrayGetEmptySocketTimer(
-    SocketTimer* const array_of_socket_timers, const size_t array_length) {
+  SocketTimer* const array_of_socket_timers, const size_t array_length) {
   return SocketTimerArrayGetSocketTimer(
-      array_of_socket_timers, array_length, kEipInvalidSocket);
+    array_of_socket_timers, array_length, kEipInvalidSocket);
 }

+ 4 - 4
source/src/ports/socket_timer.h

@@ -69,9 +69,9 @@ void SocketTimerArrayInitialize(SocketTimer* const array_of_socket_timers,
  * @return The Socket Timer of found, otherwise NULL
  */
 SocketTimer* SocketTimerArrayGetSocketTimer(
-    SocketTimer* const array_of_socket_timers,
-    const size_t array_length,
-    const int socket);
+  SocketTimer* const array_of_socket_timers,
+  const size_t array_length,
+  const int socket);
 
 /** @brief
  * Get an empty Socket Timer entry
@@ -82,6 +82,6 @@ SocketTimer* SocketTimerArrayGetSocketTimer(
  * @return An empty Socket Timer entry, or NULL if non is available
  */
 SocketTimer* SocketTimerArrayGetEmptySocketTimer(
-    SocketTimer* const array_of_socket_timers, const size_t array_length);
+  SocketTimer* const array_of_socket_timers, const size_t array_length);
 
 #endif /* SRC_PORTS_SOCKET_TIMER_H_ */

+ 7 - 7
source/src/utils/doublylinkedlist.c

@@ -35,7 +35,7 @@ void DoublyLinkedListDestroy(DoublyLinkedList* list) {
 }
 
 DoublyLinkedListNode* DoublyLinkedListNodeCreate(
-    const void* const data, NodeMemoryAllocator const allocator) {
+  const void* const data, NodeMemoryAllocator const allocator) {
   DoublyLinkedListNode* new_node = (DoublyLinkedListNode*)allocator();
   new_node->data                 = (void*)data;
   return new_node;
@@ -51,7 +51,7 @@ void DoublyLinkedListInsertAtHead(DoublyLinkedList* const list,
                                   const void* const data) {
   OPENER_ASSERT(list->allocator != NULL);
   DoublyLinkedListNode* new_node =
-      DoublyLinkedListNodeCreate(data, list->allocator);
+    DoublyLinkedListNodeCreate(data, list->allocator);
   if (NULL == list->first) {
     list->first = new_node;
     list->last  = new_node;
@@ -66,7 +66,7 @@ void DoublyLinkedListInsertAtTail(DoublyLinkedList* const list,
                                   const void* const data) {
   OPENER_ASSERT(list->allocator != NULL);
   DoublyLinkedListNode* new_node =
-      DoublyLinkedListNodeCreate(data, list->allocator);
+    DoublyLinkedListNodeCreate(data, list->allocator);
   if (NULL == list->last) {
     list->first = new_node;
     list->last  = new_node;
@@ -85,7 +85,7 @@ void DoublyLinkedListInsertBeforeNode(DoublyLinkedList* const list,
     DoublyLinkedListInsertAtHead(list, data);
   } else {
     DoublyLinkedListNode* new_node =
-        DoublyLinkedListNodeCreate(data, list->allocator);
+      DoublyLinkedListNodeCreate(data, list->allocator);
     new_node->previous       = node->previous;
     new_node->next           = node;
     node->previous           = new_node;
@@ -101,7 +101,7 @@ void DoublyLinkedListInsertAfterNode(DoublyLinkedList* const list,
     DoublyLinkedListInsertAtTail(list, data);
   } else {
     DoublyLinkedListNode* new_node =
-        DoublyLinkedListNodeCreate(data, list->allocator);
+      DoublyLinkedListNodeCreate(data, list->allocator);
     new_node->previous   = node;
     new_node->next       = node->next;
     node->next->previous = new_node;
@@ -110,8 +110,8 @@ void DoublyLinkedListInsertAfterNode(DoublyLinkedList* const list,
 }
 
 void DoublyLinkedListRemoveNode(
-    DoublyLinkedList* const list,
-    DoublyLinkedListNode** pointer_to_node_pointer) {
+  DoublyLinkedList* const list,
+  DoublyLinkedListNode** pointer_to_node_pointer) {
   DoublyLinkedListNode* node     = *pointer_to_node_pointer;
   DoublyLinkedListNode* previous = node->previous;
   DoublyLinkedListNode* next     = node->next;

+ 1 - 1
source/src/utils/doublylinkedlist.h

@@ -41,7 +41,7 @@ void DoublyLinkedListInitialize(DoublyLinkedList* list,
 void DoublyLinkedListDestroy(DoublyLinkedList* list);
 
 DoublyLinkedListNode* DoublyLinkedListNodeCreate(
-    const void* const data, NodeMemoryAllocator const allocator);
+  const void* const data, NodeMemoryAllocator const allocator);
 
 void DoublyLinkedListNodeDestroy(const DoublyLinkedList* const list,
                                  DoublyLinkedListNode** node);

+ 2 - 1
source/src/utils/random.c

@@ -10,7 +10,8 @@
 
 Random* RandomNew(SetSeed set_seed, GetNextUInt32 get_next_uint32) {
   Random* random = malloc(sizeof(Random));
-  *random = (Random){.set_seed = set_seed, .get_next_uint32 = get_next_uint32};
+  *random =
+    (Random){ .set_seed = set_seed, .get_next_uint32 = get_next_uint32 };
   return random;
 }
 

+ 1 - 1
source/src/utils/random.h

@@ -16,7 +16,7 @@ typedef struct {
   uint32_t current_seed_value; /**< Holds the current seed/random value */
   SetSeed set_seed;            /**< Function pointer to SetSeed function */
   GetNextUInt32
-      get_next_uint32; /**< Function pointer to GetNextUInt32 function */
+    get_next_uint32; /**< Function pointer to GetNextUInt32 function */
 } Random;
 
 Random* RandomNew(SetSeed, GetNextUInt32);

+ 1 - 1
source/src/utils/xorshiftrandom.c

@@ -9,7 +9,7 @@
 #include <time.h>
 
 static uint32_t
-    xor_shift_seed; /** < File-global variable holding the current seed*/
+  xor_shift_seed; /** < File-global variable holding the current seed*/
 
 void SetXorShiftSeed(uint32_t seed) {
   xor_shift_seed = seed;

+ 4 - 4
source/tests/callback_mock.cpp

@@ -11,7 +11,7 @@ extern "C" {
 
 EipStatus ApplicationInitialization(void) {
   return (EipStatus)mock().actualCall(__func__).returnIntValueOrDefault(
-      kEipStatusOk);
+    kEipStatusOk);
 }
 
 void HandleApplication(void) {
@@ -26,7 +26,7 @@ void CheckIoConnectionEvent(unsigned int output_assembly_id,
 
 EipStatus AfterAssemblyDataReceived(CipInstance* instance) {
   return (EipStatus)mock().actualCall(__func__).returnIntValueOrDefault(
-      kEipStatusOk);
+    kEipStatusOk);
 }
 
 EipBool8 BeforeAssemblyDataSend(CipInstance* instance) {
@@ -35,12 +35,12 @@ EipBool8 BeforeAssemblyDataSend(CipInstance* instance) {
 
 EipStatus ResetDevice(void) {
   return (EipStatus)mock().actualCall(__func__).returnIntValueOrDefault(
-      kEipStatusError);
+    kEipStatusError);
 }
 
 EipStatus ResetDeviceToInitialConfiguration(void) {
   return (EipStatus)mock().actualCall(__func__).returnIntValueOrDefault(
-      kEipStatusError);
+    kEipStatusError);
 }
 
 void* CipCalloc(size_t number_of_elements, size_t size_of_element) {

+ 7 - 7
source/tests/cip/cipcommontests.cpp

@@ -20,7 +20,7 @@ ENIPMessage message; /**< Test variable holds ENIP message*/
 
 TEST_GROUP(CipCommon){
 
-    void setup(){InitializeENIPMessage(&message);
+  void setup(){ InitializeENIPMessage(&message);
 }
 }
 ;
@@ -91,11 +91,11 @@ TEST(CipCommon, EncodeCipUlint) {
 TEST(CipCommon, DecodeCipString) {
   CipMessageRouterRequest request;
   size_t number_of_strings  = 4;
-  size_t length_of_string[] = {8, 4, 0, 2};
+  size_t length_of_string[] = { 8, 4, 0, 2 };
   size_t pos_in_data        = 0;
   const CipOctet data[] =
-      "\x08\x00\x4F\x44\x56\x41\x5F\x44\x55\x54\x04\x00\x4F\x44\x56\x41\x00\x00"
-      "\x02\x00\x43\x41";  // hex data
+    "\x08\x00\x4F\x44\x56\x41\x5F\x44\x55\x54\x04\x00\x4F\x44\x56\x41\x00\x00"
+    "\x02\x00\x43\x41";  // hex data
   request.data              = data;
   request.request_data_size = sizeof(data) - 1;
 
@@ -127,11 +127,11 @@ TEST(CipCommon, DecodeCipString) {
 TEST(CipCommon, DecodeCipShortString) {
   CipMessageRouterRequest request;
   size_t number_of_strings  = 4;
-  size_t length_of_string[] = {8, 4, 0, 2};
+  size_t length_of_string[] = { 8, 4, 0, 2 };
   size_t pos_in_data        = 0;
   const CipOctet data[] =
-      "\x08\x4F\x44\x56\x41\x5F\x44\x55\x54\x04\x4F\x44\x56\x41\x00\x02\x43"
-      "\x41";  // hex data
+    "\x08\x4F\x44\x56\x41\x5F\x44\x55\x54\x04\x4F\x44\x56\x41\x00\x02\x43"
+    "\x41";  // hex data
   request.data              = data;
   request.request_data_size = sizeof(data) - 1;
 

+ 101 - 107
source/tests/cip/cipconnectionobjecttest.cpp

@@ -27,56 +27,56 @@ TEST(CipConnectionObject, InitializeEmpty) {
 
 /* Get State tests */
 TEST(CipConnectionObject, GetStateNonExistent) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.state               = 0;
   ConnectionObjectState state = ConnectionObjectGetState(&connection_object);
   CHECK_EQUAL(kConnectionObjectStateNonExistent, state);
 }
 
 TEST(CipConnectionObject, GetStateConfiguring) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.state               = 1;
   ConnectionObjectState state = ConnectionObjectGetState(&connection_object);
   CHECK_EQUAL(kConnectionObjectStateConfiguring, state);
 }
 
 TEST(CipConnectionObject, GetStateWaitingForConnectionID) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.state               = 2;
   ConnectionObjectState state = ConnectionObjectGetState(&connection_object);
   CHECK_EQUAL(kConnectionObjectStateWaitingForConnectionID, state);
 }
 
 TEST(CipConnectionObject, GetStateEstablished) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.state               = 3;
   ConnectionObjectState state = ConnectionObjectGetState(&connection_object);
   CHECK_EQUAL(kConnectionObjectStateEstablished, state);
 }
 
 TEST(CipConnectionObject, GetStateTimedOut) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.state               = 4;
   ConnectionObjectState state = ConnectionObjectGetState(&connection_object);
   CHECK_EQUAL(kConnectionObjectStateTimedOut, state);
 }
 
 TEST(CipConnectionObject, GetStateDeferredDelete) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.state               = 5;
   ConnectionObjectState state = ConnectionObjectGetState(&connection_object);
   CHECK_EQUAL(kConnectionObjectStateDeferredDelete, state);
 }
 
 TEST(CipConnectionObject, GetStateClosing) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.state               = 6;
   ConnectionObjectState state = ConnectionObjectGetState(&connection_object);
   CHECK_EQUAL(kConnectionObjectStateClosing, state);
 }
 
 TEST(CipConnectionObject, GetStateInvalid) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.state               = 7;
   ConnectionObjectState state = ConnectionObjectGetState(&connection_object);
   CHECK_EQUAL(kConnectionObjectStateInvalid, state);
@@ -84,48 +84,48 @@ TEST(CipConnectionObject, GetStateInvalid) {
 
 /* Set state tests */
 TEST(CipConnectionObject, SetStateNonExistent) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   ConnectionObjectSetState(&connection_object,
                            kConnectionObjectStateNonExistent);
   CHECK_EQUAL(0, connection_object.state);
 }
 
 TEST(CipConnectionObject, SetStateConfiguring) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   ConnectionObjectSetState(&connection_object,
                            kConnectionObjectStateConfiguring);
   CHECK_EQUAL(1, connection_object.state);
 }
 
 TEST(CipConnectionObject, SetStateWaitingForConnectionID) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   ConnectionObjectSetState(&connection_object,
                            kConnectionObjectStateWaitingForConnectionID);
   CHECK_EQUAL(2, connection_object.state);
 }
 
 TEST(CipConnectionObject, SetStateEstablished) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   ConnectionObjectSetState(&connection_object,
                            kConnectionObjectStateEstablished);
   CHECK_EQUAL(3, connection_object.state);
 }
 
 TEST(CipConnectionObject, SetStateTimedOut) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   ConnectionObjectSetState(&connection_object, kConnectionObjectStateTimedOut);
   CHECK_EQUAL(4, connection_object.state);
 }
 
 TEST(CipConnectionObject, SetStateDeferredDelete) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   ConnectionObjectSetState(&connection_object,
                            kConnectionObjectStateDeferredDelete);
   CHECK_EQUAL(5, connection_object.state);
 }
 
 TEST(CipConnectionObject, SetStateClosing) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   ConnectionObjectSetState(&connection_object, kConnectionObjectStateClosing);
   CHECK_EQUAL(6, connection_object.state);
 }
@@ -133,70 +133,70 @@ TEST(CipConnectionObject, SetStateClosing) {
 /* Get InstanceType tests */
 
 TEST(CipConnectionObject, GetInstanceType) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.instance_type =
-      kConnectionObjectInstanceTypeExplicitMessaging;
+    kConnectionObjectInstanceTypeExplicitMessaging;
   CHECK_EQUAL(kConnectionObjectInstanceTypeExplicitMessaging,
               ConnectionObjectGetInstanceType(&connection_object));
 }
 
 TEST(CipConnectionObject, InstanceTypeIExplicitMessaging) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.instance_type =
-      kConnectionObjectInstanceTypeExplicitMessaging;
+    kConnectionObjectInstanceTypeExplicitMessaging;
   CipUsint value =
-      ConnectionObjectGetInstanceTypeForAttribute(&connection_object);
+    ConnectionObjectGetInstanceTypeForAttribute(&connection_object);
   CHECK_EQUAL(0, value);
 }
 
 TEST(CipConnectionObject, InstanceTypeIO) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.instance_type       = kConnectionObjectInstanceTypeIO;
   CipUsint value =
-      ConnectionObjectGetInstanceTypeForAttribute(&connection_object);
+    ConnectionObjectGetInstanceTypeForAttribute(&connection_object);
   CHECK_EQUAL(1, value);
 }
 
 TEST(CipConnectionObject, InstanceTypeIOExclusiveOwner) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.instance_type =
-      kConnectionObjectInstanceTypeIOExclusiveOwner;
+    kConnectionObjectInstanceTypeIOExclusiveOwner;
   CipUsint value =
-      ConnectionObjectGetInstanceTypeForAttribute(&connection_object);
+    ConnectionObjectGetInstanceTypeForAttribute(&connection_object);
   CHECK_EQUAL(1, value);
 }
 
 TEST(CipConnectionObject, InstanceTypeIOInputOnly) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.instance_type = kConnectionObjectInstanceTypeIOInputOnly;
   CipUsint value =
-      ConnectionObjectGetInstanceTypeForAttribute(&connection_object);
+    ConnectionObjectGetInstanceTypeForAttribute(&connection_object);
   CHECK_EQUAL(1, value);
 }
 
 TEST(CipConnectionObject, InstanceTypeIOListenOnly) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.instance_type = kConnectionObjectInstanceTypeIOListenOnly;
   CipUsint value =
-      ConnectionObjectGetInstanceTypeForAttribute(&connection_object);
+    ConnectionObjectGetInstanceTypeForAttribute(&connection_object);
   CHECK_EQUAL(1, value);
 }
 
 TEST(CipConnectionObject, InstanceTypeCipBridged) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.instance_type = kConnectionObjectInstanceTypeCipBridged;
   CipUsint value =
-      ConnectionObjectGetInstanceTypeForAttribute(&connection_object);
+    ConnectionObjectGetInstanceTypeForAttribute(&connection_object);
   CHECK_EQUAL(2, value);
 }
 
 TEST(CipConnectionObject, IsTypeNonLOIOConnectionTrue) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.instance_type       = kConnectionObjectInstanceTypeIO;
   CHECK_EQUAL(true,
               ConnectionObjectIsTypeNonLOIOConnection(&connection_object));
   connection_object.instance_type =
-      kConnectionObjectInstanceTypeIOExclusiveOwner;
+    kConnectionObjectInstanceTypeIOExclusiveOwner;
   CHECK_EQUAL(true,
               ConnectionObjectIsTypeNonLOIOConnection(&connection_object));
   connection_object.instance_type = kConnectionObjectInstanceTypeIOInputOnly;
@@ -205,18 +205,18 @@ TEST(CipConnectionObject, IsTypeNonLOIOConnectionTrue) {
 }
 
 TEST(CipConnectionObject, IsTypeNonLOIOConnectionFalse) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.instance_type = kConnectionObjectInstanceTypeIOListenOnly;
   CHECK_EQUAL(false,
               ConnectionObjectIsTypeNonLOIOConnection(&connection_object));
 }
 
 TEST(CipConnectionObject, IsTypeIOConnectionTrue) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.instance_type       = kConnectionObjectInstanceTypeIO;
   CHECK_EQUAL(true, ConnectionObjectIsTypeIOConnection(&connection_object));
   connection_object.instance_type =
-      kConnectionObjectInstanceTypeIOExclusiveOwner;
+    kConnectionObjectInstanceTypeIOExclusiveOwner;
   CHECK_EQUAL(true, ConnectionObjectIsTypeIOConnection(&connection_object));
   connection_object.instance_type = kConnectionObjectInstanceTypeIOInputOnly;
   CHECK_EQUAL(true, ConnectionObjectIsTypeIOConnection(&connection_object));
@@ -225,253 +225,247 @@ TEST(CipConnectionObject, IsTypeIOConnectionTrue) {
 }
 
 TEST(CipConnectionObject, IsTypeIOConnectionFalse) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.instance_type       = kConnectionObjectInstanceTypeInvalid;
   CHECK_EQUAL(false, ConnectionObjectIsTypeIOConnection(&connection_object));
   connection_object.instance_type =
-      kConnectionObjectInstanceTypeExplicitMessaging;
+    kConnectionObjectInstanceTypeExplicitMessaging;
   CHECK_EQUAL(false, ConnectionObjectIsTypeIOConnection(&connection_object));
   connection_object.instance_type = kConnectionObjectInstanceTypeCipBridged;
   CHECK_EQUAL(false, ConnectionObjectIsTypeIOConnection(&connection_object));
 }
 
 TEST(CipConnectionObject, TransportClassTriggerDirectionServer) {
-  CipConnectionObject connection_object     = {0};
+  CipConnectionObject connection_object     = { 0 };
   connection_object.transport_class_trigger = 0x80;
   ConnectionObjectTransportClassTriggerDirection direction =
-      ConnectionObjectGetTransportClassTriggerDirection(&connection_object);
+    ConnectionObjectGetTransportClassTriggerDirection(&connection_object);
   CHECK_EQUAL(kConnectionObjectTransportClassTriggerDirectionServer, direction);
 }
 
 TEST(CipConnectionObject, TransportClassTriggerDirectionClient) {
-  CipConnectionObject connection_object     = {0};
+  CipConnectionObject connection_object     = { 0 };
   connection_object.transport_class_trigger = 0x00;
   ConnectionObjectTransportClassTriggerDirection direction =
-      ConnectionObjectGetTransportClassTriggerDirection(&connection_object);
+    ConnectionObjectGetTransportClassTriggerDirection(&connection_object);
   CHECK_EQUAL(kConnectionObjectTransportClassTriggerDirectionClient, direction);
 }
 
 TEST(CipConnectionObject, TransportClassTriggerProductionTriggerInvalid) {
-  CipConnectionObject connection_object     = {0};
+  CipConnectionObject connection_object     = { 0 };
   connection_object.transport_class_trigger = 3 << 4;
   ConnectionObjectTransportClassTriggerProductionTrigger production_trigger =
-      ConnectionObjectGetTransportClassTriggerProductionTrigger(
-          &connection_object);
+    ConnectionObjectGetTransportClassTriggerProductionTrigger(
+      &connection_object);
   CHECK_EQUAL(kConnectionObjectTransportClassTriggerProductionTriggerInvalid,
               production_trigger);
 }
 
 TEST(CipConnectionObject, TransportClassTriggerProductionTriggerCyclic) {
-  CipConnectionObject connection_object     = {0};
+  CipConnectionObject connection_object     = { 0 };
   connection_object.transport_class_trigger = 0x00;
   ConnectionObjectTransportClassTriggerProductionTrigger production_trigger =
-      ConnectionObjectGetTransportClassTriggerProductionTrigger(
-          &connection_object);
+    ConnectionObjectGetTransportClassTriggerProductionTrigger(
+      &connection_object);
   CHECK_EQUAL(kConnectionObjectTransportClassTriggerProductionTriggerCyclic,
               production_trigger);
 }
 
 TEST(CipConnectionObject, TransportClassTriggerProductionTriggerChangeOfState) {
-  CipConnectionObject connection_object     = {0};
+  CipConnectionObject connection_object     = { 0 };
   connection_object.transport_class_trigger = 1 << 4;
   ConnectionObjectTransportClassTriggerProductionTrigger production_trigger =
-      ConnectionObjectGetTransportClassTriggerProductionTrigger(
-          &connection_object);
+    ConnectionObjectGetTransportClassTriggerProductionTrigger(
+      &connection_object);
   CHECK_EQUAL(
-      kConnectionObjectTransportClassTriggerProductionTriggerChangeOfState,
-      production_trigger);
+    kConnectionObjectTransportClassTriggerProductionTriggerChangeOfState,
+    production_trigger);
 }
 
 TEST(CipConnectionObject,
      TransportClassTriggerProductionTriggerApplicationObject) {
-  CipConnectionObject connection_object     = {0};
+  CipConnectionObject connection_object     = { 0 };
   connection_object.transport_class_trigger = 2 << 4;
   ConnectionObjectTransportClassTriggerProductionTrigger production_trigger =
-      ConnectionObjectGetTransportClassTriggerProductionTrigger(
-          &connection_object);
+    ConnectionObjectGetTransportClassTriggerProductionTrigger(
+      &connection_object);
   CHECK_EQUAL(
-      kConnectionObjectTransportClassTriggerProductionTriggerApplicationObject,
-      production_trigger);
+    kConnectionObjectTransportClassTriggerProductionTriggerApplicationObject,
+    production_trigger);
 }
 
 TEST(CipConnectionObject, TransportClassTriggerClassInvalid) {
-  CipConnectionObject connection_object     = {0};
+  CipConnectionObject connection_object     = { 0 };
   connection_object.transport_class_trigger = 5;
   ConnectionObjectTransportClassTriggerTransportClass transport_class =
-      ConnectionObjectGetTransportClassTriggerTransportClass(
-          &connection_object);
+    ConnectionObjectGetTransportClassTriggerTransportClass(&connection_object);
   CHECK_EQUAL(kConnectionObjectTransportClassTriggerTransportClassInvalid,
               transport_class);
 }
 
 TEST(CipConnectionObject, TransportClassTriggerClass0) {
-  CipConnectionObject connection_object     = {0};
+  CipConnectionObject connection_object     = { 0 };
   connection_object.transport_class_trigger = 0;
   ConnectionObjectTransportClassTriggerTransportClass transport_class =
-      ConnectionObjectGetTransportClassTriggerTransportClass(
-          &connection_object);
+    ConnectionObjectGetTransportClassTriggerTransportClass(&connection_object);
   CHECK_EQUAL(kConnectionObjectTransportClassTriggerTransportClass0,
               transport_class);
 }
 
 TEST(CipConnectionObject, TransportClassTriggerClass1) {
-  CipConnectionObject connection_object     = {0};
+  CipConnectionObject connection_object     = { 0 };
   connection_object.transport_class_trigger = 1;
   ConnectionObjectTransportClassTriggerTransportClass transport_class =
-      ConnectionObjectGetTransportClassTriggerTransportClass(
-          &connection_object);
+    ConnectionObjectGetTransportClassTriggerTransportClass(&connection_object);
   CHECK_EQUAL(kConnectionObjectTransportClassTriggerTransportClass1,
               transport_class);
 }
 
 TEST(CipConnectionObject, TransportClassTriggerClass2) {
-  CipConnectionObject connection_object     = {0};
+  CipConnectionObject connection_object     = { 0 };
   connection_object.transport_class_trigger = 2;
   ConnectionObjectTransportClassTriggerTransportClass transport_class =
-      ConnectionObjectGetTransportClassTriggerTransportClass(
-          &connection_object);
+    ConnectionObjectGetTransportClassTriggerTransportClass(&connection_object);
   CHECK_EQUAL(kConnectionObjectTransportClassTriggerTransportClass2,
               transport_class);
 }
 
 TEST(CipConnectionObject, TransportClassTriggerClass3) {
-  CipConnectionObject connection_object     = {0};
+  CipConnectionObject connection_object     = { 0 };
   connection_object.transport_class_trigger = 3;
   ConnectionObjectTransportClassTriggerTransportClass transport_class =
-      ConnectionObjectGetTransportClassTriggerTransportClass(
-          &connection_object);
+    ConnectionObjectGetTransportClassTriggerTransportClass(&connection_object);
   CHECK_EQUAL(kConnectionObjectTransportClassTriggerTransportClass3,
               transport_class);
 }
 
 TEST(CipConnectionObject, ExpectedPacketRate) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.t_to_o_requested_packet_interval =
-      11 * 1000;  // 11 ms in µs
+    11 * 1000;  // 11 ms in µs
   ConnectionObjectSetExpectedPacketRate(&connection_object);
   CipUint expected_packet_rate =
-      ConnectionObjectGetExpectedPacketRate(&connection_object);
+    ConnectionObjectGetExpectedPacketRate(&connection_object);
   CHECK_EQUAL(20, expected_packet_rate);
 }
 
 TEST(CipConnectionObject, ExpectedPacketRateBelowTimerResolution) {
-  CipConnectionObject connection_object              = {0};
+  CipConnectionObject connection_object              = { 0 };
   connection_object.t_to_o_requested_packet_interval = 9 * 1000;  // 9 ms in µs
   ConnectionObjectSetExpectedPacketRate(&connection_object);
   CipUint expected_packet_rate =
-      ConnectionObjectGetExpectedPacketRate(&connection_object);
+    ConnectionObjectGetExpectedPacketRate(&connection_object);
   CHECK_EQUAL(10, expected_packet_rate);
 }
 
 TEST(CipConnectionObject, ExpectedPacketRateZero) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   connection_object.t_to_o_requested_packet_interval =
-      0;  // A value of zero needs to be maintained, as this deactivates timeout
+    0;  // A value of zero needs to be maintained, as this deactivates timeout
   ConnectionObjectSetExpectedPacketRate(&connection_object);
   CipUint expected_packet_rate =
-      ConnectionObjectGetExpectedPacketRate(&connection_object);
+    ConnectionObjectGetExpectedPacketRate(&connection_object);
   CHECK_EQUAL(0, expected_packet_rate);
 }
 
 TEST(CipConnectionObject, ParseConnectionData) {
-  CipConnectionObject connection_object = {0};
+  CipConnectionObject connection_object = { 0 };
   const CipOctet message[] =
-      "\x06\x28\x00\x00\x00\x00\x00\x00\x00\x00\x98\xff\x18\x00\x78\x56"
-      "\x34\x12\x00\x00\x00\x00\xe0\x93\x04\x00\x02\x40\xa0\x86\x01\x00"
-      "\x22\x20\x01\x04\x20\x04\x24\x97\x2c\x98\x2c\x64";
+    "\x06\x28\x00\x00\x00\x00\x00\x00\x00\x00\x98\xff\x18\x00\x78\x56"
+    "\x34\x12\x00\x00\x00\x00\xe0\x93\x04\x00\x02\x40\xa0\x86\x01\x00"
+    "\x22\x20\x01\x04\x20\x04\x24\x97\x2c\x98\x2c\x64";
 
   const CipOctet* message_runner = (const CipOctet*)message;
 
   ConnectionObjectInitializeFromMessage(&message_runner, &connection_object);
   CipUdint o_to_t_network_connection_id =
-      ConnectionObjectGetCipConsumedConnectionID(&connection_object);
+    ConnectionObjectGetCipConsumedConnectionID(&connection_object);
   CHECK_EQUAL(0, o_to_t_network_connection_id);
 
   CipUdint t_to_o_network_connection_id =
-      ConnectionObjectGetCipProducedConnectionID(&connection_object);
+    ConnectionObjectGetCipProducedConnectionID(&connection_object);
   CHECK_EQUAL(0, t_to_o_network_connection_id);
 
   CipUint connection_serial_number =
-      ConnectionObjectGetConnectionSerialNumber(&connection_object);
+    ConnectionObjectGetConnectionSerialNumber(&connection_object);
   CHECK_EQUAL(0xff98, connection_serial_number);
 
   CipUint vendor_id = ConnectionObjectGetOriginatorVendorId(&connection_object);
   CHECK_EQUAL(0x0018, vendor_id);
 
   CipUdint originator_serial_number =
-      ConnectionObjectGetOriginatorSerialNumber(&connection_object);
+    ConnectionObjectGetOriginatorSerialNumber(&connection_object);
   CHECK_EQUAL(0x12345678, originator_serial_number);
 
   CipUsint connection_timeout_multiplier =
-      ConnectionObjectGetConnectionTimeoutMultiplier(&connection_object);
+    ConnectionObjectGetConnectionTimeoutMultiplier(&connection_object);
   CHECK_EQUAL(0, connection_timeout_multiplier);
 
   CipUdint o_to_t_rpi_in_microseconds =
-      ConnectionObjectGetOToTRequestedPacketInterval(&connection_object);
+    ConnectionObjectGetOToTRequestedPacketInterval(&connection_object);
   CHECK_EQUAL(300000, o_to_t_rpi_in_microseconds);
 
   bool o_to_t_redundant_owner =
-      ConnectionObjectIsOToTRedundantOwner(&connection_object);
+    ConnectionObjectIsOToTRedundantOwner(&connection_object);
   CHECK_EQUAL(false, o_to_t_redundant_owner);
 
   ConnectionObjectConnectionType o_to_t_connection_type =
-      ConnectionObjectGetOToTConnectionType(&connection_object);
+    ConnectionObjectGetOToTConnectionType(&connection_object);
   CHECK_EQUAL(kConnectionObjectConnectionTypePointToPoint,
               o_to_t_connection_type);
 
   ConnectionObjectPriority o_to_t_priority =
-      ConnectionObjectGetOToTPriority(&connection_object);
+    ConnectionObjectGetOToTPriority(&connection_object);
   CHECK_EQUAL(kConnectionObjectPriorityLow, o_to_t_priority);
 
   ConnectionObjectConnectionSizeType o_to_t_connection_size_type =
-      ConnectionObjectGetOToTConnectionSizeType(&connection_object);
+    ConnectionObjectGetOToTConnectionSizeType(&connection_object);
   CHECK_EQUAL(kConnectionObjectConnectionSizeTypeFixed,
               o_to_t_connection_size_type);
 
   size_t o_to_t_connection_size =
-      ConnectionObjectGetOToTConnectionSize(&connection_object);
+    ConnectionObjectGetOToTConnectionSize(&connection_object);
   CHECK_EQUAL(2ULL, o_to_t_connection_size);
 
   // T to O Tests
 
   CipUdint t_to_o_rpi_in_microseconds =
-      ConnectionObjectGetTToORequestedPacketInterval(&connection_object);
+    ConnectionObjectGetTToORequestedPacketInterval(&connection_object);
   CHECK_EQUAL(100000, t_to_o_rpi_in_microseconds);
 
   bool t_to_o_redundant_owner =
-      ConnectionObjectIsTToORedundantOwner(&connection_object);
+    ConnectionObjectIsTToORedundantOwner(&connection_object);
   CHECK_EQUAL(false, t_to_o_redundant_owner);
 
   ConnectionObjectConnectionType t_to_o_connection_type =
-      ConnectionObjectGetTToOConnectionType(&connection_object);
+    ConnectionObjectGetTToOConnectionType(&connection_object);
   CHECK_EQUAL(kConnectionObjectConnectionTypeMulticast, t_to_o_connection_type);
 
   ConnectionObjectPriority t_to_o_priority =
-      ConnectionObjectGetTToOPriority(&connection_object);
+    ConnectionObjectGetTToOPriority(&connection_object);
   CHECK_EQUAL(kConnectionObjectPriorityLow, t_to_o_priority);
 
   ConnectionObjectConnectionSizeType t_to_o_connection_size_type =
-      ConnectionObjectGetTToOConnectionSizeType(&connection_object);
+    ConnectionObjectGetTToOConnectionSizeType(&connection_object);
   CHECK_EQUAL(kConnectionObjectConnectionSizeTypeFixed,
               t_to_o_connection_size_type);
 
   size_t t_to_o_connection_size =
-      ConnectionObjectGetTToOConnectionSize(&connection_object);
+    ConnectionObjectGetTToOConnectionSize(&connection_object);
   CHECK_EQUAL(34ULL, t_to_o_connection_size);
 
   ConnectionObjectTransportClassTriggerDirection direction =
-      ConnectionObjectGetTransportClassTriggerDirection(&connection_object);
+    ConnectionObjectGetTransportClassTriggerDirection(&connection_object);
   CHECK_EQUAL(kConnectionObjectTransportClassTriggerDirectionClient, direction);
 
   ConnectionObjectTransportClassTriggerProductionTrigger trigger =
-      ConnectionObjectGetTransportClassTriggerProductionTrigger(
-          &connection_object);
+    ConnectionObjectGetTransportClassTriggerProductionTrigger(
+      &connection_object);
   CHECK_EQUAL(kConnectionObjectTransportClassTriggerProductionTriggerCyclic,
               trigger);
 
   ConnectionObjectTransportClassTriggerTransportClass transport_class =
-      ConnectionObjectGetTransportClassTriggerTransportClass(
-          &connection_object);
+    ConnectionObjectGetTransportClassTriggerTransportClass(&connection_object);
   CHECK_EQUAL(kConnectionObjectTransportClassTriggerTransportClass1,
               transport_class);
 }

+ 2 - 2
source/tests/cip/cipelectronickeyformattest.cpp

@@ -150,8 +150,8 @@ TEST(CipElectronicKeyFormat, GetMinorRevision) {
 
 TEST(CipElectronicKeyFormat, ParseElectronicKeyTest) {
   /* Size of an electronic key is 1 + 1 + 8 (Segment, Key format, Key) */
-  const CipOctet message[] = {
-      0x34, 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x84, 0x05};
+  const CipOctet message[]       = { 0x34, 0x04, 0x00, 0x01, 0x00,
+                                     0x02, 0x00, 0x03, 0x84, 0x05 };
   const CipOctet* message_buffer = message;
   GetElectronicKeyFormat4FromMessage(&message_buffer, key);
 

+ 4 - 4
source/tests/cip/cipelectronickeytest.cpp

@@ -25,19 +25,19 @@ TEST(CipElectronicKey, SetKeyFormat) {
 }
 
 TEST(CipElectronicKey, GetKeyFormat) {
-  CipElectronicKey key = {.key_format = 4, .key_data = NULL};
+  CipElectronicKey key = { .key_format = 4, .key_data = NULL };
   CHECK_EQUAL(4, ElectronicKeyGetKeyFormat(&key));
 }
 
 TEST(CipElectronicKey, SetKeyData) {
-  char dummyFormatData[] = {0, 1, 2, 3, 4, 5};
+  char dummyFormatData[] = { 0, 1, 2, 3, 4, 5 };
   CipElectronicKey key;
   ElectronicKeySetKeyData(&key, dummyFormatData);
   POINTERS_EQUAL(dummyFormatData, key.key_data);
 }
 
 TEST(CipElectronicKey, GetKeyData) {
-  char dummyFormatData[] = {0, 1, 2, 3, 4, 5};
-  CipElectronicKey key   = {.key_format = 0, .key_data = dummyFormatData};
+  char dummyFormatData[] = { 0, 1, 2, 3, 4, 5 };
+  CipElectronicKey key   = { .key_format = 0, .key_data = dummyFormatData };
   POINTERS_EQUAL(dummyFormatData, ElectronicKeyGetKeyData(&key));
 }

+ 138 - 138
source/tests/cip/cipepathtest.cpp

@@ -19,224 +19,224 @@ TEST_GROUP(CipEpath){
 
 /** Segment type tests **/
 TEST(CipEpath, GetSegmentTypePortSegment) {
-  const unsigned char message[] = {0x00};
+  const unsigned char message[] = { 0x00 };
   SegmentType segment_type      = GetPathSegmentType(message);
   CHECK_EQUAL(kSegmentTypePortSegment, segment_type);
 }
 
 TEST(CipEpath, GetSegmentTypeLogicalSegment) {
-  const unsigned char message[] = {0x20};
+  const unsigned char message[] = { 0x20 };
   SegmentType segment_type      = GetPathSegmentType(message);
   CHECK_EQUAL(kSegmentTypeLogicalSegment, segment_type);
 }
 
 TEST(CipEpath, GetSegmentTypeNetworkSegment) {
-  const unsigned char message[] = {0x40};
+  const unsigned char message[] = { 0x40 };
   SegmentType segment_type      = GetPathSegmentType(message);
   CHECK_EQUAL(kSegmentTypeNetworkSegment, segment_type);
 }
 
 TEST(CipEpath, GetSegmentTypeSymbolicSegment) {
-  const unsigned char message[] = {0x60};
+  const unsigned char message[] = { 0x60 };
   SegmentType segment_type      = GetPathSegmentType(message);
   CHECK_EQUAL(kSegmentTypeSymbolicSegment, segment_type);
 }
 
 TEST(CipEpath, GetSegmentTypeDataSegment) {
-  const unsigned char message[] = {0x80};
+  const unsigned char message[] = { 0x80 };
   SegmentType segment_type      = GetPathSegmentType(message);
   CHECK_EQUAL(kSegmentTypeDataSegment, segment_type);
 }
 
 TEST(CipEpath, GetSegmentTypeDataTypeConstructed) {
-  const unsigned char message[] = {0xA0};
+  const unsigned char message[] = { 0xA0 };
   SegmentType segment_type      = GetPathSegmentType(message);
   CHECK_EQUAL(kSegmentTypeDataTypeConstructed, segment_type);
 }
 
 TEST(CipEpath, GetSegmentTypeDataTypeElementary) {
-  const unsigned char message[] = {0xC0};
+  const unsigned char message[] = { 0xC0 };
   SegmentType segment_type      = GetPathSegmentType(message);
   CHECK_EQUAL(kSegmentTypeDataTypeElementary, segment_type);
 }
 
 TEST(CipEpath, GetSegmentTypeReserved) {
-  const unsigned char message[] = {0xE0};
+  const unsigned char message[] = { 0xE0 };
   SegmentType segment_type      = GetPathSegmentType(message);
   CHECK_EQUAL(kSegmentTypeReserved, segment_type);
 }
 /* Set Segment Type tests*/
 TEST(CipEpath, SetSegmentTypePortSegment) {
-  unsigned char message[] = {0xFF};
+  unsigned char message[] = { 0xFF };
   SetPathSegmentType(kSegmentTypePortSegment, message);
   CHECK_EQUAL(0x00, message[0]);
 }
 
 TEST(CipEpath, SetSegmentTypeLogicalSegment) {
-  unsigned char message[] = {0xFF};
+  unsigned char message[] = { 0xFF };
   SetPathSegmentType(kSegmentTypeLogicalSegment, message);
   CHECK_EQUAL(0x20, message[0]);
 }
 
 TEST(CipEpath, SetSegmentTypeNetworkSegment) {
-  unsigned char message[] = {0xFF};
+  unsigned char message[] = { 0xFF };
   SetPathSegmentType(kSegmentTypeNetworkSegment, message);
   CHECK_EQUAL(0x40, message[0]);
 }
 
 TEST(CipEpath, SetSegmentTypeSymbolicSegment) {
-  unsigned char message[] = {0xFF};
+  unsigned char message[] = { 0xFF };
   SetPathSegmentType(kSegmentTypeSymbolicSegment, message);
   CHECK_EQUAL(0x60, message[0]);
 }
 
 TEST(CipEpath, SetSegmentTypeDataSegment) {
-  unsigned char message[] = {0xFF};
+  unsigned char message[] = { 0xFF };
   SetPathSegmentType(kSegmentTypeDataSegment, message);
   CHECK_EQUAL(0x80, message[0]);
 }
 
 TEST(CipEpath, SetSegmentTypeDataTypeConstructed) {
-  unsigned char message[] = {0xFF};
+  unsigned char message[] = { 0xFF };
   SetPathSegmentType(kSegmentTypeDataTypeConstructed, message);
   CHECK_EQUAL(0xA0, message[0]);
 }
 
 TEST(CipEpath, SetSegmentTypeDataTypeElementary) {
-  unsigned char message[] = {0xFF};
+  unsigned char message[] = { 0xFF };
   SetPathSegmentType(kSegmentTypeDataTypeElementary, message);
   CHECK_EQUAL(0xC0, message[0]);
 }
 
 TEST(CipEpath, SetSegmentTypeReserved) {
-  unsigned char message[] = {0xFF};
+  unsigned char message[] = { 0xFF };
   SetPathSegmentType(kSegmentTypeReserved, message);
   CHECK_EQUAL(0xE0, message[0]);
 }
 
 /** Port segment tests **/
 TEST(CipEpath, GetPortSegmentExtendedAddressSizeTrue) {
-  const unsigned char message[] = {0x10};
+  const unsigned char message[] = { 0x10 };
   bool extended_address = GetPathPortSegmentExtendedLinkAddressSizeBit(message);
   CHECK_EQUAL(true, extended_address);
 }
 
 TEST(CipEpath, GetPortSegmentExtendedAddressSizeFalse) {
-  const unsigned char message[] = {0x00};
+  const unsigned char message[] = { 0x00 };
   bool extended_address = GetPathPortSegmentExtendedLinkAddressSizeBit(message);
   CHECK_EQUAL(false, extended_address);
 }
 
 TEST(CipEpath, GetPortSegmentPortIdentifier) {
-  const unsigned char message[] = {0x0F};
+  const unsigned char message[] = { 0x0F };
   unsigned int port             = GetPathPortSegmentPortIdentifier(message);
   unsigned int mes              = (unsigned int)(message[0]);
   CHECK_EQUAL(15, mes);
 }
 
 TEST(CipEpath, SetPortSegmentPortIdentifier) {
-  unsigned char message[] = {0x00};
+  unsigned char message[] = { 0x00 };
   SetPathPortSegmentPortIdentifier(15, message);
   CHECK_EQUAL(15, (unsigned int)(message[0]));
 }
 
 TEST(CipEpath, GetPortSegmentLinkAddressSize) {
-  const unsigned char message[] = {0x10, 0x04};
+  const unsigned char message[] = { 0x10, 0x04 };
   unsigned int size             = GetPathPortSegmentLinkAddressSize(message);
   CHECK_EQUAL(4, size);
 }
 
 TEST(CipEpath, GetPortSegmentExtendedPortNumberNoExtendedAddress) {
-  const unsigned char message[] = {0x0F, 0x22, 0x64};
+  const unsigned char message[] = { 0x0F, 0x22, 0x64 };
   unsigned int extended_port    = GetPathPortSegmentExtendedPortNumber(message);
   CHECK_EQUAL(25634, extended_port);
 }
 
 TEST(CipEpath, GetPortSegmentExtendedPortNumberWithExtendedAddress) {
-  const unsigned char message[] = {0x1F, 0x00, 0x22, 0x64};
+  const unsigned char message[] = { 0x1F, 0x00, 0x22, 0x64 };
   unsigned int extended_port    = GetPathPortSegmentExtendedPortNumber(message);
   CHECK_EQUAL(25634, extended_port);
 }
 
 TEST(CipEpath, SetPortSegmentExtendedPortNoExtendedAddress) {
-  unsigned char message[]       = {0x00, 0x00, 0x00};
-  const char expected_message[] = {0x0F, 0x22, 0x64};
+  unsigned char message[]       = { 0x00, 0x00, 0x00 };
+  const char expected_message[] = { 0x0F, 0x22, 0x64 };
   SetPathPortSegmentExtendedPortIdentifier((unsigned int)25634, message);
   MEMCMP_EQUAL(expected_message, message, 3);
 }
 
 TEST(CipEpath, SetPortSegmentExtendedPortWithExtendedAddress) {
-  unsigned char message[]       = {0x10, 0x00, 0x00, 0x00};
-  const char expected_message[] = {0x1F, 0x00, 0x22, 0x64};
+  unsigned char message[]       = { 0x10, 0x00, 0x00, 0x00 };
+  const char expected_message[] = { 0x1F, 0x00, 0x22, 0x64 };
   SetPathPortSegmentExtendedPortIdentifier((unsigned int)25634, message);
   MEMCMP_EQUAL(expected_message, message, 4);
 }
 
 TEST(CipEpath, GetLogicalSegmentLogicalTypeClassId) {
-  const unsigned char message[] = {0x20};
+  const unsigned char message[] = { 0x20 };
   const LogicalSegmentLogicalType type =
-      GetPathLogicalSegmentLogicalType(message);
+    GetPathLogicalSegmentLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentLogicalTypeClassId, type);
 }
 
 TEST(CipEpath, GetLogicalSegmentLogicalTypeInstanceId) {
-  const unsigned char message[] = {0x24};
+  const unsigned char message[] = { 0x24 };
   const LogicalSegmentLogicalType type =
-      GetPathLogicalSegmentLogicalType(message);
+    GetPathLogicalSegmentLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentLogicalTypeInstanceId, type);
 }
 
 TEST(CipEpath, GetLogicalSegmentLogicalTypeMemberId) {
-  const unsigned char message[] = {0x28};
+  const unsigned char message[] = { 0x28 };
   const LogicalSegmentLogicalType type =
-      GetPathLogicalSegmentLogicalType(message);
+    GetPathLogicalSegmentLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentLogicalTypeMemberId, type);
 }
 
 TEST(CipEpath, GetLogicalSegmentLogicalTypeConnectionPoint) {
-  const unsigned char message[] = {0x2C};
+  const unsigned char message[] = { 0x2C };
   const LogicalSegmentLogicalType type =
-      GetPathLogicalSegmentLogicalType(message);
+    GetPathLogicalSegmentLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentLogicalTypeConnectionPoint, type);
 }
 
 TEST(CipEpath, GetLogicalSegmentLogicalTypeAttributeId) {
-  const unsigned char message[] = {0x30};
+  const unsigned char message[] = { 0x30 };
   const LogicalSegmentLogicalType type =
-      GetPathLogicalSegmentLogicalType(message);
+    GetPathLogicalSegmentLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentLogicalTypeAttributeId, type);
 }
 
 TEST(CipEpath, GetLogicalSegmentLogicalTypeSpecial) {
-  const unsigned char message[] = {0x34};
+  const unsigned char message[] = { 0x34 };
   const LogicalSegmentLogicalType type =
-      GetPathLogicalSegmentLogicalType(message);
+    GetPathLogicalSegmentLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentLogicalTypeSpecial, type);
 }
 
 TEST(CipEpath, GetLogicalSegmentLogicalTypeServiceId) {
-  const unsigned char message[] = {0x38};
+  const unsigned char message[] = { 0x38 };
   const LogicalSegmentLogicalType type =
-      GetPathLogicalSegmentLogicalType(message);
+    GetPathLogicalSegmentLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentLogicalTypeServiceId, type);
 }
 
 TEST(CipEpath, GetLogicalSegmentLogicalTypeExtendedLogical) {
-  const unsigned char message[] = {0x3C};
+  const unsigned char message[] = { 0x3C };
   const LogicalSegmentLogicalType type =
-      GetPathLogicalSegmentLogicalType(message);
+    GetPathLogicalSegmentLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentLogicalTypeExtendedLogical, type);
 }
 
 TEST(CipEpath, SetLogicalSegmentLogicalTypeClassId) {
-  CipOctet message[] = {SEGMENT_TYPE_LOGICAL_SEGMENT};
+  CipOctet message[] = { SEGMENT_TYPE_LOGICAL_SEGMENT };
   SetPathLogicalSegmentLogicalType(kLogicalSegmentLogicalTypeClassId, message);
   CHECK_EQUAL(SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_TYPE_CLASS_ID,
               message[0]);
 }
 
 TEST(CipEpath, SetLogicalSegmentLogicalTypeInstanceId) {
-  CipOctet message[] = {SEGMENT_TYPE_LOGICAL_SEGMENT};
+  CipOctet message[] = { SEGMENT_TYPE_LOGICAL_SEGMENT };
   SetPathLogicalSegmentLogicalType(kLogicalSegmentLogicalTypeInstanceId,
                                    message);
   CHECK_EQUAL(SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_TYPE_INSTANCE_ID,
@@ -244,23 +244,23 @@ TEST(CipEpath, SetLogicalSegmentLogicalTypeInstanceId) {
 }
 
 TEST(CipEpath, SetLogicalSegmentLogicalTypeMemberId) {
-  CipOctet message[] = {SEGMENT_TYPE_LOGICAL_SEGMENT};
+  CipOctet message[] = { SEGMENT_TYPE_LOGICAL_SEGMENT };
   SetPathLogicalSegmentLogicalType(kLogicalSegmentLogicalTypeMemberId, message);
   CHECK_EQUAL(SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_TYPE_MEMBER_ID,
               message[0]);
 }
 
 TEST(CipEpath, SetLogicalSegmentLogicalTypeConnectionPoint) {
-  CipOctet message[] = {SEGMENT_TYPE_LOGICAL_SEGMENT};
+  CipOctet message[] = { SEGMENT_TYPE_LOGICAL_SEGMENT };
   SetPathLogicalSegmentLogicalType(kLogicalSegmentLogicalTypeConnectionPoint,
                                    message);
   CHECK_EQUAL(
-      SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_TYPE_CONNECTION_POINT,
-      message[0]);
+    SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_TYPE_CONNECTION_POINT,
+    message[0]);
 }
 
 TEST(CipEpath, SetLogicalSegmentLogicalTypeAttributeId) {
-  CipOctet message[] = {SEGMENT_TYPE_LOGICAL_SEGMENT};
+  CipOctet message[] = { SEGMENT_TYPE_LOGICAL_SEGMENT };
   SetPathLogicalSegmentLogicalType(kLogicalSegmentLogicalTypeAttributeId,
                                    message);
   CHECK_EQUAL(SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_TYPE_ATTRIBUTE_ID,
@@ -268,14 +268,14 @@ TEST(CipEpath, SetLogicalSegmentLogicalTypeAttributeId) {
 }
 
 TEST(CipEpath, SetLogicalSegmentLogicalTypeSpecial) {
-  CipOctet message[] = {SEGMENT_TYPE_LOGICAL_SEGMENT};
+  CipOctet message[] = { SEGMENT_TYPE_LOGICAL_SEGMENT };
   SetPathLogicalSegmentLogicalType(kLogicalSegmentLogicalTypeSpecial, message);
   CHECK_EQUAL(SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_TYPE_SPECIAL,
               message[0]);
 }
 
 TEST(CipEpath, SetLogicalSegmentLogicalTypeServiceId) {
-  CipOctet message[] = {SEGMENT_TYPE_LOGICAL_SEGMENT};
+  CipOctet message[] = { SEGMENT_TYPE_LOGICAL_SEGMENT };
   SetPathLogicalSegmentLogicalType(kLogicalSegmentLogicalTypeServiceId,
                                    message);
   CHECK_EQUAL(SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_TYPE_SERVICE_ID,
@@ -283,37 +283,37 @@ TEST(CipEpath, SetLogicalSegmentLogicalTypeServiceId) {
 }
 
 TEST(CipEpath, SetLogicalSegmentLogicalTypeExtendedLogicalPath) {
-  CipOctet message[] = {SEGMENT_TYPE_LOGICAL_SEGMENT};
+  CipOctet message[] = { SEGMENT_TYPE_LOGICAL_SEGMENT };
   SetPathLogicalSegmentLogicalType(kLogicalSegmentLogicalTypeExtendedLogical,
                                    message);
   CHECK_EQUAL(
-      SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_TYPE_EXTENDED_LOGICAL,
-      message[0]);
+    SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_TYPE_EXTENDED_LOGICAL,
+    message[0]);
 }
 
 TEST(CipEpath, GetLogicalSegmentLogicalFormatEightBits) {
-  const unsigned char message[] = {0x20};
+  const unsigned char message[] = { 0x20 };
   const LogicalSegmentLogicalFormat format =
-      GetPathLogicalSegmentLogicalFormat(message);
+    GetPathLogicalSegmentLogicalFormat(message);
   CHECK_EQUAL(kLogicalSegmentLogicalFormatEightBit, format);
 }
 
 TEST(CipEpath, GetLogicalSegmentLogicalFormatSixteenBits) {
-  const unsigned char message[] = {0x21};
+  const unsigned char message[] = { 0x21 };
   const LogicalSegmentLogicalFormat format =
-      GetPathLogicalSegmentLogicalFormat(message);
+    GetPathLogicalSegmentLogicalFormat(message);
   CHECK_EQUAL(kLogicalSegmentLogicalFormatSixteenBit, format);
 }
 
 TEST(CipEpath, GetLogicalSegmentLogicalFormatThirtyTwoBits) {
-  const unsigned char message[] = {0x22};
+  const unsigned char message[] = { 0x22 };
   const LogicalSegmentLogicalFormat format =
-      GetPathLogicalSegmentLogicalFormat(message);
+    GetPathLogicalSegmentLogicalFormat(message);
   CHECK_EQUAL(kLogicalSegmentLogicalFormatThirtyTwoBit, format);
 }
 
 TEST(CipEpath, SetLogicalSegmentLogicalFormatEightBits) {
-  CipOctet message[] = {SEGMENT_TYPE_LOGICAL_SEGMENT};
+  CipOctet message[] = { SEGMENT_TYPE_LOGICAL_SEGMENT };
   SetPathLogicalSegmentLogicalFormat(kLogicalSegmentLogicalFormatEightBit,
                                      message);
   CHECK_EQUAL(SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_FORMAT_EIGHT_BIT,
@@ -321,7 +321,7 @@ TEST(CipEpath, SetLogicalSegmentLogicalFormatEightBits) {
 }
 
 TEST(CipEpath, SetLogicalSegmentLogicalFormatSixteenBits) {
-  CipOctet message[] = {SEGMENT_TYPE_LOGICAL_SEGMENT};
+  CipOctet message[] = { SEGMENT_TYPE_LOGICAL_SEGMENT };
   SetPathLogicalSegmentLogicalFormat(kLogicalSegmentLogicalFormatSixteenBit,
                                      message);
   CHECK_EQUAL(SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_FORMAT_SIXTEEN_BIT,
@@ -329,12 +329,12 @@ TEST(CipEpath, SetLogicalSegmentLogicalFormatSixteenBits) {
 }
 
 TEST(CipEpath, SetLogicalSegmentLogicalFormatThirtyTwoBits) {
-  CipOctet message[] = {SEGMENT_TYPE_LOGICAL_SEGMENT};
+  CipOctet message[] = { SEGMENT_TYPE_LOGICAL_SEGMENT };
   SetPathLogicalSegmentLogicalFormat(kLogicalSegmentLogicalFormatThirtyTwoBit,
                                      message);
   CHECK_EQUAL(
-      SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_FORMAT_THIRTY_TWO_BIT,
-      message[0]);
+    SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_FORMAT_THIRTY_TWO_BIT,
+    message[0]);
 }
 
 TEST(CipEpath, GetLogicalValue8Bit) {
@@ -355,7 +355,7 @@ TEST(CipEpath, GetLogicalValue16Bit) {
   CipOctet* message          = (CipOctet*)calloc(6, sizeof(CipOctet));
   CipOctet* original_address = message;
   message[0] =
-      SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_FORMAT_SIXTEEN_BIT;
+    SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_FORMAT_SIXTEEN_BIT;
   message[1]      = 0;
   message[2]      = 21;
   message[3]      = 22;
@@ -370,7 +370,7 @@ TEST(CipEpath, GetLogicalValue32Bit) {
   CipOctet* message          = (CipOctet*)calloc(6, sizeof(CipOctet));
   CipOctet* original_address = message;
   message[0] =
-      SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_FORMAT_THIRTY_TWO_BIT;
+    SEGMENT_TYPE_LOGICAL_SEGMENT | LOGICAL_SEGMENT_FORMAT_THIRTY_TWO_BIT;
   message[1]      = 0;
   message[2]      = 21;
   message[3]      = 22;
@@ -383,19 +383,19 @@ TEST(CipEpath, GetLogicalValue32Bit) {
 
 TEST(CipEpath, SetLogicalValue8Bit) {
   const CipUsint value                      = 54;
-  CipMessageRouterResponse response         = {0};
+  CipMessageRouterResponse response         = { 0 };
   response.message.current_message_position = response.message.message_buffer;
   CipEpathSetLogicalValue(
-      value, kLogicalSegmentLogicalFormatEightBit, &response);
+    value, kLogicalSegmentLogicalFormatEightBit, &response);
   CHECK_EQUAL(value, *response.message.message_buffer);
 }
 
 TEST(CipEpath, SetLogicalValue16Bit) {
   const CipUsint value                      = 54;
-  CipMessageRouterResponse response         = {0};
+  CipMessageRouterResponse response         = { 0 };
   response.message.current_message_position = response.message.message_buffer;
   CipEpathSetLogicalValue(
-      value, kLogicalSegmentLogicalFormatSixteenBit, &response);
+    value, kLogicalSegmentLogicalFormatSixteenBit, &response);
   CHECK_EQUAL(value, *(response.message.message_buffer + 1));
   CHECK_EQUAL(0, *(response.message.message_buffer + 2));
   CHECK_EQUAL(0, *(response.message.message_buffer + 3));
@@ -404,10 +404,10 @@ TEST(CipEpath, SetLogicalValue16Bit) {
 
 TEST(CipEpath, SetLogicalValue32Bit) {
   const CipUsint value                      = 54;
-  CipMessageRouterResponse response         = {0};
+  CipMessageRouterResponse response         = { 0 };
   response.message.current_message_position = response.message.message_buffer;
   CipEpathSetLogicalValue(
-      value, kLogicalSegmentLogicalFormatThirtyTwoBit, &response);
+    value, kLogicalSegmentLogicalFormatThirtyTwoBit, &response);
   CHECK_EQUAL(value, *(response.message.message_buffer + 1));
   CHECK_EQUAL(0, *(response.message.message_buffer + 2));
   CHECK_EQUAL(0, *(response.message.message_buffer + 3));
@@ -418,91 +418,91 @@ TEST(CipEpath, SetLogicalValue32Bit) {
 }
 
 TEST(CipEpath, GetLogicalSegmentExtendedLogicalTypeReserved) {
-  const unsigned char message[] = {0x3C, 0x00};
+  const unsigned char message[] = { 0x3C, 0x00 };
   const LogicalSegmentExtendedLogicalType extended_type =
-      GetPathLogicalSegmentExtendedLogicalType(message);
+    GetPathLogicalSegmentExtendedLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentExtendedLogicalTypeReserved, extended_type);
 }
 
 TEST(CipEpath, GetLogicalSegmentExtendedLogicalTypeArrayIndex) {
-  const unsigned char message[] = {0x3C, 0x01};
+  const unsigned char message[] = { 0x3C, 0x01 };
   const LogicalSegmentExtendedLogicalType extended_type =
-      GetPathLogicalSegmentExtendedLogicalType(message);
+    GetPathLogicalSegmentExtendedLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentExtendedLogicalTypeArrayIndex, extended_type);
 }
 
 TEST(CipEpath, GetLogicalSegmentExtendedLogicalTypeIndirectArrayIndex) {
-  const unsigned char message[] = {0x3C, 0x02};
+  const unsigned char message[] = { 0x3C, 0x02 };
   const LogicalSegmentExtendedLogicalType extended_type =
-      GetPathLogicalSegmentExtendedLogicalType(message);
+    GetPathLogicalSegmentExtendedLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentExtendedLogicalTypeIndirectArrayIndex,
               extended_type);
 }
 
 TEST(CipEpath, GetLogicalSegmentExtendedLogicalTypeBitIndex) {
-  const unsigned char message[] = {0x3C, 0x03};
+  const unsigned char message[] = { 0x3C, 0x03 };
   const LogicalSegmentExtendedLogicalType extended_type =
-      GetPathLogicalSegmentExtendedLogicalType(message);
+    GetPathLogicalSegmentExtendedLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentExtendedLogicalTypeBitIndex, extended_type);
 }
 
 TEST(CipEpath, GetLogicalSegmentExtendedLogicalTypeIndirectBitIndex) {
-  const unsigned char message[] = {0x3C, 0x04};
+  const unsigned char message[] = { 0x3C, 0x04 };
   const LogicalSegmentExtendedLogicalType extended_type =
-      GetPathLogicalSegmentExtendedLogicalType(message);
+    GetPathLogicalSegmentExtendedLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentExtendedLogicalTypeIndirectBitIndex,
               extended_type);
 }
 
 TEST(CipEpath, GetLogicalSegmentExtendedLogicalTypeStructureMemberNumber) {
-  const unsigned char message[] = {0x3C, 0x05};
+  const unsigned char message[] = { 0x3C, 0x05 };
   const LogicalSegmentExtendedLogicalType extended_type =
-      GetPathLogicalSegmentExtendedLogicalType(message);
+    GetPathLogicalSegmentExtendedLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentExtendedLogicalTypeStructureMemberNumber,
               extended_type);
 }
 
 TEST(CipEpath, GetLogicalSegmentExtendedLogicalTypeStructureMemberHandle) {
-  const unsigned char message[] = {0x3C, 0x06};
+  const unsigned char message[] = { 0x3C, 0x06 };
   const LogicalSegmentExtendedLogicalType extended_type =
-      GetPathLogicalSegmentExtendedLogicalType(message);
+    GetPathLogicalSegmentExtendedLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentExtendedLogicalTypeStructureMemberHandle,
               extended_type);
 }
 
 TEST(CipEpath, GetLogicalSegmentSpecialTypeLogicalTypeReserved) {
-  const unsigned char message[] = {0x35};
+  const unsigned char message[] = { 0x35 };
   LogicalSegmentSpecialTypeLogicalFormat special_type =
-      GetPathLogicalSegmentSpecialTypeLogicalType(message);
+    GetPathLogicalSegmentSpecialTypeLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentSpecialTypeLogicalFormatReserved, special_type);
 }
 
 TEST(CipEpath, GetLogicalSegmentSpecialTypeLogicalTypeElectronicKey) {
-  const unsigned char message[] = {0x34};
+  const unsigned char message[] = { 0x34 };
   LogicalSegmentSpecialTypeLogicalFormat special_type =
-      GetPathLogicalSegmentSpecialTypeLogicalType(message);
+    GetPathLogicalSegmentSpecialTypeLogicalType(message);
   CHECK_EQUAL(kLogicalSegmentSpecialTypeLogicalFormatElectronicKey,
               special_type);
 }
 
 TEST(CipEpath, GetPathLogicalSegmentElectronicKeyFormatReserved) {
-  const unsigned char message[] = {0x34, 0x00};
+  const unsigned char message[] = { 0x34, 0x00 };
   ElectronicKeySegmentFormat key_format =
-      GetPathLogicalSegmentElectronicKeyFormat(message);
+    GetPathLogicalSegmentElectronicKeyFormat(message);
   CHECK_EQUAL(kElectronicKeySegmentFormatReserved, key_format);
 }
 
 TEST(CipEpath, GetElectronicKeyFormat4FromMessage) {
-  const unsigned char message[] = {0x34, 0x04};
+  const unsigned char message[] = { 0x34, 0x04 };
   ElectronicKeySegmentFormat key_format =
-      GetPathLogicalSegmentElectronicKeyFormat(message);
+    GetPathLogicalSegmentElectronicKeyFormat(message);
   CHECK_EQUAL(kElectronicKeySegmentFormatKeyFormat4, key_format);
 }
 
 TEST(CipEpath, GetLogicalSegmentElectronicKeyFormat4) {
   /* Size of an electronic key is 1 + 1 + 8 (Segment, Key format, Key) */
-  const CipOctet message[] = {
-      0x34, 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x04, 0x05};
+  const CipOctet message[]             = { 0x34, 0x04, 0x00, 0x01, 0x00,
+                                           0x02, 0x00, 0x03, 0x04, 0x05 };
   const CipOctet* message_pp           = (const CipOctet*)message;
   const CipOctet* message_buffer       = message;
   ElectronicKeyFormat4* electronic_key = ElectronicKeyFormat4New();
@@ -514,180 +514,180 @@ TEST(CipEpath, GetLogicalSegmentElectronicKeyFormat4) {
 }
 
 TEST(CipEpath, GetPathNetworkSegmentSubtypeReserved) {
-  const unsigned char message[]  = {0x40};
+  const unsigned char message[]  = { 0x40 };
   NetworkSegmentSubtype sub_type = GetPathNetworkSegmentSubtype(message);
   CHECK_EQUAL(kNetworkSegmentSubtypeReserved, sub_type);
 }
 
 TEST(CipEpath, GetPathNetworkSegmentSubtypeScheduled) {
-  const unsigned char message[]  = {0x41};
+  const unsigned char message[]  = { 0x41 };
   NetworkSegmentSubtype sub_type = GetPathNetworkSegmentSubtype(message);
   CHECK_EQUAL(kNetworkSegmentSubtypeScheduleSegment, sub_type);
 }
 
 TEST(CipEpath, GetPathNetworkSegmentSubtypeFixedTag) {
-  const unsigned char message[]  = {0x42};
+  const unsigned char message[]  = { 0x42 };
   NetworkSegmentSubtype sub_type = GetPathNetworkSegmentSubtype(message);
   CHECK_EQUAL(kNetworkSegmentSubtypeFixedTagSegment, sub_type);
 }
 
 TEST(CipEpath,
      GetPathNetworkSegmentSubtypeProductionInhibitTimerInMilliseconds) {
-  const unsigned char message[]  = {0x43};
+  const unsigned char message[]  = { 0x43 };
   NetworkSegmentSubtype sub_type = GetPathNetworkSegmentSubtype(message);
   CHECK_EQUAL(kNetworkSegmentSubtypeProductionInhibitTimeInMilliseconds,
               sub_type);
 }
 
 TEST(CipEpath, GetPathNetworkSegmentSubtypeSafety) {
-  const unsigned char message[]  = {0x44};
+  const unsigned char message[]  = { 0x44 };
   NetworkSegmentSubtype sub_type = GetPathNetworkSegmentSubtype(message);
   CHECK_EQUAL(kNetworkSegmentSubtypeSafetySegment, sub_type);
 }
 
 TEST(CipEpath,
      GetPathNetworkSegmentSubtypeProductionInhibitTimerInMicroseconds) {
-  const unsigned char message[]  = {0x50};
+  const unsigned char message[]  = { 0x50 };
   NetworkSegmentSubtype sub_type = GetPathNetworkSegmentSubtype(message);
   CHECK_EQUAL(kNetworkSegmentSubtypeProductionInhibitTimeInMicroseconds,
               sub_type);
 }
 
 TEST(CipEpath, GetPathNetworkSegmentSubtypeExtendedNetwork) {
-  const unsigned char message[]  = {0x5F};
+  const unsigned char message[]  = { 0x5F };
   NetworkSegmentSubtype sub_type = GetPathNetworkSegmentSubtype(message);
   CHECK_EQUAL(kNetworkSegmentSubtypeExtendedNetworkSegment, sub_type);
 }
 
 TEST(CipEpath, GetPathNetworkSegmentProductionInhibitTimeInMilliseconds) {
-  const unsigned char message[] = {0x43, 0xFF};
+  const unsigned char message[] = { 0x43, 0xFF };
   CipUsint time_im_milliseconds =
-      GetPathNetworkSegmentProductionInhibitTimeInMilliseconds(message);
+    GetPathNetworkSegmentProductionInhibitTimeInMilliseconds(message);
   CHECK_EQUAL(255, time_im_milliseconds);
 }
 
 TEST(CipEpath, GetPathNetworkSegmentProductionInhibitTimeInMicroseconds) {
-  const unsigned char message[] = {0x50, 0x02, 0x00, 0x00, 0x00, 0xFF};
+  const unsigned char message[] = { 0x50, 0x02, 0x00, 0x00, 0x00, 0xFF };
   CipUdint time_in_microseconds =
-      GetPathNetworkSegmentProductionInhibitTimeInMicroseconds(message);
+    GetPathNetworkSegmentProductionInhibitTimeInMicroseconds(message);
   CHECK_EQUAL(4278190080, time_in_microseconds);
 }
 
 TEST(CipEpath, GetPathDataSegmentSubtypeReserverd) {
-  const unsigned char message[] = {0x81};
+  const unsigned char message[] = { 0x81 };
   DataSegmentSubtype type       = GetPathDataSegmentSubtype(message);
   CHECK_EQUAL(kDataSegmentSubtypeReserved, type);
 }
 
 TEST(CipEpath, GetPathDataSegmentSubtypeSimpleData) {
-  const unsigned char message[] = {0x80};
+  const unsigned char message[] = { 0x80 };
   DataSegmentSubtype type       = GetPathDataSegmentSubtype(message);
   CHECK_EQUAL(kDataSegmentSubtypeSimpleData, type);
 }
 
 TEST(CipEpath, GetPathDataSegmentSubtypeANSIExtendedSymbol) {
-  const unsigned char message[] = {0x91};
+  const unsigned char message[] = { 0x91 };
   DataSegmentSubtype type       = GetPathDataSegmentSubtype(message);
   CHECK_EQUAL(kDataSegmentSubtypeANSIExtendedSymbol, type);
 }
 
 TEST(CipEpath, GetPathDataSegmentSimpleDataWordLength) {
-  const unsigned char message[] = {0x80, 0x25};
+  const unsigned char message[] = { 0x80, 0x25 };
   CipUsint length = GetPathDataSegmentSimpleDataWordLength(message);
   CHECK_EQUAL(37, length);
 }
 
 TEST(CipEpath, GetPathSymbolicSegmentFormatASCII) {
-  const unsigned char message[] = {0x61};
+  const unsigned char message[] = { 0x61 };
   SymbolicSegmentFormat format  = GetPathSymbolicSegmentFormat(message);
   CHECK_EQUAL(kSymbolicSegmentFormatASCII, format);
 }
 
 TEST(CipEpath, GetPathSymbolicSegmentFormatExtendedFormat) {
-  const unsigned char message[] = {0x60};
+  const unsigned char message[] = { 0x60 };
   SymbolicSegmentFormat format  = GetPathSymbolicSegmentFormat(message);
   CHECK_EQUAL(kSymbolicSegmentFormatExtendedString, format);
 }
 
 TEST(CipEpath, GetPathSymbolicSegmentASCIIFormatLength) {
-  const unsigned char message[] = {0x61};
+  const unsigned char message[] = { 0x61 };
   SymbolicSegmentFormat format  = GetPathSymbolicSegmentFormat(message);
   CHECK_EQUAL(kSymbolicSegmentFormatASCII, format);
 }
 
 TEST(CipEpath, GetPathSymbolicSegmentNumericTypeReserved) {
-  const unsigned char message[] = {0x60, 0xC0};
+  const unsigned char message[] = { 0x60, 0xC0 };
   SymbolicSegmentExtendedFormat format =
-      GetPathSymbolicSegmentNumericType(message);
+    GetPathSymbolicSegmentNumericType(message);
   CHECK_EQUAL(kSymbolicSegmentExtendedFormatReserved, format);
 }
 
 TEST(CipEpath, GetPathSymbolicSegmentNumericTypeUSINT) {
-  const unsigned char message[] = {0x60, 0xC6};
+  const unsigned char message[] = { 0x60, 0xC6 };
   SymbolicSegmentExtendedFormat format =
-      GetPathSymbolicSegmentNumericType(message);
+    GetPathSymbolicSegmentNumericType(message);
   CHECK_EQUAL(kSymbolicSegmentExtendedFormatNumericSymbolUSINT, format);
 }
 
 TEST(CipEpath, GetPathSymbolicSegmentNumericTypeUINT) {
-  const unsigned char message[] = {0x60, 0xC7};
+  const unsigned char message[] = { 0x60, 0xC7 };
   SymbolicSegmentExtendedFormat format =
-      GetPathSymbolicSegmentNumericType(message);
+    GetPathSymbolicSegmentNumericType(message);
   CHECK_EQUAL(kSymbolicSegmentExtendedFormatNumericSymbolUINT, format);
 }
 
 TEST(CipEpath, GetPathSymbolicSegmentNumericTypeUDINT) {
-  const unsigned char message[] = {0x60, 0xC8};
+  const unsigned char message[] = { 0x60, 0xC8 };
   SymbolicSegmentExtendedFormat format =
-      GetPathSymbolicSegmentNumericType(message);
+    GetPathSymbolicSegmentNumericType(message);
   CHECK_EQUAL(kSymbolicSegmentExtendedFormatNumericSymbolUDINT, format);
 }
 
 TEST(CipEpath, GetPathSymbolicSegmentExtendedFormatReserverd) {
-  const unsigned char message[] = {0x60, 0x00};
+  const unsigned char message[] = { 0x60, 0x00 };
   SymbolicSegmentExtendedFormat format =
-      GetPathSymbolicSegmentExtendedFormat(message);
+    GetPathSymbolicSegmentExtendedFormat(message);
   CHECK_EQUAL(kSymbolicSegmentExtendedFormatReserved, format);
 }
 
 TEST(CipEpath, GetPathSymbolicSegmentExtendedFormatDoubleChars) {
-  const unsigned char message[] = {0x60, 0x20};
+  const unsigned char message[] = { 0x60, 0x20 };
   SymbolicSegmentExtendedFormat format =
-      GetPathSymbolicSegmentExtendedFormat(message);
+    GetPathSymbolicSegmentExtendedFormat(message);
   CHECK_EQUAL(kSymbolicSegmentExtendedFormatDoubleByteChars, format);
 }
 
 TEST(CipEpath, GetPathSymbolicSegmentExtendedFormatTripleChars) {
-  const unsigned char message[] = {0x60, 0x40};
+  const unsigned char message[] = { 0x60, 0x40 };
   SymbolicSegmentExtendedFormat format =
-      GetPathSymbolicSegmentExtendedFormat(message);
+    GetPathSymbolicSegmentExtendedFormat(message);
   CHECK_EQUAL(kSymbolicSegmentExtendedFormatTripleByteChars, format);
 }
 
 TEST(CipEpath, GetPathSymbolicSegmentExtendedFormatUSINT) {
-  const unsigned char message[] = {0x60, 0xC6};
+  const unsigned char message[] = { 0x60, 0xC6 };
   SymbolicSegmentExtendedFormat format =
-      GetPathSymbolicSegmentExtendedFormat(message);
+    GetPathSymbolicSegmentExtendedFormat(message);
   CHECK_EQUAL(kSymbolicSegmentExtendedFormatNumericSymbolUSINT, format);
 }
 
 TEST(CipEpath, GetPathSymbolicSegmentExtendedFormatUINT) {
-  const unsigned char message[] = {0x60, 0xC7};
+  const unsigned char message[] = { 0x60, 0xC7 };
   SymbolicSegmentExtendedFormat format =
-      GetPathSymbolicSegmentExtendedFormat(message);
+    GetPathSymbolicSegmentExtendedFormat(message);
   CHECK_EQUAL(kSymbolicSegmentExtendedFormatNumericSymbolUINT, format);
 }
 
 TEST(CipEpath, GetPathSymbolicSegmentExtendedFormatUDINT) {
-  const unsigned char message[] = {0x60, 0xC8};
+  const unsigned char message[] = { 0x60, 0xC8 };
   SymbolicSegmentExtendedFormat format =
-      GetPathSymbolicSegmentExtendedFormat(message);
+    GetPathSymbolicSegmentExtendedFormat(message);
   CHECK_EQUAL(kSymbolicSegmentExtendedFormatNumericSymbolUDINT, format);
 }
 
 TEST(CipEpath, GetPathSymbolicSegmentExtendedFormatNumericReserved) {
-  const unsigned char message[] = {0x60, 0xC9};
+  const unsigned char message[] = { 0x60, 0xC9 };
   SymbolicSegmentExtendedFormat format =
-      GetPathSymbolicSegmentExtendedFormat(message);
+    GetPathSymbolicSegmentExtendedFormat(message);
   CHECK_EQUAL(kSymbolicSegmentExtendedFormatReserved, format);
 }

+ 9 - 9
source/tests/cip/cipstringtests.cpp

@@ -15,7 +15,7 @@ extern "C" {
 #include "cipstring.h"
 }
 
-TEST_GROUP(CipString){void setup(){mock().disable();
+TEST_GROUP(CipString){ void setup(){ mock().disable();
 }
 }
 ;
@@ -54,7 +54,7 @@ TEST(CipString, FreeCipStringNWithContent) {
 };
 
 TEST(CipString, CreateStringNFromData) {
-  const CipOctet data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
+  const CipOctet data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
   CipStringN* string;
   string = (CipStringN*)CipCalloc(1, sizeof(CipStringN));
   SetCipStringNByData(string, 4, 3, data);
@@ -65,7 +65,7 @@ TEST(CipString, CreateStringNFromData) {
 }
 
 TEST(CipString, CreateStringNFromCString) {
-  const char data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0};
+  const char data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0 };
   CipStringN* string;
   string = (CipStringN*)CipCalloc(1, sizeof(CipStringN));
   SetCipStringNByCstr(string, data, 3);
@@ -107,7 +107,7 @@ TEST(CipString, FreeCipString2WithContent) {
 };
 
 TEST(CipString, CreateString2FromData) {
-  const CipOctet data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
+  const CipOctet data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
   CipString2* string;
   string = (CipString2*)CipCalloc(1, sizeof(CipString2));
   SetCipString2ByData(string, 6, data);
@@ -117,7 +117,7 @@ TEST(CipString, CreateString2FromData) {
 }
 
 TEST(CipString, CreateString2FromCString) {
-  const char data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0};
+  const char data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0 };
   CipString2* string;
   string = (CipString2*)CipCalloc(1, sizeof(CipString2));
   SetCipString2ByCstr(string, data);
@@ -158,7 +158,7 @@ TEST(CipString, FreeCipStringWithContent) {
 };
 
 TEST(CipString, CreateStringFromData) {
-  const CipOctet data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
+  const CipOctet data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
   CipString* string;
   string = (CipString*)CipCalloc(1, sizeof(CipString));
   SetCipStringByData(string, sizeof(data), data);
@@ -168,7 +168,7 @@ TEST(CipString, CreateStringFromData) {
 }
 
 TEST(CipString, CreateStringFromCString) {
-  const char data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0};
+  const char data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0 };
   CipString* string;
   string = (CipString*)CipCalloc(1, sizeof(CipString));
   SetCipStringByCstr(string, data);
@@ -209,7 +209,7 @@ TEST(CipString, FreeCipShortStringWithContent) {
 };
 
 TEST(CipString, CreateShortStringFromData) {
-  const CipOctet data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
+  const CipOctet data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
   CipShortString* string;
   string = (CipShortString*)CipCalloc(1, sizeof(CipShortString));
   SetCipShortStringByData(string, sizeof(data), data);
@@ -219,7 +219,7 @@ TEST(CipString, CreateShortStringFromData) {
 }
 
 TEST(CipString, CreateShortStringFromCString) {
-  const char data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0};
+  const char data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0 };
   CipShortString* string;
   string = (CipShortString*)CipCalloc(1, sizeof(CipShortString));
   SetCipShortStringByCstr(string, data);

+ 28 - 28
source/tests/enet_encap/encaptest.cpp

@@ -21,41 +21,41 @@ TEST_GROUP(EncapsulationProtocol){
 
 TEST(EncapsulationProtocol, AnswerListIdentityRequest) {
   CipOctet incoming_message[] =
-      "\x63\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd7\xdd\x00\x00"
-      "\x00\x00\x00\x00\x00\x00\x00\x00";
+    "\x63\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd7\xdd\x00\x00"
+    "\x00\x00\x00\x00\x00\x00\x00\x00";
 
   CipOctet expected_outgoing_message[] =
-      "\x63\x00\x31\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd7\xdd\x00\x00"
-      "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x0c\x00\x2b\x00\x01\x00"
-      "\x00\x02\xaf\x12\xc0\xa8\x38\x65\x00\x00\x00\x00\x00\x00\x00\x00"
-      "\x01\x00\x0c\x00\xe9\xfd\x02\x01\x00\x00\x15\xcd\x5b\x07\x09\x4f"
-      "\x70\x45\x4e\x65\x72\x20\x50\x43\xff";
+    "\x63\x00\x31\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd7\xdd\x00\x00"
+    "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x0c\x00\x2b\x00\x01\x00"
+    "\x00\x02\xaf\x12\xc0\xa8\x38\x65\x00\x00\x00\x00\x00\x00\x00\x00"
+    "\x01\x00\x0c\x00\xe9\xfd\x02\x01\x00\x00\x15\xcd\x5b\x07\x09\x4f"
+    "\x70\x45\x4e\x65\x72\x20\x50\x43\xff";
 
   ENIPMessage outgoing_message;
   InitializeENIPMessage(&outgoing_message);
 
   EncapsulationData receive_data;
   CreateEncapsulationStructure(
-      incoming_message, sizeof(incoming_message), &receive_data);
+    incoming_message, sizeof(incoming_message), &receive_data);
 
   EncapsulateListIdentityResponseMessage(&receive_data, &outgoing_message);
 }
 
 TEST(EncapsulationProtocol, AnswerListServicesRequest) {
   CipOctet incoming_message[] =
-      "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe0\xdd\x00\x00"
-      "\x00\x00\x00\x00\x00\x00\x00\x00";
+    "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe0\xdd\x00\x00"
+    "\x00\x00\x00\x00\x00\x00\x00\x00";
 
   CipOctet expected_outgoing_message[] =
-      "\x04\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe0\xdd\x00\x00"
-      "\x00\x00\x00\x00\x00\x00\x00\x00";
+    "\x04\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe0\xdd\x00\x00"
+    "\x00\x00\x00\x00\x00\x00\x00\x00";
 
   ENIPMessage outgoing_message;
   InitializeENIPMessage(&outgoing_message);
 
-  EncapsulationData recieved_data = {0};
+  EncapsulationData recieved_data = { 0 };
   CreateEncapsulationStructure(
-      incoming_message, sizeof(incoming_message), &recieved_data);
+    incoming_message, sizeof(incoming_message), &recieved_data);
 
   HandleReceivedListServicesCommand(&recieved_data, &outgoing_message);
 }
@@ -68,48 +68,48 @@ TEST(EncapsulationProtocol, AnswerListInterfacesRequest) {
   ENIPMessage outgoing_message;
   InitializeENIPMessage(&outgoing_message);
 
-  EncapsulationData received_data = {0};
+  EncapsulationData received_data = { 0 };
   CreateEncapsulationStructure(
-      incoming_message, sizeof(incoming_message), &received_data);
+    incoming_message, sizeof(incoming_message), &received_data);
 
   HandleReceivedListInterfacesCommand(&received_data, &outgoing_message);
 }
 
 TEST(EncapsulationProtocol, AnswerRegisterSessionRequestWrongProtocolVersion) {
   CipOctet incoming_message[] =
-      "\x65\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x67\x88\x00\x00"
-      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
+    "\x65\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x67\x88\x00\x00"
+    "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
 
   CipOctet expected_outgoing_message[] = "";
 
   ENIPMessage outgoing_message;
   InitializeENIPMessage(&outgoing_message);
 
-  EncapsulationData received_data = {0};
+  EncapsulationData received_data = { 0 };
   CreateEncapsulationStructure(
-      incoming_message, sizeof(incoming_message), &received_data);
+    incoming_message, sizeof(incoming_message), &received_data);
 
   HandleReceivedRegisterSessionCommand(0, &received_data, &outgoing_message);
 }
 
 TEST(EncapsulationProtocol, SendRRData) {
   CipOctet incoming_message[] =
-      "\x6f\x00\x0c\x00\x01\x00\x00\x00\x00\x00\x00\x00\xf0\xdd\x00\x00"
-      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00"
-      "\x01\x00\x00\x00";
+    "\x6f\x00\x0c\x00\x01\x00\x00\x00\x00\x00\x00\x00\xf0\xdd\x00\x00"
+    "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00"
+    "\x01\x00\x00\x00";
 
   CipOctet expected_outgoing_message[] = "";
 
-  ENIPMessage outgoing_message = {0};
+  ENIPMessage outgoing_message = { 0 };
   InitializeENIPMessage(&outgoing_message);
 
-  EncapsulationData received_data = {0};
+  EncapsulationData received_data = { 0 };
   CreateEncapsulationStructure(
-      incoming_message, sizeof(incoming_message), &received_data);
+    incoming_message, sizeof(incoming_message), &received_data);
 
-  struct sockaddr_in fake_originator       = {0};
+  struct sockaddr_in fake_originator       = { 0 };
   struct sockaddr* fake_originator_pointer = (struct sockaddr*)&fake_originator;
 
   HandleReceivedSendRequestResponseDataCommand(
-      &received_data, fake_originator_pointer, &outgoing_message);
+    &received_data, fake_originator_pointer, &outgoing_message);
 }

+ 10 - 10
source/tests/enet_encap/endianconvtest.cpp

@@ -22,7 +22,7 @@ TEST_GROUP(EndianConversion){
 };
 
 TEST(EndianConversion, GetSintFromMessage) {
-  const CipOctet test_message[]   = {8};
+  const CipOctet test_message[]   = { 8 };
   const CipOctet* message_pointer = test_message;
   const CipOctet** const message  = &message_pointer;
   CipSint returned_value          = GetSintFromMessage(message);
@@ -32,7 +32,7 @@ TEST(EndianConversion, GetSintFromMessage) {
 }
 
 TEST(EndianConversion, GetUsintFromMessage) {
-  const CipOctet test_message[]   = {8};
+  const CipOctet test_message[]   = { 8 };
   const CipOctet* message_pointer = test_message;
   const CipOctet** const message  = &message_pointer;
   CipUsint returned_value         = GetUsintFromMessage(message);
@@ -42,7 +42,7 @@ TEST(EndianConversion, GetUsintFromMessage) {
 }
 
 TEST(EndianConversion, GetByteFromMessage) {
-  const CipOctet test_message[]   = {8};
+  const CipOctet test_message[]   = { 8 };
   const CipOctet* message_pointer = test_message;
   const CipOctet** const message  = &message_pointer;
   CipByte returned_value          = GetByteFromMessage(message);
@@ -52,7 +52,7 @@ TEST(EndianConversion, GetByteFromMessage) {
 }
 
 TEST(EndianConversion, GetIntFromMessage) {
-  const CipOctet test_message[]   = {8, 60};
+  const CipOctet test_message[]   = { 8, 60 };
   const CipOctet* message_pointer = test_message;
   const CipOctet** const message  = &message_pointer;
   CipInt returned_value           = GetIntFromMessage(message);
@@ -62,7 +62,7 @@ TEST(EndianConversion, GetIntFromMessage) {
 }
 
 TEST(EndianConversion, GetUintFromMessage) {
-  const CipOctet test_message[]   = {8, 60};
+  const CipOctet test_message[]   = { 8, 60 };
   const CipOctet* message_pointer = test_message;
   const CipOctet** const message  = &message_pointer;
   CipUint returned_value          = GetUintFromMessage(message);
@@ -72,7 +72,7 @@ TEST(EndianConversion, GetUintFromMessage) {
 }
 
 TEST(EndianConversion, GetWordFromMessage) {
-  const CipOctet test_message[]   = {8, 60};
+  const CipOctet test_message[]   = { 8, 60 };
   const CipOctet* message_pointer = test_message;
   const CipOctet** const message  = &message_pointer;
   CipWord returned_value          = GetWordFromMessage(message);
@@ -82,7 +82,7 @@ TEST(EndianConversion, GetWordFromMessage) {
 }
 
 TEST(EndianConversion, GetDintFromMessage) {
-  const CipOctet test_message[]   = {28, 53, 41, 37};
+  const CipOctet test_message[]   = { 28, 53, 41, 37 };
   const CipOctet* message_pointer = test_message;
   const CipOctet** const message  = &message_pointer;
   CipDint returned_value          = GetDintFromMessage(message);
@@ -92,7 +92,7 @@ TEST(EndianConversion, GetDintFromMessage) {
 }
 
 TEST(EndianConversion, GetUdintFromMessage) {
-  const CipOctet test_message[]   = {28, 53, 41, 37};
+  const CipOctet test_message[]   = { 28, 53, 41, 37 };
   const CipOctet* message_pointer = test_message;
   const CipOctet** const message  = &message_pointer;
   CipUdint returned_value         = GetUdintFromMessage(message);
@@ -102,7 +102,7 @@ TEST(EndianConversion, GetUdintFromMessage) {
 }
 
 TEST(EndianConversion, GetDwordFromMessage) {
-  const CipOctet test_message[]   = {28, 53, 41, 37};
+  const CipOctet test_message[]   = { 28, 53, 41, 37 };
   const CipOctet* message_pointer = test_message;
   const CipOctet** const message  = &message_pointer;
   CipDword returned_value         = GetDwordFromMessage(message);
@@ -112,7 +112,7 @@ TEST(EndianConversion, GetDwordFromMessage) {
 }
 
 TEST(EndianConversion, GetLintFromMessage) {
-  const CipOctet test_message[]   = {81, 126, 166, 15, 70, 97, 208, 236};
+  const CipOctet test_message[]   = { 81, 126, 166, 15, 70, 97, 208, 236 };
   const CipOctet* message_pointer = test_message;
   const CipOctet** const message  = &message_pointer;
   EipUint64 returned_value        = GetLintFromMessage(message);

+ 3 - 3
source/tests/ports/socket_timer_tests.cpp

@@ -30,19 +30,19 @@ TEST(SocketTimer, NoEmptySocketTimerAvailable) {
 }
 
 TEST(SocketTimer, SetSocket) {
-  SocketTimer timer = {socket : -1, last_update : 0};
+  SocketTimer timer = { socket : -1, last_update : 0 };
   SocketTimerSetSocket(&timer, 1);
   CHECK_EQUAL(1, timer.socket);
 }
 
 TEST(SocketTimer, UpdateSocketTimer) {
-  SocketTimer timer = {socket : -1, last_update : 0};
+  SocketTimer timer = { socket : -1, last_update : 0 };
   SocketTimerSetLastUpdate(&timer, 10);
   CHECK_EQUAL(10, SocketTimerGetLastUpdate(&timer));
 }
 
 TEST(SocketTimer, ClearSocketTimer) {
-  SocketTimer timer = {socket : 5, last_update : 100};
+  SocketTimer timer = { socket : 5, last_update : 100 };
   SocketTimerClear(&timer);
   CHECK_EQUAL(-1, timer.socket);
   CHECK_EQUAL(0, timer.last_update);

+ 5 - 5
source/tests/utils/doublylinkedlistTests.cpp

@@ -18,7 +18,7 @@ TEST_GROUP(DoublyLinkedList){
 
 const size_t kNodesAmount = 5;
 
-static DoublyLinkedListNode nodes[kNodesAmount] = {0};
+static DoublyLinkedListNode nodes[kNodesAmount] = { 0 };
 
 DoublyLinkedListNode* CallocAllocator() {
   return (DoublyLinkedListNode*)calloc(1, sizeof(DoublyLinkedListNode));
@@ -49,7 +49,7 @@ void ArrayFree(DoublyLinkedListNode** node) {
 TEST(DoublyLinkedList, CallocAllocatorCreateTest) {
   int test_data = 8;
   DoublyLinkedListNode* node =
-      DoublyLinkedListNodeCreate(&test_data, CallocAllocator);
+    DoublyLinkedListNodeCreate(&test_data, CallocAllocator);
   CHECK_EQUAL(test_data, *((int*)node->data));
   CallocDeallocator(&node);
 }
@@ -57,7 +57,7 @@ TEST(DoublyLinkedList, CallocAllocatorCreateTest) {
 TEST(DoublyLinkedList, CallocFreeTest) {
   int test_data = 8;
   DoublyLinkedListNode* node =
-      DoublyLinkedListNodeCreate(&test_data, CallocAllocator);
+    DoublyLinkedListNodeCreate(&test_data, CallocAllocator);
   CallocDeallocator(&node);
   POINTERS_EQUAL(NULL, node);
 }
@@ -65,7 +65,7 @@ TEST(DoublyLinkedList, CallocFreeTest) {
 TEST(DoublyLinkedList, ArrayAllocatorCreateTest) {
   int test_data = 8;
   DoublyLinkedListNode* node =
-      DoublyLinkedListNodeCreate(&test_data, ArrayAllocator);
+    DoublyLinkedListNodeCreate(&test_data, ArrayAllocator);
   CHECK_EQUAL(test_data, *((int*)node->data));
   ArrayFree(&node);
 }
@@ -73,7 +73,7 @@ TEST(DoublyLinkedList, ArrayAllocatorCreateTest) {
 TEST(DoublyLinkedList, ArrayAllocatorDeleteTest) {
   int test_data = 8;
   DoublyLinkedListNode* node =
-      DoublyLinkedListNodeCreate(&test_data, ArrayAllocator);
+    DoublyLinkedListNodeCreate(&test_data, ArrayAllocator);
   DoublyLinkedListNode* assigned_array_slot = node;
   ArrayFree(&node);
   CHECK_EQUAL(8, test_data);

Some files were not shown because too many files changed in this diff