فهرست منبع

Merge branch 'PeterChristen577-Without-raw'

Martin Melik-Merkumians 3 سال پیش
والد
کامیت
6068d32066

+ 34 - 22
source/src/cip/cipconnectionmanager.c

@@ -201,26 +201,26 @@ void InitializeConnectionManager(CipClass *class) {
   CipClass *meta_class = class->class_instance.cip_class;
 
   InsertAttribute( (CipInstance *) class, 1, kCipUint, EncodeCipUint, NULL,
-                   (void *) &class->revision, kGetableSingleAndAll );                                                      /* revision */
+                   (void *) &class->revision, kGetableSingleAndAll ); /* revision */
   InsertAttribute( (CipInstance *) class, 2, kCipUint, EncodeCipUint, NULL,
-                   (void *) &class->number_of_instances, kGetableSingleAndAll );                                                      /*  largest instance number */
+                   (void *) &class->number_of_instances, kGetableSingleAndAll ); /* largest instance number */
   InsertAttribute( (CipInstance *) class, 3, kCipUint, EncodeCipUint, NULL,
-                   (void *) &class->number_of_instances, kGetableSingle );                                                      /* number of instances currently existing*/
+                   (void *) &class->number_of_instances, kGetableSingle ); /* number of instances currently existing*/
   InsertAttribute( (CipInstance *) class, 4, kCipUint, EncodeCipUint, NULL,
-                   (void *) &kCipUintZero, kNotSetOrGetable );                                                      /* optional attribute list - default = 0 */
+                   (void *) &kCipUintZero, kNotSetOrGetable ); /* optional attribute list - default = 0 */
   InsertAttribute( (CipInstance *) class, 5, kCipUint, EncodeCipUint, NULL,
-                   (void *) &kCipUintZero, kNotSetOrGetable );                                                      /* optional service list - default = 0 */
+                   (void *) &kCipUintZero, kNotSetOrGetable ); /* optional service list - default = 0 */
   InsertAttribute( (CipInstance *) class, 6, kCipUint, EncodeCipUint, NULL,
                    (void *) &meta_class->highest_attribute_number,
-                   kGetableSingleAndAll );                                                                                                      /* max class attribute number*/
+                   kGetableSingleAndAll ); /* max class attribute number*/
   InsertAttribute( (CipInstance *) class, 7, kCipUint, EncodeCipUint, NULL,
                    (void *) &class->highest_attribute_number,
-                   kGetableSingleAndAll );                                                                                                 /* max instance attribute number*/
+                   kGetableSingleAndAll ); /* max instance attribute number*/
 
   InsertService(meta_class,
                 kGetAttributeAll,
                 &GetAttributeAll,
-                "GetAttributeAll");                                                 /* bind instance services to the metaclass*/
+                "GetAttributeAll"); /* bind instance services to the metaclass*/
   InsertService(meta_class,
                 kGetAttributeSingle,
                 &GetAttributeSingle,
@@ -294,9 +294,9 @@ EipStatus HandleReceivedConnectedData(const EipUint8 *const data,
     if( (g_common_packet_format_data_item.address_item.type_id ==
          kCipItemIdConnectionAddress)
         || (g_common_packet_format_data_item.address_item.type_id ==
-            kCipItemIdSequencedAddressItem) ) {                                                       /* found connected address item or found sequenced address item -> for now the sequence number will be ignored */
+            kCipItemIdSequencedAddressItem) ) { /* found connected address item or found sequenced address item -> for now the sequence number will be ignored */
       if(g_common_packet_format_data_item.data_item.type_id ==
-         kCipItemIdConnectedDataItem) {                                                       /* connected data item received */
+         kCipItemIdConnectedDataItem) { /* connected data item received */
 
         CipConnectionObject *connection_object = GetConnectedObject(
           g_common_packet_format_data_item.address_item.data.connection_identifier);
@@ -461,7 +461,7 @@ EipStatus HandleNonNullNonMatchingForwardOpenRequest(
 
   /*parsing is now finished all data is available and check now establish the connection */
   ConnectionManagementHandling *connection_management_entry =
-    GetConnectionManagementEntry(                                                           /* Gets correct open connection function for the targeted object */
+    GetConnectionManagementEntry( /* Gets correct open connection function for the targeted object */
       g_dummy_connection_object.configuration_path.class_id);
   if(NULL != connection_management_entry) {
     temp = connection_management_entry->open_connection_function(
@@ -700,7 +700,7 @@ EipStatus ForwardClose(CipInstance *instance,
   if(kConnectionManagerExtendedStatusCodeErrorConnectionTargetConnectionNotFound
      == connection_status) {
     OPENER_TRACE_INFO(
-      "Connection not found! Requested connection triad: %u, %u, %u\n",
+      "Connection not found! Requested connection tried: %u, %u, %i\n",
       connection_serial_number,
       originator_vendor_id,
       originator_serial_number);
@@ -788,7 +788,7 @@ EipStatus SearchConnectionData(CipInstance *instance,
     &message_router_request->data);
 
   OPENER_TRACE_INFO(
-    "SearchConnectionData for ConnSerNo: %d, OrigVendId: %d, OrigSerNo: %ld,\n",
+    "SearchConnectionData for ConnSerNo: %d, OrigVendId: %d, OrigSerNo: %i,\n",
     Connection_serial_number,
     Originator_vendor_id,
     Originator_serial_number);
@@ -910,7 +910,7 @@ EipStatus ManageConnections(MilliSeconds elapsed_time) {
        ConnectionObjectGetState(connection_object) ) {
       if( (NULL != connection_object->consuming_instance) || /* we have a consuming connection check inactivity watchdog timer */
           (kConnectionObjectTransportClassTriggerDirectionServer ==
-           ConnectionObjectGetTransportClassTriggerDirection(connection_object) ) )                                                    /* all server connections have to maintain an inactivity watchdog timer */
+           ConnectionObjectGetTransportClassTriggerDirection(connection_object) ) ) /* all server connections have to maintain an inactivity watchdog timer */
       {
         if(elapsed_time >= connection_object->inactivity_watchdog_timer) {
           /* we have a timed out connection perform watchdog time out action*/
@@ -929,7 +929,7 @@ EipStatus ManageConnections(MilliSeconds elapsed_time) {
         /* client connection */
         if( (0 != ConnectionObjectGetExpectedPacketRate(connection_object) )
             && (kEipInvalidSocket !=
-                connection_object->socket[kUdpCommuncationDirectionProducing]) )                   /* only produce for the master connection */
+                connection_object->socket[kUdpCommuncationDirectionProducing]) ) /* only produce for the master connection */
         {
           if(kConnectionObjectTransportClassTriggerProductionTriggerCyclic !=
              ConnectionObjectGetTransportClassTriggerProductionTrigger(
@@ -951,9 +951,18 @@ EipStatus ManageConnections(MilliSeconds elapsed_time) {
               OPENER_TRACE_ERR(
                 "sending of UDP data in manage Connection failed\n");
             }
-            /* reload the timer value */
-            connection_object->transmission_trigger_timer =
+            /* add the RPI to the timer value */
+            connection_object->transmission_trigger_timer +=
               ConnectionObjectGetRequestedPacketInterval(connection_object);
+            /* decrecment the elapsed time from timer value, if less than timer value */
+            if (connection_object->transmission_trigger_timer > elapsed_time) {
+              connection_object->transmission_trigger_timer -= elapsed_time;
+            } else {  /* elapsed time was longer than RPI */
+              connection_object->transmission_trigger_timer = 0;
+              OPENER_TRACE_INFO("elapsed time: %lu ms was longer than RPI: %u ms\n",
+                                elapsed_time,
+                                ConnectionObjectGetRequestedPacketInterval(connection_object));
+            }
             if(kConnectionObjectTransportClassTriggerProductionTriggerCyclic !=
                ConnectionObjectGetTransportClassTriggerProductionTrigger(
                  connection_object) ) {
@@ -1146,7 +1155,7 @@ EipStatus AssembleForwardCloseResponse(EipUint16 connection_serial_number,
     message_router_response->size_of_additional_status = 0;
   } else {
     AddSintToMessage(*message_router_request->data,
-                     &message_router_response->message);                                /* remaining path size */
+                     &message_router_response->message); /* remaining path size */
     if(kConnectionManagerExtendedStatusWrongCloser == extended_error_code) {
       message_router_response->general_status = kCipErrorPrivilegeViolation;
     } else {
@@ -1433,7 +1442,7 @@ EipUint8 ParseConnectionPath(CipConnectionObject *connection_object,
     /* Get instance ID */
     if(kSegmentTypeLogicalSegment == GetPathSegmentType(message) &&
        kLogicalSegmentLogicalTypeInstanceId ==
-       GetPathLogicalSegmentLogicalType(message) ) {                                                                                                     /* store the configuration ID for later checking in the application connection types */
+       GetPathLogicalSegmentLogicalType(message) ) { /* store the configuration ID for later checking in the application connection types */
       instance_id = CipEpathGetLogicalValue(&message);
 
       OPENER_TRACE_INFO("Configuration instance id %" PRId32 "\n",
@@ -1501,7 +1510,7 @@ EipUint8 ParseConnectionPath(CipConnectionObject *connection_object,
       if(kConnectionObjectConnectionTypeNull ==
          originator_to_target_connection_type) {
         if(kConnectionObjectConnectionTypeNull ==
-           target_to_originator_connection_type) {                                        /* configuration only connection */
+           target_to_originator_connection_type) { /* configuration only connection */
           number_of_encoded_paths = 0;
           OPENER_TRACE_WARN("assembly: type invalid\n");
         } else { /* 1 path -> path is for production */
@@ -1511,7 +1520,7 @@ EipUint8 ParseConnectionPath(CipConnectionObject *connection_object,
         }
       } else {
         if(kConnectionObjectConnectionTypeNull ==
-           target_to_originator_connection_type) {                                        /* 1 path -> path is for consumption */
+           target_to_originator_connection_type) { /* 1 path -> path is for consumption */
           OPENER_TRACE_INFO("assembly: type consume\n");
           number_of_encoded_paths = 1;
           paths_to_encode[0] = &(connection_object->consumed_path);
@@ -1529,7 +1538,7 @@ EipUint8 ParseConnectionPath(CipConnectionObject *connection_object,
            && (kLogicalSegmentLogicalTypeInstanceId ==
                GetPathLogicalSegmentLogicalType(message)
                || kLogicalSegmentLogicalTypeConnectionPoint ==
-               GetPathLogicalSegmentLogicalType(message) ) )                                            /* Connection Point interpreted as InstanceNr -> only in Assembly Objects */
+               GetPathLogicalSegmentLogicalType(message) ) ) /* Connection Point interpreted as InstanceNr -> only in Assembly Objects */
         {   /* Attribute Id or Connection Point */
           CipDword attribute_id = CipEpathGetLogicalValue(&message);
           CipConnectionPathEpath connection_epath =
@@ -1621,6 +1630,9 @@ EipUint8 ParseConnectionPath(CipConnectionObject *connection_object,
 
 void CloseConnection(CipConnectionObject *RESTRICT connection_object) {
 
+  OPENER_TRACE_INFO("cipconnectionmanager: CloseConnection, trigger: %d \n",
+  	ConnectionObjectGetTransportClassTriggerTransportClass(connection_object));
+
   if(kConnectionObjectTransportClassTriggerTransportClass3 !=
      ConnectionObjectGetTransportClassTriggerTransportClass(connection_object) )
   {

+ 47 - 51
source/src/cip/cipioconnection.c

@@ -21,9 +21,6 @@
 #include "endianconv.h"
 #include "opener_error.h"
 
-/*The port to be used per default for I/O messages on UDP.*/
-const int kOpenerEipIoUdpPort = 0x08AE;
-
 /* producing multicast connection have to consider the rules that apply for
  * application connection types.
  */
@@ -418,34 +415,20 @@ EipStatus OpenConsumingPointToPointConnection(
   { .sin_family = AF_INET, .sin_addr.s_addr = INADDR_ANY, .sin_port = htons(
       kOpenerEipIoUdpPort) };
 
-  // retrieve network adapter to bind only this one
-  struct sockaddr_in producing_address;
-  socklen_t producing_address_length = sizeof(struct sockaddr_in);
-  if(getsockname(g_current_active_tcp_socket,
-                 (struct sockaddr *) &producing_address,
-                 &producing_address_length) < 0) {
-    int error_code = GetSocketErrorNumber();
-    char *error_message = GetErrorMessage(error_code);
-    OPENER_TRACE_WARN("networkhandler: could not get sockname: %d - %s\n",
-                      error_code, error_message);
-    FreeErrorMessage(error_message);
-  } else {
-    addr.sin_addr = producing_address.sin_addr;
-  }
-
   CipUsint qos_for_socket = ConnectionObjectGetTToOPriority(connection_object);
-  int socket = CreateUdpSocket(kUdpCommuncationDirectionConsuming,
-                               &addr,
-                               qos_for_socket);                                            /* the address is only needed for bind used if consuming */
-  if(socket == kEipInvalidSocket) {
+  int error = SetQos(qos_for_socket);
+  if (error != 0) {
     OPENER_TRACE_ERR(
-      "cannot create UDP socket in OpenPointToPointConnection\n");
+      "cannot set QoS for UDP socket in OpenPointToPointConnection\n");
     return kEipStatusError;
   }
+  /* store the address of the originator for packet scanning */
+  connection_object->originator_address.sin_family = AF_INET;
+  connection_object->originator_address.sin_addr.s_addr = GetPeerAddress();
+  connection_object->originator_address.sin_port = htons(kOpenerEipIoUdpPort);
 
-  connection_object->originator_address = addr; /* store the address of the originator for packet scanning */
-  addr.sin_addr.s_addr = INADDR_ANY; /* restore the address */
-  connection_object->socket[kUdpCommuncationDirectionConsuming] = socket;
+  connection_object->socket[kUdpCommuncationDirectionConsuming] = 
+      g_network_status.udp_io_messaging;
 
   sock_addr_info->length = 16;
   sock_addr_info->type_id = kCipItemIdSocketAddressInfoOriginatorToTarget;
@@ -462,7 +445,8 @@ CipError OpenProducingPointToPointConnection(
   CipConnectionObject *connection_object,
   CipCommonPacketFormatData *common_packet_format_data)
 {
-  in_port_t port = htons(kOpenerEipIoUdpPort); /* the default port to be used if no port information is part of the forward open request */
+  /* the default port to be used if no port information is part of the forward open request */
+  in_port_t port = htons(kOpenerEipIoUdpPort); 
 
   if(kCipItemIdSocketAddressInfoTargetToOriginator ==
      common_packet_format_data->address_info_item[0].type_id) {
@@ -475,20 +459,19 @@ CipError OpenProducingPointToPointConnection(
   }
 
   connection_object->remote_address.sin_family = AF_INET;
-  connection_object->remote_address.sin_addr.s_addr = 0; /* we don't know the address of the originate will be set in the IApp_CreateUDPSocket */
+  connection_object->remote_address.sin_addr.s_addr = GetPeerAddress(); 
   connection_object->remote_address.sin_port = port;
 
   CipUsint qos_for_socket = ConnectionObjectGetTToOPriority(connection_object);
-  int socket = CreateUdpSocket(kUdpCommuncationDirectionProducing,
-                               &connection_object->remote_address,
-                               qos_for_socket);                                                                         /* the address is only needed for bind used if consuming */
-  if(socket == kEipInvalidSocket) {
+  int error = SetQos(qos_for_socket);
+  if (error != 0) {
     OPENER_TRACE_ERR(
-      "cannot create UDP socket in OpenPointToPointConnection\n");
-    /* *pa_pnExtendedError = 0x0315; miscellaneous*/
-    return kCipErrorConnectionFailure;
+        "cannot set QoS for UDP socket in OpenPointToPointConnection\n");
+    return kEipStatusError;
   }
-  connection_object->socket[kUdpCommuncationDirectionProducing] = socket;
+
+  connection_object->socket[kUdpCommuncationDirectionProducing] =
+      g_network_status.udp_io_messaging;
 
   return kCipErrorSuccess;
 }
@@ -614,10 +597,10 @@ EipStatus OpenMulticastConnection(UdpCommuncationDirection direction,
   }
 
   if(kCipItemIdSocketAddressInfoTargetToOriginator ==
-     common_packet_format_data->address_info_item[j].type_id) {                                                  /* we are using an unused item initialize it with the default multicast address */
+     common_packet_format_data->address_info_item[j].type_id) {
+    /* we are using an unused item initialize it with the default multicast address */
     common_packet_format_data->address_info_item[j].sin_family = htons(AF_INET);
-    common_packet_format_data->address_info_item[j].sin_port = htons(
-      kOpenerEipIoUdpPort);
+    common_packet_format_data->address_info_item[j].sin_port = htons(kOpenerEipIoUdpPort);
     common_packet_format_data->address_info_item[j].sin_addr =
       g_tcpip.mcast_config.starting_multicast_address;
     memset(common_packet_format_data->address_info_item[j].nasin_zero, 0, 8);
@@ -641,14 +624,21 @@ EipStatus OpenMulticastConnection(UdpCommuncationDirection direction,
     common_packet_format_data->address_info_item[j].sin_port;
 
   CipUsint qos_for_socket = ConnectionObjectGetTToOPriority(connection_object);
-  int socket = CreateUdpSocket(direction, &socket_address, qos_for_socket); /* the address is only needed for bind used if consuming */
-  if(socket == kEipInvalidSocket) {
-    OPENER_TRACE_ERR("cannot create UDP socket in OpenMulticastConnection\n");
+  int error = SetQos(qos_for_socket);
+  if (error != 0) {
+    OPENER_TRACE_ERR(
+        "cannot set QoS for UDP socket in OpenMulticastConnection\n");
     return kEipStatusError;
   }
-  connection_object->socket[direction] = socket;
+  if (direction == kUdpCommuncationDirectionProducing) {
+    SetSocketOptionsMulticastProduce();
+  }
+
+  connection_object->socket[direction] = g_network_status.udp_io_messaging;
 
   if(direction == kUdpCommuncationDirectionConsuming) {
+    /* store the originators address */
+    socket_address.sin_addr.s_addr = GetPeerAddress();
     common_packet_format_data->address_info_item[j].type_id =
       kCipItemIdSocketAddressInfoOriginatorToTarget;
     connection_object->originator_address = socket_address;
@@ -818,7 +808,8 @@ EipStatus SendConnectedData(CipConnectionObject *connection_object) {
   common_packet_format_data->item_count = 2;
   if(kConnectionObjectTransportClassTriggerTransportClass0 !=
      ConnectionObjectGetTransportClassTriggerTransportClass(connection_object) )
-  {                                                                                                                                        /* use Sequenced Address Items if not Connection Class 0 */
+  /* use Sequenced Address Items if not Connection Class 0 */
+  {                                          
     common_packet_format_data->address_item.type_id =
       kCipItemIdSequencedAddressItem;
     common_packet_format_data->address_item.length = 8;
@@ -889,8 +880,6 @@ EipStatus SendConnectedData(CipConnectionObject *connection_object) {
   outgoing_message.used_message_length += producing_instance_attributes->length;
 
   return SendUdpData(&connection_object->remote_address,
-                     connection_object->socket[
-                       kUdpCommuncationDirectionProducing],
                      &outgoing_message);
 }
 
@@ -948,7 +937,9 @@ EipStatus HandleReceivedIoConnectionData(CipConnectionObject *connection_object,
 CipError OpenCommunicationChannels(CipConnectionObject *connection_object) {
 
   CipError cip_error = kCipErrorSuccess;
-  /*get pointer to the CPF data, currently we have just one global instance of the struct. This may change in the future*/
+  CreateUdpSocket(); /* open UDP socket for IO messaging*/
+  
+/*get pointer to the CPF data, currently we have just one global instance of the struct. This may change in the future*/
   CipCommonPacketFormatData *common_packet_format_data =
     &g_common_packet_format_data_item;
 
@@ -960,7 +951,8 @@ CipError OpenCommunicationChannels(CipConnectionObject *connection_object) {
 
   /* open a connection "point to point" or "multicast" based on the ConnectionParameter */
   if(originator_to_target_connection_type ==
-     kConnectionObjectConnectionTypeMulticast)                                         /* Multicast consuming */
+     kConnectionObjectConnectionTypeMulticast)
+  /* Multicast consuming */
   {
     if(OpenMulticastConnection(kUdpCommuncationDirectionConsuming,
                                connection_object,
@@ -969,7 +961,8 @@ CipError OpenCommunicationChannels(CipConnectionObject *connection_object) {
       return kCipErrorConnectionFailure;
     }
   } else if(originator_to_target_connection_type ==
-            kConnectionObjectConnectionTypePointToPoint)                                         /* Point to Point consuming */
+            kConnectionObjectConnectionTypePointToPoint)
+  /* Point to Point consuming */
   {
     if(OpenConsumingPointToPointConnection(connection_object,
                                            common_packet_format_data) ==
@@ -980,7 +973,8 @@ CipError OpenCommunicationChannels(CipConnectionObject *connection_object) {
   }
 
   if(target_to_originator_connection_type ==
-     kConnectionObjectConnectionTypeMulticast)                                         /* Multicast producing */
+     kConnectionObjectConnectionTypeMulticast)  
+  /* Multicast producing */
   {
     if(OpenProducingMulticastConnection(connection_object,
                                         common_packet_format_data) ==
@@ -989,7 +983,8 @@ CipError OpenCommunicationChannels(CipConnectionObject *connection_object) {
       return kCipErrorConnectionFailure;
     }
   } else if(target_to_originator_connection_type ==
-            kConnectionObjectConnectionTypePointToPoint)                                         /* Point to Point producing */
+            kConnectionObjectConnectionTypePointToPoint)  
+  /* Point to Point producing */
   {
 
     if(OpenProducingPointToPointConnection(connection_object,
@@ -1014,4 +1009,5 @@ void CloseCommunicationChannelsAndRemoveFromActiveConnectionsList(
 
   RemoveFromActiveConnections(connection_object);
   ConnectionObjectInitializeEmpty(connection_object);
+  OPENER_TRACE_INFO("cipioconnection: CloseCommunicationChannelsAndRemoveFromActiveConnectionsList\n");
 }

+ 14 - 16
source/src/enet_encap/encap.h

@@ -8,6 +8,7 @@
 
 #include "typedefs.h"
 #include "cipconnectionobject.h"
+#include "generic_networkhandler.h"
 
 /** @file encap.h
  * @brief This file contains the public interface of the encapsulation layer
@@ -21,9 +22,6 @@
 
 #define ENCAPSULATION_HEADER_LENGTH     24
 
-/** @brief Ethernet/IP standard port */
-static const int kOpenerEthernetPort = 0xAF12;
-
 /** @brief definition of status codes in encapsulation protocol
  * All other codes are either legacy codes, or reserved for future use
  *  */
@@ -39,22 +37,22 @@ typedef enum {
 
 /*** structs ***/
 typedef struct encapsulation_data {
-    CipUint command_code;
-    CipUint data_length;
-    CipUdint session_handle;
-    CipUdint status;
-    CipOctet sender_context[8]; /**< length of 8, according to the specification */
-    CipUdint options;
-    const EipUint8 *communication_buffer_start; /**< Pointer to the communication buffer used for this message */
-    const EipUint8 *current_communication_buffer_position; /**< The current position in the communication buffer during the decoding process */
+  CipUint command_code;
+  CipUint data_length;
+  CipUdint session_handle;
+  CipUdint status;
+  CipOctet sender_context[8]; /**< length of 8, according to the specification */
+  CipUdint options;
+  const EipUint8 *communication_buffer_start; /**< Pointer to the communication buffer used for this message */
+  const EipUint8 *current_communication_buffer_position; /**< The current position in the communication buffer during the decoding process */
 } EncapsulationData;
 
 typedef struct encapsulation_service_information {
-    EipUint16 type_code;
-    EipUint16 length;
-    EipUint16 encapsulation_protocol_version;
-    EipUint16 capability_flags;
-    EipInt8 name_of_service[16];
+  EipUint16 type_code;
+  EipUint16 length;
+  EipUint16 encapsulation_protocol_version;
+  EipUint16 capability_flags;
+  EipInt8 name_of_service[16];
 } EncapsulationServiceInformation;
 
 /*** global variables (public) ***/

+ 16 - 42
source/src/opener_api.h

@@ -742,8 +742,7 @@ EipStatus HandleReceivedExplictUdpData(const int socket_handle,
  *           connection hijacking
  *  @return EIP_OK on success
  */
-EipStatus
-HandleReceivedConnectedData(const EipUint8 *const received_data,
+EipStatus HandleReceivedConnectedData(const EipUint8 *const received_data,
                             int received_data_length,
                             struct sockaddr_in *from_address);
 
@@ -760,8 +759,7 @@ HandleReceivedConnectedData(const EipUint8 *const received_data,
  *
  * @return EIP_OK on success
  */
-EipStatus
-ManageConnections(MilliSeconds elapsed_time);
+EipStatus ManageConnections(MilliSeconds elapsed_time);
 
 /** @ingroup CIP_API
  * @brief Trigger the production of an application triggered connection.
@@ -782,8 +780,7 @@ ManageConnections(MilliSeconds elapsed_time);
  * connection
  * @return EIP_OK on success
  */
-EipStatus
-TriggerConnections(unsigned int output_assembly_id,
+EipStatus TriggerConnections(unsigned int output_assembly_id,
                    unsigned int input_assembly_id);
 
 /** @ingroup CIP_API
@@ -816,8 +813,7 @@ void CloseSession(int socket_handle);
  *  return status EIP_ERROR .. error
  *                EIP_OK ... successful finish
  */
-EipStatus
-ApplicationInitialization(void);
+EipStatus ApplicationInitialization(void);
 
 /** @ingroup CIP_CALLBACK_API
  * @brief Allow the device specific application to perform its execution
@@ -858,8 +854,7 @@ void CheckIoConnectionEvent(unsigned int output_assembly_id,
  * The length of the data is already checked within the stack. Therefore the
  * user only has to check if the data is valid.
  */
-EipStatus
-AfterAssemblyDataReceived(CipInstance *instance);
+EipStatus AfterAssemblyDataReceived(CipInstance *instance);
 
 /** @ingroup CIP_CALLBACK_API
  * @brief Inform the application that the data of an assembly
@@ -873,8 +868,7 @@ AfterAssemblyDataReceived(CipInstance *instance);
  *          - true assembly data has changed
  *          - false assembly data has not changed
  */
-EipBool8
-BeforeAssemblyDataSend(CipInstance *instance);
+EipBool8 BeforeAssemblyDataSend(CipInstance *instance);
 
 /** @ingroup CIP_CALLBACK_API
  * @brief Emulate as close a possible a power cycle of the device
@@ -882,8 +876,7 @@ BeforeAssemblyDataSend(CipInstance *instance);
  * @return if the service is supported the function will not return.
  *     EIP_ERROR if this service is not supported
  */
-EipStatus
-ResetDevice(void);
+EipStatus ResetDevice(void);
 
 /** @ingroup CIP_CALLBACK_API
  * @brief Reset the device to the initial configuration and emulate as close as
@@ -892,8 +885,7 @@ ResetDevice(void);
  * @return if the service is supported the function will not return.
  *     EIP_ERROR if this service is not supported
  */
-EipStatus
-ResetDeviceToInitialConfiguration(void);
+EipStatus ResetDeviceToInitialConfiguration(void);
 
 /** @ingroup CIP_CALLBACK_API
  * @brief Allocate memory for the CIP stack
@@ -927,37 +919,19 @@ void CipFree(void *data);
 void RunIdleChanged(EipUint32 run_idle_value);
 
 /** @ingroup CIP_CALLBACK_API
- * @brief create a producing or consuming UDP socket
- *
- * @param communication_direction kUdpCommunicationDirectionProducing or kUdpCommunicationDirectionConsuming
- * @param socket_data pointer to the address holding structure
- *     Attention: For producing point-to-point connection the
- *     *pa_pstAddr->sin_addr.s_addr member is set to 0 by OpENer. The network
- *     layer of the application has to set the correct address of the
- *     originator.
- *     Attention: For consuming connection the network layer has to set the
- * pa_pstAddr->sin_addr.s_addr to the correct address of the originator.
- * FIXME add an additional parameter that can be used by the CIP stack to
- * request the originators sockaddr_in data.
- * @param qos_for_socket CIP QoS object parameter value
- * @return socket identifier on success
- *         -1 on error
- */
-int CreateUdpSocket(UdpCommuncationDirection communication_direction,
-                    struct sockaddr_in *socket_data,
-                    CipUsint qos_for_socket);
+ * @brief Create the UDP socket for the implicit IO messaging, 
+ * one socket handles all connections
+ * @return the socket handle if successful, else kEipInvalidSocket
+*/ 
+int CreateUdpSocket(void);
 
 /** @ingroup CIP_CALLBACK_API
- * @brief Create a producing or consuming UDP socket
- *
- * @param socket_data Pointer to the "send to" address
- * @param socket_handle Socket descriptor to send on
+ * @brief Sends the data for the implicit IO messaging via UDP socket
+ * @param socket_data Address message to be sent
  * @param outgoing message The constructed outgoing message
  * @return kEipStatusOk on success
  */
-EipStatus
-SendUdpData(const struct sockaddr_in *const socket_data,
-            const int socket_handle,
+EipStatus SendUdpData(const struct sockaddr_in *const socket_data,
             const ENIPMessage *const outgoing_message);
 
 /** @ingroup CIP_CALLBACK_API

+ 1 - 1
source/src/ports/CMakeLists.txt

@@ -15,7 +15,7 @@ opener_common_includes()
 #######################################
 opener_platform_support("INCLUDES")
 
-set( PLATFORM_GENERIC_SRC generic_networkhandler.c socket_timer.c  udp_protocol.c )
+set( PLATFORM_GENERIC_SRC generic_networkhandler.c socket_timer.c )
 
 add_library( PLATFORM_GENERIC ${PLATFORM_GENERIC_SRC} )
 

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

@@ -175,7 +175,7 @@ static void LeaveStack(int signal) {
 static DWORD executeEventLoop(LPVOID thread_arg) {
   /* The event loop. Put other processing you need done continually in here */
   while (0 == g_end_stack) {
-    if ( kEipStatusOk != NetworkHandlerProcessOnce() ) {
+    if ( kEipStatusOk != NetworkHandlerProcessCyclic() ) {
       break;
     }
   }

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

@@ -8,7 +8,6 @@
 #include <signal.h>
 #include <time.h>
 #include <unistd.h>
-#include <sys/capability.h>
 
 #ifdef OPENER_RT
 #include <pthread.h>
@@ -67,35 +66,6 @@ volatile int g_end_stack = 0;
 int main(int argc,
          char *arg[]) {
 
-  cap_t capabilities;
-  cap_value_t capabilities_list[1];
-
-  capabilities = cap_get_proc();
-  if(NULL == capabilities) {
-    printf("Could not get capabilities\n");
-    exit(EXIT_FAILURE);
-  }
-
-  capabilities_list[0] = CAP_NET_RAW;
-  if(-1 ==
-     cap_set_flag(capabilities, CAP_EFFECTIVE, 1, capabilities_list,
-                  CAP_SET) ) {
-    cap_free(capabilities);
-    printf("Could not set CAP_NET_RAW capability\n");
-    exit(EXIT_FAILURE);
-  }
-
-  if(-1 == cap_set_proc(capabilities) ) {
-    cap_free(capabilities);
-    printf("Could not push CAP_NET_RAW capability to process\n");
-    exit(EXIT_FAILURE);
-  }
-
-  if(-1 == cap_free(capabilities) ) {
-    printf("Could not free capabilities value\n");
-    exit(EXIT_FAILURE);
-  }
-
   if(argc != 2) {
     fprintf(stderr, "Wrong number of command line parameters!\n");
     fprintf(stderr, "Usage: %s [interface name]\n", arg[0]);
@@ -286,7 +256,7 @@ static void *executeEventLoop(void *pthread_arg) {
 
   /* The event loop. Put other processing you need done continually in here */
   while(!g_end_stack) {
-    if(kEipStatusOk != NetworkHandlerProcessOnce() ) {
+    if(kEipStatusOk != NetworkHandlerProcessCyclic() ) {
       OPENER_TRACE_ERR("Error in NetworkHandler loop! Exiting OpENer!\n");
       break;
     }

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

@@ -173,7 +173,7 @@ static void LeaveStack(int signal) {
 static DWORD executeEventLoop(LPVOID thread_arg) {
 	/* The event loop. Put other processing you need done continually in here */
 	while (0 == g_end_stack) {
-		if (kEipStatusOk != NetworkHandlerProcessOnce()) {
+		if (kEipStatusOk != NetworkHandlerProcessCyclic()) {
 			break;
 		}
 	}

+ 177 - 206
source/src/ports/generic_networkhandler.c

@@ -25,19 +25,22 @@
 #include "ciptcpipinterface.h"
 #include "opener_user_conf.h"
 #include "cipqos.h"
-#include "udp_protocol.h"
 
 #define MAX_NO_OF_TCP_SOCKETS 10
 
+/** @brief Ethernet/IP standard port */
+extern const int kOpenerEipIoUdpPort = 0x08AE;
+const int kOpenerEthernetPort = 0xAF12;
+
 /* ----- Windows size_t PRI macros ------------- */
-#if defined (__MINGW32__) /* This is a Mingw compiler */
+#if defined(__MINGW32__) /* This is a Mingw compiler */
 #define PRIuSZT PRIuPTR
 #define PRIxSZT PRIxPTR
 #else
 /* Even the Visual Studio compilers / libraries since VS2015 know that now. */
 #define PRIuSZT "zu"
 #define PRIxSZT "zx"
-#endif  /* if defined(__MINGW32__) */
+#endif /* if defined(__MINGW32__) */
 
 #if defined(_WIN32)
 /* Most network functions take their I/O buffers as (char *) pointers that
@@ -86,10 +89,10 @@ void CheckAndHandleUdpUnicastSocket(void);
  */
 void CheckAndHandleUdpGlobalBroadcastSocket(void);
 
-/** @brief check if on one of the UDP consuming sockets data has been received and if yes handle it correctly
+/** @brief check if on the UDP consuming socket data has been received and if yes handle it correctly
  *
  */
-void CheckAndHandleConsumingUdpSockets(void);
+void CheckAndHandleConsumingUdpSocket(void);
 
 /** @brief Handles data on an established TCP connection, processed connection is given by socket
  *
@@ -133,9 +136,9 @@ EipStatus NetworkHandlerInitialize(void) {
          socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) ) == -1 ) {
     int error_code = GetSocketErrorNumber();
     char *error_message = GetErrorMessage(error_code);
-    OPENER_TRACE_ERR("error allocating socket stream listener, %d - %s\n",
-                     error_code,
-                     error_message);
+    OPENER_TRACE_ERR("networkhandler tcp_listener: error allocating socket, %d - %s\n",
+        error_code,
+        error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
@@ -146,13 +149,13 @@ EipStatus NetworkHandlerInitialize(void) {
                 (char *) &set_socket_option_value,
                 sizeof(set_socket_option_value) ) == -1) {
     OPENER_TRACE_ERR(
-      "error setting socket option SO_REUSEADDR on tcp_listener\n");
+        "networkhandler tcp_listener: error setting socket option SO_REUSEADDR\n");
     return kEipStatusError;
   }
 
   if(SetSocketToNonBlocking(g_network_status.tcp_listener) < 0) {
     OPENER_TRACE_ERR(
-      "error setting socket to non-blocking on new socket\n");
+        "networkhandler tcp_listener: error setting socket to non-blocking on new socket\n");
     return kEipStatusError;
   }
 
@@ -162,9 +165,9 @@ EipStatus NetworkHandlerInitialize(void) {
     int error_code = GetSocketErrorNumber();
     char *error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-      "error allocating UDP global broadcast listener socket, %d - %s\n",
-      error_code,
-      error_message);
+        "networkhandler udp_global_broadcast_listener: error allocating socket, %d - %s\n",
+        error_code,
+        error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
@@ -174,8 +177,8 @@ EipStatus NetworkHandlerInitialize(void) {
          socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) ) == kEipInvalidSocket ) {
     int error_code = GetSocketErrorNumber();
     char *error_message = GetErrorMessage(error_code);
-    OPENER_TRACE_ERR("error allocating UDP unicast listener socket, %d - %s\n",
-                     error_code, error_message);
+    OPENER_TRACE_ERR("networkhandler udp_unicast_listener: error allocating socket, %d - %s\n",
+        error_code, error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
@@ -187,14 +190,14 @@ EipStatus NetworkHandlerInitialize(void) {
                 sizeof(set_socket_option_value) )
      == -1) {
     OPENER_TRACE_ERR(
-      "error setting socket option SO_REUSEADDR on udp_broadcast_listener\n");
+        "networkhandler udp_global_broadcast_listener: error setting socket option SO_REUSEADDR\n");
     return kEipStatusError;
   }
 
   if(SetSocketToNonBlocking(g_network_status.udp_global_broadcast_listener) <
      0) {
     OPENER_TRACE_ERR(
-      "error setting socket to non-blocking on new socket\n");
+        "networkhandler udp_global_broadcast_listener: error setting socket to non-blocking on new socket\n");
     return kEipStatusError;
   }
 
@@ -204,28 +207,28 @@ EipStatus NetworkHandlerInitialize(void) {
                 (char *) &set_socket_option_value,
                 sizeof(set_socket_option_value) ) == -1) {
     OPENER_TRACE_ERR(
-      "error setting socket option SO_REUSEADDR on udp_unicast_listener\n");
+        "networkhandler udp_unicast_listener: error setting socket option SO_REUSEADDR\n");
     return kEipStatusError;
   }
 
   if(SetSocketToNonBlocking(g_network_status.udp_unicast_listener) < 0) {
     OPENER_TRACE_ERR(
-      "error setting socket to non-blocking on udp_unicast_listener\n");
+        "networkhandler udp_unicast_listener: error setting socket to non-blocking\n");
     return kEipStatusError;
   }
 
-  struct sockaddr_in my_address = { .sin_family = AF_INET, .sin_port = htons(
-                                      kOpenerEthernetPort),
-                                    .sin_addr.s_addr =
-                                      g_network_status.ip_address };
+  struct sockaddr_in my_address = {
+    .sin_family = AF_INET,
+    .sin_port = htons(kOpenerEthernetPort),
+    .sin_addr.s_addr = g_network_status.ip_address};
 
   /* bind the new socket to port 0xAF12 (CIP) */
   if( (bind(g_network_status.tcp_listener, (struct sockaddr *) &my_address,
             sizeof(struct sockaddr) ) ) == -1 ) {
     int error_code = GetSocketErrorNumber();
     char *error_message = GetErrorMessage(error_code);
-    OPENER_TRACE_ERR("error with TCP bind: %d - %s\n", error_code,
-                     error_message);
+    OPENER_TRACE_ERR("networkhandler tcp_listener: error with TCP bind: %d - %s\n", error_code,
+        error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
@@ -235,8 +238,8 @@ EipStatus NetworkHandlerInitialize(void) {
             sizeof(struct sockaddr) ) ) == -1 ) {
     int error_code = GetSocketErrorNumber();
     char *error_message = GetErrorMessage(error_code);
-    OPENER_TRACE_ERR( "error with UDP unicast bind: %d - %s\n",
-                      error_code, error_message);
+    OPENER_TRACE_ERR( "networkhandler udp_unicast_listener: error with UDP bind: %d - %s\n",
+        error_code, error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
@@ -248,17 +251,18 @@ EipStatus NetworkHandlerInitialize(void) {
     int error_code = GetSocketErrorNumber();
     char *error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-      "networkhandler: error set QoS on UDP unicast socket %d: %d - %s\n",
-      g_network_status.udp_unicast_listener,
-      error_code,
-      error_message);
+        "networkhandler udp_unicast_listener: error set QoS %d: %d - %s\n",
+        g_network_status.udp_unicast_listener,
+        error_code,
+        error_message);
     FreeErrorMessage(error_message);
     /* print message but don't abort by intent */
   }
 
-  struct sockaddr_in global_broadcast_address =
-  { .sin_family = AF_INET, .sin_port = htons(kOpenerEthernetPort),
-    .sin_addr.s_addr = htonl(INADDR_ANY) };
+  struct sockaddr_in global_broadcast_address = {
+    .sin_family = AF_INET,
+    .sin_port = htons(kOpenerEthernetPort),
+    .sin_addr.s_addr = htonl(INADDR_ANY)};
 
   /* enable the UDP socket to receive broadcast messages */
   set_socket_option_value = 1;
@@ -269,8 +273,8 @@ EipStatus NetworkHandlerInitialize(void) {
     int error_code = GetSocketErrorNumber();
     char *error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-      "error with setting broadcast receive for UDP socket: %d - %s\n",
-      error_code, error_message);
+        "networkhandler udp_global_broadcast_listener: error with setting broadcast receive: %d - %s\n",
+        error_code, error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
@@ -280,9 +284,9 @@ EipStatus NetworkHandlerInitialize(void) {
             sizeof(struct sockaddr) ) ) == -1 ) {
     int error_code = GetSocketErrorNumber();
     char *error_message = GetErrorMessage(error_code);
-    OPENER_TRACE_ERR("error with global broadcast UDP bind: %d - %s\n",
-                     error_code,
-                     error_message);
+    OPENER_TRACE_ERR("networkhandler udp_global_broadcast_listener: error with UDP bind: %d - %s\n",
+        error_code,
+        error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
@@ -294,10 +298,10 @@ EipStatus NetworkHandlerInitialize(void) {
     int error_code = GetSocketErrorNumber();
     char *error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-      "networkhandler: error set QoS on UDP broadcast socket %d: %d - %s\n",
-      g_network_status.udp_global_broadcast_listener,
-      error_code,
-      error_message);
+        "networkhandler udp_global_broadcast_listener: error set QoS %d: %d - %s\n",
+        g_network_status.udp_global_broadcast_listener,
+        error_code,
+        error_message);
     FreeErrorMessage(error_message);
     /* print message but don't abort by intent */
   }
@@ -311,10 +315,10 @@ EipStatus NetworkHandlerInitialize(void) {
     int error_code = GetSocketErrorNumber();
     char *error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-      "networkhandler: error set QoS on listen socket %d: %d - %s\n",
-      g_network_status.tcp_listener,
-      error_code,
-      error_message);
+        "networkhandler tcp_listener: error set QoS %d: %d - %s\n",
+        g_network_status.tcp_listener,
+        error_code,
+        error_message);
     FreeErrorMessage(error_message);
     /* print message but don't abort by intent */
   }
@@ -324,9 +328,9 @@ EipStatus NetworkHandlerInitialize(void) {
               MAX_NO_OF_TCP_SOCKETS) ) == -1 ) {
     int error_code = GetSocketErrorNumber();
     char *error_message = GetErrorMessage(error_code);
-    OPENER_TRACE_ERR("networkhandler: error with listen: %d - %s\n",
-                     error_code,
-                     error_message);
+    OPENER_TRACE_ERR("networkhandler tcp_listener: error with listen: %d - %s\n",
+        error_code,
+        error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
@@ -426,7 +430,7 @@ void CheckAndHandleTcpListenerSocket(void) {
   }
 }
 
-EipStatus NetworkHandlerProcessOnce(void) {
+EipStatus NetworkHandlerProcessCyclic(void) {
 
   read_socket = master_socket;
 
@@ -463,7 +467,7 @@ EipStatus NetworkHandlerProcessOnce(void) {
     CheckAndHandleTcpListenerSocket();
     CheckAndHandleUdpUnicastSocket();
     CheckAndHandleUdpGlobalBroadcastSocket();
-    CheckAndHandleConsumingUdpSockets();
+    CheckAndHandleConsumingUdpSocket();
 
     for(size_t socket = 0; socket <= highest_socket_handle; socket++) {
       if(true == CheckSocketSet(socket) ) {
@@ -641,48 +645,33 @@ void CheckAndHandleUdpUnicastSocket(void) {
 }
 
 EipStatus SendUdpData(const struct sockaddr_in *const address,
-                      const int socket_handle,
-                      const ENIPMessage *const outgoing_message) {
-
-  OPENER_TRACE_INFO("UDP port to be sent to: %x\n", ntohs(address->sin_port) );
-  UDPHeader header = { .source_port = 2222, .destination_port = ntohs(
-                         address->sin_port), .packet_length = kUdpHeaderLength
-                                                              +
-                                                              outgoing_message->
-                                                              used_message_length,
-                       .checksum = 0 };
-
-  char complete_message[PC_OPENER_ETHERNET_BUFFER_SIZE];
-  memcpy(complete_message + kUdpHeaderLength,
-         outgoing_message->message_buffer,
-         outgoing_message->used_message_length);
-  UDPHeaderGenerate(&header, (char *) complete_message);
-  const uint16_t udp_checksum = UDPHeaderCalculateChecksum(complete_message,
-                                                           8 + outgoing_message->used_message_length,
-                                                           g_tcpip.interface_configuration.ip_address,
-                                                           address->sin_addr.s_addr);
-  UDPHeaderSetChecksum(&header, htons(udp_checksum) );
-  UDPHeaderGenerate(&header, (char *) complete_message);
-
-  int sent_length = sendto(socket_handle,
-                           (char *) complete_message,
-                           outgoing_message->used_message_length + kUdpHeaderLength,
-                           0,
-                           (struct sockaddr *) address,
-                           sizeof(*address) );
+                      const ENIPMessage
+                      *const outgoing_message) {
+
+#if defined(OPENER_TRACE_ENABLED)
+  static char ip_str[INET_ADDRSTRLEN];
+  OPENER_TRACE_INFO(
+      "UDP packet to be sent to: %s:%d\n",
+      inet_ntop(AF_INET, &address->sin_addr, ip_str, sizeof ip_str),
+      ntohs(address->sin_port));
+#endif
 
+  int sent_length = sendto(g_network_status.udp_io_messaging,
+                           (char *)outgoing_message->message_buffer,
+                            outgoing_message->used_message_length, 0,
+                            (struct sockaddr*) address, sizeof(*address));
   if(sent_length < 0) {
     int error_code = GetSocketErrorNumber();
     char *error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR(
-      "networkhandler: error with sendto in sendUDPData: %d - %s\n",
-      error_code,
-      error_message);
+        "networkhandler: error with sendto in SendUDPData: %d - %s\n",
+        error_code,
+        error_message);
     FreeErrorMessage(error_message);
     return kEipStatusError;
   }
 
-  if(sent_length != outgoing_message->used_message_length + kUdpHeaderLength) {
+  if(sent_length != outgoing_message->used_message_length) {
     OPENER_TRACE_WARN(
       "data length sent_length mismatch; probably not all data was sent in SendUdpData, sent %d of %d\n",
       sent_length,
@@ -889,29 +878,15 @@ EipStatus HandleDataOnTcpSocket(int socket) {
   return kEipStatusError;
 }
 
-/** @brief create a new UDP socket for the connection manager
- *
- * @param communication_direction Consuming or producing port
- * @param socket_data Data for socket creation
+/** @brief Create the UDP socket for the implicit IO messaging, one socket handles all connections
  *
  * @return the socket handle if successful, else kEipInvalidSocket */
-int CreateUdpSocket(UdpCommuncationDirection communication_direction,
-                    struct sockaddr_in *socket_data,
-                    CipUsint qos_for_socket) {
-  struct sockaddr_in peer_address;
-  int new_socket = kEipInvalidSocket;
+int CreateUdpSocket(void) {
 
-  socklen_t peer_address_length = sizeof(struct sockaddr_in);
   /* create a new UDP socket */
-  if(kUdpCommuncationDirectionConsuming == communication_direction) {
-    new_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
-  }
+  g_network_status.udp_io_messaging = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
 
-  if(kUdpCommuncationDirectionProducing == communication_direction) {
-    new_socket = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
-  }
-
-  if(new_socket == kEipInvalidSocket) {
+  if (g_network_status.udp_io_messaging == kEipInvalidSocket) {
     int error_code = GetSocketErrorNumber();
     char *error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR("networkhandler: cannot create UDP socket: %d- %s\n",
@@ -921,128 +896,130 @@ int CreateUdpSocket(UdpCommuncationDirection communication_direction,
     return kEipInvalidSocket;
   }
 
-  if(SetSocketToNonBlocking(new_socket) < 0) {
+  if (SetSocketToNonBlocking(g_network_status.udp_io_messaging) < 0) {
     OPENER_TRACE_ERR(
-      "error setting socket to non-blocking on new socket\n");
-    CloseUdpSocket(new_socket);
+        "networkhandler udp_io_messaging: error setting socket to non-blocking on new socket\n");
+    CloseUdpSocket(g_network_status.udp_io_messaging);
     OPENER_ASSERT(false);/* This should never happen! */
     return kEipInvalidSocket;
   }
 
-  if(SetQosOnSocket(new_socket, CipQosGetDscpPriority(qos_for_socket) ) != 0) { /* got error */
+  OPENER_TRACE_INFO("networkhandler: UDP socket %d\n",
+                    g_network_status.udp_io_messaging);
+
+  int option_value = 1;
+  if (setsockopt(g_network_status.udp_io_messaging, SOL_SOCKET, SO_REUSEADDR,
+                 (char *)&option_value, sizeof(option_value)) < 0) {
+    OPENER_TRACE_ERR(
+        "error setting socket option SO_REUSEADDR on %s UDP socket\n");
+    CloseUdpSocket(g_network_status.udp_io_messaging);
+    return kEipInvalidSocket;
+  }
+
+  /* The bind on UDP sockets is necessary as the ENIP spec wants the source port to be specified to 2222 */
+  struct sockaddr_in source_addr = {
+    .sin_family = AF_INET,
+    .sin_addr.s_addr = htonl(INADDR_ANY),
+    .sin_port = htons(kOpenerEipIoUdpPort)};
+  
+  if (bind(g_network_status.udp_io_messaging, (struct sockaddr *)&source_addr,
+           sizeof(source_addr)) < 0) {
     int error_code = GetSocketErrorNumber();
     char *error_message = GetErrorMessage(error_code);
-    OPENER_TRACE_ERR(
-      "networkhandler: error on set QoS on socket on new socket: %d - %s\n",
-      error_code,
-      error_message);
+    OPENER_TRACE_ERR("error on bind UDP for producing messages: %d - %s\n", error_code,
+        error_message);
     FreeErrorMessage(error_message);
+    CloseUdpSocket(g_network_status.udp_io_messaging);
+    return kEipInvalidSocket;
   }
 
-  OPENER_TRACE_INFO("networkhandler: UDP socket %d\n", new_socket);
-
-  /* check if it is sending or receiving */
-  if(communication_direction == kUdpCommuncationDirectionConsuming) {
-    int option_value = 1;
-    if(setsockopt(new_socket, SOL_SOCKET, SO_REUSEADDR, (char *) &option_value,
-                  sizeof(option_value) ) < 0) {
-      OPENER_TRACE_ERR(
-        "error setting socket option SO_REUSEADDR on %s UDP socket\n",
-        (communication_direction == kUdpCommuncationDirectionConsuming) ?
-        "consuming" : "producing");
-      CloseUdpSocket(new_socket);
-      return kEipInvalidSocket;
-    }
-
-    /* bind is only for consuming necessary */
-    if( (bind(new_socket, (struct sockaddr *) socket_data,
-              sizeof(struct sockaddr) ) ) < 0 ) {
-      int error_code = GetSocketErrorNumber();
-      char *error_message = GetErrorMessage(error_code);
-      OPENER_TRACE_ERR("error on bind UDP: %d - %s\n", error_code,
-                       error_message);
-      FreeErrorMessage(error_message);
-      CloseUdpSocket(new_socket);
-      return kEipInvalidSocket;
-    }
+  /* add new socket to the master list */
+  FD_SET(g_network_status.udp_io_messaging, &master_socket);
+ 
+  if (g_network_status.udp_io_messaging > highest_socket_handle) {
+    OPENER_TRACE_INFO("New highest socket: %d\n",
+                      g_network_status.udp_io_messaging);
+    highest_socket_handle = g_network_status.udp_io_messaging;
+  }
+  return g_network_status.udp_io_messaging;
+}
 
-    OPENER_TRACE_INFO("networkhandler: bind UDP socket %d\n", new_socket);
-  } else { /* we have a producing UDP socket */
-
-    /* For multicast socket setup the TTL and specify interface to send on. */
-    if(socket_data->sin_addr.s_addr ==
-       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,
-                      NWBUF_CAST & 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_tcpip.mcast_ttl_value, error_code, error_message);
-          FreeErrorMessage(error_message);
-          CloseUdpSocket(new_socket);
-          return kEipInvalidSocket;
-        }
-      }
-      {
-        /* Need to specify the interface for outgoing multicast packets on a device
-           with multiple interfaces. */
-        struct in_addr my_addr = { .s_addr = g_network_status.ip_address };
-        if(setsockopt(new_socket, IPPROTO_IP, IP_MULTICAST_IF,
-                      NWBUF_CAST & my_addr.s_addr, sizeof my_addr.s_addr) < 0) {
-          int error_code = GetSocketErrorNumber();
-          char *error_message = GetErrorMessage(error_code);
-          OPENER_TRACE_ERR(
-            "networkhandler: could not set the multicast interface, error: %d - %s\n",
-            error_code,
-            error_message);
-          FreeErrorMessage(error_message);
-          CloseUdpSocket(new_socket);
-          return kEipInvalidSocket;
-        }
-      }
-    }
+/** @brief Set the Qos the socket for implicit IO messaging
+ *
+ * @return 0 if successful, else the error code */
+int SetQos(CipUsint qos_for_socket) {
+  if (SetQosOnSocket(g_network_status.udp_io_messaging,
+                     CipQosGetDscpPriority(qos_for_socket)) !=
+      0) { /* got error */
+    int error_code = GetSocketErrorNumber();
+    char *error_message = GetErrorMessage(error_code);
+    OPENER_TRACE_ERR("networkhandler: error on set QoS on socket: %d - %s\n",
+                     error_code, error_message);
+    return error_code;
   }
+  return 0;
+}
 
-  if( (communication_direction == kUdpCommuncationDirectionConsuming) ||
-      (0 == socket_data->sin_addr.s_addr) ) {
-    /* we have a peer to peer producer or a consuming connection*/
-    if(getpeername(g_current_active_tcp_socket,
-                   (struct sockaddr *) &peer_address,
-                   &peer_address_length) < 0) {
+/** @brief Set the socket options for Multicast Producer
+ *
+ * @return 0 if successful, else the error code */
+int SetSocketOptionsMulticastProduce(void) {
+  if (g_tcpip.mcast_ttl_value != 1) { 
+    /* we need to set a TTL value for the socket */
+    if (setsockopt(g_network_status.udp_io_messaging, IPPROTO_IP,
+                   IP_MULTICAST_TTL, NWBUF_CAST & 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 get peername: %d - %s\n",
-                       error_code,
-                       error_message);
+      OPENER_TRACE_ERR(
+          "networkhandler: could not set the TTL to: %d, error: %d - %s\n",
+          g_tcpip.mcast_ttl_value, error_code, error_message);
       FreeErrorMessage(error_message);
-      CloseUdpSocket(new_socket);
-      return kEipInvalidSocket;
+      return error_code;
     }
-    /* store the originators address */
-    socket_data->sin_addr.s_addr = peer_address.sin_addr.s_addr;
   }
-
-  if(kUdpCommuncationDirectionConsuming == communication_direction) {
-    /* add new socket to the master list */
-    FD_SET(new_socket, &master_socket);
+  /* Need to specify the interface for outgoing multicast packets on a
+   device with multiple interfaces. */
+  struct in_addr my_addr = {.s_addr = g_network_status.ip_address};
+  if (setsockopt(g_network_status.udp_io_messaging, IPPROTO_IP, IP_MULTICAST_IF,
+                 NWBUF_CAST & my_addr.s_addr, sizeof my_addr.s_addr) < 0) {
+    int error_code = GetSocketErrorNumber();
+    char *error_message = GetErrorMessage(error_code);
+    OPENER_TRACE_ERR(
+        "networkhandler: could not set the multicast interface, error: %d "
+        "- %s\n",
+        error_code, error_message);
+    FreeErrorMessage(error_message);
+    return error_code;
   }
+  return 0;
+}
 
-  if(new_socket > highest_socket_handle) {
-    OPENER_TRACE_INFO("New highest socket: %d\n", new_socket);
-    highest_socket_handle = new_socket;
+/** @brief Get the peer address
+ *
+ * @return peer address if successful, else any address (0) */
+EipUint32 GetPeerAddress(void) {
+  struct sockaddr_in peer_address;
+  socklen_t peer_address_length = sizeof(peer_address);
+
+  if (getpeername(g_current_active_tcp_socket, (struct sockaddr *)&peer_address,
+                  &peer_address_length) < 0) {
+    int error_code = GetSocketErrorNumber();
+    char *error_message = GetErrorMessage(error_code);
+    OPENER_TRACE_ERR("networkhandler: could not get peername: %d - %s\n",
+                     error_code, error_message);
+    FreeErrorMessage(error_message);
+    return htonl(INADDR_ANY);
   }
-  return new_socket;
+  return peer_address.sin_addr.s_addr;
 }
 
-void CheckAndHandleConsumingUdpSockets(void) {
+void CheckAndHandleConsumingUdpSocket(void) {
   DoublyLinkedListNode *iterator = connection_list.first;
 
   CipConnectionObject *current_connection_object = NULL;
 
-  /* see a message on one of the registered UDP sockets has been received     */
+  /* see a message of the registered UDP socket has been received     */
   while(NULL != iterator) {
     current_connection_object = (CipConnectionObject *) iterator->data;
     iterator = iterator->next; /* do this at the beginning as the close function may can make the entry invalid */
@@ -1058,14 +1035,8 @@ void CheckAndHandleConsumingUdpSockets(void) {
       socklen_t from_address_length = sizeof(from_address);
       CipOctet incoming_message[PC_OPENER_ETHERNET_BUFFER_SIZE] = { 0 };
 
-      int received_size =
-        recvfrom(
-          current_connection_object->socket[kUdpCommuncationDirectionConsuming],
-          NWBUF_CAST incoming_message,
-          sizeof(incoming_message),
-          0,
-          (struct sockaddr *) &from_address,
-          &from_address_length);
+      int received_size = recvfrom(g_network_status.udp_io_messaging, NWBUF_CAST incoming_message, sizeof(incoming_message),
+        0, (struct sockaddr*) &from_address, &from_address_length);
       if(0 == received_size) {
         int error_code = GetSocketErrorNumber();
         char *error_message = GetErrorMessage(error_code);

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

@@ -27,6 +27,10 @@
 #include "appcontype.h"
 #include "socket_timer.h"
 
+/*The port to be used per default for I/O messages on UDP.*/
+extern const int kOpenerEipIoUdpPort;
+extern const int kOpenerEthernetPort;
+
 extern SocketTimer g_timestamps[OPENER_NUMBER_OF_SUPPORTED_SESSIONS];
 
 //EipUint8 g_ethernet_communication_buffer[PC_OPENER_ETHERNET_BUFFER_SIZE]; /**< communication buffer */
@@ -52,6 +56,7 @@ typedef struct {
   int tcp_listener; /**< TCP listener socket */
   int udp_unicast_listener; /**< UDP unicast listener socket */
   int udp_global_broadcast_listener; /**< UDP global network broadcast listener */
+  int udp_io_messaging; /**< UDP IO messaging socket */
   CipUdint ip_address; /**< IP being valid during NetworkHandlerInitialize() */
   CipUdint network_mask; /**< network mask being valid during NetworkHandlerInitialize() */
   MilliSeconds elapsed_time;
@@ -69,7 +74,7 @@ void CloseUdpSocket(int socket_handle);
 
 void CloseTcpSocket(int socket_handle);
 
-EipStatus NetworkHandlerProcessOnce(void);
+EipStatus NetworkHandlerProcessCyclic(void);
 
 EipStatus NetworkHandlerFinish(void);
 
@@ -92,4 +97,19 @@ int GetMaxSocket(int socket1,
                  int socket3,
                  int socket4);
 
+/** @brief Set the Qos the socket for implicit IO messaging
+ *
+ * @return 0 if successful, else the error code */
+int SetQos(CipUsint qos_for_socket);
+
+/** @brief Set the socket options for Multicast Producer
+ *
+ * @return 0 if successful, else the error code */
+int SetSocketOptionsMulticastProduce(void);
+
+/** @brief Get the peer address
+ *
+ * @return peer address if successful, else any address (0) */
+EipUint32 GetPeerAddress(void);
+
 #endif /* GENERIC_NETWORKHANDLER_H_ */

+ 0 - 103
source/src/ports/udp_protocol.c

@@ -1,103 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2018, Rockwell Automation, Inc.
- * All rights reserved.
- *
- ******************************************************************************/
-
-#include <assert.h>
-#include "udp_protocol.h"
-#include "trace.h"
-#include "opener_user_conf.h"
-
-#ifdef WIN32
-#include <winsock2.h>
-#endif
-
-void UDPHeaderSetSourcePort(UDPHeader *const header,
-                            const uint16_t source_port) {
-  header->source_port = source_port;
-}
-
-uint16_t UDPHeaderGetSourcePort(const UDPHeader *const header) {
-  return header->source_port;
-}
-
-void UDPHeaderSetDestinationPort(UDPHeader *const header,
-                                 const uint16_t destination_port) {
-  header->destination_port = destination_port;
-}
-
-uint16_t UDPHeaderGetDestinationPort(const UDPHeader *const header) {
-  return header->destination_port;
-}
-
-void UDPHeaderSetPacketLength(UDPHeader *const header,
-                              const uint16_t packet_length) {
-  header->packet_length = packet_length;
-}
-
-uint16_t UDPHeaderGetPacketLength(const UDPHeader *const header) {
-  return header->packet_length;
-}
-
-void UDPHeaderSetChecksum(UDPHeader *const header,
-                          const uint16_t checksum) {
-  header->checksum = checksum;
-}
-
-uint16_t UDPHeaderGetChecksum(const UDPHeader *const header) {
-  return header->checksum;
-}
-
-void UDPHeaderGenerate(const UDPHeader *header,
-                       char *message) {
-  *( (uint16_t *)message ) = htons(UDPHeaderGetSourcePort(header) );
-  message += 2;
-  *( (uint16_t *)message ) = htons(UDPHeaderGetDestinationPort(header) );
-  message += 2;
-  *( (uint16_t *)message ) = htons(UDPHeaderGetPacketLength(header) );
-  message += 2;
-  *( (uint16_t *)message ) = htons(UDPHeaderGetChecksum(header) );
-  message += 2;
-}
-
-uint16_t UDPHeaderCalculateChecksum(const void *udp_packet,
-                                    const size_t udp_packet_length,
-                                    const in_addr_t source_addr,
-                                    const in_addr_t destination_addr) {
-  /* Checksum is calculated for 16-bit words */
-  const uint16_t *udp_packet_words = udp_packet;
-  uint_fast32_t checksum = 0; /**< Carry bit access is needed (17th bit) */
-
-  uint16_t i = udp_packet_length;
-  for(; i > 1; i = i - 2 ) {
-    checksum +=  *udp_packet_words;
-    udp_packet_words++;
-  }
-
-  OPENER_ASSERT( (0 == i) || (1 == i) ); /* data processed */
-
-  if (i > 0) {
-    checksum += (*( (uint8_t *)udp_packet_words ) << 8);
-    i--;
-  }
-  OPENER_ASSERT(0 == i); /* data processed */
-
-  const uint16_t *const source_addr_as_words =
-    (const uint16_t *const )&source_addr;
-  checksum += *source_addr_as_words + *(source_addr_as_words + 1);
-
-  const uint16_t *const destination_addr_as_words =
-    (const uint16_t *const )&destination_addr;
-  checksum += *destination_addr_as_words + *(destination_addr_as_words + 1);
-  checksum += htons(IPPROTO_UDP);
-  checksum += htons(udp_packet_length);
-
-  while(0xFFFF0000 & checksum) {
-    checksum = (checksum & 0xFFFF) + (checksum >> 16);
-  }
-
-  // Return one's complement
-  return (uint16_t)(~checksum);
-}
-

+ 0 - 125
source/src/ports/udp_protocol.h

@@ -1,125 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2018, Rockwell Automation, Inc.
- * All rights reserved.
- *
- ******************************************************************************/
-
-/** @file udp_protocol.h
- *  @author Martin Melik Merkumians
- *  @brief Includes a basic set of operations for UDP header creation and checksum calculation
- *
- *  In order to send UDP packets from a specified source port, the UDP header creation has to
- *  be done by hand. This file specifies the interface for OpENer's UDP header management,
- *  creation, and checksum calculation
- */
-
-#ifndef SRC_PORTS_UDP_PROTOCOL_H_
-#define SRC_PORTS_UDP_PROTOCOL_H_
-
-#include <stdint.h>
-#include <stddef.h>
-#ifdef OPENER_POSIX
-#include <netinet/in.h>
-#elif WIN32
-typedef uint32_t in_addr_t;
-#endif
-
-#define OPENER_UDP_HEADER_LENGTH (8U)
-static const size_t kUdpHeaderLength = OPENER_UDP_HEADER_LENGTH; /**< UDP header length in bytes */
-
-/** @brief Representing the needed information for the UDP header
- *
- * This struct represents the UDP header information
- */
-typedef struct {
-  uint16_t source_port;   /**< UDP source port */
-  uint16_t destination_port;   /**< UDP destination port */
-  uint16_t packet_length;   /**< UDP packet length (data + header) */
-  uint16_t checksum;   /**< UDP checksum */
-} UDPHeader;
-
-/** @brief Sets source port field
- *
- * @param header The UDP header struct instance
- * @param source_port Source port value to be set
- */
-void UDPHeaderSetSourcePort(UDPHeader *const header,
-                            const uint16_t source_port);
-
-/** @brief Gets source port field
- *
- * @param header The header struct instance
- * @return The source port
- */
-uint16_t UDPHeaderGetSourcePort(const UDPHeader *const header);
-
-/** @brief Sets destination port field
- *
- * @param header The UDP header struct instance
- * @param destination_port Destination port value to be set
- */
-void UDPHeaderSetDestinationPort(UDPHeader *const header,
-                                 const uint16_t destination_port);
-
-/** @brief Gets destination port field
- *
- * @param header The header struct instance
- * @return The destination port
- */
-uint16_t UDPHeaderGetDestinationPort(const UDPHeader *const header);
-
-/** @brief Sets packet length field
- *
- * @param header The UDP header struct instance
- * @param packet_length Length value to be set
- */
-void UDPHeaderSetPacketLength(UDPHeader *const header,
-                              const uint16_t packet_length);
-
-/** @brief Gets packet length field
- *
- * @param header The header struct instance
- * @return The packet length
- */
-uint16_t UDPHeaderGetPacketLength(const UDPHeader *const header);
-
-/** @brief Sets checksum field
- *
- * @param header The UDP header struct instance
- * @param checksum Checksum value to be set
- */
-void UDPHeaderSetChecksum(UDPHeader *const header,
-                          const uint16_t checksum);
-
-/** @brief Gets checksum field
- *
- * @param header The UDP header struct instance
- * @return The packet length
- */
-uint16_t UDPHeaderGetChecksum(const UDPHeader *const header);
-
-/** @brief Calculates the checksum based on the set UDP packet data and pseudo IP header
- *
- * @param udp_packet the UDP packet including the UDP header
- * @param udp_packet_length UPD packet length
- * @param source_addr The IP source address
- * @param destination_addr The IP destination address
- * @return The calculated checksum
- */
-uint16_t UDPHeaderCalculateChecksum(const void *udp_packet,
-                                    const size_t udp_packet_length,
-                                    const in_addr_t source_addr,
-                                    const in_addr_t destination_addr);
-
-/** @brief Generate the UDP header in the message according to the header
- *
- * The function generates the UDP header according to the header struct
- * overwriting the first 8 bytes
- *
- * @param header The UDP header struct instance
- * @param message The message buffer
- */
-void UDPHeaderGenerate(const UDPHeader *header,
-                       char *message);
-
-#endif /* SRC_PORTS_UDP_PROTOCOL_H_ */

+ 0 - 1
source/tests/OpENerTests.h

@@ -2,7 +2,6 @@
 
 IMPORT_TEST_GROUP (RandomClass);
 IMPORT_TEST_GROUP (XorShiftRandom);
-IMPORT_TEST_GROUP (UdpProtocol);
 IMPORT_TEST_GROUP (EndianConversion);
 IMPORT_TEST_GROUP (CipCommon);
 IMPORT_TEST_GROUP (CipEpath);

+ 2 - 2
source/tests/ports/CMakeLists.txt

@@ -9,8 +9,8 @@ opener_common_includes()
 #######################################
 opener_platform_support("INCLUDES")
 
-set( PortsTestSrc socket_timer_tests.cpp udp_protocol_tests.cpp)
+set( PortsTestSrc socket_timer_tests.cpp)
 
 include_directories( ${SRC_DIR}/ports )
 
-add_library( PortsTest ${PortsTestSrc} )
+add_library( PortsTest ${PortsTestSrc} )

+ 0 - 126
source/tests/ports/udp_protocol_tests.cpp

@@ -1,126 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2020, Rockwell Automation, Inc.
- * All rights reserved.
- *
- ******************************************************************************/
-
-#include <CppUTest/TestHarness.h>
-#include <stdint.h>
-#include <string.h>
-
-extern "C" {
-#include "ciptypes.h"
-#include "udp_protocol.h"
-}
-
-TEST_GROUP(UdpProtocol) {
-
-};
-
-TEST(UdpProtocol, SetSourcePort) {
-  UDPHeader header = {0};
-  UDPHeaderSetSourcePort(&header, 10);
-  CHECK_EQUAL( 10, header.source_port );
-}
-
-TEST(UdpProtocol, GetSourcePort) {
-  UDPHeader header = {0};
-  header.source_port =  5643;
-  CHECK_EQUAL( 5643, UDPHeaderGetSourcePort(&header) );
-}
-
-TEST(UdpProtocol, SetDestinationPort) {
-  UDPHeader header = {0};
-  header.destination_port = 1640;
-  CHECK_EQUAL( 1640, header.destination_port );
-}
-
-TEST(UdpProtocol, GetDestinationPort) {
-  UDPHeader header = {0};
-  UDPHeaderSetDestinationPort(&header, 9824);
-  CHECK_EQUAL( 9824, UDPHeaderGetDestinationPort(&header) );
-}
-
-TEST(UdpProtocol, SetPacketLength) {
-  UDPHeader header = {0};
-  UDPHeaderSetPacketLength(&header, 26814);
-  CHECK_EQUAL( 26814, header.packet_length);
-}
-
-TEST(UdpProtocol, GetPacketLength) {
-  UDPHeader header = {0};
-  header.packet_length = 36521;
-  CHECK_EQUAL( 36521, UDPHeaderGetPacketLength(&header) );
-}
-
-TEST(UdpProtocol, SetChecksum) {
-  UDPHeader header = {0};
-  UDPHeaderSetChecksum(&header, 0x8eaf);
-  CHECK_EQUAL( 0x8eaf, header.checksum);
-}
-
-TEST(UdpProtocol, GetChecksum) {
-  UDPHeader header = {0};
-  header.checksum = 0xaf8e;
-  CHECK_EQUAL( 0xaf8e, UDPHeaderGetChecksum(&header) );
-}
-
-TEST(UdpProtocol, HeaderGenerate) {
-  char message[OPENER_UDP_HEADER_LENGTH] = {0};
-  UDPHeader header = {0};
-  header.source_port =  5643;
-  header.destination_port = 1640;
-  header.packet_length = 36521;
-  header.checksum = 0xaf8e;
-  UDPHeaderGenerate(&header, message);
-  CHECK_EQUAL( htons(5643), *( (uint16_t *)message ) );
-  CHECK_EQUAL( htons(1640), *( ( (uint16_t *)message ) + 1 ) );
-  CHECK_EQUAL( htons(36521), *( ( (uint16_t *)message ) + 2 ) );
-  CHECK_EQUAL( htons(0xaf8e), *( ( (uint16_t *)message ) + 3 ) );
-}
-
-TEST(UdpProtocol, CalculateChecksumOddLength) {
-  char message[OPENER_UDP_HEADER_LENGTH + 13];
-  memset(message, 0, OPENER_UDP_HEADER_LENGTH + 13);
-  UDPHeader header = {0};
-  header.source_port =  5643;
-  header.destination_port = 1640;
-  header.packet_length = OPENER_UDP_HEADER_LENGTH + 13;
-  header.checksum = 0;
-  UDPHeaderGenerate(&header, message);
-  for(size_t i = kUdpHeaderLength; i < OPENER_UDP_HEADER_LENGTH + 13; i++) {
-    message[i] = i;
-  }
-
-  in_addr_t source_addr = 0x0A000001;
-  in_addr_t destination_addr = 0x0A000002;
-
-  uint16_t checksum = UDPHeaderCalculateChecksum(message,
-                                                 OPENER_UDP_HEADER_LENGTH + 13,
-                                                 source_addr,
-                                                 destination_addr);
-  CHECK_EQUAL(0xD591, checksum); // Aquired via the function under test - correctness verified via Wireshark
-}
-
-TEST(UdpProtocol, CalculateChecksumEvenLength) {
-  char message[OPENER_UDP_HEADER_LENGTH + 12];
-  memset(message, 0, OPENER_UDP_HEADER_LENGTH + 12);
-  UDPHeader header = {0};
-  header.source_port =  5643;
-  header.destination_port = 1640;
-  header.packet_length = OPENER_UDP_HEADER_LENGTH + 12;
-  header.checksum = 0;
-  UDPHeaderGenerate(&header, message);
-  for(size_t i = kUdpHeaderLength; i < OPENER_UDP_HEADER_LENGTH + 12; i++) {
-    message[i] = i;
-  }
-
-  in_addr_t source_addr = 0x0A000001;
-  in_addr_t destination_addr = 0x0A000002;
-
-  uint16_t checksum = UDPHeaderCalculateChecksum(message,
-                                                 OPENER_UDP_HEADER_LENGTH + 12,
-                                                 source_addr,
-                                                 destination_addr);
-  CHECK_EQUAL(0xEB91, checksum); // Aquired via the function under test - correctness verified via Wireshark
-}