ソースを参照

Merge branch 'develop' of github.com:EIPStackGroup/OpENer into develop

Martin Melik Merkumians 7 年 前
コミット
bab5812b85

+ 0 - 1
source/src/cip/appcontype.c

@@ -215,7 +215,6 @@ CipConnectionObject *GetExclusiveOwnerConnection(
         }
       }
       return &(g_exlusive_owner_connections[i].connection_data);
-      break;
     }
   }
   return NULL;

+ 39 - 40
source/src/cip/cipcommon.c

@@ -883,7 +883,6 @@ int DecodePaddedEPath(CipEpath *epath,
       default:
         OPENER_TRACE_ERR("wrong path requested\n");
         return kEipStatusError;
-        break;
     }
   }
 
@@ -907,136 +906,136 @@ size_t CalculateIndex(EipUint16 attribute_number) {
 }
 
 size_t GetSizeOfAttribute(const CipAttributeStruct *const attribute_struct) {
+  size_t data_type_size = 0;
   switch (attribute_struct->type) {
-
     case (kCipBool):
-      return sizeof(CipBool);
+    data_type_size = sizeof(CipBool);
       break;
     case (kCipSint):
-      return sizeof(CipSint);
+    data_type_size = sizeof(CipSint);
       break;
     case (kCipInt):
-      return sizeof(CipInt);
+    data_type_size = sizeof(CipInt);
       break;
     case (kCipDint):
-      return sizeof(CipDint);
+    data_type_size = sizeof(CipDint);
       break;
     case (kCipUsint):
-      return sizeof(CipUsint);
+    data_type_size =sizeof(CipUsint);
       break;
     case (kCipUint):
-      return sizeof(CipUint);
+    data_type_size =sizeof(CipUint);
       break;
     case (kCipUdint):
-      return sizeof(CipUdint);
+    data_type_size =sizeof(CipUdint);
       break;
     case (kCipReal):
-      return sizeof(CipReal);
+    data_type_size =sizeof(CipReal);
       break;
+#ifdef OPENER_SUPPORT_64BIT_DATATYPES
     case (kCipLreal):
-      return sizeof(CipLreal);
+    data_type_size = sizeof(CipLreal);
       break;
-#ifdef OPENER_SUPPORT_64BIT_DATATYPES
     case (kCipUlint):
-      return sizeof(CipUlint);
+    data_type_size = sizeof(CipUlint);
       break;
     case (kCipLint):
-      return sizeof(CipLint);
+    data_type_size = sizeof(CipLint);
       break;
     case (kCipLword):
-      return sizeof(CipLword);
+    data_type_size = sizeof(CipLword);
       break;
     case (kCipLtime):
-      return sizeof(CipLint);
+    data_type_size = sizeof(CipLint);
       break;
 #endif /* OPENER_SUPPORT_64BIT_DATATYPES */
 
     case (kCipStime):
-      return sizeof(CipDint);
+    data_type_size = sizeof(CipDint);
       break;
     case (kCipDate):
-      return sizeof(CipUint);
+    data_type_size = sizeof(CipUint);
       break;
     case (kCipTimeOfDay):
-      return sizeof(CipUdint);
+    data_type_size = sizeof(CipUdint);
       break;
     case (kCipDateAndTime):
-      return sizeof(CipUdint) + sizeof(CipUint);
+    data_type_size = sizeof(CipUdint) + sizeof(CipUint);
       break;
     case (kCipString): {
       CipString *data = (CipString *) attribute_struct->data;
-      return sizeof(CipUint) + (data->length) * sizeof(CipOctet);
+      data_type_size = sizeof(CipUint) + (data->length) * sizeof(CipOctet);
     }
     break;
     case (kCipByte):
-      return sizeof(CipByte);
+    data_type_size = sizeof(CipByte);
       break;
     case (kCipWord):
-      return sizeof(CipWord);
+    data_type_size = sizeof(CipWord);
       break;
     case (kCipDword):
-      return sizeof(CipDword);
+    data_type_size = sizeof(CipDword);
       break;
     case (kCipString2): {
       CipString *data = (CipString *) attribute_struct->data;
-      return sizeof(CipUint) + 2 * (data->length) * sizeof(CipOctet);
+      data_type_size = sizeof(CipUint) + 2 * (data->length) * sizeof(CipOctet);
     }
     break;
     case (kCipFtime):
-      return sizeof(CipDint);
+    data_type_size = sizeof(CipDint);
       break;
     case (kCipItime):
-      return sizeof(CipInt);
+    data_type_size = sizeof(CipInt);
       break;
     case (kCipStringN): {
       CipStringN *data = (CipStringN *) attribute_struct->data;
-      return sizeof(CipUint) + sizeof(CipUint)
+      data_type_size = sizeof(CipUint) + sizeof(CipUint)
              + (size_t) (data->length) * (size_t) (data->size);
     }
     break;
     case (kCipShortString): {
       CipShortString *data = (CipShortString *) attribute_struct->data;
-      return sizeof(CipUsint) + (data->length) * sizeof(CipOctet);
+      data_type_size = sizeof(CipUsint) + (data->length) * sizeof(CipOctet);
     }
     break;
     case (kCipTime):
-      return sizeof(CipDint);
+    data_type_size = sizeof(CipDint);
       break;
     case (kCipEpath): {
       CipEpath *data = (CipEpath *) attribute_struct->data;
-      return 2 * (data->path_size);
+      data_type_size = 2 * (data->path_size);
     }
     break;
     case (kCipEngUnit):
-      return sizeof(CipUint);
+    data_type_size = sizeof(CipUint);
       break;
     case (kCipUsintUsint):
-      return 2 * sizeof(CipUsint);
+    data_type_size = 2 * sizeof(CipUsint);
       break;
     case (kCipUdintUdintUdintUdintUdintString): {
       CipTcpIpNetworkInterfaceConfiguration *data =
         (CipTcpIpNetworkInterfaceConfiguration *) attribute_struct->data;
-      return 5 * sizeof(CipUdint) + sizeof(CipUint)
+      data_type_size = 5 * sizeof(CipUdint) + sizeof(CipUint)
              + (data->domain_name.length) * sizeof(EipByte);
     }
     break;
     case (kCip6Usint):
-      return 6 * sizeof(CipUsint);
+    data_type_size = 6 * sizeof(CipUsint);
       break;
     case (kCipMemberList):
-      return 0;
+    data_type_size = 0;
       break;
     case (kCipByteArray): {
       CipByteArray *data = (CipByteArray *) attribute_struct->data;
-      return sizeof(CipUint) + (data->length) * sizeof(CipOctet);
+      data_type_size = sizeof(CipUint) + (data->length) * sizeof(CipOctet);
     }
     break;
     case (kInternalUint6):
-      return 6 * sizeof(CipUint);
+    data_type_size = 6 * sizeof(CipUint);
       break;
     default:
-      return 0;
+      data_type_size = 0;
       break;
-
   }
+  return data_type_size;
 }

