CapXilinx 9 жил өмнө
parent
commit
425671f0df

+ 7 - 11
source/src/cip/appcontype.c

@@ -88,8 +88,7 @@ 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 config_assembly) {
   if (OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS > connection_number) {
     g_exlusive_owner_connections[connection_number].output_assembly =
       output_assembly;
@@ -103,8 +102,7 @@ void ConfigureExclusiveOwnerConnectionPoint(
 void ConfigureInputOnlyConnectionPoint(const unsigned int connection_number,
                                        const unsigned int output_assembly,
                                        const unsigned int input_assembly,
-                                       const unsigned int config_assembly)
-{
+                                       const unsigned int config_assembly) {
   if (OPENER_CIP_NUM_INPUT_ONLY_CONNS > connection_number) {
     g_input_only_connections[connection_number].output_assembly =
       output_assembly;
@@ -117,8 +115,7 @@ void ConfigureInputOnlyConnectionPoint(const unsigned int connection_number,
 void ConfigureListenOnlyConnectionPoint(const unsigned int connection_number,
                                         const unsigned int output_assembly,
                                         const unsigned int input_assembly,
-                                        const unsigned int config_assembly)
-{
+                                        const unsigned int config_assembly) {
   if (OPENER_CIP_NUM_LISTEN_ONLY_CONNS > connection_number) {
     g_listen_only_connections[connection_number].output_assembly =
       output_assembly;
@@ -203,8 +200,7 @@ ConnectionObject *GetExclusiveOwnerConnection(
 
 ConnectionObject *GetInputOnlyConnection(
   const ConnectionObject *const restrict connection_object,
-  EipUint16 *const extended_error)
-{
+  EipUint16 *const extended_error) {
   ConnectionObject *input_only_connection = NULL; //TODO: This variable has no use
 
   for (int i = 0; i < OPENER_CIP_NUM_INPUT_ONLY_CONNS; i++) {
@@ -239,8 +235,7 @@ ConnectionObject *GetInputOnlyConnection(
 
 ConnectionObject *GetListenOnlyConnection(
   const ConnectionObject *const restrict connection_object,
-  EipUint16 *const extended_error)
-{
+  EipUint16 *const extended_error) {
   ConnectionObject *listen_only_connection = NULL; //TODO: This variable has no use
 
   if ( kForwardOpenConnectionTypeMulticastConnection
@@ -404,7 +399,8 @@ EipBool8 ConnectionWithSameConfigPointExists(const EipUint32 config_point) {
 
 void InitializeIoConnectionData(void) {
   memset( g_exlusive_owner_connections, 0,
-          OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS * sizeof(ExclusiveOwnerConnection) );
+          OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS *
+          sizeof(ExclusiveOwnerConnection) );
   memset( g_input_only_connections, 0,
           OPENER_CIP_NUM_INPUT_ONLY_CONNS * sizeof(InputOnlyConnection) );
   memset( g_listen_only_connections, 0,

+ 4 - 2
source/src/cip/appcontype.h

@@ -24,7 +24,8 @@ void InitializeIoConnectionData(void);
  *        - on error: NULL
  */
 ConnectionObject *GetIoConnectionForConnectionData(
-    ConnectionObject *const restrict connection_object, EipUint16 *const extended_error);
+  ConnectionObject *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.
@@ -32,7 +33,8 @@ ConnectionObject *GetIoConnectionForConnectionData(
  *  @param input_point the Input point to be produced
  *  @return if a connection could be found a pointer to this connection if not NULL
  */
-ConnectionObject *GetExistingProducerMulticastConnection(const EipUint32 input_point);
+ConnectionObject *GetExistingProducerMulticastConnection(
+  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 charge

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

@@ -16,8 +16,9 @@ ConnectionObject *GetFreeExplicitConnection(void);
 ConnectionObject g_explicit_connections[OPENER_CIP_NUM_EXPLICIT_CONNS];
 
 /**** Implementation ****/
-EipStatus EstablishClass3Connection(ConnectionObject *restrict const connection_object,
-                              EipUint16 *const extended_error) {
+EipStatus EstablishClass3Connection(
+  ConnectionObject *restrict const connection_object,
+  EipUint16 *const extended_error) {
   EipStatus eip_status = kEipStatusOk;
 
   /*TODO add check for transport type trigger */
@@ -28,22 +29,24 @@ EipStatus EstablishClass3Connection(ConnectionObject *restrict const connection_
   if (NULL == explicit_connection) {
     eip_status = kCipErrorConnectionFailure;
     *extended_error =
-        kConnectionManagerExtendedStatusCodeErrorNoMoreConnectionsAvailable;
+      kConnectionManagerExtendedStatusCodeErrorNoMoreConnectionsAvailable;
   } else {
     CopyConnectionData(explicit_connection, connection_object);
 
-    EipUint32 produced_connection_id_buffer = explicit_connection->cip_produced_connection_id;
+    EipUint32 produced_connection_id_buffer =
+      explicit_connection->cip_produced_connection_id;
     GeneralConnectionConfiguration(explicit_connection);
-    explicit_connection->cip_produced_connection_id = produced_connection_id_buffer;
+    explicit_connection->cip_produced_connection_id =
+      produced_connection_id_buffer;
     explicit_connection->instance_type = kConnectionTypeExplicit;
     explicit_connection->socket[0] = explicit_connection->socket[1] =
-        kEipInvalidSocket;
+                                       kEipInvalidSocket;
     /* set the connection call backs */
     explicit_connection->connection_close_function =
-        RemoveFromActiveConnections;
+      RemoveFromActiveConnections;
     /* explicit connection have to be closed on time out*/
     explicit_connection->connection_timeout_function =
-        RemoveFromActiveConnections;
+      RemoveFromActiveConnections;
 
     AddNewActiveConnection(explicit_connection);
   }
@@ -56,13 +59,14 @@ EipStatus EstablishClass3Connection(ConnectionObject *restrict const connection_
  */
 ConnectionObject *GetFreeExplicitConnection(void) {
   for (int i = 0; i < OPENER_CIP_NUM_EXPLICIT_CONNS; i++) {
-    if (g_explicit_connections[i].state == kConnectionStateNonExistent)
+    if (g_explicit_connections[i].state == kConnectionStateNonExistent) {
       return &(g_explicit_connections[i]);
+    }
   }
   return NULL;
 }
 
 void InitializeClass3ConnectionData(void) {
-  memset(g_explicit_connections, 0,
-  OPENER_CIP_NUM_EXPLICIT_CONNS * sizeof(ConnectionObject));
+  memset( g_explicit_connections, 0,
+          OPENER_CIP_NUM_EXPLICIT_CONNS * sizeof(ConnectionObject) );
 }

+ 3 - 2
source/src/cip/cipclass3connection.h

@@ -23,8 +23,9 @@
  *    - kEipStatusOk ... on success
  *    - On an error the general status code to be put into the response
  */
-EipStatus EstablishClass3Connection(ConnectionObject *restrict const connection_object,
-                              EipUint16 *const extended_error);
+EipStatus EstablishClass3Connection(
+  ConnectionObject *restrict const connection_object,
+  EipUint16 *const extended_error);
 
 /** @brief Initializes the explicit connections mechanism
  *

+ 50 - 73
source/src/cip/cipconnectionmanager.c

@@ -67,8 +67,7 @@ ProductionTrigger GetProductionTrigger(
 }
 
 void SetProductionTrigger(const enum ProductionTrigger production_trigger,
-                          ConnectionObject *connection_object)
-{
+                          ConnectionObject *connection_object) {
   switch (production_trigger) {
     case kProductionTriggerCyclic:
       connection_object->transport_type_class_trigger = 0x0;
@@ -80,7 +79,7 @@ void SetProductionTrigger(const enum ProductionTrigger production_trigger,
       connection_object->transport_type_class_trigger = 0x20;
       break;
     default:
-    	//TODO: Replace with assert?
+      //TODO: Replace with assert?
       connection_object->transport_type_class_trigger = 0x30;
       break;           /**< Invalid value */
   }
@@ -92,8 +91,7 @@ CipUint GetProductionInhibitTime(
 }
 
 void SetProductionInhibitTime(const EipUint16 production_inhibit_time,
-                              ConnectionObject *const connection_object)
-{
+                              ConnectionObject *const connection_object) {
   connection_object->production_inhibit_time = production_inhibit_time;
 }
 
@@ -135,11 +133,8 @@ EipStatus GetConnectionOwner(CipInstance *instance,
                              CipMessageRouterResponse *message_router_response);
 
 EipStatus AssembleForwardOpenResponse(
-  ConnectionObject *connection_object,
-  CipMessageRouterResponse *
-  message_router_response,
-  EipUint8 general_status,
-  EipUint16 extended_status);
+  ConnectionObject *connection_object,CipMessageRouterResponse *
+  message_router_response,EipUint8 general_status,EipUint16 extended_status);
 
 EipStatus AssembleForwardCloseResponse(
   EipUint16 connection_serial_number,
@@ -266,8 +261,7 @@ EipStatus ConnectionManagerInit(EipUint16 unique_connection_id) {
 
 EipStatus HandleReceivedConnectedData(EipUint8 *data,
                                       int data_length,
-                                      struct sockaddr_in *from_address)
-{
+                                      struct sockaddr_in *from_address) {
 
   if ( ( CreateCommonPacketFormatStructure(data, data_length,
                                            &g_common_packet_format_data_item) )
@@ -302,8 +296,8 @@ EipStatus HandleReceivedConnectedData(EipUint8 *data,
             connection_object->inactivity_watchdog_timer =
               (connection_object->o_to_t_requested_packet_interval
                / 1000)
-              << (2
-                  + connection_object->connection_timeout_multiplier);
+                << (2
+                    + connection_object->connection_timeout_multiplier);
 
             /* only inform assembly object if the sequence counter is greater or equal */
             connection_object->eip_level_sequence_count_consuming =
@@ -313,9 +307,9 @@ EipStatus HandleReceivedConnectedData(EipUint8 *data,
             if (NULL
                 != connection_object->connection_receive_data_function) {
               return connection_object->connection_receive_data_function(
-                       connection_object,
-                       g_common_packet_format_data_item.data_item.data,
-                       g_common_packet_format_data_item.data_item.length);
+                connection_object,
+                g_common_packet_format_data_item.data_item.data,
+                g_common_packet_format_data_item.data_item.length);
             }
           }
         } else {
@@ -334,8 +328,7 @@ void ReadOutConnectionObjectFromMessage(
 
 void ReadOutConnectionObjectFromMessage(
   CipMessageRouterRequest *const message_router_request,
-  ConnectionObject *const connection_object)
-{
+  ConnectionObject *const connection_object) {
   connection_object->priority_timetick = *message_router_request->data++;
   connection_object->timeout_ticks = *message_router_request->data++;
   /* O_to_T Conn ID */
@@ -410,8 +403,7 @@ ForwardOpenConnectionType GetConnectionType(
  *
  */
 typedef EipStatus (*HandleForwardOpenRequestFunction)(
-  ConnectionObject *connection_object,
-  CipInstance *instance,
+  ConnectionObject *connection_object,CipInstance *instance,
   CipMessageRouterRequest *message_router_request,
   CipMessageRouterResponse *message_router_response);
 
@@ -431,14 +423,13 @@ EipStatus HandleNullNonMatchingForwardOpenRequest(
   ConnectionObject *connection_object,
   CipInstance *instance,
   CipMessageRouterRequest *message_router_request,
-  CipMessageRouterResponse *message_router_response)
-{
+  CipMessageRouterResponse *message_router_response) {
   OPENER_TRACE_INFO("Right now we cannot handle Null requests\n");
   return AssembleForwardOpenResponse(
-           connection_object,
-           message_router_response,
-           kCipErrorConnectionFailure,
-           kConnectionManagerExtendedStatusCodeNullForwardOpenNotSupported);
+    connection_object,
+    message_router_response,
+    kCipErrorConnectionFailure,
+    kConnectionManagerExtendedStatusCodeNullForwardOpenNotSupported);
 }
 
 /** @brief Handles a Null Matching Forward Open request
@@ -457,14 +448,13 @@ EipStatus HandleNullMatchingForwardOpenRequest(
   ConnectionObject *connection_object,
   CipInstance *instance,
   CipMessageRouterRequest *message_router_request,
-  CipMessageRouterResponse *message_router_response)
-{
+  CipMessageRouterResponse *message_router_response) {
   OPENER_TRACE_INFO("Right now we cannot handle Null requests\n");
   return AssembleForwardOpenResponse(
-           connection_object,
-           message_router_response,
-           kCipErrorConnectionFailure,
-           kConnectionManagerExtendedStatusCodeNullForwardOpenNotSupported);
+    connection_object,
+    message_router_response,
+    kCipErrorConnectionFailure,
+    kConnectionManagerExtendedStatusCodeNullForwardOpenNotSupported);
 }
 
 /** @brief Handles a Non Null Matching Forward Open Request
@@ -482,14 +472,13 @@ EipStatus HandleNonNullMatchingForwardOpenRequest(
   ConnectionObject *connection_object,
   CipInstance *instance,
   CipMessageRouterRequest *message_router_request,
-  CipMessageRouterResponse *message_router_response)
-{
+  CipMessageRouterResponse *message_router_response) {
   OPENER_TRACE_INFO("Right now we cannot handle reconfiguration requests\n");
   return AssembleForwardOpenResponse(
-           connection_object,
-           message_router_response,
-           kCipErrorConnectionFailure,
-           kConnectionManagerExtendedStatusCodeErrorConnectionInUseOrDuplicateForwardOpen);
+    connection_object,
+    message_router_response,
+    kCipErrorConnectionFailure,
+    kConnectionManagerExtendedStatusCodeErrorConnectionInUseOrDuplicateForwardOpen);
 }
 
 /** @brief Handles a Non Null Non Matching Forward Open Request
@@ -506,18 +495,17 @@ EipStatus HandleNonNullNonMatchingForwardOpenRequest(
   ConnectionObject *connection_object,
   CipInstance *instance,
   CipMessageRouterRequest *message_router_request,
-  CipMessageRouterResponse *message_router_response)
-{
+  CipMessageRouterResponse *message_router_response) {
 
   EipUint16 connection_status = kConnectionManagerExtendedStatusCodeSuccess;
 
   /*check if the trigger type value is ok */
   if (0x40 & g_dummy_connection_object.transport_type_class_trigger) {
     return AssembleForwardOpenResponse(
-             &g_dummy_connection_object,
-             message_router_response,
-             kCipErrorConnectionFailure,
-             kConnectionManagerExtendedStatusCodeErrorTransportClassAndTriggerCombinationNotSupported);
+      &g_dummy_connection_object,
+      message_router_response,
+      kCipErrorConnectionFailure,
+      kConnectionManagerExtendedStatusCodeErrorTransportClassAndTriggerCombinationNotSupported);
   }
 
   EipUint32 temp = ParseConnectionPath(&g_dummy_connection_object,
@@ -595,8 +583,7 @@ static const HandleForwardOpenRequestFunction
  */
 EipStatus ForwardOpen(CipInstance *instance,
                       CipMessageRouterRequest *message_router_request,
-                      CipMessageRouterResponse *message_router_response)
-{
+                      CipMessageRouterResponse *message_router_response) {
   (void) instance;       /*suppress compiler warning */
 
   uint8_t is_null_request = -1;       /* 1 = Null Request, 0 =  Non-Null Request  */
@@ -614,18 +601,18 @@ EipStatus ForwardOpen(CipInstance *instance,
   /* Check if both connection types are valid, otherwise send error response */
   if (kForwardOpenConnectionTypeReserved == o_to_t_connection_type) {
     return AssembleForwardOpenResponse(
-             &g_dummy_connection_object,
-             message_router_response,
-             kCipErrorConnectionFailure,
-             kConnectionManagerExtendedStatusCodeErrorInvalidOToTConnectionType);
+      &g_dummy_connection_object,
+      message_router_response,
+      kCipErrorConnectionFailure,
+      kConnectionManagerExtendedStatusCodeErrorInvalidOToTConnectionType);
   }
 
   if (kForwardOpenConnectionTypeReserved == t_to_o_connection_type) {
     return AssembleForwardOpenResponse(
-             &g_dummy_connection_object,
-             message_router_response,
-             kCipErrorConnectionFailure,
-             kConnectionManagerExtendedStatusCodeErrorInvalidTToOConnectionType);
+      &g_dummy_connection_object,
+      message_router_response,
+      kCipErrorConnectionFailure,
+      kConnectionManagerExtendedStatusCodeErrorInvalidTToOConnectionType);
   }
 
   /* Check if request is a Null request or a Non-Null request */
@@ -722,8 +709,7 @@ void GeneralConnectionConfiguration(ConnectionObject *connection_object) {
 
 EipStatus ForwardClose(CipInstance *instance,
                        CipMessageRouterRequest *message_router_request,
-                       CipMessageRouterResponse *message_router_response)
-{
+                       CipMessageRouterResponse *message_router_response) {
   /*Suppress compiler warning*/
   (void) instance;
 
@@ -871,12 +857,8 @@ EipStatus ManageConnections(MilliSeconds elapsed_time) {
  *   kEipStatusError .. error
  */
 EipStatus AssembleForwardOpenResponse(
-  ConnectionObject *connection_object,
-  CipMessageRouterResponse *
-  message_router_response,
-  EipUint8 general_status,
-  EipUint16 extended_status)
-{
+  ConnectionObject *connection_object,CipMessageRouterResponse *
+  message_router_response,EipUint8 general_status,EipUint16 extended_status) {
   /* write reply information in CPF struct dependent of pa_status */
   CipCommonPacketFormatData *cip_common_packet_format_data =
     &g_common_packet_format_data_item;
@@ -1013,8 +995,7 @@ EipStatus AssembleForwardCloseResponse(
   message_router_request,
   CipMessageRouterResponse *
   message_router_response,
-  EipUint16 extended_error_code)
-{
+  EipUint16 extended_error_code) {
   /* write reply information in CPF struct dependent of pa_status */
   CipCommonPacketFormatData *common_data_packet_format_data =
     &g_common_packet_format_data_item;
@@ -1113,8 +1094,7 @@ ConnectionObject *CheckForExistingConnection(
 
 EipStatus CheckElectronicKeyData(EipUint8 key_format,
                                  CipKeyData *key_data,
-                                 EipUint16 *extended_status)
-{
+                                 EipUint16 *extended_status) {
   EipByte compatiblity_mode = key_data->major_revision & 0x80;
 
   /* Remove compatibility bit */
@@ -1187,8 +1167,7 @@ EipStatus CheckElectronicKeyData(EipUint8 key_format,
 
 EipUint8 ParseConnectionPath(ConnectionObject *connection_object,
                              CipMessageRouterRequest *message_router_request,
-                             EipUint16 *extended_error)
-{
+                             EipUint16 *extended_error) {
   const EipUint8 *message = message_router_request->data;
   unsigned int remaining_path_size = connection_object->connection_path_size =
                                        *message++; /* length in words */
@@ -1511,8 +1490,7 @@ void CloseConnection(ConnectionObject *restrict connection_object) {
 }
 
 void CopyConnectionData(ConnectionObject *restrict destination,
-                        const ConnectionObject *restrict const source)
-{
+                        const ConnectionObject *restrict const source) {
   memcpy( destination, source, sizeof(ConnectionObject) );
 }
 
@@ -1592,8 +1570,7 @@ GetConnectionManagementEntry(EipUint32 class_id) {
 }
 
 EipStatus TriggerConnections(unsigned int output_assembly,
-                             unsigned int input_assembly)
-{
+                             unsigned int input_assembly) {
   EipStatus status = kEipStatusError;
 
   ConnectionObject *pstRunner = g_active_connection_list;

+ 94 - 62
source/src/cip/cipconnectionmanager.h

@@ -39,11 +39,15 @@ typedef enum {
 /** @brief Connection Manager Error codes */
 typedef enum {
   kConnectionManagerExtendedStatusCodeSuccess = 0x00, /**< Obsolete code, should be General Status - Everything is ok */
-  kConnectionManagerExtendedStatusCodeErrorConnectionInUseOrDuplicateForwardOpen = 0x0100, /**< General Status has to be 0x01, Connection is already in use, or a duplicate Forward Open was received */
-  kConnectionManagerExtendedStatusCodeErrorTransportClassAndTriggerCombinationNotSupported = 0x0103, /**< General Status has to be 0x01, A Transport class and trigger combination has been specified, which is not supported by the target application */
+  kConnectionManagerExtendedStatusCodeErrorConnectionInUseOrDuplicateForwardOpen
+    = 0x0100,                                                                              /**< General Status has to be 0x01, Connection is already in use, or a duplicate Forward Open was received */
+  kConnectionManagerExtendedStatusCodeErrorTransportClassAndTriggerCombinationNotSupported
+    = 0x0103,                                                                                        /**< General Status has to be 0x01, A Transport class and trigger combination has been specified, which is not supported by the target application */
   kConnectionManagerExtendedStatusCodeErrorOwnershipConflict = 0x0106, /**< General Status has to be 0x01, Another connection has already reserved some needed resources */
-  kConnectionManagerExtendedStatusCodeErrorConnectionTargetConnectionNotFound = 0x0107, /**< General Status has to be 0x01, Forward Close error message, if connection to be closed is not found at the target */
-  kConnectionManagerExtendedStatusCodeErrorTargetForConnectionNotConfigured = 0x0110, /**< General Status has to be 0x01, Target application not configured and connection request does not contain data segment for configuration */
+  kConnectionManagerExtendedStatusCodeErrorConnectionTargetConnectionNotFound =
+    0x0107,                                                                             /**< General Status has to be 0x01, Forward Close error message, if connection to be closed is not found at the target */
+  kConnectionManagerExtendedStatusCodeErrorTargetForConnectionNotConfigured =
+    0x0110,                                                                           /**< General Status has to be 0x01, Target application not configured and connection request does not contain data segment for configuration */
   kConnectionManagerExtendedStatusCodeErrorRpiValuesNotAcceptable = 0x0112, /**< 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 = 0x0113, /**< General Status has to be 0x01, No free connection slots available */
   kConnectionManagerExtendedStatusCodeErrorVendorIdOrProductcodeError = 0x0114, /**< 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. */
@@ -51,21 +55,28 @@ typedef enum {
   kConnectionManagerExtendedStatusCodeErrorRevisionMismatch = 0x0116, /**< 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 = 0x0119, /**< General Status has to be 0x01, listen-only connection cannot be established, if no non-listen only connections are established  */
   kConnectionManagerExtendedStatusCodeTargetObjectOutOfConnections = 0x011A, /**< Maximum number of connections supported by the instance of the target object exceeded */
-  kConnectionManagerExtendedStatusCodeProductionInhibitTimerGreaterThanRpi = 0x011B, /**< The Production Inhibit Time is greater than the Target to Originator RPI */
+  kConnectionManagerExtendedStatusCodeProductionInhibitTimerGreaterThanRpi =
+    0x011B,                                                                          /**< The Production Inhibit Time is greater than the Target to Originator RPI */
   kConnectionManagerExtendedStatusCodeTransportClassNotSupported = 0x011C, /**< The transport class requested in the Transport Type/Trigger parameter is not supported. */
   kConnectionManagerExtendedStatusCodeProductionTriggerNotSuppoerted = 0x011D, /**< The production trigger requested in the Transport Type/Trigger parameter is not supported. */
   kConnectionManagerExtendedStatusCodeDirectionNotSupported = 0x011E, /**< The direction requested in the Transport Type/Trigger parameter is not supported */
-  kConnectionManagerExtendedStatusCodeInvalidOToTNetworkConnectionFixVar = 0x011F, /**< Shall be returned as the result of specifying an O->T fixed / variable flag that is not supported. */
-  kConnectionManagerExtendedStatusCodeInvalidTToONetworkConnectionFixVar = 0x0120, /**< Shall be returned as the result of specifying an T->O fixed / variable flag that is not supported. */
-  kConnectionManagerExtendedStatusCodeInvalidOToTNetworkConnectionPriority = 0x0121, /**< Shall be returned as the result of specifying an O->T priority code that is not supported. */
-  kConnectionManagerExtendedStatusCodeInvalidTToONetworkConnectionPriority = 0x0122, /**< Shall be returned as the result of specifying an T->O priority code that is not supported. */
+  kConnectionManagerExtendedStatusCodeInvalidOToTNetworkConnectionFixVar =
+    0x011F,                                                                        /**< Shall be returned as the result of specifying an O->T fixed / variable flag that is not supported. */
+  kConnectionManagerExtendedStatusCodeInvalidTToONetworkConnectionFixVar =
+    0x0120,                                                                        /**< Shall be returned as the result of specifying an T->O fixed / variable flag that is not supported. */
+  kConnectionManagerExtendedStatusCodeInvalidOToTNetworkConnectionPriority =
+    0x0121,                                                                          /**< Shall be returned as the result of specifying an O->T priority code that is not supported. */
+  kConnectionManagerExtendedStatusCodeInvalidTToONetworkConnectionPriority =
+    0x0122,                                                                          /**< Shall be returned as the result of specifying an T->O priority code that is not supported. */
   kConnectionManagerExtendedStatusCodeErrorInvalidOToTConnectionType = 0x0123, /**< Shall be returned as the result of specifying an O->T connection type that is not supported */
   kConnectionManagerExtendedStatusCodeErrorInvalidTToOConnectionType = 0x0124, /**< Shall be returned as the result of specifying a T->O connection type that is not supported */
-  kConnectionManagerExtendedStatusCodeInvalidOToTNetworkConnectionRedundantOwner = 0x0125, /**< Shall be returned as the result of specifying an O->T Redundant Owner flag that is not supported. */
+  kConnectionManagerExtendedStatusCodeInvalidOToTNetworkConnectionRedundantOwner
+    = 0x0125,                                                                              /**< Shall be returned as the result of specifying an O->T Redundant Owner flag that is not supported. */
   kConnectionManagerExtendedStatusCodeInvalidConfigurationSize = 0x0126, /**< 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 = 0x0127, /**< 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 = 0x0128, /**< 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 = 0x0129, /**< Configuration application path specified does not correspond to a valid configuration application path within the target application. This error could also be returned if a configuration application path was required, but not provided by a connection request. */
+  kConnectionManagerExtendedStatusCodeInvalidConfigurationApplicationPath =
+    0x0129,                                                                         /**< Configuration application path specified does not correspond to a valid configuration application path within the target application. This error could also be returned if a configuration application path was required, but not provided by a connection request. */
   kConnectionManagerExtendedStatusCodeInvalidConsumingApplicationPath = 0x012A, /**< 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 = 0x012B, /**< 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 = 0x012C,
@@ -75,36 +86,51 @@ typedef enum {
   kConnectionManagerExtendedStatusCodeInconsistentConsumeDataFormat = 0x0130,
   kConnectionManagerExtendedStatusCodeInconsistentProduceDataFormat = 0x0131,
   kConnectionManagerExtendedStatusCodeNullForwardOpenNotSupported = 0x0132,
-  kConnectionManagerExtendedStatusCodeConnectionTimeoutMultiplierNotAcceptable = 0x0133,
+  kConnectionManagerExtendedStatusCodeConnectionTimeoutMultiplierNotAcceptable =
+    0x0133,
   kConnectionManagerExtendedStatusCodeConnectionTimedOut = 0x0203,
   kConnectionManagerExtendedStatusCodeUnconnectedRequestTimedOut = 0x0204,
-  kConnectionManagerExtendedStatusCodeErrorParameterErrorInUnconnectedSendService = 0x0205, /**<  */
-  kConnectionManagerExtendedStatusCodeMessageToLargeForUnconnectedSendService = 0x0206,
-  kConnectionManagerExtendedStatusCodeUnconnectedAcknowledgeWithoutReply = 0x0207,
+  kConnectionManagerExtendedStatusCodeErrorParameterErrorInUnconnectedSendService
+    = 0x0205,                                                                               /**<  */
+  kConnectionManagerExtendedStatusCodeMessageToLargeForUnconnectedSendService =
+    0x0206,
+  kConnectionManagerExtendedStatusCodeUnconnectedAcknowledgeWithoutReply =
+    0x0207,
   kConnectionManagerExtendedStatusCodeNoBufferMemoryAvailable = 0x0301,
-  kConnectionManagerExtendedStatusCodeNetworkBandwithNotAvailableForData = 0x0302,
-  kConnectionManagerExtendedStatusCodeNoConsumedConnectionIdFilterAvailable = 0x0303,
-  kConnectionManagerExtendedStatusCodeNotConfiguredToSendScheduledPriorityData = 0x0304,
+  kConnectionManagerExtendedStatusCodeNetworkBandwithNotAvailableForData =
+    0x0302,
+  kConnectionManagerExtendedStatusCodeNoConsumedConnectionIdFilterAvailable =
+    0x0303,
+  kConnectionManagerExtendedStatusCodeNotConfiguredToSendScheduledPriorityData =
+    0x0304,
   kConnectionManagerExtendedStatusCodeScheduleSignatureMismatch = 0x0305,
-  kConnectionManagerExtendedStatusCodeScheduleSignatureValidationNotPossible = 0x0306,
+  kConnectionManagerExtendedStatusCodeScheduleSignatureValidationNotPossible =
+    0x0306,
   kConnectionManagerExtendedStatusCodePortNotAvailable = 0x0311,
   kConnectionManagerExtendedStatusCodeLinkAddressNotValid = 0x0312,
   kConnectionManagerExtendedStatusCodeErrorInvalidSegmentTypeInPath = 0x0315, /**<  */
-  kConnectionManagerExtendedStatusCodeForwardCloseServiceConnectionPathMismatch = 0x0316,
+  kConnectionManagerExtendedStatusCodeForwardCloseServiceConnectionPathMismatch
+    = 0x0316,
   kConnectionManagerExtendedStatusCodeSchedulingNotSpecified = 0x0317,
   kConnectionManagerExtendedStatusCodeLinkAddressToSelfInvalid = 0x0318,
   kConnectionManagerExtendedStatusCodeSecondaryResourcesUnavailable = 0x0319,
   kConnectionManagerExtendedStatusCodeRackConnectionAlreadyEstablished = 0x031A,
-  kConnectionManagerExtendedStatusCodeModuleConnectionAlreadyEstablished = 0x031B,
+  kConnectionManagerExtendedStatusCodeModuleConnectionAlreadyEstablished =
+    0x031B,
   kConnectionManagerExtendedStatusCodeMiscellaneous = 0x031C,
   kConnectionManagerExtendedStatusCodeRedundantConnectionMismatch = 0x031D,
-  kConnectionManagerExtendedStatusCodeNoMoreUserConfigurableLinkConsumerResourcesAvailableInTheProducingModule = 0x031E,
-  kConnectionManagerExtendedStatusCodeNoUserConfigurableLinkConsumerResourcesConfiguredInTheProducingModule = 0x031F,
+  kConnectionManagerExtendedStatusCodeNoMoreUserConfigurableLinkConsumerResourcesAvailableInTheProducingModule
+    = 0x031E,
+  kConnectionManagerExtendedStatusCodeNoUserConfigurableLinkConsumerResourcesConfiguredInTheProducingModule
+    = 0x031F,
   kConnectionManagerExtendedStatusCodeNetworkLinkOffline = 0x0800,
   kConnectionManagerExtendedStatusCodeNoTargetApplicationDataAvailable = 0x0810,
-  kConnectionManagerExtendedStatusCodeNoOriginatorApplicationDataAvailable = 0x0811,
-  kConnectionManagerExtendedStatusCodeNodeAddressHasChangedSinceTheNetworkWasScheduled = 0x0812,
-  kConnectionManagerExtendedStatusCodeNotConfiguredForOffSubnetMulticast = 0x0813,
+  kConnectionManagerExtendedStatusCodeNoOriginatorApplicationDataAvailable =
+    0x0811,
+  kConnectionManagerExtendedStatusCodeNodeAddressHasChangedSinceTheNetworkWasScheduled
+    = 0x0812,
+  kConnectionManagerExtendedStatusCodeNotConfiguredForOffSubnetMulticast =
+    0x0813,
   kConnectionManagerExtendedStatusCodeInvalidProduceConsumeDataFormat = 0x0814
 } ConnectionManagerExtendedStatusCode;
 
@@ -122,15 +148,19 @@ typedef enum ProductionTrigger {
   kProductionTriggerApplicationObjectTriggered = 2
 } ProductionTrigger;
 
-ProductionTrigger GetProductionTrigger(const ConnectionObject const* connection_object);
+ProductionTrigger GetProductionTrigger(
+  const ConnectionObject const *connection_object);
 
-void SetProductionTrigger(const ProductionTrigger production_trigger, ConnectionObject *connection_object);
+void SetProductionTrigger(const ProductionTrigger production_trigger,
+                          ConnectionObject *connection_object);
 
-CipUint GetProductionInhibitTime(const ConnectionObject const* connection_object);
+CipUint GetProductionInhibitTime(const ConnectionObject const *connection_object);
 
-void SetProductionInhibitTime(const EipUint16 production_inhibit_time, ConnectionObject *const connection_object);
+void SetProductionInhibitTime(const EipUint16 production_inhibit_time,
+                              ConnectionObject *const connection_object);
 
-CipUdint GetTargetToOriginatorRequestedPackedInterval(const ConnectionObject const* connection_object);
+CipUdint GetTargetToOriginatorRequestedPackedInterval(
+  const ConnectionObject const *connection_object);
 
 /** @brief macros for comparing sequence numbers according to CIP spec vol
  * 2 3-4.2 for int type variables
@@ -139,17 +169,17 @@ CipUdint GetTargetToOriginatorRequestedPackedInterval(const ConnectionObject con
  *  b
  *  @define SEQ_GT32(a, b) Checks if sequence number a is greater than b
  */
-#define SEQ_LEQ32(a, b) ((int)((a) - (b)) <= 0)
-#define SEQ_GEQ32(a, b) ((int)((a) - (b)) >= 0)
-#define SEQ_GT32(a, b) ((int)((a) - (b)) > 0)
+#define SEQ_LEQ32(a, b) ( (int)( (a) - (b) ) <= 0 )
+#define SEQ_GEQ32(a, b) ( (int)( (a) - (b) ) >= 0 )
+#define SEQ_GT32(a, b) ( (int)( (a) - (b) ) > 0 )
 
 /** @brief similar macros for comparing 16 bit sequence numbers
  * @define SEQ_LEQ16(a, b) Checks if sequence number a is less or equal than b
  * @define SEQ_GEQ16(a, b) Checks if sequence number a is greater or equal than
  *  b
  */
-#define SEQ_LEQ16(a, b) ((short)((a) - (b)) <= 0)
-#define SEQ_GEQ16(a, b) ((short)((a) - (b)) >= 0)
+#define SEQ_LEQ16(a, b) ( (short)( (a) - (b) ) <= 0 )
+#define SEQ_GEQ16(a, b) ( (short)( (a) - (b) ) >= 0 )
 
 /** @brief States of a connection */
 typedef enum {
@@ -174,7 +204,7 @@ typedef enum {
 typedef enum {
   kWatchdogTimeoutActionTransitionToTimedOut = 0, /**< , invalid for explicit message connections */
   kWatchdogTimeoutActionAutoDelete = 1, /**< Default for explicit message connections,
-   default for I/O connections on EIP */
+                                           default for I/O connections on EIP */
   kWatchdogTimeoutActionAutoReset = 2, /**< Invalid for explicit message connections */
   kWatchdogTimeoutActionDeferredDelete = 3 /**< Only valid for DeviceNet, invalid for I/O connections */
 } WatchdogTimeoutAction;
@@ -183,7 +213,7 @@ typedef struct {
   ConnectionState state;
   EipUint16 connection_id;
 /*TODO think if this is needed anymore
- TCMReceiveDataFunc m_ptfuncReceiveData; */
+   TCMReceiveDataFunc m_ptfuncReceiveData; */
 } LinkConsumer;
 
 typedef struct {
@@ -206,10 +236,10 @@ typedef struct connection_object {
   ConnectionType instance_type; /**< Indicates either I/O or Messaging connection */
   EipByte transport_type_class_trigger;
   /* conditional
-  EipUint16 device_net_produced_connection_id;
-  EipUint16 device_net_consumed_connection_id;
-  EipByte device_net_initial_comm_characteristcs;
-  */
+     EipUint16 device_net_produced_connection_id;
+     EipUint16 device_net_consumed_connection_id;
+     EipByte device_net_initial_comm_characteristcs;
+   */
 
   EipUint16 produced_connection_size;
   EipUint16 consumed_connection_size;
@@ -225,8 +255,8 @@ typedef struct connection_object {
   EipUint16 consumed_connection_path_length;
   CipEpath consumed_connection_path; /**< Packed EPATH */
   /** @brief Minimal time between the production of two application triggered
-    * or change of state triggered I/O connection messages
-    */
+   * or change of state triggered I/O connection messages
+   */
   EipUint16 production_inhibit_time;
   EipUint16 connection_timeout_multiplier;
   /* Conditional
@@ -256,20 +286,20 @@ typedef struct connection_object {
   /*S_CIP_CM_Object *p_stProducingCMObject; */
 
   EipUint32 eip_level_sequence_count_producing; /* the EIP level sequence Count
-   for Class 0/1
-   Producing Connections may have a
-   different
-   value than SequenceCountProducing */
+                                                   for Class 0/1
+                                                   Producing Connections may have a
+                                                   different
+                                                   value than SequenceCountProducing */
   EipUint32 eip_level_sequence_count_consuming; /* the EIP level sequence Count
-   for Class 0/1
-   Producing Connections may have a
-   different
-   value than SequenceCountProducing */
+                                                   for Class 0/1
+                                                   Producing Connections may have a
+                                                   different
+                                                   value than SequenceCountProducing */
 
   EipUint16 sequence_count_producing; /* sequence Count for Class 1 Producing
-   Connections */
+                                         Connections */
   EipUint16 sequence_count_consuming; /* sequence Count for Class 1 Producing
-   Connections */
+                                         Connections */
 
   EipInt32 transmission_trigger_timer;
   EipInt32 inactivity_watchdog_timer;
@@ -283,9 +313,9 @@ typedef struct connection_object {
 
   struct sockaddr_in remote_address; /* socket address for produce */
   struct sockaddr_in originator_address; /* the address of the originator that
-   established the connection. needed
-   for scanning if the right packet is
-   arriving */
+                                            established the connection. needed
+                                            for scanning if the right packet is
+                                            arriving */
   int socket[2]; /* socket handles, indexed by kConsuming or kProducing */
 
   /* pointers to connection handling functions */
@@ -320,7 +350,7 @@ EipStatus ConnectionManagerInit(EipUint16 unique_connection_id);
  *   @return pointer to connected Object
  *           0 .. connection not present in device
  */
-ConnectionObject* GetConnectedObject(EipUint32 connection_id);
+ConnectionObject *GetConnectedObject(EipUint32 connection_id);
 
 /**  Get a connection object for a given output assembly.
  *
@@ -336,14 +366,15 @@ ConnectionObject *GetConnectedOutputAssembly(EipUint32 output_assembly_id);
  * @param destination Destination of the copy operation
  * @param osurce Source of the copy operation
  */
-void CopyConnectionData(ConnectionObject *restrict destination, const ConnectionObject *restrict const source);
+void CopyConnectionData(ConnectionObject *restrict destination,
+                        const ConnectionObject *restrict const source);
 
 /** @brief Close the given connection
  *
  * This function will take the data form the connection and correctly closes the
- *connection (e.g., open sockets)
+ * connection (e.g., open sockets)
  * @param connection_object pointer to the connection object structure to be
- *closed
+ * closed
  */
 void CloseConnection(ConnectionObject *restrict connection_object);
 
@@ -378,6 +409,7 @@ void RemoveFromActiveConnections(ConnectionObject *connection_object);
 /** @brief returns the connection type of the supplied network connection parameter
  *
  */
-ForwardOpenConnectionType GetConnectionType(EipUint16 network_connection_parameter);
+ForwardOpenConnectionType GetConnectionType(
+  EipUint16 network_connection_parameter);
 
 #endif /* OPENER_CIPCONNECTIONMANAGER_H_ */

+ 76 - 46
source/src/cip/cipconnectionobject.c

@@ -13,7 +13,7 @@ typedef struct {
   CipUint *array;
 } CipConnectionBindingList;
 
-typedef struct {
+typedef struct cip_connection_object {
   CipUsint state; /**< Attribute 1: State of the object, see enum CipConnectionObjectState */
   CipUsint instance_type; /**< Attribute 2: Defines instance type I/O, explicit, or bridged, see enum CipConnectionObjectInstanceType */
   CipByte transport_class_trigger; /**< Attribute 3 */
@@ -33,88 +33,118 @@ typedef struct {
   CipUint production_inhibit_time; /**< Attribute 17: */
   CipUsint connection_timeout_multiplier; /**< Attribute 18: */
   CipConnectionBindingList connection_binding_list; /**< Attribute 19: */
-} ConnectionObject;
+} CipConnectionObject;
+
+const size_t ConnectionObjectSize = sizeof(CipConnectionObject);
 
-CipConnectionObjectState ConnectionObjectGetState(const ConnectionObject *restrict const connection_object) {
-	return (CipConnectionObjectState) connection_object->state;
+CipConnectionObjectState ConnectionObjectGetState(
+  const CipConnectionObject *restrict const connection_object) {
+  return (CipConnectionObjectState) connection_object->state;
 }
 
-CipConnectionObjectInstanceType ConnectionObjectGetInstanceType(const ConnectionObject *restrict const connection_object) {
-	return (CipConnectionObjectInstanceType) connection_object->instance_type;
+CipConnectionObjectInstanceType ConnectionObjectGetInstanceType(
+  const CipConnectionObject *restrict const connection_object) {
+  return (CipConnectionObjectInstanceType) connection_object->instance_type;
 }
 
-CipConnectionObjectTransportClassTriggerDirection GetTransportClassTriggerDirection(const ConnectionObject *restrict const connection_object) {
-	const CipByte direction_mask = 0x80; /* Last bit of the byte is the direction flag */
-	CipByte direction = connection_object->transport_class_trigger & direction_mask;
-	return (CipConnectionObjectTransportClassTriggerDirection)direction >> 7; /* Move to match enum values 0 or 1 */
+CipConnectionObjectTransportClassTriggerDirection
+GetTransportClassTriggerDirection(
+  const CipConnectionObject *restrict const connection_object) {
+  const CipByte direction_mask = 0x80;       /* Last bit of the byte is the direction flag */
+  CipByte direction = connection_object->transport_class_trigger &
+                      direction_mask;
+  return (CipConnectionObjectTransportClassTriggerDirection)direction >> 7;       /* Move to match enum values 0 or 1 */
 }
 
-CipConnectionObjectTransportClassTriggerProductionTrigger GetTransportClassTriggerProductionTrigger(const ConnectionObject *restrict const connection_object) {
-	const CipByte production_trigger_mask = 0x70; /* Bits 4-7 are representing the production trigger */
-	CipByte production_trigger = connection_object->transport_class_trigger & production_trigger_mask;
-	return (CipConnectionObjectTransportClassTriggerProductionTrigger) production_trigger >> 4;
+CipConnectionObjectTransportClassTriggerProductionTrigger
+GetTransportClassTriggerProductionTrigger(
+  const CipConnectionObject *restrict const connection_object) {
+  const CipByte production_trigger_mask = 0x70;       /* Bits 4-7 are representing the production trigger */
+  CipByte production_trigger = connection_object->transport_class_trigger &
+                               production_trigger_mask;
+  return (CipConnectionObjectTransportClassTriggerProductionTrigger)
+         production_trigger >> 4;
 }
 
-CipConnectionObjectTransportClass GetTransportClassTriggerTransportClass(const ConnectionObject *restrict const connection_object) {
-	const CipByte transport_class_mask = 0x0F;
-	CipByte transport_class = connection_object->transport_class_trigger & transport_class_mask;
-	return (CipConnectionObjectTransportClass) transport_class;
+CipConnectionObjectTransportClass GetTransportClassTriggerTransportClass(
+  const CipConnectionObject *restrict const connection_object) {
+  const CipByte transport_class_mask = 0x0F;
+  CipByte transport_class = connection_object->transport_class_trigger &
+                            transport_class_mask;
+  return (CipConnectionObjectTransportClass) transport_class;
 }
 
-CipUint ConnectionObjectGetProducedConnectionSize(const ConnectionObject *restrict const connection_object) {
-	return connection_object->produced_connection_size;
+CipUint ConnectionObjectGetProducedConnectionSize(
+  const CipConnectionObject *restrict const connection_object) {
+  return connection_object->produced_connection_size;
 }
 
-CipUint ConnectionObjectGetConsumedConnectionSize(const ConnectionObject *restrict const connection_object) {
-	return connection_object->consumed_connection_size;
+CipUint ConnectionObjectGetConsumedConnectionSize(
+  const CipConnectionObject *restrict const connection_object) {
+  return connection_object->consumed_connection_size;
 }
 
-CipUint ConnectionObjectGetExpectedPacketRate(const ConnectionObject *restrict const connection_object) {
-	return connection_object->expected_packet_rate;
+CipUint ConnectionObjectGetExpectedPacketRate(
+  const CipConnectionObject *restrict const connection_object) {
+  return connection_object->expected_packet_rate;
 }
 
-CipUdint ConnectionObjectGetCipProducedConnectionId(const ConnectionObject *restrict const connection_object) {
-	return connection_object->cip_produced_connection_id;
+CipUdint ConnectionObjectGetCipProducedConnectionId(
+  const CipConnectionObject *restrict const connection_object) {
+  return connection_object->cip_produced_connection_id;
 }
 
-CipUdint ConnectionObjectGetCipConsumedConnectionId(const ConnectionObject *restrict const connection_object) {
-	return connection_object->cip_consumed_connection_id;
+CipUdint ConnectionObjectGetCipConsumedConnectionId(
+  const CipConnectionObject *restrict const connection_object) {
+  return connection_object->cip_consumed_connection_id;
 }
 
-CipConnectionObjectWatchdogTimeoutAction ConnectionObjectGetWatchdogTimeoutActionValue(const ConnectionObject *restrict const connection_object) {
-	return (CipConnectionObjectWatchdogTimeoutAction) connection_object->watchdog_timeout_action;
+CipConnectionObjectWatchdogTimeoutAction
+ConnectionObjectGetWatchdogTimeoutActionValue(
+  const CipConnectionObject *restrict const connection_object) {
+  return (CipConnectionObjectWatchdogTimeoutAction) connection_object->
+         watchdog_timeout_action;
 }
 
-CipUint ConnectionObjectGetProducedConnectionPathLength(const ConnectionObject *restrict const connection_object) {
-	return connection_object->produced_connection_path_length;
+CipUint ConnectionObjectGetProducedConnectionPathLength(
+  const CipConnectionObject *restrict const connection_object) {
+  return connection_object->produced_connection_path_length;
 }
 
-CipEpath ConnectionObjectGetProducedConnectionPath(const ConnectionObject *restrict const connection_object) {
-	return connection_object->produced_connection_path;
+CipEpath ConnectionObjectGetProducedConnectionPath(
+  const CipConnectionObject *restrict const connection_object) {
+  return connection_object->produced_connection_path;
 }
 
-CipUint ConnectionObjectGetConsumedConnectionPathLength(const ConnectionObject *restrict const connection_object) {
-	return connection_object->consumed_connection_path_length;
+CipUint ConnectionObjectGetConsumedConnectionPathLength(
+  const CipConnectionObject *restrict const connection_object) {
+  return connection_object->consumed_connection_path_length;
 }
 
-CipEpath ConnectionObjectGetConsumedConnectionPath(const ConnectionObject *restrict const connection_object) {
-	return connection_object->consumed_connection_path;
+CipEpath ConnectionObjectGetConsumedConnectionPath(
+  const CipConnectionObject *restrict const connection_object) {
+  return connection_object->consumed_connection_path;
 }
 
-CipUint ConnectionObjectGetProductionInhibitTime(const ConnectionObject *restrict const connection_object) {
-	return connection_object->production_inhibit_time;
+CipUint ConnectionObjectGetProductionInhibitTime(
+  const CipConnectionObject *restrict const connection_object) {
+  return connection_object->production_inhibit_time;
 }
 
-CipUsint ConnectionObjectGetConnectionTimeoutMultiplier(const ConnectionObject *restrict const connection_object) {
-	return connection_object->connection_timeout_multiplier;
+CipUsint ConnectionObjectGetConnectionTimeoutMultiplier(
+  const CipConnectionObject *restrict const connection_object) {
+  return connection_object->connection_timeout_multiplier;
 }
 
-CipConnectionBindingList ConnectionObjectGetConnectionBindingList(const ConnectionObject *restrict const connection_object) {
-	return connection_object->connection_binding_list;
+CipConnectionBindingList ConnectionObjectGetConnectionBindingList(
+  const CipConnectionObject *restrict const connection_object) {
+  return connection_object->connection_binding_list;
 }
 
-EipStatus ConnectionObjectGetAttributeSingle(CipInstance *const restrict instance, CipMessageRouterRequest *restrict const message_router_request,
-                                             CipMessageRouterResponse *restrict const message_router_response) {
+EipStatus ConnectionObjectGetAttributeSingle(
+  CipInstance *const restrict instance,
+  CipMessageRouterRequest *restrict const message_router_request,
+  CipMessageRouterResponse *restrict const message_router_response) {
 
 }
 

+ 6 - 3
source/src/cip/cipconnectionobject.h

@@ -9,7 +9,9 @@
 
 static const int kConnectionObjectClassId = 0x05;
 
-typedef struct ConnectionObject;
+typedef struct cip_connection_object CipConnectionObject;
+
+extern const size_t CipConnectionObjectSize;
 
 /** @brief Valid values for the state attribute of the Connection Object */
 typedef enum {
@@ -36,7 +38,8 @@ typedef enum {
 typedef enum {
   kCipConnectionObjectTransportClassTriggerProductionTriggerCyclic = 0,
   kCipConnectionObjectTransportClassTriggerProductionTriggerChangeOfState = 1,
-  kCipConnectionObjectTransportClassTriggerProductionTriggerApplicationObject = 2
+  kCipConnectionObjectTransportClassTriggerProductionTriggerApplicationObject =
+    2
 } CipConnectionObjectTransportClassTriggerProductionTrigger;
 
 typedef enum {
@@ -57,6 +60,6 @@ typedef enum {
   kCipConnectionObjectWatchdogTimeoutActionDeferredDelete = 3
 } CipConnectionObjectWatchdogTimeoutAction;
 
-ConnectionObject *NewCipConnectionObject(CipConnectionObjectInstanceType type);
+CipConnectionObject *NewCipConnectionObject(CipConnectionObjectInstanceType type);
 
 #endif /* OPENER_SRC_CIP_CIPCONNECTIONOBJECT_H_ */

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

@@ -16,7 +16,7 @@ typedef struct electronic_key_format_4 {
   CipUsint minor_revision;
 } ElectronicKeyFormat4;
 
-const unsigned int kElectronicKeyFormat4Size = sizeof(ElectronicKeyFormat4);
+const size_t kElectronicKeyFormat4Size = sizeof(ElectronicKeyFormat4);
 
 ElectronicKeyFormat4 *ElectronicKeyFormat4New() {
   return (ElectronicKeyFormat4 *)calloc( 1, sizeof(ElectronicKeyFormat4) );

+ 4 - 7
source/src/cip/cipelectronickey.h

@@ -16,7 +16,7 @@
  */
 typedef struct electronic_key_format_4 ElectronicKeyFormat4;
 
-extern const unsigned int kElectronicKeyFormat4Size;
+extern const size_t kElectronicKeyFormat4Size;
 
 /** @brief Constructor for the electroic key format 4 class
  *
@@ -53,8 +53,7 @@ CipUint ElectronicKeyFormat4GetVendorId(
  *	@param electronic_key A format 4 electronic key
  */
 void ElectronicKeyFormat4SetDeviceType(
-  const CipUint device_type,
-  ElectronicKeyFormat4 *const
+  const CipUint device_type,ElectronicKeyFormat4 *const
   electronic_key);
 
 /** @brief Gets the device type from a format 4 electronic key
@@ -71,8 +70,7 @@ CipUint ElectronicKeyFormat4GetDeviceType(
  *      @param electronic_key The electronic key to be modified
  */
 void ElectronicKeyFormat4SetProductCode(
-  const CipUint product_code,
-  ElectronicKeyFormat4 *const
+  const CipUint product_code,ElectronicKeyFormat4 *const
   electronic_key);
 
 /** @brief Gets the product code from an format 4 electronic key
@@ -114,8 +112,7 @@ bool ElectronicKeyFormat4GetMajorRevisionCompatibility(
  *      @param electronic_key The electronic key to be modified
  */
 void ElectronicKeyFormat4SetMinorRevision(
-  const CipUsint minor_revision,
-  ElectronicKeyFormat4 *const
+  const CipUsint minor_revision,ElectronicKeyFormat4 *const
   electronic_key);
 
 /** @brief Gets the minor revision from an format 4 electronic key

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

@@ -340,7 +340,7 @@ void GetPathLogicalSegmentElectronicKeyFormat4(
   OPENER_ASSERT( kElectronicKeySegmentFormatKeyFormat4 ==
                  GetPathLogicalSegmentElectronicKeyFormat(cip_path) );
 
-  const char *message_runner = (const char *)(cip_path + 2);
+  const EipUint8 *message_runner = (const EipUint8 *)(cip_path + 2);
   ElectronicKeyFormat4SetVendorId(GetIntFromMessage(&message_runner), key);
   ElectronicKeyFormat4SetDeviceType(GetIntFromMessage(&message_runner), key);
   ElectronicKeyFormat4SetProductCode(GetIntFromMessage(&message_runner), key);

+ 14 - 22
source/src/cip/cipioconnection.c

@@ -82,8 +82,7 @@ unsigned int g_config_data_length = 0; /**< length of g_config_data_buffer. Init
 
 EipUint32 g_run_idle_state; /**< buffer for holding the run idle information. */
 
-EipUint16 ProcessProductionInhibitTime(ConnectionObject *io_connection_object)
-{
+EipUint16 ProcessProductionInhibitTime(ConnectionObject *io_connection_object) {
   if ( kProductionTriggerCyclic
        == GetProductionTrigger(io_connection_object) ) {
     if ( 256 == GetProductionInhibitTime(io_connection_object) ) {
@@ -132,8 +131,7 @@ void SetIoConnectionCallbacks(ConnectionObject *const io_connection_object) {
 
 EipUint16 SetupIoConnectionOriginatorToTargetConnectionPoint(
   ConnectionObject *const io_connection_object,
-  ConnectionObject *const restrict connection_object)
-{
+  ConnectionObject *const restrict connection_object) {
   CipClass *const assembly_class = GetCipClass(kCipAssemblyClassCode);
   CipInstance *instance = NULL;
   if ( NULL
@@ -186,8 +184,7 @@ EipUint16 SetupIoConnectionOriginatorToTargetConnectionPoint(
 
 EipUint16 SetupIoConnectionTargetToOriginatorConnectionPoint(
   ConnectionObject *const io_connection_object,
-  ConnectionObject *const restrict connection_object)
-{
+  ConnectionObject *const restrict connection_object) {
   /*setup producer side*/
   CipClass *const assembly_class = GetCipClass(kCipAssemblyClassCode);
   CipInstance *instance = NULL;
@@ -249,8 +246,7 @@ EipUint16 SetupIoConnectionTargetToOriginatorConnectionPoint(
  */
 EipStatus EstablishIoConnection(
   ConnectionObject *restrict const connection_object,
-  EipUint16 *const extended_error)
-{
+  EipUint16 *const extended_error) {
   EipStatus eip_status = kEipStatusOk;
 
   ConnectionObject *io_connection_object = GetIoConnectionForConnectionData(
@@ -341,8 +337,7 @@ EipStatus EstablishIoConnection(
  */
 EipStatus OpenConsumingPointToPointConnection(
   ConnectionObject *const connection_object,
-  CipCommonPacketFormatData *const common_packet_format_data)
-{
+  CipCommonPacketFormatData *const common_packet_format_data) {
   /*static EIP_UINT16 nUDPPort = 2222; TODO think on improving the udp port assigment for point to point connections */
   int j = 0;
 
@@ -383,8 +378,7 @@ EipStatus OpenConsumingPointToPointConnection(
 
 EipStatus OpenProducingPointToPointConnection(
   ConnectionObject *connection_object,
-  CipCommonPacketFormatData *common_packet_format_data)
-{
+  CipCommonPacketFormatData *common_packet_format_data) {
   in_port_t port = htons(kOpenerEipIoUdpPort); /* the default port to be used if no port information is part of the forward open request */
 
   if (kCipItemIdSocketAddressInfoTargetToOriginator
@@ -416,15 +410,15 @@ EipStatus OpenProducingPointToPointConnection(
 
 EipStatus OpenProducingMulticastConnection(
   ConnectionObject *connection_object,
-  CipCommonPacketFormatData *common_packet_format_data)
-{
+  CipCommonPacketFormatData *common_packet_format_data) {
   ConnectionObject *existing_connection_object =
     GetExistingProducerMulticastConnection(
       connection_object->connection_path.connection_point[1]);
 
   if (NULL == existing_connection_object) { /* we are the first connection producing for the given Input Assembly */
     return OpenMulticastConnection(kUdpCommuncationDirectionProducing,
-                                   connection_object, common_packet_format_data);
+                                   connection_object,
+                                   common_packet_format_data);
   } else {
     /* we need to inform our originator on the correct connection id */
     connection_object->cip_produced_connection_id = existing_connection_object
@@ -484,8 +478,7 @@ EipStatus OpenProducingMulticastConnection(
 EipStatus OpenMulticastConnection(
   UdpCommuncationDirection direction,
   ConnectionObject *connection_object,
-  CipCommonPacketFormatData *common_packet_format_data)
-{
+  CipCommonPacketFormatData *common_packet_format_data) {
   int j = -1;
 
   int address_info_item_which_contains_o_to_t = -1;
@@ -799,15 +792,14 @@ EipStatus SendConnectedData(ConnectionObject *connection_object) {
   reply_length += common_packet_format_data->data_item.length;
 
   return SendUdpData(
-           &connection_object->remote_address,
-           connection_object->socket[kUdpCommuncationDirectionProducing],
-           &g_message_data_reply_buffer[0], reply_length);
+    &connection_object->remote_address,
+    connection_object->socket[kUdpCommuncationDirectionProducing],
+    &g_message_data_reply_buffer[0], reply_length);
 }
 
 EipStatus HandleReceivedIoConnectionData(ConnectionObject *connection_object,
                                          const EipUint8 *data,
-                                         EipUint16 data_length)
-{
+                                         EipUint16 data_length) {
 
   /* check class 1 sequence number*/
   if ( (connection_object->transport_type_class_trigger & 0x0F) == 1 ) {

+ 7 - 4
source/src/cip/cipioconnection.h

@@ -52,8 +52,9 @@
  *    - kEipStatusOk ... on success
  *    - On an error the general status code to be put into the response
  */
-EipStatus EstablishIoConnection(ConnectionObject *restrict const connection_object,
-                         EipUint16 *const extended_error);
+EipStatus EstablishIoConnection(
+  ConnectionObject *restrict const connection_object,
+  EipUint16 *const extended_error);
 
 /** @brief Take the data given in the connection object structure and open the necessary communication channels
  *
@@ -71,7 +72,7 @@ EipStatus OpenCommunicationChannels(ConnectionObject *connection_object);
  * @param connection_object pointer to the connection object data
  */
 void CloseCommunicationChannelsAndRemoveFromActiveConnectionsList(
-    ConnectionObject *connection_object);
+  ConnectionObject *connection_object);
 
 extern EipUint8 *g_config_data_buffer;
 extern unsigned int g_config_data_length;
@@ -87,6 +88,8 @@ extern unsigned int g_config_data_length;
  *    - kEipStatusOk ... on success
  *    - On an error the general status code to be put into the response
  */
-EipStatus EstablishIoConnection(ConnectionObject*const restrict connection_object, EipUint16*const extended_error);
+EipStatus EstablishIoConnection(
+  ConnectionObject *const restrict connection_object,
+  EipUint16 *const extended_error);
 
 #endif /* OPENER_CIPIOCONNECTION_H_ */

+ 73 - 54
source/src/cip/cipmessagerouter.c

@@ -1,6 +1,6 @@
 /*******************************************************************************
  * Copyright (c) 2009, Rockwell Automation, Inc.
- * All rights reserved. 
+ * All rights reserved.
  *
  ******************************************************************************/
 #include "opener_api.h"
@@ -17,7 +17,7 @@ CipMessageRouterResponse g_message_router_response;
  *
  * A linked list of this  object is the registry of classes known to the message router
  * for small devices with very limited memory it could make sense to change this list into an
- * array with a given max size for removing the need for having to dynamically allocate 
+ * array with a given max size for removing the need for having to dynamically allocate
  * memory. The size of the array could be a parameter in the platform config file.
  */
 typedef struct cip_message_router_object {
@@ -36,7 +36,7 @@ CipMessageRouterObject *g_first_object = NULL;
 EipStatus RegisterCipClass(CipClass *cip_class);
 
 /** @brief Create Message Router Request structure out of the received data.
- * 
+ *
  * Parses the UCMM header consisting of: service, IOI size, IOI, data into a request structure
  * @param data pointer to the message data received
  * @param data_length number of bytes in the message
@@ -44,23 +44,25 @@ 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);
 
 EipStatus CipMessageRouterInit() {
 
   CipClass *message_router = CreateCipClass(kCipMessageRouterClassCode, /* class ID*/
-                                  0, /* # of class attributes */
-                                  0xffffffff, /* class getAttributeAll mask*/
-                                  0, /* # of class services*/
-                                  0, /* # of instance attributes*/
-                                  0xffffffff, /* instance getAttributeAll mask*/
-                                  0, /* # of instance services*/
-                                  1, /* # of instances*/
-                                  "message router", /* class name*/
-                                  1); /* revision */
-  if (message_router == NULL)
+                                            0, /* # of class attributes */
+                                            0xffffffff, /* class getAttributeAll mask*/
+                                            0, /* # of class services*/
+                                            0, /* # of instance attributes*/
+                                            0xffffffff, /* instance getAttributeAll mask*/
+                                            0, /* # of instance services*/
+                                            1, /* # of instances*/
+                                            "message router", /* class name*/
+                                            1); /* revision */
+  if (NULL == message_router) {
     return kEipStatusError;
+  }
 
   /* reserved for future use -> set to zero */
   g_message_router_response.reserved = 0;
@@ -82,8 +84,9 @@ CipMessageRouterObject *GetRegisteredObject(EipUint32 class_id) {
   while (NULL != object) /* for each entry in list*/
   {
     OPENER_ASSERT(object->cip_class != NULL);
-    if (object->cip_class->class_id == class_id)
+    if (object->cip_class->class_id == class_id) {
       return object; /* return registration node if it matches class ID*/
+    }
     object = object->next;
   }
   return NULL;
@@ -92,22 +95,28 @@ CipMessageRouterObject *GetRegisteredObject(EipUint32 class_id) {
 CipClass *GetCipClass(const EipUint32 class_id) {
   CipMessageRouterObject *message_router_object = GetRegisteredObject(class_id);
 
-  if (message_router_object)
+  if (message_router_object) {
     return message_router_object->cip_class;
-  else
+  }
+  else{
     return NULL;
+  }
 }
 
-CipInstance *GetCipInstance(const CipClass *restrict const cip_class, EipUint32 instance_number) {
+CipInstance *GetCipInstance(const CipClass *restrict const cip_class,
+                            EipUint32 instance_number) {
 
-  if (instance_number == 0)
+  if (instance_number == 0) {
     return (CipInstance *) cip_class; /* if the instance number is zero, return the class object itself*/
 
+  }
   /* pointer to linked list of instances from the class object*/
-  for (CipInstance *instance = cip_class->instances; instance; instance = instance->next) /* follow the list*/
+  for (CipInstance *instance = cip_class->instances; instance;
+       instance = instance->next)                                                         /* follow the list*/
   {
-    if (instance->instance_number == instance_number)
+    if (instance->instance_number == instance_number) {
       return instance; /* if the number matches, return the instance*/
+    }
   }
 
   return NULL;
@@ -116,14 +125,16 @@ CipInstance *GetCipInstance(const CipClass *restrict const cip_class, EipUint32
 EipStatus RegisterCipClass(CipClass *cip_class) {
   CipMessageRouterObject **message_router_object = &g_first_object;
 
-  while (*message_router_object)
+  while (*message_router_object) {
     message_router_object = &(*message_router_object)->next; /* follow the list until p points to an empty link (list end)*/
 
+  }
   *message_router_object = (CipMessageRouterObject *) CipCalloc(
-      1, sizeof(CipMessageRouterObject)); /* create a new node at the end of the list*/
-  if (*message_router_object == 0)
+    1, sizeof(CipMessageRouterObject) );  /* create a new node at the end of the list*/
+  if (*message_router_object == 0) {
     return kEipStatusError; /* check for memory error*/
 
+  }
   (*message_router_object)->cip_class = cip_class; /* fill in the new node*/
   (*message_router_object)->next = NULL;
 
@@ -137,38 +148,42 @@ EipStatus NotifyMessageRouter(EipUint8 *data, int data_length) {
   g_message_router_response.data = g_message_data_reply_buffer; /* set reply buffer, using a fixed buffer (about 100 bytes) */
 
   OPENER_TRACE_INFO("NotifyMessageRouter: routing unconnected message\n");
-  if (kCipErrorSuccess
-      != (status = CreateMessageRouterRequestStructure(
-          data, data_length, &g_message_router_request))) { /* error from create MR structure*/
-    OPENER_TRACE_ERR("NotifyMessageRouter: error from createMRRequeststructure\n");
+  if ( kCipErrorSuccess
+       != ( status = CreateMessageRouterRequestStructure(
+              data, data_length, &g_message_router_request) ) ) { /* error from create MR structure*/
+    OPENER_TRACE_ERR(
+      "NotifyMessageRouter: error from createMRRequeststructure\n");
     g_message_router_response.general_status = status;
     g_message_router_response.size_of_additional_status = 0;
     g_message_router_response.reserved = 0;
     g_message_router_response.data_length = 0;
     g_message_router_response.reply_service = (0x80
-        | g_message_router_request.service);
+                                               | 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);
+      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);
       g_message_router_response.general_status =
-          kCipErrorPathDestinationUnknown; /*according to the test tool this should be the correct error flag instead of CIP_ERROR_OBJECT_DOES_NOT_EXIST;*/
+        kCipErrorPathDestinationUnknown;   /*according to the test tool this should be the correct error flag instead of CIP_ERROR_OBJECT_DOES_NOT_EXIST;*/
       g_message_router_response.size_of_additional_status = 0;
       g_message_router_response.reserved = 0;
       g_message_router_response.data_length = 0;
       g_message_router_response.reply_service = (0x80
-          | g_message_router_request.service);
+                                                 | g_message_router_request.
+                                                 service);
     } else {
       /* call notify function from Object with ClassID (gMRRequest.RequestPath.ClassID)
-       object will or will not make an reply into gMRResponse*/
+         object will or will not make an reply into gMRResponse*/
       g_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);
+      OPENER_TRACE_INFO(
+        "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,
                                &g_message_router_response);
@@ -176,16 +191,16 @@ EipStatus NotifyMessageRouter(EipUint8 *data, int data_length) {
 #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
     }
@@ -194,15 +209,16 @@ EipStatus NotifyMessageRouter(EipUint8 *data, int data_length) {
 }
 
 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++;  /*TODO: Fix for 16 bit path lengths (+1 */
   data_length--;
 
   int number_of_decoded_bytes = DecodePaddedEPath(
-      &(message_router_request->request_path), &data);
+    &(message_router_request->request_path), &data);
   if (number_of_decoded_bytes < 0) {
     return kCipErrorPathSegmentError;
   }
@@ -210,10 +226,12 @@ CipError CreateMessageRouterRequestStructure(
   message_router_request->data = data;
   message_router_request->data_length = data_length - number_of_decoded_bytes;
 
-  if (message_router_request->data_length < 0)
+  if (message_router_request->data_length < 0) {
     return kCipErrorPathSizeInvalid;
-  else
+  }
+  else{
     return kCipErrorSuccess;
+  }
 }
 
 void DeleteAllClasses(void) {
@@ -239,14 +257,15 @@ void DeleteAllClasses(void) {
 
     /*clear meta class data*/
     CipFree(
-        message_router_object_to_delete->cip_class->class_instance.cip_class
-            ->class_name);
+      message_router_object_to_delete->cip_class->class_instance.cip_class
+      ->class_name);
     CipFree(
-        message_router_object_to_delete->cip_class->class_instance.cip_class
-            ->services);
+      message_router_object_to_delete->cip_class->class_instance.cip_class
+      ->services);
     CipFree(message_router_object_to_delete->cip_class->class_instance.cip_class);
     /*clear class data*/
-    CipFree(message_router_object_to_delete->cip_class->class_instance.attributes);
+    CipFree(
+      message_router_object_to_delete->cip_class->class_instance.attributes);
     CipFree(message_router_object_to_delete->cip_class->services);
     CipFree(message_router_object_to_delete->cip_class);
     CipFree(message_router_object_to_delete);

+ 10 - 7
source/src/cip/ciptypes.h

@@ -140,23 +140,26 @@ typedef struct {
  *
  */
 typedef struct {
-  EipUint8 path_size;
-  /**< Size of the Path in 16-bit words *//* TODO: Fix, should be UINT
-     (EIP_UINT16) */
+  EipUint8 path_size;/**< Path size in 16 bit words (path_size * 16 bit) */
   EipUint16 class_id; /**< Class ID of the linked object */
   EipUint16 instance_number; /**< Requested Instance Number of the linked object */
   EipUint16 attribute_number; /**< Requested Attribute Number of the linked object */
 } CipEpath;
 
+typedef enum connection_point_type {
+  kConnectionPointTypeProducing = 0,
+  kConnectionPointTypeConsuming,
+  kConnectionPointTypeConfig,
+  kConnectionPointTypeMaxValue
+} ConnectionPointType;
+
 /** @brief CIP Connection Path
  *
  */
 typedef struct {
-  EipUint8 path_size;
-  /**< Size of the Path in 16-bit words *//* TODO: Fix, should be UINT
-     (EIP_UINT16) */
+  EipUint8 path_size; /**< Path size in 16 bit words (path_size * 16 bit) */
   EipUint32 class_id; /**< Class ID of the linked object */
-  EipUint32 connection_point[3]; /* TODO:  Why array length 3? */
+  EipUint32 connection_point[kConnectionPointTypeMaxValue];
   EipUint8 data_segment;
   EipUint8 *segment_data;
 } CipConnectionPath;

+ 139 - 118
source/src/enet_encap/cpf.c

@@ -1,6 +1,6 @@
 /*******************************************************************************
  * Copyright (c) 2009, Rockwell Automation, Inc.
- * All rights reserved. 
+ * All rights reserved.
  *
  ******************************************************************************/
 #include <string.h>
@@ -26,35 +26,35 @@ int NotifyCommonPacketFormat(EncapsulationData *const receive_data,
                              EipUint8 *reply_buffer) {
   int return_value = kEipStatusError;
 
-  if ((return_value = CreateCommonPacketFormatStructure(
-      receive_data->current_communication_buffer_position,
-      receive_data->data_length, &g_common_packet_format_data_item))
-      == kEipStatusError) {
+  if ( ( return_value = CreateCommonPacketFormatStructure(
+           receive_data->current_communication_buffer_position,
+           receive_data->data_length, &g_common_packet_format_data_item) )
+       == kEipStatusError ) {
     OPENER_TRACE_ERR("notifyCPF: error from createCPFstructure\n");
   } else {
     return_value = kEipStatusOk; /* In cases of errors we normally need to send an error response */
     if (g_common_packet_format_data_item.address_item.type_id
         == kCipItemIdNullAddress) /* check if NullAddressItem received, otherwise it is no unconnected message and should not be here*/
-        { /* found null address item*/
+    {     /* 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);
+          g_common_packet_format_data_item.data_item.data,
+          g_common_packet_format_data_item.data_item.length);
         if (return_value != kEipStatusError) {
           return_value = AssembleLinearMessage(
-              &g_message_router_response, &g_common_packet_format_data_item,
-              reply_buffer);
+            &g_message_router_response, &g_common_packet_format_data_item,
+            reply_buffer);
         }
       } 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");
         receive_data->status = kEncapsulationProtocolIncorrectData;
       }
     } 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");
       receive_data->status = kEncapsulationProtocolIncorrectData;
     }
   }
@@ -65,8 +65,8 @@ int NotifyConnectedCommonPacketFormat(EncapsulationData *received_data,
                                       EipUint8 *reply_buffer) {
 
   int 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");
@@ -74,45 +74,49 @@ int NotifyConnectedCommonPacketFormat(EncapsulationData *received_data,
     return_value = kEipStatusError; /* For connected explicit messages status always has to be 0*/
     if (g_common_packet_format_data_item.address_item.type_id
         == kCipItemIdConnectionAddress) /* check if ConnectedAddressItem received, otherwise it is no connected message and should not be here*/
-        { /* ConnectedAddressItem item */
+    {     /* ConnectedAddressItem item */
       ConnectionObject *connection_object = GetConnectedObject(
-          g_common_packet_format_data_item.address_item.data
-              .connection_identifier);
+        g_common_packet_format_data_item.address_item.data
+        .connection_identifier);
       if (NULL != connection_object) {
         /* reset the watchdog timer */
         connection_object->inactivity_watchdog_timer = (connection_object
-            ->o_to_t_requested_packet_interval / 1000)
-            << (2 + connection_object->connection_timeout_multiplier);
+                                                        ->
+                                                        o_to_t_requested_packet_interval
+                                                        / 1000)
+                                                       << (2 +
+                                                           connection_object->
+                                                           connection_timeout_multiplier);
 
         /*TODO check connection id  and sequence count    */
         if (g_common_packet_format_data_item.data_item.type_id
             == 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 =
-              (EipUint32) GetIntFromMessage((const EipUint8 ** const)&buffer);
+            (EipUint32) GetIntFromMessage( (const EipUint8 **const)&buffer );
           return_value = NotifyMessageRouter(
-              buffer, g_common_packet_format_data_item.data_item.length - 2);
+            buffer, g_common_packet_format_data_item.data_item.length - 2);
 
           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;
             return_value = AssembleLinearMessage(
-                &g_message_router_response, &g_common_packet_format_data_item,
-                reply_buffer);
+              &g_message_router_response, &g_common_packet_format_data_item,
+              reply_buffer);
           }
         } 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 return_value;
@@ -125,11 +129,12 @@ int NotifyConnectedCommonPacketFormat(EncapsulationData *received_data,
  * @param common_packet_format_data	Pointer to structure of CPF data item.
  *
  *   @return kEipStatusOk .. success
- * 	       kEipStatusError .. error
+ *             kEipStatusError .. error
  */
 EipStatus CreateCommonPacketFormatStructure(
-    const EipUint8 *data, int data_length,
-    CipCommonPacketFormatData *common_packet_format_data) {
+  const EipUint8 *data,
+  int 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;
@@ -143,12 +148,12 @@ EipStatus CreateCommonPacketFormatStructure(
     length_count += 4;
     if (common_packet_format_data->address_item.length >= 4) {
       common_packet_format_data->address_item.data.connection_identifier =
-          GetDintFromMessage(&data);
+        GetDintFromMessage(&data);
       length_count += 4;
     }
     if (common_packet_format_data->address_item.length == 8) {
       common_packet_format_data->address_item.data.sequence_number =
-          GetDintFromMessage(&data);
+        GetDintFromMessage(&data);
       length_count += 4;
     }
   }
@@ -162,21 +167,22 @@ EipStatus CreateCommonPacketFormatStructure(
   for (int j = 0; j < (common_packet_format_data->item_count - 2); j++) /* TODO there needs to be a limit check here???*/
   {
     common_packet_format_data->address_info_item[j].type_id = GetIntFromMessage(
-        &data);
-    OPENER_TRACE_INFO("Sockaddr type id: %x\n", common_packet_format_data->address_info_item[j].type_id);
+      &data);
+    OPENER_TRACE_INFO("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)) {
+    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 =
-          GetDintFromMessage(&data);
+        GetDintFromMessage(&data);
       for (int i = 0; i < 8; i++) {
         common_packet_format_data->address_info_item[j].nasin_zero[i] = *data;
         data++;
@@ -198,7 +204,7 @@ 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 */
       return kEipStatusOk;
@@ -215,7 +221,7 @@ EipStatus CreateCommonPacketFormatStructure(
  *
  * @return The new size of the message frame after encoding
  */
-int EncodeNullAddressItem(EipUint8** message, int size) {
+int EncodeNullAddressItem(EipUint8 **message, int size) {
   size += AddIntToMessage(kCipItemIdNullAddress, message);
   /* null address item -> address length set to 0 */
   size += AddIntToMessage(0, message);
@@ -231,14 +237,15 @@ int EncodeNullAddressItem(EipUint8** message, int size) {
  * @return The new size of the message frame after encoding
  */
 int EncodeConnectedAddressItem(
-    EipUint8** message,
-    CipCommonPacketFormatData* common_packet_format_data_item, int size) {
+  EipUint8 **message,
+  CipCommonPacketFormatData *common_packet_format_data_item,
+  int size) {
   /* connected data item -> address length set to 4 and copy ConnectionIdentifier */
   size += AddIntToMessage(kCipItemIdConnectionAddress, message);
   size += AddIntToMessage(4, message);
   size += AddDintToMessage(
-      common_packet_format_data_item->address_item.data.connection_identifier,
-      message);
+    common_packet_format_data_item->address_item.data.connection_identifier,
+    message);
   return size;
 }
 
@@ -252,17 +259,18 @@ int EncodeConnectedAddressItem(
  * @return New message size after encoding
  */
 int EncodeSequencedAddressItem(
-    EipUint8** message,
-    CipCommonPacketFormatData* common_packet_format_data_item, int size) {
+  EipUint8 **message,
+  CipCommonPacketFormatData *common_packet_format_data_item,
+  int size) {
   /* sequenced address item -> address length set to 8 and copy ConnectionIdentifier and SequenceNumber */
   size += AddIntToMessage(kCipItemIdSequencedAddressItem, message);
   size += AddIntToMessage(sequenced_address_item_length, message);
   size += AddDintToMessage(
-      common_packet_format_data_item->address_item.data.connection_identifier,
-      message);
+    common_packet_format_data_item->address_item.data.connection_identifier,
+    message);
   size += AddDintToMessage(
-      common_packet_format_data_item->address_item.data.sequence_number,
-      message);
+    common_packet_format_data_item->address_item.data.sequence_number,
+    message);
   return size;
 }
 
@@ -275,8 +283,9 @@ int EncodeSequencedAddressItem(
  *
  * @return The new size of the message frame after encoding
  */
-int EncodeItemCount(CipCommonPacketFormatData* common_packet_format_data_item,
-                    EipUint8** message, int size) {
+int EncodeItemCount(CipCommonPacketFormatData *common_packet_format_data_item,
+                    EipUint8 **message,
+                    int size) {
   size += AddIntToMessage(common_packet_format_data_item->item_count, message); /* item count */
   return size;
 }
@@ -291,8 +300,9 @@ int EncodeItemCount(CipCommonPacketFormatData* common_packet_format_data_item,
  * @return The new size of the message frame after encoding
  */
 int EncodeDataItemType(
-    CipCommonPacketFormatData* common_packet_format_data_item,
-    EipUint8** message, int size) {
+  CipCommonPacketFormatData *common_packet_format_data_item,
+  EipUint8 **message,
+  int size) {
   size += AddIntToMessage(common_packet_format_data_item->data_item.type_id,
                           message);
   return size;
@@ -308,8 +318,9 @@ int EncodeDataItemType(
  * @return The new size of the message frame after encoding
  */
 int EncodeDataItemLength(
-    CipCommonPacketFormatData* common_packet_format_data_item,
-    EipUint8** message, int size) {
+  CipCommonPacketFormatData *common_packet_format_data_item,
+  EipUint8 **message,
+  int size) {
   size += AddIntToMessage(common_packet_format_data_item->data_item.length,
                           message);
   return size;
@@ -325,11 +336,12 @@ int EncodeDataItemLength(
  * @return The new size of the message frame after encoding
  */
 int EncodeDataItemData(
-    CipCommonPacketFormatData* common_packet_format_data_item,
-    EipUint8** message, int size) {
+  CipCommonPacketFormatData *common_packet_format_data_item,
+  EipUint8 **message,
+  int size) {
   for (int i = 0; i < common_packet_format_data_item->data_item.length; i++) {
     size += AddSintToMessage(
-        *(common_packet_format_data_item->data_item.data + i), message);
+      *(common_packet_format_data_item->data_item.data + i), message);
   }
   return size;
 }
@@ -345,12 +357,12 @@ int EncodeDataItemData(
  */
 
 int EncodeConnectedDataItemLength(
-    CipMessageRouterResponse* message_router_response, EipUint8** message,
-    int size) {
+  CipMessageRouterResponse *message_router_response, EipUint8 **message,
+  int size) {
   size += AddIntToMessage(
-      (EipUint16) (message_router_response->data_length + 4 + 2 /* TODO: Magic numbers */
-          + (2 * message_router_response->size_of_additional_status)),
-      message);
+    (EipUint16) ( message_router_response->data_length + 4 + 2  /* TODO: Magic numbers */
+                  + (2 * message_router_response->size_of_additional_status) ),
+    message);
   return size;
 }
 
@@ -365,12 +377,13 @@ int EncodeConnectedDataItemLength(
  *
  */
 int EncodeSequenceNumber(
-    int size, const CipCommonPacketFormatData* common_packet_format_data_item,
-    EipUint8** message) {
+  int size,
+  const CipCommonPacketFormatData *common_packet_format_data_item,
+  EipUint8 **message) {
   size += AddIntToMessage(
-      (EipUint16) common_packet_format_data_item->address_item.data
-          .sequence_number,
-      message);
+    (EipUint16) common_packet_format_data_item->address_item.data
+    .sequence_number,
+    message);
   return size;
 }
 
@@ -383,8 +396,9 @@ int EncodeSequenceNumber(
  *
  * @return The new size of the message buffer
  */
-int EncodeReplyService(int size, EipUint8** message,
-                       CipMessageRouterResponse* message_router_response) {
+int EncodeReplyService(int size,
+                       EipUint8 **message,
+                       CipMessageRouterResponse *message_router_response) {
   size += AddSintToMessage(message_router_response->reply_service, message);
   return size;
 }
@@ -399,8 +413,8 @@ int EncodeReplyService(int size, EipUint8** message,
  * @return New size of the message buffer
  */
 int EncodeReservedFieldOfLengthByte(
-    int size, EipUint8** message,
-    CipMessageRouterResponse* message_router_response) {
+  int size, EipUint8 **message,
+  CipMessageRouterResponse *message_router_response) {
   size += AddSintToMessage(message_router_response->reserved, message);
   return size;
 }
@@ -414,8 +428,9 @@ int EncodeReservedFieldOfLengthByte(
  *
  * @return New size of the message buffer
  */
-int EncodeGeneralStatus(int size, EipUint8** message,
-                        CipMessageRouterResponse* message_router_response) {
+int EncodeGeneralStatus(int size,
+                        EipUint8 **message,
+                        CipMessageRouterResponse *message_router_response) {
   size += AddSintToMessage(message_router_response->general_status, message);
   return size;
 }
@@ -431,8 +446,8 @@ int EncodeGeneralStatus(int size, EipUint8** message,
  */
 
 int EncodeExtendedStatusLength(
-    int size, EipUint8** message,
-    CipMessageRouterResponse* message_router_response) {
+  int size, EipUint8 **message,
+  CipMessageRouterResponse *message_router_response) {
   size += AddSintToMessage(message_router_response->size_of_additional_status,
                            message);
   return size;
@@ -448,11 +463,12 @@ int EncodeExtendedStatusLength(
  * @return New size of the message buffer
  */
 int EncodeExtendedStatusDataItems(
-    int size, CipMessageRouterResponse* message_router_response,
-    EipUint8** message) {
-  for (int i = 0; i < message_router_response->size_of_additional_status; i++)
+  int size, CipMessageRouterResponse *message_router_response,
+  EipUint8 **message) {
+  for (int i = 0; i < message_router_response->size_of_additional_status; i++) {
     size += AddIntToMessage(message_router_response->additional_status[i],
                             message);
+  }
 
   return size;
 }
@@ -470,8 +486,9 @@ int EncodeExtendedStatusDataItems(
  * @return New size of the message buffer
  */
 
-int EncodeExtendedStatus(int size, EipUint8** message,
-                         CipMessageRouterResponse* message_router_response) {
+int EncodeExtendedStatus(int size,
+                         EipUint8 **message,
+                         CipMessageRouterResponse *message_router_response) {
   size = EncodeExtendedStatusLength(size, message, message_router_response);
   size = EncodeExtendedStatusDataItems(size, message_router_response, message);
 
@@ -488,12 +505,12 @@ int EncodeExtendedStatus(int size, EipUint8** message,
  * @return New size of the message buffer
  */
 int EncodeUnconnectedDataItemLength(
-    int size, CipMessageRouterResponse* message_router_response,
-    EipUint8** message) {
+  int size, CipMessageRouterResponse *message_router_response,
+  EipUint8 **message) {
   size += AddIntToMessage(
-      (EipUint16) (message_router_response->data_length + 4 /* TODO: Magic number */
-          + (2 * message_router_response->size_of_additional_status)),
-      message);
+    (EipUint16) ( message_router_response->data_length + 4  /* TODO: Magic number */
+                  + (2 * message_router_response->size_of_additional_status) ),
+    message);
   return size;
 }
 
@@ -505,10 +522,10 @@ int EncodeUnconnectedDataItemLength(
  * @param message Message frame to which the data is added
  */
 int EncodeMessageRouterResponseData(
-    int size, CipMessageRouterResponse* message_router_response,
-    EipUint8** message) {
+  int size, CipMessageRouterResponse *message_router_response,
+  EipUint8 **message) {
   for (int i = 0; i < message_router_response->data_length; i++) {
-    size += AddSintToMessage((message_router_response->data)[i], &*message);
+    size += AddSintToMessage( (message_router_response->data)[i], &*message );
   }
   return size;
 }
@@ -524,13 +541,14 @@ int EncodeMessageRouterResponseData(
  * @return New size of the message buffer
  */
 int EncodeSockaddrInfoItemTypeId(
-    int size, int item_type,
-    CipCommonPacketFormatData* common_packet_format_data_item,
-    EipUint8** message) {
+  int size,
+  int item_type,
+  CipCommonPacketFormatData *common_packet_format_data_item,
+  EipUint8 **message) {
   OPENER_ASSERT(item_type == 0 || item_type == 1);
   size += AddIntToMessage(
-      common_packet_format_data_item->address_info_item[item_type].type_id,
-      message);
+    common_packet_format_data_item->address_info_item[item_type].type_id,
+    message);
 
   return size;
 }
@@ -546,10 +564,13 @@ int EncodeSockaddrInfoItemTypeId(
  * @return New size of the message buffer
  */
 int EncodeSockaddrInfoLength(
-    int size, int item_type, CipCommonPacketFormatData* common_packet_format_data_item,
-    EipUint8** message) {
+  int size,
+  int item_type,
+  CipCommonPacketFormatData *common_packet_format_data_item,
+  EipUint8 **message) {
   size += AddIntToMessage(
-      common_packet_format_data_item->address_info_item[item_type].length, message);
+    common_packet_format_data_item->address_info_item[item_type].length,
+    message);
   return size;
 }
 
@@ -560,12 +581,12 @@ int EncodeSockaddrInfoLength(
  * @param common_packet_format_data_item pointer to CPF structure which has to be aligned into linear memory.
  * @param message		pointer to linear memory.
  *  @return length of reply in message in bytes
- * 			-1 .. error
+ *                      -1 .. error
  */
 int AssembleLinearMessage(
-    CipMessageRouterResponse *message_router_response,
-    CipCommonPacketFormatData *common_packet_format_data_item,
-    EipUint8 *message) {
+  CipMessageRouterResponse *message_router_response,
+  CipCommonPacketFormatData *common_packet_format_data_item,
+  EipUint8 *message) {
 
   size_t message_size = 0;
 
@@ -600,14 +621,14 @@ int AssembleLinearMessage(
   }
 
   /* process Data Item */
-  if ((common_packet_format_data_item->data_item.type_id
-      == kCipItemIdUnconnectedDataItem)
-      || (common_packet_format_data_item->data_item.type_id
-          == kCipItemIdConnectedDataItem)) {
+  if ( (common_packet_format_data_item->data_item.type_id
+        == kCipItemIdUnconnectedDataItem)
+       || (common_packet_format_data_item->data_item.type_id
+           == kCipItemIdConnectedDataItem) ) {
 
     if (message_router_response) {
       message_size = EncodeDataItemType(common_packet_format_data_item,
-                                         &message, message_size);
+                                        &message, message_size);
 
       if (common_packet_format_data_item->data_item.type_id
           == kCipItemIdConnectedDataItem) { /* Connected Item */
@@ -653,24 +674,24 @@ int AssembleLinearMessage(
    * devices which depend on CPF items to appear in the order of their
    * ID number */
   for (int type = kCipItemIdSocketAddressInfoOriginatorToTarget;
-      type <= kCipItemIdSocketAddressInfoTargetToOriginator; type++) {
+       type <= kCipItemIdSocketAddressInfoTargetToOriginator; type++) {
     for (int j = 0; j < 2; j++) {
       if (common_packet_format_data_item->address_info_item[j].type_id
           == type) {
         message_size = EncodeSockaddrInfoItemTypeId(
-            message_size, j, common_packet_format_data_item, &message);
+          message_size, j, common_packet_format_data_item, &message);
 
         message_size = EncodeSockaddrInfoLength(message_size, j,
                                                 common_packet_format_data_item,
                                                 &message);
 
         message_size += EncapsulateIpAddress(
-            common_packet_format_data_item->address_info_item[j].sin_port,
-            common_packet_format_data_item->address_info_item[j].sin_addr,
-            &message);
+          common_packet_format_data_item->address_info_item[j].sin_port,
+          common_packet_format_data_item->address_info_item[j].sin_addr,
+          &message);
 
         message_size += FillNextNMessageOctetsWithValueAndMoveToNextPosition(
-            0, 8, &message);
+          0, 8, &message);
         break;
       }
     }