Forráskód Böngészése

Merge pull request #268 from EIPStackGroup/Issue_257

Closes #257
Martin Melik-Merkumians 6 éve
szülő
commit
ec4e88dd99

+ 42 - 1
source/CMakeLists.txt

@@ -45,7 +45,10 @@ if(OPENER_CONSUMED_DATA_HAS_RUN_IDLE_HEADER)
   add_definitions(-DOPENER_CONSUMED_DATA_HAS_RUN_IDLE_HEADER)
 endif()
 
-# The number of bytes used for the buffer that will be used for generating any reply data of messages. There are two uses in OpENer: 1. Explicit messages will use this buffer to store the data generated by the request 2. I/O Connections will use this buffer for the produced data"
+# The number of bytes used for the buffer that will be used for generating any reply data of messages.
+# There are two uses in OpENer:
+#   1. Explicit messages will use this buffer to store the data generated by the request
+#   2. I/O Connections will use this buffer for the produced data
 set( OPENER_MESSAGE_DATA_REPLY_BUFFER "100" CACHE STRING "The number of bytes used for the reply message buffer")
 add_definitions(-DOPENER_MESSAGE_DATA_REPLY_BUFFER=${OPENER_MESSAGE_DATA_REPLY_BUFFER} )
 
@@ -83,6 +86,44 @@ endif(OpENer_TRACES)
 #######################################
 set( OPENER_BUILD_SHARED_LIBS OFF CACHE BOOL "Builds OpENer as separate lib and sample application" )
 
+#######################################
+# OpENer documentation target "doc"   #
+#######################################
+
+# check if Doxygen is installed
+find_package(Doxygen)
+if (DOXYGEN_FOUND)
+    # set input and output files
+    set(DOXYGEN_IN ${OpENer_SOURCE_DIR}/opener.doxyfile.in)
+    set(DOXYGEN_OUT ${OpENer_BINARY_DIR}/opener.doxyfile)
+
+    # exclude subdirectories of non active platforms depending on OpENer_PLATFORM
+    set(OpENer_EXCLUDE_PATTERNS "")
+    if (NOT (${OpENer_PLATFORM} STREQUAL "POSIX"))
+        set(OpENer_EXCLUDE_PATTERNS "${OpENer_EXCLUDE_PATTERNS} */src/ports/POSIX/*")
+    endif ()
+    if (NOT (${OpENer_PLATFORM} STREQUAL "WIN32"))
+        set(OpENer_EXCLUDE_PATTERNS "${OpENer_EXCLUDE_PATTERNS} */src/ports/WIN32/*")
+    endif ()
+    if (NOT (${OpENer_PLATFORM} STREQUAL "MINGW"))
+        set(OpENer_EXCLUDE_PATTERNS "${OpENer_EXCLUDE_PATTERNS} */src/ports/MINGW/*")
+    endif ()
+
+    # request to configure the file
+    configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
+
+    # note the option ALL which will build the docs always with the default target
+    add_custom_target( doc # ALL
+        COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
+        WORKING_DIRECTORY ${OpENer_SOURCE_DIR}
+        COMMENT "Generating API documentation with Doxygen"
+        VERBATIM )
+    message("-- Doxygen setup done")
+else (DOXYGEN_FOUND)
+  message("Doxygen needs to be installed to generate the Doxygen documentation")
+endif (DOXYGEN_FOUND)
+
+
 #######################################
 # Test switch                         #
 #######################################

+ 6 - 8
source/opener.doxyfile → source/opener.doxyfile.in

@@ -38,7 +38,7 @@ PROJECT_NAME           = "OpENer - Open Source EtherNet/IP(TM)  I/O Target Stack
 # could be handy for archiving the generated documentation or if some version
 # control system is used.
 
-PROJECT_NUMBER         = 2.2
+PROJECT_NUMBER         = @OpENer_VERSION_MAJOR@.@OpENer_VERSION_MINOR@
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer a
@@ -58,7 +58,7 @@ PROJECT_LOGO           =
 # entered, it will be relative to the location where doxygen was started. If
 # left blank the current directory will be used.
 
-OUTPUT_DIRECTORY       = doc/api_doc
+OUTPUT_DIRECTORY       = @OpENer_BINARY_DIR@/api_doc
 
 # If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
 # directories (in 2 levels) under the output directory of each output format and
@@ -758,7 +758,7 @@ WARN_LOGFILE           =
 # spaces.
 # Note: If this tag is empty the current directory is searched.
 
-INPUT                  = src
+INPUT                  = @OpENer_SOURCE_DIR@/src
 
 # This tag can be used to specify the character encoding of the source files
 # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
@@ -793,9 +793,7 @@ RECURSIVE              = YES
 # Note that relative paths are relative to the directory from which doxygen is
 # run.
 
-EXCLUDE                = src/ports/platform-pc/.deps \
-                         src/enet_encap/.deps \
-                         src/cip/.deps
+EXCLUDE                =
 
 # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
 # directories that are symbolic links (a Unix file system feature) are excluded
@@ -811,7 +809,7 @@ EXCLUDE_SYMLINKS       = NO
 # Note that the wildcards are matched against the file with absolute path, so to
 # exclude all test directories for example use the pattern */test/*
 
-EXCLUDE_PATTERNS       = 
+EXCLUDE_PATTERNS       = */.deps @OpENer_EXCLUDE_PATTERNS@
 
 # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
 # (namespaces, classes, functions, etc.) that should be excluded from the
@@ -828,7 +826,7 @@ EXCLUDE_SYMBOLS        =
 # that contain example code fragments that are included (see the \include
 # command).
 
-EXAMPLE_PATH           = ./
+EXAMPLE_PATH           = @OpENer_SOURCE_DIR@
 
 # If the value of the EXAMPLE_PATH tag contains directories, you can use the
 # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and

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