+ 2 - 0
source/src/cip/cipcommon.h

@@ -86,5 +86,7 @@ EipStatus GetAttributeAll(CipInstance *instance,
  */
 int DecodePaddedEPath(CipEpath *epath,
                       const EipUint8 **message);
+
 size_t GetSizeOfAttribute(const CipAttributeStruct *const attribute_struct);
+
 #endif /* OPENER_CIPCOMMON_H_ */

+ 0 - 1
source/src/cip/cipconnectionmanager.c

@@ -1370,7 +1370,6 @@ EipUint8 ParseConnectionPath(
             *extended_error = connection_path_size - remaining_path; /*offset in 16Bit words where within the connection path the error happend*/
             return
               kConnectionManagerGeneralStatusPathSegmentErrorInUnconnectedSend;
-            break;
         }
       }
     }

+ 44 - 36
source/src/cip/cipconnectionobject.c

@@ -174,31 +174,34 @@ void ConnectionObjectInitializeFromMessage(
 
 ConnectionObjectState ConnectionObjectGetState(
   const CipConnectionObject *const connection_object) {
+  ConnectionObjectState new_state = kConnectionObjectStateInvalid;
   switch (connection_object->state) {
     case CIP_CONNECTION_OBJECT_STATE_NON_EXISTENT:
-      return kConnectionObjectStateNonExistent;
+      new_state = kConnectionObjectStateNonExistent;
       break;
     case CIP_CONNECTION_OBJECT_STATE_CONFIGURING:
-      return kConnectionObjectStateConfiguring;
+      new_state = kConnectionObjectStateConfiguring;
       break;
     case CIP_CONNECTION_OBJECT_STATE_WAITING_FOR_CONNECTION_ID:
-      return kConnectionObjectStateWaitingForConnectionID;
+      new_state = kConnectionObjectStateWaitingForConnectionID;
       break;
     case CIP_CONNECTION_OBJECT_STATE_ESTABLISHED:
-      return kConnectionObjectStateEstablished;
+      new_state = kConnectionObjectStateEstablished;
       break;
     case CIP_CONNECTION_OBJECT_STATE_TIMEOUT:
-      return kConnectionObjectStateTimedOut;
+      new_state = kConnectionObjectStateTimedOut;
       break;
     case CIP_CONNECTION_OBJECT_STATE_DEFERRED_DELETE:
-      return kConnectionObjectStateDeferredDelete;
+      new_state = kConnectionObjectStateDeferredDelete;
       break;
     case CIP_CONNECTION_OBJECT_STATE_CLOSING:
-      return kConnectionObjectStateClosing;
+      new_state = kConnectionObjectStateClosing;
       break;
     default:
-      return kConnectionObjectStateInvalid;
+      new_state = kConnectionObjectStateInvalid;
+      break;
   }
+  return new_state;
 }
 
 void ConnectionObjectSetState(CipConnectionObject *const connection_object,
@@ -264,25 +267,26 @@ void ConnectionObjectSetInstanceType(
 
 CipUsint ConnectionObjectGetInstanceTypeForAttribute(
   const CipConnectionObject *const connection_object) {
+  CipUsint instance_type = kConnectionObjectInstanceTypeInvalid;
   switch (connection_object->instance_type) {
     case kConnectionObjectInstanceTypeExplicitMessaging:
-      return CIP_CONNECTION_OBJECT_INSTANCE_TYPE_EXPLICIT_MESSAGING;
+      instance_type = CIP_CONNECTION_OBJECT_INSTANCE_TYPE_EXPLICIT_MESSAGING;
       break;
     case kConnectionObjectInstanceTypeIO:
     case kConnectionObjectInstanceTypeIOExclusiveOwner:
     case kConnectionObjectInstanceTypeIOInputOnly:
     case kConnectionObjectInstanceTypeIOListenOnly:
-      return CIP_CONNECTION_OBJECT_INSTANCE_TYPE_IO;
+      instance_type = CIP_CONNECTION_OBJECT_INSTANCE_TYPE_IO;
       break;
     case kConnectionObjectInstanceTypeCipBridged:
-      return CIP_CONNECTION_OBJECT_INSTANCE_TYPE_CIP_BRIDGED;
+      instance_type = CIP_CONNECTION_OBJECT_INSTANCE_TYPE_CIP_BRIDGED;
       break;
     default:
-      OPENER_ASSERT(false)
+      OPENER_ASSERT(false) /* This is a fault case */
+      instance_type = kConnectionObjectInstanceTypeInvalid;
       break;
   }
-  OPENER_ASSERT(false) //We should never come to this point
-  return 255;
+  return instance_type;
 }
 
 bool ConnectionObjectIsTypeIOConnection(
@@ -313,50 +317,53 @@ ConnectionObjectTransportClassTriggerProductionTrigger
 ConnectionObjectGetTransportClassTriggerProductionTrigger(
   const CipConnectionObject *const connection_object) {
   const CipByte kTransportClassTriggerProductionTriggerMask = 0x70;
+
+  ConnectionObjectTransportClassTriggerProductionTrigger production_trigger = kConnectionObjectTransportClassTriggerProductionTriggerInvalid;
   switch ( (connection_object->transport_class_trigger) &
            kTransportClassTriggerProductionTriggerMask ) {
     case
       CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_PRODUCTION_TRIGGER_CYCLIC:
-      return kConnectionObjectTransportClassTriggerProductionTriggerCyclic;
+        production_trigger = kConnectionObjectTransportClassTriggerProductionTriggerCyclic;
       break;
     case
-      CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_PRODUCTION_TRIGGER_CHANGE_OF_STATE
-      :
-      return
-        kConnectionObjectTransportClassTriggerProductionTriggerChangeOfState;
+      CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_PRODUCTION_TRIGGER_CHANGE_OF_STATE:
+        production_trigger = kConnectionObjectTransportClassTriggerProductionTriggerChangeOfState;
       break;
     case
-      CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_PRODUCTION_TRIGGER_APPLICATION_OBJECT
-      :
-      return
-        kConnectionObjectTransportClassTriggerProductionTriggerApplicationObject;
+      CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_PRODUCTION_TRIGGER_APPLICATION_OBJECT:
+        production_trigger = kConnectionObjectTransportClassTriggerProductionTriggerApplicationObject;
       break;
     default:
-      return kConnectionObjectTransportClassTriggerProductionTriggerInvalid;
+      production_trigger = kConnectionObjectTransportClassTriggerProductionTriggerInvalid;
+      break;
   }
+  return production_trigger;
 }
 
 ConnectionObjectTransportClassTriggerTransportClass
 ConnectionObjectGetTransportClassTriggerTransportClass(
   const CipConnectionObject *const connection_object) {
   const CipByte kTransportClassTriggerTransportClassMask = 0x0F;
+
+  ConnectionObjectTransportClassTriggerTransportClass transport_class_trigger = kConnectionObjectTransportClassTriggerTransportClassInvalid;
   switch ( (connection_object->transport_class_trigger) &
            kTransportClassTriggerTransportClassMask ) {
     case CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_TRANSPORT_CLASS_0:
-      return kConnectionObjectTransportClassTriggerTransportClass0;
+      transport_class_trigger = kConnectionObjectTransportClassTriggerTransportClass0;
       break;
     case CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_TRANSPORT_CLASS_1:
-      return kConnectionObjectTransportClassTriggerTransportClass1;
+      transport_class_trigger = kConnectionObjectTransportClassTriggerTransportClass1;
       break;
     case CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_TRANSPORT_CLASS_2:
-      return kConnectionObjectTransportClassTriggerTransportClass2;
+      transport_class_trigger = kConnectionObjectTransportClassTriggerTransportClass2;
       break;
     case CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_TRANSPORT_CLASS_3:
-      return kConnectionObjectTransportClassTriggerTransportClass3;
+      transport_class_trigger = kConnectionObjectTransportClassTriggerTransportClass3;
       break;
     default:
-      return kConnectionObjectTransportClassTriggerTransportClassInvalid;
+      transport_class_trigger = kConnectionObjectTransportClassTriggerTransportClassInvalid;
   }
+  return transport_class_trigger;
 }
 
 CipUint ConnectionObjectGetProducedConnectionSize(
@@ -378,8 +385,7 @@ CipUint ConnectionObjectGetConsumedConnectionSize(
 
 void ConnectionObjectSetConsumedConnectionSize(
   CipConnectionObject *const connection_object,
-  const CipUint
-  consumed_connection_size) {
+  const CipUint consumed_connection_size) {
   connection_object->consumed_connection_size = consumed_connection_size;
 }
 
@@ -446,23 +452,25 @@ void ConnectionObjectSetCipConsumedConnectionID(
 
 ConnectionObjectWatchdogTimeoutAction ConnectionObjectGetWatchdogTimeoutAction(
   const CipConnectionObject *const connection_object) {
+  ConnectionObjectWatchdogTimeoutAction timeout_action = kConnectionObjectWatchdogTimeoutActionInvalid;
   switch (connection_object->watchdog_timeout_action) {
     case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_TRANSITION_TO_TIMED_OUT:
-      return kConnectionObjectWatchdogTimeoutActionTransitionToTimedOut;
+      timeout_action = kConnectionObjectWatchdogTimeoutActionTransitionToTimedOut;
       break;
     case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_AUTO_DELETE:
-      return kConnectionObjectWatchdogTimeoutActionAutoDelete;
+      timeout_action = kConnectionObjectWatchdogTimeoutActionAutoDelete;
       break;
     case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_AUTO_RESET:
-      return kConnectionObjectWatchdogTimeoutActionAutoReset;
+      timeout_action = kConnectionObjectWatchdogTimeoutActionAutoReset;
       break;
     case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_DEFERRED_DELETE:
-      return kConnectionObjectWatchdogTimeoutActionDeferredDelete;
+      timeout_action = kConnectionObjectWatchdogTimeoutActionDeferredDelete;
       break;
     default:
-      return kConnectionObjectWatchdogTimeoutActionInvalid;
+      timeout_action = kConnectionObjectWatchdogTimeoutActionInvalid;
       break;
   }
+  return timeout_action;
 }
 
 void ConnectionObjectSetWatchdogTimeoutAction(

+ 19 - 21
source/src/cip/cipepath.c

@@ -114,28 +114,28 @@ void SetPathSegmentType(SegmentType segment_type,
                         unsigned char *const cip_path) {
   switch (segment_type) {
     case kSegmentTypePortSegment:
-      *cip_path |= SEGMENT_TYPE_PORT_SEGMENT;
+      *cip_path = SEGMENT_TYPE_PORT_SEGMENT;
       break;
     case kSegmentTypeLogicalSegment:
-      *cip_path |= SEGMENT_TYPE_LOGICAL_SEGMENT;
+      *cip_path = SEGMENT_TYPE_LOGICAL_SEGMENT;
       break;
     case kSegmentTypeNetworkSegment:
-      *cip_path |= SEGMENT_TYPE_NETWORK_SEGMENT;
+      *cip_path = SEGMENT_TYPE_NETWORK_SEGMENT;
       break;
     case kSegmentTypeSymbolicSegment:
-      *cip_path |= SEGMENT_TYPE_SYMBOLIC_SEGMENT;
+      *cip_path = SEGMENT_TYPE_SYMBOLIC_SEGMENT;
       break;
     case kSegmentTypeDataSegment:
-      *cip_path |= SEGMENT_TYPE_DATA_SEGMENT;
+      *cip_path = SEGMENT_TYPE_DATA_SEGMENT;
       break;
     case kSegmentTypeDataTypeConstructed:
-      *cip_path |= SEGMENT_TYPE_DATA_TYPE_CONSTRUCTED;
+      *cip_path = SEGMENT_TYPE_DATA_TYPE_CONSTRUCTED;
       break;
     case kSegmentTypeDataTypeElementary:
-      *cip_path |= SEGMENT_TYPE_DATA_TYPE_ELEMENTARTY;
+      *cip_path = SEGMENT_TYPE_DATA_TYPE_ELEMENTARTY;
       break;
     case kSegmentTypeReserved:
-      *cip_path |= SEGMENT_TYPE_SEGMENT_RESERVED;
+      *cip_path = SEGMENT_TYPE_SEGMENT_RESERVED;
       break;
     default:
       OPENER_ASSERT(
@@ -356,25 +356,24 @@ const CipDword CipEpathGetLogicalValue(const EipUint8 **message) {
 size_t CipEpathSetLogicalValue(const CipDword logical_value,
                                const LogicalSegmentLogicalFormat logical_format,
                                CipOctet **message) {
+  size_t written_bytes = 0;
   switch(logical_value) {
     case kLogicalSegmentLogicalFormatEightBit:
-      AddSintToMessage(logical_value, message);
-      return 1; break;
+      written_bytes = AddSintToMessage(logical_value, message);
+      break;
     case kLogicalSegmentLogicalFormatSixteenBit:
-      MoveMessageNOctets(1, (const CipOctet **)message);
-      AddIntToMessage(logical_value, message);
-      return 3; break;
+      written_bytes = MoveMessageNOctets(1, (const CipOctet **)message); /* Needed for padding */
+      written_bytes += AddIntToMessage(logical_value, message);
+      break;
     case kLogicalSegmentLogicalFormatThirtyTwoBit:
-      MoveMessageNOctets(1,(const CipOctet **)message);
-      AddDintToMessage(logical_value, message);
-      return 5; break;
-
+      written_bytes = MoveMessageNOctets(1,(const CipOctet **)message); /* Needed for padding */
+      written_bytes += AddDintToMessage(logical_value, message);
+      break;
     default:
       OPENER_ASSERT(false) /* This should never happen! */
-      return 0;
+      written_bytes = 0;
   }
-  OPENER_ASSERT(false) /* This should never happen! */
-  return 0;
+  return written_bytes;
 }
 
 LogicalSegmentExtendedLogicalType GetPathLogicalSegmentExtendedLogicalType(
@@ -421,7 +420,6 @@ GetPathLogicalSegmentSpecialTypeLogicalType(const unsigned char *const cip_path)
       result = kLogicalSegmentSpecialTypeLogicalFormatElectronicKey; break;
     default: result = kLogicalSegmentSpecialTypeLogicalFormatReserved; break;
   }
-
   return result;
 }
 

+ 13 - 16
source/src/cip/cipqos.c

@@ -89,32 +89,29 @@ EipStatus SetAttributeSingleQoS(
 }
 
 CipUsint GetPriorityForSocket(ConnectionObjectPriority priority) {
+
+  CipUsint priority_value = dscp_explicit;
   switch (priority) {
-    case kConnectionObjectPriorityLow: {
-      return dscp_low;
+    case kConnectionObjectPriorityLow:
+      priority_value = dscp_low;
       break;
-    }
-    case kConnectionObjectPriorityHigh: {
-      return dscp_high;
+    case kConnectionObjectPriorityHigh:
+      priority_value = dscp_high;
       break;
-    }
-    case kConnectionObjectPriorityScheduled: {
-      return dscp_scheduled;
+    case kConnectionObjectPriorityScheduled:
+      priority_value = dscp_scheduled;
       break;
-    }
-    case kConnectionObjectPriorityUrgent: {
-      return dscp_urgent;
+    case kConnectionObjectPriorityUrgent:
+      priority_value = dscp_urgent;
       break;
-    }
-    default: {
-      return dscp_explicit;
+    default:
+      priority_value = dscp_explicit;
       break;
-    }
   }
+  return priority_value;
 }
 
 void InitializeCipQos(CipClass *class) {
-
   CipClass *meta_class = class->class_instance.cip_class;
 }
 

+ 2 - 4
source/src/enet_encap/cpf.c

@@ -539,16 +539,14 @@ int EncodeExtendedStatusLength(
  *
  * @return New size of the message buffer
  */
-int EncodeExtendedStatusDataItems(
+size_t EncodeExtendedStatusDataItems(
   const CipMessageRouterResponse *const message_router_response,
   ENIPMessage *const outgoing_message) {
-  for (size_t i = 0; i < message_router_response->size_of_additional_status;
-       i++) {
+  for (size_t i = 0; i < message_router_response->size_of_additional_status && i < MAX_SIZE_OF_ADD_STATUS;i++) {
     outgoing_message->used_message_length += AddIntToMessage(
       message_router_response->additional_status[i],
       &outgoing_message->current_message_position);
   }
-
   return outgoing_message->used_message_length;
 }
 

+ 1 - 0
source/tests/OpENerTests.h

@@ -3,6 +3,7 @@
 IMPORT_TEST_GROUP(RandomClass);
 IMPORT_TEST_GROUP(XorShiftRandom);
 IMPORT_TEST_GROUP(EndianConversion);
+IMPORT_TEST_GROUP(CipCommon);
 IMPORT_TEST_GROUP(CipEpath);
 IMPORT_TEST_GROUP(CipElectronicKey);
 IMPORT_TEST_GROUP(CipConnectionManager);

+ 1 - 1
source/tests/cip/CMakeLists.txt

@@ -8,7 +8,7 @@ opener_common_includes()
 #######################################
 opener_platform_support("INCLUDES")
 
-set( CipTestSrc cipepathtest.cpp cipelectronickeytest.cpp cipconnectionmanagertest.cpp cipconnectionobjecttest.cpp )
+set( CipTestSrc cipepathtest.cpp cipelectronickeytest.cpp cipconnectionmanagertest.cpp cipconnectionobjecttest.cpp cipcommontests.cpp)
 
 include_directories( ${SRC_DIR}/cip )
 

+ 249 - 0
source/tests/cip/cipcommontests.cpp

@@ -0,0 +1,249 @@
+/*******************************************************************************
+ * Copyright (c) 2018, Rockwell Automation, Inc.
+ * All rights reserved.
+ *
+ ******************************************************************************/
+
+#include <CppUTest/TestHarness.h>
+#include <stdint.h>
+#include <string.h>
+
+extern "C" {
+
+#include "cipcommon.h"
+
+}
+
+TEST_GROUP(CipCommon) {
+
+};
+
+TEST(CipCommon, GetSizeOfAttributeCipBool) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipBool;
+  CHECK_EQUAL(sizeof(CipBool), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipSint) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipSint;
+  CHECK_EQUAL(sizeof(CipSint), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipInt) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipInt;
+  CHECK_EQUAL(sizeof(CipInt), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipDint) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipDint;
+  CHECK_EQUAL(sizeof(CipDint), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipUsint) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipUsint;
+  CHECK_EQUAL(sizeof(CipUsint), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipUint) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipUint;
+  CHECK_EQUAL(sizeof(CipUint), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipUdint) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipUdint;
+  CHECK_EQUAL(sizeof(CipUdint), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipReal) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipReal;
+  CHECK_EQUAL(sizeof(CipReal), GetSizeOfAttribute(&attribute));
+}
+
+#ifdef OPENER_SUPPORT_64BIT_DATATYPES
+TEST(CipCommon, GetSizeOfAttributeCipLreal) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipLreal;
+  CHECK_EQUAL(sizeof(CipLreal), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipUlint) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipUlint;
+  CHECK_EQUAL(sizeof(CipUlint), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipLint) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipLint;
+  CHECK_EQUAL(sizeof(CipLint), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipLword) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipLword;
+  CHECK_EQUAL(sizeof(CipLword), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipLtime) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipLtime;
+  CHECK_EQUAL(sizeof(CipLint), GetSizeOfAttribute(&attribute));
+}
+#endif /* OPENER_SUPPORT_64BIT_DATATYPES */
+
+TEST(CipCommon, GetSizeOfAttributeCipStime) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipStime;
+  CHECK_EQUAL(sizeof(CipDint), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipData) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipDate;
+  CHECK_EQUAL(sizeof(CipUint), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipTimeOfDay) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipTimeOfDay;
+  CHECK_EQUAL(sizeof(CipUdint), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipDateAndTime) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipDateAndTime;
+  CHECK_EQUAL(sizeof(CipUdint) + sizeof(CipUint), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipString) {
+  CipAttributeStruct attribute;
+  char demo_string[] = "Hello World!";
+  CipString test_string = { .length = sizeof(demo_string), .string = (EipByte*)demo_string };
+  attribute.type = kCipString;
+  attribute.data = (void*)&test_string;
+
+  CHECK_EQUAL(sizeof(test_string.length) + test_string.length * sizeof(CipOctet), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipByte) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipByte;
+  CHECK_EQUAL(sizeof(CipByte), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipWord) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipWord;
+  CHECK_EQUAL(sizeof(CipWord), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipDword) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipDword;
+  CHECK_EQUAL(sizeof(CipDword), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipString2) {
+  CipAttributeStruct attribute;
+  char demo_string[] = "H e l l o   W o r l d !"; /* \0 termination symbol is seen as second byte for ! */
+  CipString test_string = { .length = sizeof(demo_string)/2, .string = (EipByte*)demo_string };
+  attribute.type = kCipString;
+  attribute.data = (void*)&test_string;
+
+  CHECK_EQUAL(sizeof(test_string.length) + test_string.length * sizeof(CipOctet), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipFtime) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipFtime;
+  CHECK_EQUAL(sizeof(CipDint), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipItime) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipItime;
+  CHECK_EQUAL(sizeof(CipInt), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipStringN){
+  CipAttributeStruct attribute;
+  char demo_string[] = "Hello World!";
+  CipStringN test_string = { .size = 1, .length = sizeof(demo_string), .string = (EipByte*) demo_string };
+  attribute.type = kCipStringN;
+  attribute.data = (void*) &test_string;
+
+  CHECK_EQUAL(sizeof(test_string.size) + sizeof(test_string.length) + test_string.size * test_string.length * sizeof(CipOctet), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipTime) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipTime;
+  CHECK_EQUAL(sizeof(CipDint), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipEpath) {
+  /* TODO: Fix me */
+  CipAttributeStruct attribute;
+  attribute.type = kCipItime;
+  CHECK_EQUAL(sizeof(CipInt), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipEngUnit) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipEngUnit;
+  CHECK_EQUAL(sizeof(CipUint), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipUsintUsint) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipUsintUsint;
+  CHECK_EQUAL(2 * sizeof(CipUsint), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipUdintUdintUdintUdintUdintString) {
+  CipTcpIpNetworkInterfaceConfiguration config;
+  char domain_name[] = "www.github.com/EIPStackGroup/OpENer";
+  config.domain_name.length = sizeof(domain_name);
+  config.domain_name.string = (EipByte*)domain_name;
+  CipAttributeStruct attribute;
+  attribute.type = kCipUdintUdintUdintUdintUdintString;
+  attribute.data = (void*)&config;
+  CHECK_EQUAL(5 * sizeof(CipUdint) + sizeof(CipUint) + sizeof(domain_name) * sizeof(EipByte), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCip6Usint) {
+  CipAttributeStruct attribute;
+  attribute.type = kCip6Usint;
+  CHECK_EQUAL(6 * sizeof(CipUsint), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipMemberList) {
+  CipAttributeStruct attribute;
+  attribute.type = kCipMemberList;
+  CHECK_EQUAL(0, GetSizeOfAttribute(&attribute));
+  /* Currently not implemented */
+}
+
+TEST(CipCommon, GetSizeOfAttributeCipByteArray) {
+  CipByte data_array[] = {1,2,3,4,5,6,7,8,9};
+  CipByteArray array;
+  array.data = (EipByte*)&data_array;
+  array.length = sizeof(data_array);
+  CipAttributeStruct attribute;
+  attribute.type = kCipByteArray;
+  attribute.data = (void*)&array;
+  CHECK_EQUAL(sizeof(CipUint) + array.length * sizeof(CipByte), GetSizeOfAttribute(&attribute));
+}
+
+TEST(CipCommon, GetSizeOfAttributeInternalUint6) {
+  CipAttributeStruct attribute;
+  attribute.type = kInternalUint6;
+  CHECK_EQUAL(6 * sizeof(CipUint), GetSizeOfAttribute(&attribute));
+}

+ 53 - 8
source/tests/cip/cipconnectionobjecttest.cpp

@@ -18,62 +18,107 @@ TEST_GROUP(CipConnectionObject) {
 
 };
 
-TEST(CipConnectionObject, StateNonExistent) {
+/* Get State tests */
+TEST(CipConnectionObject, GetStateNonExistent) {
   CipConnectionObject connection_object = { 0 };
   connection_object.state = 0;
   ConnectionObjectState state = ConnectionObjectGetState(&connection_object);
   CHECK_EQUAL(kConnectionObjectStateNonExistent, state);
 }
 
-TEST(CipConnectionObject, StateConfiguring) {
+TEST(CipConnectionObject, GetStateConfiguring) {
   CipConnectionObject connection_object = { 0 };
   connection_object.state = 1;
   ConnectionObjectState state = ConnectionObjectGetState(&connection_object);
   CHECK_EQUAL(kConnectionObjectStateConfiguring, state);
 }
 
-TEST(CipConnectionObject, StateWaitingForConnectionID) {
+TEST(CipConnectionObject, GetStateWaitingForConnectionID) {
   CipConnectionObject connection_object = { 0 };
   connection_object.state = 2;
   ConnectionObjectState state = ConnectionObjectGetState(&connection_object);
   CHECK_EQUAL(kConnectionObjectStateWaitingForConnectionID, state);
 }
 
-TEST(CipConnectionObject, StateEstablished) {
+TEST(CipConnectionObject, GetStateEstablished) {
   CipConnectionObject connection_object = { 0 };
   connection_object.state = 3;
   ConnectionObjectState state = ConnectionObjectGetState(&connection_object);
   CHECK_EQUAL(kConnectionObjectStateEstablished, state);
 }
 
-TEST(CipConnectionObject, StateTimedOut) {
+TEST(CipConnectionObject, GetStateTimedOut) {
   CipConnectionObject connection_object = { 0 };
   connection_object.state = 4;
   ConnectionObjectState state = ConnectionObjectGetState(&connection_object);
   CHECK_EQUAL(kConnectionObjectStateTimedOut, state);
 }
 
-TEST(CipConnectionObject, StateDeferredDelete) {
+TEST(CipConnectionObject, GetStateDeferredDelete) {
   CipConnectionObject connection_object = { 0 };
   connection_object.state = 5;
   ConnectionObjectState state = ConnectionObjectGetState(&connection_object);
   CHECK_EQUAL(kConnectionObjectStateDeferredDelete, state);
 }
 
-TEST(CipConnectionObject, StateClosing) {
+TEST(CipConnectionObject, GetStateClosing) {
   CipConnectionObject connection_object = { 0 };
   connection_object.state = 6;
   ConnectionObjectState state = ConnectionObjectGetState(&connection_object);
   CHECK_EQUAL(kConnectionObjectStateClosing, state);
 }
 
-TEST(CipConnectionObject, StateInvalid) {
+TEST(CipConnectionObject, GetStateInvalid) {
   CipConnectionObject connection_object = { 0 };
   connection_object.state = 7;
   ConnectionObjectState state = ConnectionObjectGetState(&connection_object);
   CHECK_EQUAL(kConnectionObjectStateInvalid, state);
 }
 
+/* Set state tests */
+TEST(CipConnectionObject, SetStateNonExistent) {
+  CipConnectionObject connection_object = { 0 };
+  ConnectionObjectSetState(&connection_object, kConnectionObjectStateNonExistent);
+  CHECK_EQUAL(0, connection_object.state);
+}
+
+TEST(CipConnectionObject, SetStateConfiguring) {
+  CipConnectionObject connection_object = { 0 };
+  ConnectionObjectSetState(&connection_object, kConnectionObjectStateConfiguring);
+  CHECK_EQUAL(1, connection_object.state);
+}
+
+TEST(CipConnectionObject, SetStateWaitingForConnectionID) {
+  CipConnectionObject connection_object = { 0 };
+  ConnectionObjectSetState(&connection_object, kConnectionObjectStateWaitingForConnectionID);
+  CHECK_EQUAL(2, connection_object.state);
+}
+
+TEST(CipConnectionObject, SetStateEstablished) {
+  CipConnectionObject connection_object = { 0 };
+  ConnectionObjectSetState(&connection_object, kConnectionObjectStateEstablished);
+  CHECK_EQUAL(3, connection_object.state);
+}
+
+TEST(CipConnectionObject, SetStateTimedOut) {
+  CipConnectionObject connection_object = { 0 };
+  ConnectionObjectSetState(&connection_object, kConnectionObjectStateTimedOut);
+  CHECK_EQUAL(4, connection_object.state);
+}
+
+TEST(CipConnectionObject, SetStateDeferredDelete) {
+  CipConnectionObject connection_object = { 0 };
+  ConnectionObjectSetState(&connection_object, kConnectionObjectStateDeferredDelete);
+  CHECK_EQUAL(5, connection_object.state);
+}
+
+TEST(CipConnectionObject, SetStateClosing) {
+  CipConnectionObject connection_object = { 0 };
+  ConnectionObjectSetState(&connection_object, kConnectionObjectStateClosing);
+  CHECK_EQUAL(6, connection_object.state);
+}
+
+/* Get InstanceType tests */
 TEST(CipConnectionObject, InstanceTypeIExplicitMessaging) {
   CipConnectionObject connection_object = { 0 };
   connection_object.instance_type =

+ 48 - 0
source/tests/cip/cipepathtest.cpp

@@ -66,6 +66,54 @@ TEST(CipEpath, GetSegmentTypeReserved) {
   SegmentType segment_type = GetPathSegmentType(message);
   CHECK_EQUAL(kSegmentTypeReserved, segment_type);
 }
+/* Set Segment Type tests*/
+TEST(CipEpath, SetSegmentTypePortSegment) {
+  unsigned char message[] = {0xFF};
+  SetPathSegmentType(kSegmentTypePortSegment, message);
+  CHECK_EQUAL(0x00, message[0]);
+}
+
+TEST(CipEpath, SetSegmentTypeLogicalSegment) {
+  unsigned char message[] = {0xFF};
+  SetPathSegmentType(kSegmentTypeLogicalSegment, message);
+  CHECK_EQUAL(0x20, message[0]);
+}
+
+TEST(CipEpath, SetSegmentTypeNetworkSegment) {
+  unsigned char message[] = {0xFF};
+  SetPathSegmentType(kSegmentTypeNetworkSegment, message);
+  CHECK_EQUAL(0x40, message[0]);
+}
+
+TEST(CipEpath, SetSegmentTypeSymbolicSegment) {
+  unsigned char message[] = {0xFF};
+  SetPathSegmentType(kSegmentTypeSymbolicSegment, message);
+  CHECK_EQUAL(0x60, message[0]);
+}
+
+TEST(CipEpath, SetSegmentTypeDataSegment) {
+  unsigned char message[] = {0xFF};
+  SetPathSegmentType(kSegmentTypeDataSegment, message);
+  CHECK_EQUAL(0x80, message[0]);
+}
+
+TEST(CipEpath, SetSegmentTypeDataTypeConstructed) {
+  unsigned char message[] = {0xFF};
+  SetPathSegmentType(kSegmentTypeDataTypeConstructed, message);
+  CHECK_EQUAL(0xA0, message[0]);
+}
+
+TEST(CipEpath, SetSegmentTypeDataTypeElementary) {
+  unsigned char message[] = {0xFF};
+  SetPathSegmentType(kSegmentTypeDataTypeElementary, message);
+  CHECK_EQUAL(0xC0, message[0]);
+}
+
+TEST(CipEpath, SetSegmentTypeReserved) {
+  unsigned char message[] = {0xFF};
+  SetPathSegmentType(kSegmentTypeReserved, message);
+  CHECK_EQUAL(0xE0, message[0]);
+}
 
 /** Port segment tests **/
 TEST(CipEpath, GetPortSegmentExtendedAddressSizeTrue) {