Răsfoiți Sursa

Refactoring of TCP/IP interface module to get a object structure

The new ciptcpipinterface.h header declares a new type CipTcpIpObject
that contains all of the object's attributes.

Refactor all affected sources. No functional change intended.

Signed-off-by: Stefan Mätje <stefan.maetje@esd.eu>
Stefan Mätje 6 ani în urmă
părinte
comite
a0e7c7a14e

+ 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);
     }

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

@@ -504,9 +504,8 @@ EipStatus OpenProducingMulticastConnection(
   connection_object->remote_address.sin_addr.s_addr = 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].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;
   }

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

@@ -17,50 +17,43 @@
 #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 = {
+  0x01, /* attribute #1 TCP status with 1 we indicate that we got a valid configuration from DHCP or BOOTP */
+  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. */
+  0x02, /* attribute #3 config_control: 0x02 means that the device shall obtain its interface configuration values via DHCP. */
+  {     /* 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)*/
+  },
+  { /* attribute #5 interface_configuration */
+    0, /* IP address */
+    0, /* NetworkMask */
+    0, /* Gateway */
+    0, /* NameServer */
+    0, /* NameServer2 */
+    { /* DomainName */
+      0, NULL,
+    }
+  },
+  { /* attribute #6 hostname */
+    0,
+    NULL
+  },
+  1,  /* attribute #8 mcast TTL value */
+  {   /* 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 */
+  },
+  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 +174,25 @@ 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);
+                  (void *) &g_tcpip.encapsulation_inactivity_timeout, kSetAndGetAble);
 
   InsertService(tcp_ip_class, kGetAttributeSingle,
                 &GetAttributeSingleTcpIpInterface,
@@ -215,14 +208,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 +264,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,

+ 20 - 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,28 @@ 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 data
+ *
+ */
+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 */
+
+  /** #9 The multicast configuration for this device */
+  MulticastAddressConfiguration mcast_config;
 
-extern CipUint g_encapsulation_inactivity_timeout; /**< Number of seconds of inactivity before TCP connection is closed, Default is 120 */
+  /** #13 Number of seconds of inactivity before TCP connection is closed */
+  CipUint encapsulation_inactivity_timeout;
+} CipTcpIpObject;
 
-extern MulticastAddressConfiguration g_multicast_configuration; /**< Multicast configuration */
+
+/* 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;

+ 3 - 4
source/src/enet_encap/encap.c

@@ -17,6 +17,7 @@
 #include "cipmessagerouter.h"
 #include "cipconnectionmanager.h"
 #include "cipidentity.h"
+#include "ciptcpipinterface.h"
 #include "generic_networkhandler.h"
 #include "trace.h"
 #include "socket_timer.h"
@@ -33,8 +34,6 @@ 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 +126,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++) {
@@ -456,7 +455,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 */

+ 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();

+ 28 - 28
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,23 @@ 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 +170,26 @@ 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);
+    g_tcpip.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,
+    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 +198,7 @@ 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 +206,7 @@ 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 +216,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 - 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 - 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();

+ 11 - 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.
  *
  */
@@ -170,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) */
@@ -610,7 +608,7 @@ 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);
@@ -702,7 +700,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);
@@ -930,16 +928,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;
@@ -949,7 +947,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 ) {
@@ -1092,7 +1090,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,
@@ -1106,7 +1104,7 @@ 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);