@@ -32,7 +32,7 @@ EipStatus SetAssemblyAttributeSingle(CipInstance *const instance,
 CipClass *CreateAssemblyClass(void) {
   /* create the CIP Assembly object with zero instances */
   CipClass *assembly_class = CreateCipClass(kCipAssemblyClassCode,
-                                            0,             /* # class attributes*/
+                                            0, /* # class attributes*/
                                             7, /* # highest class attribute number*/
                                             1, /* # class services*/
                                             2, /* # instance attributes*/

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

@@ -9,7 +9,7 @@
 #include "typedefs.h"
 #include "ciptypes.h"
 
-/** @brief Assembly class id */
+/** @brief Assembly class code */
 static const CipUint kCipAssemblyClassCode = 0x04u;
 
 /* public functions */

+ 6 - 6
source/src/cip/cipcommon.c

@@ -561,9 +561,9 @@ int EncodeData(const EipUint8 cip_type,
 
     case (kCipUdintUdintUdintUdintUdintString): {
       /* TCP/IP attribute 5 */
-      CipTcpIpNetworkInterfaceConfiguration *
+      CipTcpIpInterfaceConfiguration *
         tcp_ip_network_interface_configuration =
-        (CipTcpIpNetworkInterfaceConfiguration *) cip_data;
+        (CipTcpIpInterfaceConfiguration *) cip_data;
       counter += AddDintToMessage(
         ntohl(tcp_ip_network_interface_configuration->ip_address),
         cip_message);
@@ -905,9 +905,9 @@ int DecodePaddedEPath(CipEpath *epath,
 }
 
 void AllocateAttributeMasks(CipClass *target_class) {
-  size_t size = 1 + CalculateIndex(target_class->highest_attribute_number);
+  unsigned size = 1 + CalculateIndex(target_class->highest_attribute_number);
   OPENER_TRACE_INFO(
-    ">>> Allocate memory for %s %lu bytes times 3 for masks\n",
+    ">>> Allocate memory for %s %u bytes times 3 for masks\n",
     target_class->class_name, size);
   target_class->get_single_bit_mask = CipCalloc(size, sizeof(uint8_t) );
   target_class->set_bit_mask = CipCalloc(size, sizeof(uint8_t) );
@@ -1027,8 +1027,8 @@ size_t GetSizeOfAttribute(const CipAttributeStruct *const attribute_struct) {
       data_type_size = 2 * sizeof(CipUsint);
       break;
     case (kCipUdintUdintUdintUdintUdintString): {
-      CipTcpIpNetworkInterfaceConfiguration *data =
-        (CipTcpIpNetworkInterfaceConfiguration *) attribute_struct->data;
+      CipTcpIpInterfaceConfiguration *data =
+        (CipTcpIpInterfaceConfiguration *) attribute_struct->data;
       data_type_size = 5 * sizeof(CipUdint) + sizeof(CipUint)
                        + (data->domain_name.length) * sizeof(EipByte);
     }

+ 8 - 12
source/src/cip/cipconnectionmanager.c

@@ -28,11 +28,6 @@
 #include "cipelectronickey.h"
 #include "cipqos.h"
 
-/* values needed from the CIP identity object */
-extern EipUint16 vendor_id_;
-extern EipUint16 device_type_;
-extern EipUint16 product_code_;
-extern CipRevision revision_;
 
 const size_t g_kForwardOpenHeaderLength = 36; /**< the length in bytes of the forward open command specific data till the start of the connection path (including con path size)*/
 
@@ -988,9 +983,10 @@ EipStatus CheckElectronicKeyData(
     key_data);
 
   /* Check VendorID and ProductCode, must match, or 0 */
-  if ( ( (ElectronicKeyFormat4GetVendorId(key_data) != vendor_id_) &&
+  if ( ( (ElectronicKeyFormat4GetVendorId(key_data) != g_identity.vendor_id) &&
          (ElectronicKeyFormat4GetVendorId(key_data) != 0) )
-       || ( (ElectronicKeyFormat4GetProductCode(key_data) != product_code_)
+       || ( (ElectronicKeyFormat4GetProductCode(key_data) !=
+             g_identity.product_code)
             && (ElectronicKeyFormat4GetProductCode(key_data) != 0) ) ) {
     *extended_status =
       kConnectionManagerExtendedStatusCodeErrorVendorIdOrProductcodeError;
@@ -999,7 +995,7 @@ EipStatus CheckElectronicKeyData(
     /* VendorID and ProductCode are correct */
 
     /* Check DeviceType, must match or 0 */
-    if ( (ElectronicKeyFormat4GetDeviceType(key_data) != device_type_)
+    if ( (ElectronicKeyFormat4GetDeviceType(key_data) != g_identity.device_type)
          && (ElectronicKeyFormat4GetDeviceType(key_data) != 0) ) {
       *extended_status =
         kConnectionManagerExtendedStatusCodeErrorDeviceTypeError;
@@ -1015,9 +1011,9 @@ EipStatus CheckElectronicKeyData(
 
         /* Check Major / Minor Revision, Major must match, Minor match or 0 */
         if ( (ElectronicKeyFormat4GetMajorRevision(key_data) !=
-              revision_.major_revision)
+              g_identity.revision.major_revision)
              || ( (ElectronicKeyFormat4GetMinorRevision(key_data) !=
-                   revision_.minor_revision)
+                   g_identity.revision.minor_revision)
                   && (ElectronicKeyFormat4GetMinorRevision(key_data) != 0) ) ) {
           *extended_status =
             kConnectionManagerExtendedStatusCodeErrorRevisionMismatch;
@@ -1028,10 +1024,10 @@ EipStatus CheckElectronicKeyData(
 
         /* Major must match, Minor != 0 and <= MinorRevision */
         if ( (ElectronicKeyFormat4GetMajorRevision(key_data) ==
-              revision_.major_revision)
+              g_identity.revision.major_revision)
              && (ElectronicKeyFormat4GetMinorRevision(key_data) > 0)
              && (ElectronicKeyFormat4GetMinorRevision(key_data) <=
-                 revision_.minor_revision) ) {
+                 g_identity.revision.minor_revision) ) {
           return kEipStatusOk;
         } else {
           *extended_status =

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

@@ -9,7 +9,7 @@
 #include "typedefs.h"
 #include "ciptypes.h"
 
-/** @brief This Ethernet Link class id as #define is still needed for a static
+/** @brief This Ethernet Link class code as #define is still needed for a static
  *  initialization. */
 #define CIP_ETHERNETLINK_CLASS_CODE   0xF6u
 /** @brief Ethernet Link class code */

+ 50 - 26
source/src/cip/cipidentity.c

@@ -25,10 +25,10 @@
  * --------------------
  */
 
-#include <string.h>
-
 #include "cipidentity.h"
 
+#include <string.h>
+
 #include "opener_user_conf.h"
 #include "cipcommon.h"
 #include "cipmessagerouter.h"
@@ -37,31 +37,39 @@
 #include "opener_api.h"
 #include "trace.h"
 
-/* attributes in CIP Identity Object */
 
-CipUint vendor_id_ = OPENER_DEVICE_VENDOR_ID; /**< Attribute 1: Vendor ID */
-CipUint device_type_ = OPENER_DEVICE_TYPE; /**< Attribute 2: Device Type */
-CipUint product_code_ = OPENER_DEVICE_PRODUCT_CODE; /**< Attribute 3: Product Code */
-CipRevision revision_ = { OPENER_DEVICE_MAJOR_REVISION,
-                          OPENER_DEVICE_MINOR_REVISION }; /**< Attribute 4: Revision / USINT Major, USINT Minor */
-CipWord status_ = 0; /**< Attribute 5: Status */
-CipUdint serial_number_ = 0; /**< Attribute 6: Serial Number, has to be set prior to OpENer initialization */
-CipShortString product_name_ = { sizeof(OPENER_DEVICE_NAME) - 1,
-                                 OPENER_DEVICE_NAME }; /**< Attribute 7: Product Name */
-CipUsint g_state = 255;
+/** @brief Definition of the global Identity Object */
+CipIdentityObject g_identity =
+{
+  .vendor_id = OPENER_DEVICE_VENDOR_ID, /* Attribute 1: Vendor ID */
+  .device_type = OPENER_DEVICE_TYPE, /* Attribute 2: Device Type */
+  .product_code = OPENER_DEVICE_PRODUCT_CODE, /* Attribute 3: Product Code */
+  .revision = { /* Attribute 4: Revision / CipUsint Major, CipUsint Minor */
+    OPENER_DEVICE_MAJOR_REVISION,
+    OPENER_DEVICE_MINOR_REVISION
+  },
+  .status = 0, /* Attribute 5: Status */
+  .serial_number = 0, /* Attribute 6: Serial Number */
+  .product_name = { /* Attribute 7: Product Name */
+    sizeof(OPENER_DEVICE_NAME) - 1,
+    (EipByte *)OPENER_DEVICE_NAME
+  },
+  .state = 255,
+};
+
 
 /** Private functions, sets the devices serial number
  * @param serial_number The serial number of the device
  */
 void SetDeviceSerialNumber(const EipUint32 serial_number) {
-  serial_number_ = serial_number;
+  g_identity.serial_number = serial_number;
 }
 
 /** @brief Private function, sets the devices status
  * @param status The serial number of the device
  */
 void SetDeviceStatus(const EipUint16 status) {
-  status_ = status;
+  g_identity.status = status;
 }
 
 /** @brief Reset service
@@ -122,7 +130,7 @@ static EipStatus Reset(CipInstance *instance,
   return eip_status;
 }
 
-void InitializeCipIdentiy(CipClass *class) {
+void InitializeCipIdentity(CipClass *class) {
 
 
   CipClass *meta_class = class->class_instance.cip_class;
@@ -159,22 +167,38 @@ EipStatus CipIdentityInit() {
                                    1, /* # of instances*/
                                    "identity", /* # class name (for debug)*/
                                    1, /* # class revision*/
-                                   &InitializeCipIdentiy); /* # function pointer for initialization*/
+                                   &InitializeCipIdentity); /* # function pointer for initialization*/
 
   if (class == 0) {
     return kEipStatusError;
   }
 
   CipInstance *instance = GetCipInstance(class, 1);
-  InsertAttribute(instance, 1, kCipUint, &vendor_id_, kGetableSingleAndAll);
-  InsertAttribute(instance, 2, kCipUint, &device_type_, kGetableSingleAndAll);
-  InsertAttribute(instance, 3, kCipUint, &product_code_, kGetableSingleAndAll);
-  InsertAttribute(instance, 4, kCipUsintUsint, &revision_,
+  InsertAttribute(instance,
+                  1,
+                  kCipUint,
+                  &g_identity.vendor_id,
+                  kGetableSingleAndAll);
+  InsertAttribute(instance,
+                  2,
+                  kCipUint,
+                  &g_identity.device_type,
+                  kGetableSingleAndAll);
+  InsertAttribute(instance,
+                  3,
+                  kCipUint,
+                  &g_identity.product_code,
+                  kGetableSingleAndAll);
+  InsertAttribute(instance, 4, kCipUsintUsint, &g_identity.revision,
+                  kGetableSingleAndAll);
+  InsertAttribute(instance,
+                  5,
+                  kCipWord,
+                  &g_identity.status,
                   kGetableSingleAndAll);
-  InsertAttribute(instance, 5, kCipWord, &status_, kGetableSingleAndAll);
-  InsertAttribute(instance, 6, kCipUdint, &serial_number_,
+  InsertAttribute(instance, 6, kCipUdint, &g_identity.serial_number,
                   kGetableSingleAndAll);
-  InsertAttribute(instance, 7, kCipShortString, &product_name_,
+  InsertAttribute(instance, 7, kCipShortString, &g_identity.product_name,
                   kGetableSingleAndAll);
   InsertService(class, kGetAttributeSingle, &GetAttributeSingle,
                 "GetAttributeSingle");
@@ -187,6 +211,6 @@ EipStatus CipIdentityInit() {
 void CipIdentitySetExtendedDeviceStatus(
   CipIdentityExtendedStatus extended_status) {
   OPENER_TRACE_INFO("Setting extended status: %x\n", extended_status);
-  status_ &= ~(0x70);
-  status_ |= extended_status;
+  g_identity.status &= ~(0x70);
+  g_identity.status |= extended_status;
 }

+ 17 - 0
source/src/cip/cipidentity.h

@@ -31,6 +31,7 @@ typedef enum {
                                        to the "Major Unrecoverable Fault" state */
 } CipIdentityStatus;
 
+/** @brief Constants for the extended status field in the Status word */
 typedef enum {
   kSelftestingUnknown = 0x0000,
   kFirmwareUpdateInProgress = 0x0010,
@@ -42,7 +43,23 @@ typedef enum {
   kAtLeastOneIoConnectionEstablishedAllInIdleMode = 0x0070
 } CipIdentityExtendedStatus;
 
+/** @brief Declaration of the Identity object's structure type
+ */
+typedef struct {
+  CipUint vendor_id; /**< Attribute 1: Vendor ID */
+  CipUint device_type; /**< Attribute 2: Device Type */
+  CipUint product_code; /**< Attribute 3: Product Code */
+  CipRevision revision; /**< Attribute 4: Revision / CipUsint Major, CipUsint Minor */
+  CipWord status; /**< Attribute 5: Status */
+  CipUdint serial_number; /**< Attribute 6: Serial Number, has to be set prior to OpENer's network initialization */
+  CipShortString product_name; /**< Attribute 7: Product Name */
+  CipUsint state; /** Attribute 8: state */
+} CipIdentityObject;
+
+
 /* global public variables */
+CipIdentityObject g_identity;
+
 
 /* public functions */
 /** @brief CIP Identity object constructor

+ 2 - 3
source/src/cip/cipioconnection.c

@@ -504,8 +504,7 @@ EipStatus OpenProducingMulticastConnection(
   connection_object->remote_address.sin_addr.s_addr = common_packet_format_data
                                                       ->address_info_item[j].
                                                       sin_addr =
-                                                        g_multicast_configuration
-                                                        .
+                                                        g_tcpip.mcast_config.
                                                         starting_multicast_address;
   memset(common_packet_format_data->address_info_item[j].nasin_zero, 0, 8);
   common_packet_format_data->address_info_item[j].sin_family = htons(AF_INET);
@@ -577,7 +576,7 @@ EipStatus OpenMulticastConnection(
     common_packet_format_data->address_info_item[j].sin_port = htons(
       kOpenerEipIoUdpPort);
     common_packet_format_data->address_info_item[j].sin_addr =
-      g_multicast_configuration.starting_multicast_address;
+      g_tcpip.mcast_config.starting_multicast_address;
     memset(common_packet_format_data->address_info_item[j].nasin_zero, 0, 8);
     common_packet_format_data->address_info_item[j].length = 16;
   }

+ 51 - 63
source/src/cip/cipqos.c

@@ -23,47 +23,35 @@
 #define DEFAULT_DSCP_LOW 31u
 #define DEFAULT_DSCP_EXPLICIT 27u
 
-typedef struct cip_qos_dscp_values {
-  CipUsint dscp_event; /**< DSCP value for event messages*/
-  CipUsint dscp_general; /**< DSCP value for general messages*/
-  CipUsint dscp_urgent; /**< DSCP value for CIP transport class 0/1 Urgent priority messages */
-  CipUsint dscp_scheduled; /**< DSCP value for CIP transport class 0/1 Scheduled priority messages*/
-  CipUsint dscp_high; /**< DSCP value for CIP transport class 0/1 High priority messages */
-  CipUsint dscp_low; /**< DSCP value for CIP transport class 0/1 low priority messages */
-  CipUsint dscp_explicit; /**< DSCP value for CIP explicit messages (transport class 2/3 and UCMM)
-                                        and all other EtherNet/IP encapsulation messages */
-} CipQosDscpValues;
-
-typedef struct {
-  CipUsint q_frames_enable; /**< Enables or disable sending 802.1Q frames on CIP and IEEE 1588 messages */
-  CipQosDscpValues dscp_values; /**< Attribute set of DSCP values - beware! must not be the used set */
-} CipQosInstanceAttributes;
-
-static CipQosInstanceAttributes s_instance_1_attributes = {
+/** @brief The QoS object
+ *
+ *  The global instance of the QoS object
+ */
+CipQosObject g_qos = {
   .q_frames_enable = false,
-  .dscp_values.dscp_event = DEFAULT_DSCP_EVENT,
-  .dscp_values.dscp_general = DEFAULT_DSCP_GENERAL,
-  .dscp_values.dscp_urgent = DEFAULT_DSCP_URGENT,
-  .dscp_values.dscp_scheduled = DEFAULT_DSCP_SCHEDULED,
-  .dscp_values.dscp_high = DEFAULT_DSCP_HIGH,
-  .dscp_values.dscp_low = DEFAULT_DSCP_LOW,
-  .dscp_values.dscp_explicit = DEFAULT_DSCP_EXPLICIT
+  .dscp.event = DEFAULT_DSCP_EVENT,
+  .dscp.general = DEFAULT_DSCP_GENERAL,
+  .dscp.urgent = DEFAULT_DSCP_URGENT,
+  .dscp.scheduled = DEFAULT_DSCP_SCHEDULED,
+  .dscp.high = DEFAULT_DSCP_HIGH,
+  .dscp.low = DEFAULT_DSCP_LOW,
+  .dscp.explicit = DEFAULT_DSCP_EXPLICIT
 };
 
-/** @brief Hidden copy of data that need to be frozen on boot-up
+/** @brief Active set of DSCP data inherits its data from the QoS object on boot-up
  *
  *  The QoS DSCP values can be changed from the EIP network but the changes should come
  *  into effect only after a restart. Values are initialized with the default values.
  *  Changes are activated via the Identity Reset function
  */
-static CipQosDscpValues s_currently_used_dscp_values = {
-  .dscp_event = DEFAULT_DSCP_EVENT,
-  .dscp_general = DEFAULT_DSCP_GENERAL,
-  .dscp_urgent = DEFAULT_DSCP_URGENT,
-  .dscp_scheduled = DEFAULT_DSCP_SCHEDULED,
-  .dscp_high = DEFAULT_DSCP_HIGH,
-  .dscp_low = DEFAULT_DSCP_LOW,
-  .dscp_explicit = DEFAULT_DSCP_EXPLICIT
+static CipQosDscpValues s_active_dscp = {
+  .event = DEFAULT_DSCP_EVENT,
+  .general = DEFAULT_DSCP_GENERAL,
+  .urgent = DEFAULT_DSCP_URGENT,
+  .scheduled = DEFAULT_DSCP_SCHEDULED,
+  .high = DEFAULT_DSCP_HIGH,
+  .low = DEFAULT_DSCP_LOW,
+  .explicit = DEFAULT_DSCP_EXPLICIT
 };
 
 /************** Functions ****************************************/
@@ -97,16 +85,15 @@ EipStatus SetAttributeSingleQoS(
 
   if( NULL != attribute &&
       ( set_bit_mask & ( 1 << ( (attribute_number) % 8 ) ) ) ) {
-    CipUint attribute_value_recieved = GetDintFromMessage(
+    CipUsint attribute_value_received = GetUsintFromMessage(
       &(message_router_request->data) );
 
-    if( !( (attribute_value_recieved <= 0) ||
-           (attribute_value_recieved >= 63) ) ) {
+    if( attribute_value_received < 64u ) {
       OPENER_TRACE_INFO(" setAttribute %d\n", attribute_number);
 
       if(NULL != attribute->data) {
         CipUsint *data = (CipUsint *) attribute->data;
-        *(data) = attribute_value_recieved;
+        *(data) = attribute_value_received;
 
         message_router_response->general_status = kCipErrorSuccess;
       } else {
@@ -131,23 +118,23 @@ EipStatus SetAttributeSingleQoS(
 
 CipUsint CipQosGetDscpPriority(ConnectionObjectPriority priority) {
 
-  CipUsint priority_value = s_currently_used_dscp_values.dscp_explicit;
+  CipUsint priority_value = s_active_dscp.explicit;
   switch (priority) {
     case kConnectionObjectPriorityLow:
-      priority_value = s_currently_used_dscp_values.dscp_low;
+      priority_value = s_active_dscp.low;
       break;
     case kConnectionObjectPriorityHigh:
-      priority_value = s_currently_used_dscp_values.dscp_high;
+      priority_value = s_active_dscp.high;
       break;
     case kConnectionObjectPriorityScheduled:
-      priority_value = s_currently_used_dscp_values.dscp_scheduled;
+      priority_value = s_active_dscp.scheduled;
       break;
     case kConnectionObjectPriorityUrgent:
-      priority_value = s_currently_used_dscp_values.dscp_urgent;
+      priority_value = s_active_dscp.urgent;
       break;
     case kConnectionObjectPriorityExplicit: /* Fall-through wanted here */
     default:
-      priority_value = s_currently_used_dscp_values.dscp_explicit;
+      priority_value = s_active_dscp.explicit;
       break;
   }
   return priority_value;
@@ -181,42 +168,42 @@ EipStatus CipQoSInit() {
   InsertAttribute(instance,
                   1,
                   kCipUsint,
-                  (void *) &s_instance_1_attributes.q_frames_enable,
+                  (void *) &g_qos.q_frames_enable,
                   kNotSetOrGetable);
   InsertAttribute(instance,
                   2,
                   kCipUsint,
-                  (void *) &s_instance_1_attributes.dscp_values.dscp_event,
+                  (void *) &g_qos.dscp.event,
                   kNotSetOrGetable);
   InsertAttribute(instance,
                   3,
                   kCipUsint,
-                  (void *) &s_instance_1_attributes.dscp_values.dscp_general,
+                  (void *) &g_qos.dscp.general,
                   kNotSetOrGetable);
   InsertAttribute(instance,
                   4,
                   kCipUsint,
-                  (void *) &s_instance_1_attributes.dscp_values.dscp_urgent,
+                  (void *) &g_qos.dscp.urgent,
                   kGetableSingle | kSetable);
   InsertAttribute(instance,
                   5,
                   kCipUsint,
-                  (void *) &s_instance_1_attributes.dscp_values.dscp_scheduled,
+                  (void *) &g_qos.dscp.scheduled,
                   kGetableSingle | kSetable);
   InsertAttribute(instance,
                   6,
                   kCipUsint,
-                  (void *) &s_instance_1_attributes.dscp_values.dscp_high,
+                  (void *) &g_qos.dscp.high,
                   kGetableSingle | kSetable);
   InsertAttribute(instance,
                   7,
                   kCipUsint,
-                  (void *) &s_instance_1_attributes.dscp_values.dscp_low,
+                  (void *) &g_qos.dscp.low,
                   kGetableSingle | kSetable);
   InsertAttribute(instance,
                   8,
                   kCipUsint,
-                  (void *) &s_instance_1_attributes.dscp_values.dscp_explicit,
+                  (void *) &g_qos.dscp.explicit,
                   kGetableSingle | kSetable);
 
   InsertService(qos_class, kGetAttributeSingle, &GetAttributeSingleQoS,
@@ -227,19 +214,20 @@ EipStatus CipQoSInit() {
   return kEipStatusOk;
 }
 
-void CipQosUpdateUsedSetQosValues() {
-  s_currently_used_dscp_values = s_instance_1_attributes.dscp_values;
+void CipQosUpdateUsedSetQosValues(void) {
+  s_active_dscp = g_qos.dscp;
 }
 
-void CipQosResetAttributesToDefaultValues() {
-  const CipQosDscpValues kDefaultValues = {
-    .dscp_event = DEFAULT_DSCP_EVENT,
-    .dscp_general = DEFAULT_DSCP_GENERAL,
-    .dscp_urgent = DEFAULT_DSCP_URGENT,
-    .dscp_scheduled = DEFAULT_DSCP_SCHEDULED,
-    .dscp_high = DEFAULT_DSCP_HIGH,
-    .dscp_low = DEFAULT_DSCP_LOW,
-    .dscp_explicit = DEFAULT_DSCP_EXPLICIT
+void CipQosResetAttributesToDefaultValues(void) {
+  static const CipQosDscpValues kDefaultValues = {
+    .event = DEFAULT_DSCP_EVENT,
+    .general = DEFAULT_DSCP_GENERAL,
+    .urgent = DEFAULT_DSCP_URGENT,
+    .scheduled = DEFAULT_DSCP_SCHEDULED,
+    .high = DEFAULT_DSCP_HIGH,
+    .low = DEFAULT_DSCP_LOW,
+    .explicit = DEFAULT_DSCP_EXPLICIT
   };
-  s_instance_1_attributes.dscp_values = kDefaultValues;
+  g_qos.q_frames_enable = false;
+  g_qos.dscp = kDefaultValues;
 }

+ 30 - 6
source/src/cip/cipqos.h

@@ -19,21 +19,45 @@
 /** @brief QoS Object class code */
 static const CipUint kCipQoSClassCode = 0x48u;
 
+/* public types */
+
+/** This type represents the group of DSCP values of the QoS object. */
+typedef struct cip_qos_dscp_values {
+  CipUsint event; /**< Attr. #2: DSCP value for event messages */
+  CipUsint general; /**< Attr. #3: DSCP value for general messages */
+  CipUsint urgent; /**< Attr. #4: DSCP value for CIP transport class 0/1 Urgent priority messages */
+  CipUsint scheduled; /**< Attr. #5: DSCP value for CIP transport class 0/1 Scheduled priority messages */
+  CipUsint high; /**< Attr. #6: DSCP value for CIP transport class 0/1 High priority messages */
+  CipUsint low; /**< Attr. #7: DSCP value for CIP transport class 0/1 low priority messages */
+  CipUsint explicit; /**< Attr. #8: DSCP value for CIP explicit messages (transport class 2/3 and UCMM)
+                                        and all other EtherNet/IP encapsulation messages */
+} CipQosDscpValues;
+
+/** This type represents the QoS object */
+typedef struct {
+  CipUsint q_frames_enable; /**< Attr. #1: Enables or disable sending 802.1Q frames on CIP and IEEE 1588 messages */
+  CipQosDscpValues dscp; /**< Attributes #2 ... #8 of DSCP values - beware! must not be the used set */
+} CipQosObject;
+
+
+/* public data */
+extern CipQosObject g_qos;
+
+
 /* public functions */
-/** @brief Initializing the data structures of the TCP/IP interface object
+/** @brief Provide the matching DSCP value for a given connection object priority level
  */
 CipUsint CipQosGetDscpPriority(ConnectionObjectPriority priority);
 
+/** @brief Create and initialize the QoS object
+ */
 EipStatus CipQoSInit(void);
 
 /** @brief Updates the currently used set of DSCP priority values
- *
  */
-void CipQosUpdateUsedSetQosValues(
-  );
+void CipQosUpdateUsedSetQosValues(void);
 
 /** @brief Reset attribute values to default. Does not update currently used set */
-void CipQosResetAttributesToDefaultValues(
-  );
+void CipQosResetAttributesToDefaultValues(void);
 
 #endif  /* OPENER_CIPQOS_H_*/

+ 60 - 63
source/src/cip/ciptcpipinterface.c

@@ -3,10 +3,10 @@
  * All rights reserved.
  *
  ******************************************************************************/
-#include <string.h>
-
 #include "ciptcpipinterface.h"
 
+#include <string.h>
+
 #include "opener_user_conf.h"
 #include "cipcommon.h"
 #include "cipmessagerouter.h"
@@ -17,50 +17,44 @@
 #include "trace.h"
 #include "cipassembly.h"
 
-CipDword tcp_status_ = 0x1; /**< #1  TCP status with 1 we indicate that we got a valid configuration from DHCP or BOOTP */
-CipDword configuration_capability_ = 0x04; /**< #2  This is a default value meaning that it is a DHCP client see 5-3.2.2.2 EIP specification*/
-CipDword configuration_control_ = 0x02; /**< #3  This is a TCP/IP object attribute. 0x02 means that the device shall obtain its interface configuration values via DHCP. */
-CipEpath physical_link_object_ = /**< #4 */
-{ 2, /**< EIP_UINT16 (UINT) PathSize in 16 Bit chunks*/
-  CIP_ETHERNETLINK_CLASS_CODE, /**< Class Code*/
-  1, /**< EIP_UINT16 InstanceNr*/
-  0 /**< EIP_UINT16 AttributNr (not used as this is the EPATH the EthernetLink object)*/
-};
-
-CipTcpIpNetworkInterfaceConfiguration interface_configuration_ = /**< #5 IP, network mask, gateway, name server 1 & 2, domain name*/
-{ 0, /* default IP address */
-  0, /* NetworkMask */
-  0, /* Gateway */
-  0, /* NameServer */
-  0, /* NameServer2 */
-  { /* DomainName */
-    0, NULL,
-  } };
-
-CipString hostname_ = /**< #6 Hostname*/
-{ 0, NULL };
-/** @brief #8 the time to live value to be used for multi-cast connections
- *
- * Currently we implement it non set-able and with the default value of 1.
- */
-EipUint8 g_time_to_live_value = 1;
 
-/** @brief #9 The multicast configuration for this device
- *
- * Currently we implement it non set-able and use the default
- * allocation algorithm
- */
-MulticastAddressConfiguration g_multicast_configuration = { 0, /* use the default allocation algorithm */
-                                                            0, /* reserved */
-                                                            1, /* we currently use only one multicast address */
-                                                            0 /* the multicast address will be allocated on ip address configuration */
+/** definition of TCP/IP object instance 1 data */
+CipTcpIpObject g_tcpip =
+{
+  .status = 0x01, /* attribute #1 TCP status with 1 we indicate that we got a valid configuration from DHCP or BOOTP */
+  .config_capability = 0x04, /* attribute #2 config_capability: This is a default value meaning that it is a DHCP client see 5-3.2.2.2 EIP specification. */
+  .config_control = 0x02, /* attribute #3 config_control: 0x02 means that the device shall obtain its interface configuration values via DHCP. */
+  .physical_link_object = {     /* attribute #4 physical link object */
+    2,  /* PathSize in 16 Bit chunks */
+    CIP_ETHERNETLINK_CLASS_CODE, /* Class Code */
+    1,  /* Instance # */
+    0   /* Attribute # (not used as this is the EPATH to the EthernetLink object)*/
+  },
+  .interface_configuration = { /* attribute #5 interface_configuration */
+    0, /* IP address */
+    0, /* NetworkMask */
+    0, /* Gateway */
+    0, /* NameServer */
+    0, /* NameServer2 */
+    { /* DomainName */
+      0, NULL,
+    }
+  },
+  .hostname = { /* attribute #6 hostname */
+    0,
+    NULL
+  },
+  .mcast_ttl_value = 1,  /* attribute #8 mcast TTL value */
+  .mcast_config = {   /* attribute #9 multicast configuration */
+    0,  /* use the default allocation algorithm */
+    0,  /* reserved */
+    1,  /* we currently use only one multicast address */
+    0   /* the multicast address will be allocated on IP address configuration */
+  },
+  .encapsulation_inactivity_timeout = 120 /* attribute #13 encapsulation_inactivity_timeout, use a default value of 120 */
 };
 
-/** @brief #13 Number of seconds of inactivity before TCP connection is closed
- *
- * Currently we implemented with the default value of 120 seconds.
- */
-CipUint g_encapsulation_inactivity_timeout = 120;
+
 
 /************** Functions ****************************************/
 EipStatus GetAttributeSingleTcpIpInterface(
@@ -181,25 +175,28 @@ EipStatus CipTcpIpInterfaceInit() {
 
   CipInstance *instance = GetCipInstance(tcp_ip_class, 1); /* bind attributes to the instance #1 that was created above */
 
-  InsertAttribute(instance, 1, kCipDword, (void *) &tcp_status_,
+  InsertAttribute(instance, 1, kCipDword, (void *) &g_tcpip.status,
                   kGetableSingleAndAll);
-  InsertAttribute(instance, 2, kCipDword, (void *) &configuration_capability_,
+  InsertAttribute(instance, 2, kCipDword, (void *) &g_tcpip.config_capability,
                   kGetableSingleAndAll);
-  InsertAttribute(instance, 3, kCipDword, (void *) &configuration_control_,
+  InsertAttribute(instance, 3, kCipDword, (void *) &g_tcpip.config_control,
                   kSetAndGetAble);
-  InsertAttribute(instance, 4, kCipEpath, &physical_link_object_,
+  InsertAttribute(instance, 4, kCipEpath, &g_tcpip.physical_link_object,
                   kGetableSingleAndAll);
   InsertAttribute(instance, 5, kCipUdintUdintUdintUdintUdintString,
-                  &interface_configuration_, kGetableSingleAndAll);
-  InsertAttribute(instance, 6, kCipString, (void *) &hostname_,
+                  &g_tcpip.interface_configuration, kGetableSingleAndAll);
+  InsertAttribute(instance, 6, kCipString, (void *) &g_tcpip.hostname,
                   kGetableSingleAndAll);
 
-  InsertAttribute(instance, 8, kCipUsint, (void *) &g_time_to_live_value,
+  InsertAttribute(instance, 8, kCipUsint, (void *) &g_tcpip.mcast_ttl_value,
                   kGetableSingleAndAll);
-  InsertAttribute(instance, 9, kCipAny, (void *) &g_multicast_configuration,
+  InsertAttribute(instance, 9, kCipAny, (void *) &g_tcpip.mcast_config,
                   kGetableSingleAndAll);
-  InsertAttribute(instance, 13, kCipUint,
-                  (void *) &g_encapsulation_inactivity_timeout, kSetAndGetAble);
+  InsertAttribute(instance,
+                  13,
+                  kCipUint,
+                  (void *) &g_tcpip.encapsulation_inactivity_timeout,
+                  kSetAndGetAble);
 
   InsertService(tcp_ip_class, kGetAttributeSingle,
                 &GetAttributeSingleTcpIpInterface,
@@ -215,14 +212,14 @@ EipStatus CipTcpIpInterfaceInit() {
 
 void ShutdownTcpIpInterface(void) {
   /*Only free the resources if they are initialized */
-  if (NULL != hostname_.string) {
-    CipFree(hostname_.string);
-    hostname_.string = NULL;
+  if (NULL != g_tcpip.hostname.string) {
+    CipFree(g_tcpip.hostname.string);
+    g_tcpip.hostname.string = NULL;
   }
 
-  if (NULL != interface_configuration_.domain_name.string) {
-    CipFree(interface_configuration_.domain_name.string);
-    interface_configuration_.domain_name.string = NULL;
+  if (NULL != g_tcpip.interface_configuration.domain_name.string) {
+    CipFree(g_tcpip.interface_configuration.domain_name.string);
+    g_tcpip.interface_configuration.domain_name.string = NULL;
   }
 }
 
@@ -271,17 +268,17 @@ EipStatus GetAttributeSingleTcpIpInterface(
 
       /* create a reply message containing the data*/
       message_router_response->data_length += EncodeData(
-        kCipUsint, &(g_multicast_configuration.alloc_control), &message);
+        kCipUsint, &(g_tcpip.mcast_config.alloc_control), &message);
       message_router_response->data_length += EncodeData(
-        kCipUsint, &(g_multicast_configuration.reserved_shall_be_zero),
+        kCipUsint, &(g_tcpip.mcast_config.reserved_shall_be_zero),
         &message);
       message_router_response->data_length += EncodeData(
         kCipUint,
-        &(g_multicast_configuration.number_of_allocated_multicast_addresses),
+        &(g_tcpip.mcast_config.number_of_allocated_multicast_addresses),
         &message);
 
       EipUint32 multicast_address = ntohl(
-        g_multicast_configuration.starting_multicast_address);
+        g_tcpip.mcast_config.starting_multicast_address);
 
       message_router_response->data_length += EncodeData(kCipUdint,
                                                          &multicast_address,

+ 19 - 8
source/src/cip/ciptcpipinterface.h

@@ -14,10 +14,6 @@
 #include "typedefs.h"
 #include "ciptypes.h"
 
-extern CipString hostname_;
-
-extern CipTcpIpNetworkInterfaceConfiguration interface_configuration_;
-
 /** @brief TCP/IP Interface class code */
 static const CipUint kCipTcpIpInterfaceClassCode = 0xF5u;
 
@@ -31,12 +27,27 @@ typedef struct multicast_address_configuration {
   CipUdint starting_multicast_address; /**< Starting multicast address from which Num Mcast addresses are allocated */
 } MulticastAddressConfiguration;
 
-/* global public variables */
-extern CipUsint g_time_to_live_value; /**< Time-to-live value for IP multicast packets. Default is 1; Minimum is 1; Maximum is 255 */
+/** @brief Declaration of the TCP/IP object's structure type
+ */
+typedef struct {
+  CipDword status;            /**< attribute #1  TCP status */
+  CipDword config_capability; /**< attribute #2 bitmap of capability flags */
+  CipDword config_control;    /**< attribute #3 bitmap: control the interface configuration method: static / BOOTP / DHCP */
+  CipEpath physical_link_object;  /**< attribute #4 references the Ethernet Link object for this  interface */
+  CipTcpIpInterfaceConfiguration interface_configuration;/**< attribute #5 IP, network mask, gateway, name server 1 & 2, domain name*/
+  CipString hostname; /**< #6 host name*/
+  CipUsint mcast_ttl_value; /**< #8 the time to live value to be used for multi-cast connections */
 
-extern CipUint g_encapsulation_inactivity_timeout; /**< Number of seconds of inactivity before TCP connection is closed, Default is 120 */
+  /** #9 The multicast configuration for this device */
+  MulticastAddressConfiguration mcast_config;
 
-extern MulticastAddressConfiguration g_multicast_configuration; /**< Multicast configuration */
+  /** #13 Number of seconds of inactivity before TCP connection is closed */
+  CipUint encapsulation_inactivity_timeout;
+} CipTcpIpObject;
+
+
+/* global public variables */
+extern CipTcpIpObject g_tcpip;  /**< declaration of TCP/IP object instance 1 data */
 
 /* public functions */
 /** @brief Initializing the data structures of the TCP/IP interface object

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

@@ -304,7 +304,7 @@ typedef struct {
   CipUdint name_server;
   CipUdint name_server_2;
   CipString domain_name;
-} CipTcpIpNetworkInterfaceConfiguration;
+} CipTcpIpInterfaceConfiguration;
 
 typedef struct {
   EipUint8 path_size;

+ 26 - 31
source/src/enet_encap/encap.c

@@ -17,24 +17,13 @@
 #include "cipmessagerouter.h"
 #include "cipconnectionmanager.h"
 #include "cipidentity.h"
+#include "ciptcpipinterface.h"
 #include "generic_networkhandler.h"
 #include "trace.h"
 #include "socket_timer.h"
 #include "opener_error.h"
 
-/*Identity data from cipidentity.c*/
-extern CipUint vendor_id_;
-extern CipUint device_type_;
-extern CipUint product_code_;
-extern CipRevision revision_;
-extern CipWord status_;
-extern CipUdint serial_number_;
-extern CipShortString product_name_;
-extern CipUsint g_state;
-
 /* IP address data taken from TCPIPInterfaceObject*/
-extern CipTcpIpNetworkInterfaceConfiguration interface_configuration_;
-
 const int kSupportedProtocolVersion = 1; /**< Supported Encapsulation protocol version */
 
 const int kEncapsulationHeaderOptionsFlag = 0x00; /**< Mask of which options are supported as of the current CIP specs no other option value as 0 should be supported.*/
@@ -127,7 +116,7 @@ void EncapsulationInit(void) {
 
   /*initialize random numbers for random delayed response message generation
    * we use the ip address as seed as suggested in the spec */
-  srand(interface_configuration_.ip_address);
+  srand(g_tcpip.interface_configuration.ip_address);
 
   /* initialize Sessions to invalid == free session */
   for (size_t i = 0; i < OPENER_NUMBER_OF_SUPPORTED_SESSIONS; i++) {
@@ -437,7 +426,7 @@ CipUint ListIdentityGetCipIdentityItemLength() {
          sizeof(CipUdint) + 8 * sizeof(CipUsint) + sizeof(CipUint) +
          sizeof(CipUint) + sizeof(CipUint) + 2 * sizeof(CipUsint) +
          sizeof(CipWord) + sizeof(CipUdint) + sizeof(CipUsint) +
-         product_name_.length + sizeof(CipUsint);
+         g_identity.product_name.length + sizeof(CipUsint);
 }
 
 void EncodeListIdentityCipIdentityItem(ENIPMessage *const outgoing_message) {
@@ -456,7 +445,7 @@ void EncodeListIdentityCipIdentityItem(ENIPMessage *const outgoing_message) {
     &outgoing_message->current_message_position);
 
   outgoing_message->used_message_length += EncapsulateIpAddress(
-    htons(kOpenerEthernetPort), interface_configuration_.ip_address,
+    htons(kOpenerEthernetPort), g_tcpip.interface_configuration.ip_address,
     &outgoing_message->current_message_position);
 
   /** Array of USINT - length 8 shall be set to zero */
@@ -464,30 +453,36 @@ void EncodeListIdentityCipIdentityItem(ENIPMessage *const outgoing_message) {
   outgoing_message->used_message_length += MoveMessageNOctets(8,
                                                               (const CipOctet **) &outgoing_message->current_message_position);
 
-  outgoing_message->used_message_length += AddIntToMessage(vendor_id_,
-                                                           &outgoing_message->current_message_position);
-  outgoing_message->used_message_length += AddIntToMessage(device_type_,
+  outgoing_message->used_message_length += AddIntToMessage(g_identity.vendor_id,
                                                            &outgoing_message->current_message_position);
-  outgoing_message->used_message_length += AddIntToMessage(product_code_,
-                                                           &outgoing_message->current_message_position);
-  *(outgoing_message->current_message_position)++ = revision_.major_revision;
+  outgoing_message->used_message_length += AddIntToMessage(
+    g_identity.device_type,
+    &outgoing_message->current_message_position);
+  outgoing_message->used_message_length += AddIntToMessage(
+    g_identity.product_code,
+    &outgoing_message->current_message_position);
+  *(outgoing_message->current_message_position)++ =
+    g_identity.revision.major_revision;
   outgoing_message->used_message_length++;
-  *(outgoing_message->current_message_position)++ = revision_.minor_revision;
+  *(outgoing_message->current_message_position)++ =
+    g_identity.revision.minor_revision;
   outgoing_message->used_message_length++;
-  outgoing_message->used_message_length += AddIntToMessage(status_,
+  outgoing_message->used_message_length += AddIntToMessage(g_identity.status,
                                                            &outgoing_message->current_message_position);
-  outgoing_message->used_message_length += AddDintToMessage(serial_number_,
-                                                            &outgoing_message->current_message_position);
+  outgoing_message->used_message_length += AddDintToMessage(
+    g_identity.serial_number,
+    &outgoing_message->current_message_position);
   *outgoing_message->current_message_position++ =
-    (unsigned char) product_name_.length;
+    (unsigned char) g_identity.product_name.length;
   outgoing_message->used_message_length++;
 
-  memcpy(outgoing_message->current_message_position, product_name_.string,
-         product_name_.length);
-  outgoing_message->current_message_position += product_name_.length;
-  outgoing_message->used_message_length += product_name_.length;
+  memcpy(outgoing_message->current_message_position,
+         g_identity.product_name.string,
+         g_identity.product_name.length);
+  outgoing_message->current_message_position += g_identity.product_name.length;
+  outgoing_message->used_message_length += g_identity.product_name.length;
 
-  *outgoing_message->current_message_position++ = g_state;
+  *outgoing_message->current_message_position++ = g_identity.state;
   outgoing_message->used_message_length++;
 
 }

+ 2 - 2
source/src/opener_api.h

@@ -60,9 +60,9 @@ void SetDeviceSerialNumber(const EipUint32 serial_number);
 /** @ingroup CIP_API
  * @brief Set the current status of the device.
  *
- * @param device_status the new status value
+ * @param status new Identity object's Status value
  */
-void SetDeviceStatus(const EipUint16 device_status);
+void SetDeviceStatus(const EipUint16 status);
 
 /** @ingroup CIP_API
  * @brief Initialize and setup the CIP-stack

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

@@ -68,6 +68,7 @@ int main(int argc,
 #ifndef WIN32
     /* register for closing signals so that we can trigger the stack to end */
     signal(SIGHUP, LeaveStack);
+    signal(SIGINT, LeaveStack); /* needed to be able to abort with ^C */
 #endif
 
     /* The event loop. Put other processing you need done continually in here */
@@ -88,6 +89,6 @@ int main(int argc,
 
 void LeaveStack(int pa_nSig) {
   (void) pa_nSig; /* kill unused parameter warning */
-  OPENER_TRACE_STATE("got signal HUP\n");
+  OPENER_TRACE_STATE("got signal %d\n",pa_nSig);
   g_end_stack = 1;
 }

+ 26 - 34
source/src/ports/MINGW/networkconfig.c

@@ -58,19 +58,19 @@ EipStatus ConfigureNetworkInterface(const char *const network_interface) {
                  6 * sizeof(CipUsint) );
         }
 
-        interface_configuration_.ip_address = inet_addr(
+        g_tcpip.interface_configuration.ip_address = inet_addr(
           pAdapter->IpAddressList.IpAddress.String);
-        interface_configuration_.network_mask = inet_addr(
+        g_tcpip.interface_configuration.network_mask = inet_addr(
           pAdapter->IpAddressList.IpMask.String);
-        interface_configuration_.gateway = inet_addr(
+        g_tcpip.interface_configuration.gateway = inet_addr(
           pAdapter->GatewayList.IpAddress.String);
 
-        CipUdint host_id = ntohl(interface_configuration_.ip_address)
-                           & ~ntohl(interface_configuration_.network_mask);              /* see CIP spec 3-5.3 for multicast address algorithm*/
+        CipUdint host_id = ntohl(g_tcpip.interface_configuration.ip_address)
+                           & ~ntohl(g_tcpip.interface_configuration.network_mask);              /* see CIP spec 3-5.3 for multicast address algorithm*/
         host_id -= 1;
         host_id &= 0x3ff;
 
-        g_multicast_configuration.starting_multicast_address = htonl(
+        g_tcpip.mcast_config.starting_multicast_address = htonl(
           ntohl(inet_addr("239.192.1.0") ) + (host_id << 5) );
       }
       pAdapter = pAdapter->Next;
@@ -148,36 +148,27 @@ void ConfigureDomainName() {
         char pStringBuf[INET_ADDRSTRLEN];
         if (i != 0) {
 
-          if (NULL != interface_configuration_.domain_name.string) {
+          if (NULL != g_tcpip.interface_configuration.domain_name.string) {
             /* if the string is already set to a value we have to free the resources
              * before we can set the new value in order to avoid memory leaks.
              */
-            CipFree(interface_configuration_.domain_name.string);
+            CipFree(g_tcpip.interface_configuration.domain_name.string);
           }
-          interface_configuration_.domain_name.length = strlen(
+          g_tcpip.interface_configuration.domain_name.length = strlen(
             pCurrAddresses->DnsSuffix);
-          if (interface_configuration_.domain_name.length) {
-            interface_configuration_.domain_name.string = (CipByte *)CipCalloc(
-              interface_configuration_.domain_name.length + 1,
-              sizeof(CipUsint) );
-            strcpy(interface_configuration_.domain_name.string,
+          if (g_tcpip.interface_configuration.domain_name.length) {
+            g_tcpip.interface_configuration.domain_name.string =
+              (CipByte *)CipCalloc(
+                g_tcpip.interface_configuration.domain_name.length + 1,
+                sizeof(CipUsint) );
+            strcpy(g_tcpip.interface_configuration.domain_name.string,
                    pCurrAddresses->DnsSuffix);
           }
           else {
-            interface_configuration_.domain_name.string = NULL;
+            g_tcpip.interface_configuration.domain_name.string = NULL;
           }
-/*
-          inet_ntop(AF_INET,
-                   pCurrAddresses->FirstDnsServerAddress->Address.lpSockaddr->sa_data + 2,
-                   interface_configuration_.name_server,
-                   sizeof(interface_configuration_.name_server) );
-          inet_ntop(AF_INET,
-                   pCurrAddresses->FirstDnsServerAddress->Next->Address.lpSockaddr->sa_data + 2,
-                   interface_configuration_.name_server_2,
-                   sizeof(interface_configuration_.name_server_2) );
- */
         }
-        else{ interface_configuration_.domain_name.length = 0;}
+        else{ g_tcpip.interface_configuration.domain_name.length = 0;}
 
       }
       pCurrAddresses = pCurrAddresses->Next;
@@ -240,18 +231,19 @@ void ConfigureHostName(void) {
 
 
 
-  if (NULL != hostname_.string) {
+  if (NULL != g_tcpip.hostname.string) {
     /* if the string is already set to a value we have to free the resources
      * before we can set the new value in order to avoid memory leaks.
      */
-    CipFree(hostname_.string);
+    CipFree(g_tcpip.hostname.string);
   }
-  hostname_.length = strlen(hostname);
-  if (hostname_.length) {
-    hostname_.string = (CipByte *) CipCalloc( hostname_.length + 1,
-                                              sizeof(CipByte) );
-    strcpy(hostname_.string, hostname);
+  g_tcpip.hostname.length = strlen(hostname);
+  if (g_tcpip.hostname.length) {
+    g_tcpip.hostname.string = (CipByte *) CipCalloc(
+      g_tcpip.hostname.length + 1,
+      sizeof(CipByte) );
+    strcpy(g_tcpip.hostname.string, hostname);
   } else {
-    hostname_.string = NULL;
+    g_tcpip.hostname.string = NULL;
   }
 }

+ 2 - 3
source/src/ports/MINGW/sample_application/sampleapplication.c

@@ -9,6 +9,7 @@
 
 #include "opener_api.h"
 #include "appcontype.h"
+#include "ciptcpipinterface.h"
 #include "cipqos.h"
 
 #define DEMO_APP_INPUT_ASSEMBLY_NUM                100 //0x064
@@ -20,8 +21,6 @@
 
 /* global variables for demo application (4 assembly data fields)  ************/
 
-extern CipUint g_encapsulation_inactivity_timeout;
-
 EipUint8 g_assembly_data064[40]; /* Input */
 EipUint8 g_assembly_data096[40]; /* Output */
 EipUint8 g_assembly_data097[10]; /* Config */
@@ -130,7 +129,7 @@ EipStatus ResetDevice(void) {
 
 EipStatus ResetDeviceToInitialConfiguration(void) {
   /*rest the parameters */
-  g_encapsulation_inactivity_timeout = 120;
+  g_tcpip.encapsulation_inactivity_timeout = 120;
   CipQosResetAttributesToDefaultValues();
   /*than perform device reset*/
   ResetDevice();

+ 2 - 1
source/src/ports/POSIX/main.c

@@ -117,6 +117,7 @@ int main(int argc,
 #ifndef WIN32
     /* register for closing signals so that we can trigger the stack to end */
     signal(SIGHUP, LeaveStack);
+    signal(SIGINT, LeaveStack); /* needed to be able to abort with ^C */
 #endif
 #ifdef OPENER_RT
     /* Memory lock all*/
@@ -189,7 +190,7 @@ int main(int argc,
 
 void LeaveStack(int signal) {
   (void) signal;       /* kill unused parameter warning */
-  OPENER_TRACE_STATE("got signal HUP\n");
+  OPENER_TRACE_STATE("got signal %d\n",signal);
   g_end_stack = 1;
 }
 

+ 37 - 30
source/src/ports/POSIX/networkconfig.c

@@ -71,8 +71,8 @@ EipStatus ConfigureNetworkInterface(const char *const network_interface) {
       return kEipStatusError;
     }
 
-    interface_configuration_.ip_address = ipaddr;
-    interface_configuration_.network_mask = netaddr;
+    g_tcpip.interface_configuration.ip_address = ipaddr;
+    g_tcpip.interface_configuration.network_mask = netaddr;
 
     close(fd);
   }
@@ -108,23 +108,24 @@ EipStatus ConfigureNetworkInterface(const char *const network_interface) {
 
   if(inet_pton(AF_INET, gateway_string, &gateway) == 1) {
     if(INADDR_LOOPBACK != gateway) {
-      interface_configuration_.gateway = gateway;
+      g_tcpip.interface_configuration.gateway = gateway;
     }
     else{
-      interface_configuration_.gateway = 0;
+      g_tcpip.interface_configuration.gateway = 0;
     }
   }
   else{
-    interface_configuration_.gateway = 0;
+    g_tcpip.interface_configuration.gateway = 0;
   }
 
   /* calculate the CIP multicast address. The multicast address is calculated, not input*/
-  EipUint32 host_id = ntohl(interface_configuration_.ip_address) & ~ntohl(
-    interface_configuration_.network_mask);                                                                       /* see CIP spec 3-5.3 for multicast address algorithm*/
+  EipUint32 host_id = ntohl(g_tcpip.interface_configuration.ip_address) &
+                      ~ntohl(
+    g_tcpip.interface_configuration.network_mask);                                                                       /* see CIP spec 3-5.3 for multicast address algorithm*/
   host_id -= 1;
   host_id &= 0x3ff;
 
-  g_multicast_configuration.starting_multicast_address =
+  g_tcpip.mcast_config.starting_multicast_address =
     htonl(ntohl(inet_addr("239.192.1.0") ) + (host_id << 5) );
 
   fclose(file_handle);
@@ -170,26 +171,29 @@ void ConfigureDomainName() {
     strtok_r(file_buffer, " ", &strtok_save);
     domain_name_string = strtok_r(file_buffer, "\n", &strtok_save);
 
-    if(NULL != interface_configuration_.domain_name.string) {
+    if(NULL != g_tcpip.interface_configuration.domain_name.string) {
       /* if the string is already set to a value we have to free the resources
        * before we can set the new value in order to avoid memory leaks.
        */
-      CipFree(interface_configuration_.domain_name.string);
+      CipFree(g_tcpip.interface_configuration.domain_name.string);
     }
-    interface_configuration_.domain_name.length = strlen(domain_name_string);
-
-    if(interface_configuration_.domain_name.length) {
-      interface_configuration_.domain_name.string = (EipByte *) CipCalloc(
-        interface_configuration_.domain_name.length + 1,
-        sizeof(EipByte) );
+    g_tcpip.interface_configuration.domain_name.length = strlen(
+      domain_name_string);
+
+    if(g_tcpip.interface_configuration.domain_name.length) {
+      g_tcpip.interface_configuration.domain_name.string =
+        (EipByte *) CipCalloc(
+          g_tcpip.interface_configuration.domain_name.length + 1,
+          sizeof(EipByte) );
       /* *.domain_name.string was calloced with *.domain_name.length+1 which
        *    provides a trailing '\0' when memcpy( , , *.length) is done!
        */
-      memcpy(interface_configuration_.domain_name.string, domain_name_string,
-             interface_configuration_.domain_name.length);
+      memcpy(g_tcpip.interface_configuration.domain_name.string,
+             domain_name_string,
+             g_tcpip.interface_configuration.domain_name.length);
     }
     else{
-      interface_configuration_.domain_name.string = NULL;
+      g_tcpip.interface_configuration.domain_name.string = NULL;
     }
   }
 
@@ -198,7 +202,8 @@ void ConfigureDomainName() {
     strtok_r(file_buffer, " ", &strtok_save);
     dns1_string = strtok_r(NULL, "\n", &strtok_save);
 
-    inet_pton(AF_INET, dns1_string, &interface_configuration_.name_server);
+    inet_pton(AF_INET, dns1_string,
+              &g_tcpip.interface_configuration.name_server);
   }
 
   if(strstr(file_buffer, "nameserver ") ) {
@@ -206,7 +211,9 @@ void ConfigureDomainName() {
     strtok_r(file_buffer, " ", &strtok_save);
     dns2_string = strtok_r(file_buffer, "\n", &strtok_save);
 
-    inet_pton(AF_INET, dns2_string, &interface_configuration_.name_server_2);
+    inet_pton(AF_INET,
+              dns2_string,
+              &g_tcpip.interface_configuration.name_server_2);
   }
 
   free(file_buffer);
@@ -216,20 +223,20 @@ void ConfigureHostName() {
   char name[1024] = { 0 };
   gethostname(name, sizeof(name) );
 
-  if(NULL != hostname_.string) {
+  if(NULL != g_tcpip.hostname.string) {
     /* if the string is already set to a value we have to free the resources
      * before we can set the new value in order to avoid memory leaks.
      */
-    CipFree(hostname_.string);
+    CipFree(g_tcpip.hostname.string);
   }
-  hostname_.length = strlen(name);
-  if(hostname_.length) {
-    hostname_.string =
-      (EipByte *) CipCalloc(hostname_.length + 1, sizeof(EipByte) );
-    snprintf( (char *)hostname_.string,
-              (hostname_.length + 1) * sizeof(EipByte), "%s", name );
+  g_tcpip.hostname.length = strlen(name);
+  if(g_tcpip.hostname.length) {
+    g_tcpip.hostname.string =
+      (EipByte *) CipCalloc(g_tcpip.hostname.length + 1, sizeof(EipByte) );
+    snprintf( (char *)g_tcpip.hostname.string,
+              (g_tcpip.hostname.length + 1) * sizeof(EipByte), "%s", name );
   }
   else{
-    hostname_.string = NULL;
+    g_tcpip.hostname.string = NULL;
   }
 }

+ 2 - 0
source/src/ports/POSIX/opener_error.c

@@ -10,6 +10,8 @@
  *
  */
 
+#undef _GNU_SOURCE  /* Force the use of the XSI compliant strerror_r() function. */
+
 #include <errno.h>
 #include <stddef.h>
 #include <stdlib.h>

+ 2 - 3
source/src/ports/POSIX/sample_application/sampleapplication.c

@@ -12,6 +12,7 @@
 #include "appcontype.h"
 #include "trace.h"
 #include "cipidentity.h"
+#include "ciptcpipinterface.h"
 #include "cipqos.h"
 
 #define DEMO_APP_INPUT_ASSEMBLY_NUM                100 //0x064
@@ -23,8 +24,6 @@
 
 /* global variables for demo application (4 assembly data fields)  ************/
 
-extern CipUint g_encapsulation_inactivity_timeout;
-
 EipUint8 g_assembly_data064[32]; /* Input */
 EipUint8 g_assembly_data096[32]; /* Output */
 EipUint8 g_assembly_data097[10]; /* Config */
@@ -137,7 +136,7 @@ EipStatus ResetDevice(void) {
 
 EipStatus ResetDeviceToInitialConfiguration(void) {
   /*rest the parameters */
-  g_encapsulation_inactivity_timeout = 120;
+  g_tcpip.encapsulation_inactivity_timeout = 120;
   CipQosResetAttributesToDefaultValues();
   /*than perform device reset*/
   ResetDevice();

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

@@ -68,6 +68,7 @@ int main(int argc,
 #ifndef WIN32
     /* register for closing signals so that we can trigger the stack to end */
     signal(SIGHUP, LeaveStack);
+    signal(SIGINT, LeaveStack); /* needed to be able to abort with ^C */
 #endif
 
     /* The event loop. Put other processing you need done continually in here */
@@ -88,6 +89,6 @@ int main(int argc,
 
 void LeaveStack(int pa_nSig) {
   (void) pa_nSig; /* kill unused parameter warning */
-  OPENER_TRACE_STATE("got signal HUP\n");
+  OPENER_TRACE_STATE("got signal %d\n",pa_nSig);
   g_end_stack = 1;
 }

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

@@ -26,10 +26,10 @@
 #pragma comment(lib, "Ws2_32.lib")
 
 static EipStatus WideToCipString(const WCHAR *const src,
-    CipString *const dest);
+                                 CipString *const dest);
 
 static CipUdint GetDnsServerAddress(
-    const IP_ADAPTER_DNS_SERVER_ADDRESS_XP * const RESTRICT in);
+  const IP_ADAPTER_DNS_SERVER_ADDRESS_XP *const RESTRICT in);
 
 
 void ConfigureIpMacAddress(const CipUint interface_index) {
@@ -66,20 +66,20 @@ void ConfigureIpMacAddress(const CipUint interface_index) {
         }
 
         inet_pton(AF_INET, pAdapter->IpAddressList.IpAddress.String,
-                  &interface_configuration_.ip_address);
+                  &g_tcpip.interface_configuration.ip_address);
         inet_pton(AF_INET, pAdapter->IpAddressList.IpMask.String,
-                  &interface_configuration_.network_mask);
+                  &g_tcpip.interface_configuration.network_mask);
         inet_pton(AF_INET, pAdapter->GatewayList.IpAddress.String,
-                  &interface_configuration_.gateway);
+                  &g_tcpip.interface_configuration.gateway);
 
-        CipUdint host_id = ntohl(interface_configuration_.ip_address)
-                           & ~ntohl(interface_configuration_.network_mask);              /* see CIP spec 3-5.3 for multicast address algorithm*/
+        CipUdint host_id = ntohl(g_tcpip.interface_configuration.ip_address)
+                           & ~ntohl(g_tcpip.interface_configuration.network_mask);              /* see CIP spec 3-5.3 for multicast address algorithm*/
         host_id -= 1;
         host_id &= 0x3ff;
 
         CipUdint multicast_base;
         inet_pton(AF_INET, "239.192.1.0", &multicast_base);
-        g_multicast_configuration.starting_multicast_address = htonl(
+        g_tcpip.mcast_config.starting_multicast_address = htonl(
           ntohl(multicast_base) + (host_id << 5) );
       }
       pAdapter = pAdapter->Next;
@@ -154,17 +154,17 @@ void ConfigureDomainName(const CipUint interface_index) {
         char pStringBuf[INET_ADDRSTRLEN];
         if (i != 0) {
           WideToCipString(pCurrAddresses->DnsSuffix,
-                          &interface_configuration_.domain_name);
-
-          interface_configuration_.name_server =
-              GetDnsServerAddress(pCurrAddresses->FirstDnsServerAddress);
-          interface_configuration_.name_server_2 =
-              (pCurrAddresses->FirstDnsServerAddress != NULL)
-                  ? GetDnsServerAddress(
-                        pCurrAddresses->FirstDnsServerAddress->Next)
-                  : 0;
+                          &g_tcpip.interface_configuration.domain_name);
+
+          g_tcpip.interface_configuration.name_server =
+            GetDnsServerAddress(pCurrAddresses->FirstDnsServerAddress);
+          g_tcpip.interface_configuration.name_server_2 =
+            (pCurrAddresses->FirstDnsServerAddress != NULL)
+            ? GetDnsServerAddress(
+              pCurrAddresses->FirstDnsServerAddress->Next)
+            : 0;
         }
-        else{ interface_configuration_.domain_name.length = 0;}
+        else{ g_tcpip.interface_configuration.domain_name.length = 0;}
 
       }
       pCurrAddresses = pCurrAddresses->Next;
@@ -220,9 +220,9 @@ static EipStatus WideToCipString(const WCHAR *const src,
   OPENER_ASSERT(dest != NULL);
 
   /*
-  * Evaluate the source string, ensuring the number of characters fit in
-  * EipUint16, excluding the null terminator.
-  */
+   * Evaluate the source string, ensuring the number of characters fit in
+   * EipUint16, excluding the null terminator.
+   */
   const size_t num_chars = wcslen(src);
   if (num_chars >= UINT16_MAX) {
     return kEipStatusError;
@@ -241,7 +241,7 @@ static EipStatus WideToCipString(const WCHAR *const src,
     /* Transfer the string to the new buffer. */
     size_t converted_chars;
     const errno_t result =
-        wcstombs_s(&converted_chars, buf, buffer_size, src, num_chars);
+      wcstombs_s(&converted_chars, buf, buffer_size, src, num_chars);
     OPENER_ASSERT(result == 0);
   }
 
@@ -269,16 +269,16 @@ static EipStatus WideToCipString(const WCHAR *const src,
 
 
 /** @brief Extracts a DNS server IP address.
-*
-* @param in DNS server address structure from GetAdapterAddresses().
-*
-* @return The IPv4 address in network byte order.
-*/
+ *
+ * @param in DNS server address structure from GetAdapterAddresses().
+ *
+ * @return The IPv4 address in network byte order.
+ */
 static CipUdint GetDnsServerAddress(
-    const IP_ADAPTER_DNS_SERVER_ADDRESS_XP * const RESTRICT in) {
+  const IP_ADAPTER_DNS_SERVER_ADDRESS_XP *const RESTRICT in) {
   return (in != NULL)
-             ? ((SOCKADDR_IN *)in->Address.lpSockaddr)->sin_addr.S_un.S_addr
-             : 0;
+         ? ( (SOCKADDR_IN *)in->Address.lpSockaddr )->sin_addr.S_un.S_addr
+         : 0;
 }
 
 
@@ -307,20 +307,20 @@ void ConfigureHostName(const CipUint interface_index) {
 
 
 
-  if (NULL != hostname_.string) {
+  if (NULL != g_tcpip.hostname.string) {
     /* if the string is already set to a value we have to free the resources
      * before we can set the new value in order to avoid memory leaks.
      */
-    CipFree(hostname_.string);
+    CipFree(g_tcpip.hostname.string);
   }
-  hostname_.length = strlen(hostname);
-  if (hostname_.length) {
+  g_tcpip.hostname.length = strlen(hostname);
+  if (g_tcpip.hostname.length) {
     /* Storage space for the string must include NULL termination. */
-    size_t buf_length = hostname_.length + 1;
-    hostname_.string = (CipByte *) CipCalloc( buf_length,
-                                              sizeof(CipByte) );
-    strcpy_s(hostname_.string, buf_length, hostname);
+    size_t buf_length = g_tcpip.hostname.length + 1;
+    g_tcpip.hostname.string = (CipByte *) CipCalloc( buf_length,
+                                                     sizeof(CipByte) );
+    strcpy_s(g_tcpip.hostname.string, buf_length, hostname);
   } else {
-    hostname_.string = NULL;
+    g_tcpip.hostname.string = NULL;
   }
 }

+ 2 - 3
source/src/ports/WIN32/sample_application/sampleapplication.c

@@ -8,6 +8,7 @@
 #include <stdlib.h>
 
 #include "opener_api.h"
+#include "ciptcpipinterface.h"
 #include "cipqos.h"
 
 #define DEMO_APP_INPUT_ASSEMBLY_NUM                100 //0x064
@@ -19,8 +20,6 @@
 
 /* global variables for demo application (4 assembly data fields)  ************/
 
-extern CipUint g_encapsulation_inactivity_timeout;
-
 EipUint8 g_assembly_data064[32]; /* Input */
 EipUint8 g_assembly_data096[32]; /* Output */
 EipUint8 g_assembly_data097[10]; /* Config */
@@ -129,7 +128,7 @@ EipStatus ResetDevice(void) {
 
 EipStatus ResetDeviceToInitialConfiguration(void) {
   /*rest the parameters */
-  g_encapsulation_inactivity_timeout = 120;
+  g_tcpip.encapsulation_inactivity_timeout = 120;
   CipQosResetAttributesToDefaultValues();
   /*than perform device reset*/
   ResetDevice();

+ 15 - 13
source/src/ports/generic_networkhandler.c

@@ -27,8 +27,6 @@
 
 #define MAX_NO_OF_TCP_SOCKETS 10
 
-extern CipTcpIpNetworkInterfaceConfiguration interface_configuration_;
-
 /** @brief handle any connection request coming in the TCP server socket.
  *
  */
@@ -71,6 +69,8 @@ EipStatus NetworkHandlerInitialize(void) {
   }
 
   SocketTimerArrayInitialize(g_timestamps, OPENER_NUMBER_OF_SUPPORTED_SESSIONS);
+  /* Activate the current DSCP values to become the used set of values. */
+  CipQosUpdateUsedSetQosValues();
 
   /* clear the master an temp sets */
   FD_ZERO(&master_socket);
@@ -168,7 +168,7 @@ EipStatus NetworkHandlerInitialize(void) {
   struct sockaddr_in my_address = {
     .sin_family = AF_INET,
     .sin_port = htons(kOpenerEthernetPort),
-    .sin_addr.s_addr = interface_configuration_.ip_address
+    .sin_addr.s_addr = g_tcpip.interface_configuration.ip_address
   };
 
   /* bind the new socket to port 0xAF12 (CIP) */
@@ -608,7 +608,8 @@ EipStatus SendUdpData(struct sockaddr_in *address,
   UDPHeaderSetChecksum(&header,
                        htons(UDPHeaderCalculateChecksum(complete_message,
                                                         8 + data_length,
-                                                        interface_configuration_
+                                                        g_tcpip.
+                                                        interface_configuration
                                                         .ip_address,
                                                         address->sin_addr.s_addr) ) );
   UDPHeaderGenerate(&header, (char *)complete_message);
@@ -700,7 +701,7 @@ EipStatus HandleDataOnTcpSocket(int socket) {
 
     do {
       OPENER_TRACE_INFO(
-        "Entering consumption loop, remaining data to receive: %zu\n",
+        "Entering consumption loop, remaining data to receive: %ld\n",
         data_sent);
       number_of_read_bytes = recv(socket, &incoming_message[0],
                                   data_sent, 0);
@@ -928,16 +929,16 @@ int CreateUdpSocket(UdpCommuncationDirection communication_direction,
 
     /* For multicast socket setup the TTL and specify interface to send on. */
     if (socket_data->sin_addr.s_addr
-        == g_multicast_configuration.starting_multicast_address) {
-      if (1 != g_time_to_live_value) { /* we need to set a TTL value for the socket */
+        == g_tcpip.mcast_config.starting_multicast_address) {
+      if (1 != g_tcpip.mcast_ttl_value) { /* we need to set a TTL value for the socket */
         if ( setsockopt(new_socket, IPPROTO_IP, IP_MULTICAST_TTL,
-                        &g_time_to_live_value,
-                        sizeof(g_time_to_live_value) ) < 0 ) {
+                        &g_tcpip.mcast_ttl_value,
+                        sizeof(g_tcpip.mcast_ttl_value) ) < 0 ) {
           int error_code = GetSocketErrorNumber();
           char *error_message = GetErrorMessage(error_code);
           OPENER_TRACE_ERR(
             "networkhandler: could not set the TTL to: %d, error: %d - %s\n",
-            g_time_to_live_value, error_code, error_message);
+            g_tcpip.mcast_ttl_value, error_code, error_message);
           FreeErrorMessage(error_message);
           CloseUdpSocket(new_socket);
           return kEipInvalidSocket;
@@ -947,7 +948,7 @@ int CreateUdpSocket(UdpCommuncationDirection communication_direction,
         /* Need to specify the interface for outgoing multicast packets on a device
             with multiple interfaces. */
         struct in_addr my_addr =
-        { .s_addr = interface_configuration_.ip_address };
+        { .s_addr = g_tcpip.interface_configuration.ip_address };
         if ( setsockopt(new_socket, IPPROTO_IP, IP_MULTICAST_IF,
                         &my_addr.s_addr,
                         sizeof my_addr.s_addr ) < 0 ) {
@@ -1090,7 +1091,7 @@ int GetMaxSocket(int socket1,
 }
 
 void CheckEncapsulationInactivity(int socket_handle) {
-  if (0 < g_encapsulation_inactivity_timeout) { //*< Encapsulation inactivity timeout is enabled
+  if (0 < g_tcpip.encapsulation_inactivity_timeout) { //*< Encapsulation inactivity timeout is enabled
     SocketTimer *socket_timer = SocketTimerArrayGetSocketTimer(
       g_timestamps,
       OPENER_NUMBER_OF_SUPPORTED_SESSIONS,
@@ -1104,7 +1105,8 @@ void CheckEncapsulationInactivity(int socket_handle) {
         socket_timer);
 
       if ( diff_milliseconds >=
-           (MilliSeconds) (1000UL * g_encapsulation_inactivity_timeout) ) {
+           (MilliSeconds) (1000UL *
+                           g_tcpip.encapsulation_inactivity_timeout) ) {
 
         size_t encapsulation_session_handle =
           GetSessionFromSocket(socket_handle);

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

@@ -221,7 +221,7 @@ TEST(CipCommon, GetSizeOfAttributeCipUsintUsint) {
 }
 
 TEST(CipCommon, GetSizeOfAttributeCipUdintUdintUdintUdintUdintString) {
-  CipTcpIpNetworkInterfaceConfiguration config;
+  CipTcpIpInterfaceConfiguration config;
   char domain_name[] = "www.github.com/EIPStackGroup/OpENer";
   config.domain_name.length = sizeof(domain_name);
   config.domain_name.string = (EipByte *)domain_name;