Просмотр исходного кода

Merge

Signed-off-by: CapXilinx <melik-merkumians@acin.tuwien.ac.at>
CapXilinx 8 лет назад
Родитель
Сommit
5e357c1d2c

+ 153 - 100
source/src/cip/cipconnectionmanager.c

@@ -51,7 +51,8 @@ typedef struct {
 
 /* Connection Object functions */
 ProductionTrigger GetProductionTrigger(
-  const ConnectionObject *const connection_object) {
+  const ConnectionObject *const connection_object
+  ) {
   const unsigned int ProductionTriggerMask = 0x70;
 
   switch (connection_object->transport_type_class_trigger
@@ -67,9 +68,10 @@ ProductionTrigger GetProductionTrigger(
   }
 }
 
-void SetProductionTrigger(const enum ProductionTrigger production_trigger,
-                          ConnectionObject *connection_object)
-{
+void SetProductionTrigger(
+  const enum ProductionTrigger production_trigger,
+  ConnectionObject *connection_object
+  ) {
   switch (production_trigger) {
     case kProductionTriggerCyclic:
       connection_object->transport_type_class_trigger = 0x0;
@@ -88,24 +90,28 @@ void SetProductionTrigger(const enum ProductionTrigger production_trigger,
 }
 
 CipUint GetProductionInhibitTime(
-  const ConnectionObject *const connection_object) {
+  const ConnectionObject *const connection_object
+  ) {
   return connection_object->production_inhibit_time;
 }
 
-void SetProductionInhibitTime(const EipUint16 production_inhibit_time,
-                              ConnectionObject *const connection_object)
-{
+void SetProductionInhibitTime(
+  const EipUint16 production_inhibit_time,
+  ConnectionObject *const connection_object
+  ) {
   connection_object->production_inhibit_time = production_inhibit_time;
 }
 
 CipUdint GetTargetToOriginatorRequestedPackedInterval(
-  const ConnectionObject *const RESTRICT connection_object) {
+  const ConnectionObject *const RESTRICT connection_object
+  ) {
   return connection_object->t_to_o_requested_packet_interval;
 }
 
 ConnectionObjectFixedVariable
 GetConnectionObjectTargetToOriginatorFixedOrVariableConnectionSize(
-  const ConnectionObject *const RESTRICT connection_object) {
+  const ConnectionObject *const RESTRICT connection_object
+  ) {
   const EipUint16 kFixedOrVariableMask = 1 << 9;
   if ( ( (connection_object->t_to_o_network_connection_parameter) &
          kFixedOrVariableMask ) == kFixedOrVariableMask ) {
@@ -138,20 +144,23 @@ ConnectionObject g_dummy_connection_object;
 EipUint32 g_incarnation_id;
 
 /* private functions */
-EipStatus ForwardOpen(CipInstance *instance,
-                      CipMessageRouterRequest *message_router_request,
-                      CipMessageRouterResponse *message_router_response,
-                      struct sockaddr *originator_address);
+EipStatus ForwardOpen(
+  CipInstance *instance,
+  CipMessageRouterRequest *message_router_request,
+  CipMessageRouterResponse *message_router_response,
+  struct sockaddr *originator_address);
 
-EipStatus ForwardClose(CipInstance *instance,
-                       CipMessageRouterRequest *message_router_request,
-                       CipMessageRouterResponse *message_router_response,
-                       struct sockaddr *originator_address);
+EipStatus ForwardClose(
+  CipInstance *instance,
+  CipMessageRouterRequest *message_router_request,
+  CipMessageRouterResponse *message_router_response,
+  struct sockaddr *originator_address);
 
-EipStatus GetConnectionOwner(CipInstance *instance,
-                             CipMessageRouterRequest *message_router_request,
-                             CipMessageRouterResponse *message_router_response,
-                             struct sockaddr *originator_address);
+EipStatus GetConnectionOwner(
+  CipInstance *instance,
+  CipMessageRouterRequest *message_router_request,
+  CipMessageRouterResponse *message_router_response,
+  struct sockaddr *originator_address);
 
 EipStatus AssembleForwardOpenResponse(
   ConnectionObject *connection_object,
@@ -188,9 +197,10 @@ ConnectionObject *CheckForExistingConnection(
  *    - EIP_OK ... on success
  *    - On an error the general status code to be put into the response
  */
-EipStatus CheckElectronicKeyData(EipUint8 key_format,
-                                 CipKeyData *key_data,
-                                 EipUint16 *extended_status);
+EipStatus CheckElectronicKeyData(
+  EipUint8 key_format,
+  CipKeyData *key_data,
+  EipUint16 *extended_status);
 
 /** @brief Parse the connection path of a forward open request
  *
@@ -203,13 +213,16 @@ EipStatus CheckElectronicKeyData(EipUint8 key_format,
  *    - EIP_OK ... on success
  *    - On an error the general status code to be put into the response
  */
-EipUint8 ParseConnectionPath(ConnectionObject *connection_object,
-                             CipMessageRouterRequest *message_router_request,
-                             EipUint16 *extended_error);
+EipUint8 ParseConnectionPath(
+  ConnectionObject *connection_object,
+  CipMessageRouterRequest *message_router_request,
+  EipUint16 *extended_error);
 
-ConnectionManagementHandling *GetConnectionManagementEntry(EipUint32 class_id);
+ConnectionManagementHandling *GetConnectionManagementEntry(
+  EipUint32 class_id);
 
-void InitializeConnectionManagerData(void);
+void InitializeConnectionManagerData(
+  void);
 
 void AddNullAddressItem(
   CipCommonPacketFormatData *common_data_packet_format_data);
@@ -219,7 +232,9 @@ void AddNullAddressItem(
  *
  * @return The padded logical path
  */
-unsigned int GetPaddedLogicalPath(const EipUint8 **logical_path_segment) {
+unsigned int GetPaddedLogicalPath(
+  const EipUint8 **logical_path_segment
+  ) {
   unsigned int padded_logical_path = *(*logical_path_segment)++;
 
   if ( (padded_logical_path & 3) == 0 ) {
@@ -241,13 +256,17 @@ unsigned int GetPaddedLogicalPath(const EipUint8 **logical_path_segment) {
  * and the per-new-connection-incremented connection number/counter.
  * @return new connection id
  */
-EipUint32 GetConnectionId(void) {
+EipUint32 GetConnectionId(
+  void
+  ) {
   static EipUint32 connection_id = 18;
   connection_id++;
   return ( g_incarnation_id | (connection_id & 0x0000FFFF) );
 }
 
-void InitializeConnectionManager(CipClass *class) {
+void InitializeConnectionManager(
+  CipClass *class
+  ) {
 
   CipClass *meta_class = class->class_instance.cip_class;
 
@@ -271,7 +290,9 @@ void InitializeConnectionManager(CipClass *class) {
 
 }
 
-EipStatus ConnectionManagerInit(EipUint16 unique_connection_id) {
+EipStatus ConnectionManagerInit(
+  EipUint16 unique_connection_id
+  ) {
   InitializeConnectionManagerData();
 
   CipClass *connection_manager = CreateCipClass(
@@ -307,10 +328,11 @@ EipStatus ConnectionManagerInit(EipUint16 unique_connection_id) {
   return kEipStatusOk;
 }
 
-EipStatus HandleReceivedConnectedData(EipUint8 *data,
-                                      int data_length,
-                                      struct sockaddr_in *from_address)
-{
+EipStatus HandleReceivedConnectedData(
+  EipUint8 *data,
+  int data_length,
+  struct sockaddr_in *from_address
+  ) {
 
   if ( ( CreateCommonPacketFormatStructure(data, data_length,
                                            &g_common_packet_format_data_item) )
@@ -378,8 +400,8 @@ void ReadOutConnectionObjectFromMessage(
 
 void ReadOutConnectionObjectFromMessage(
   CipMessageRouterRequest *const message_router_request,
-  ConnectionObject *const connection_object)
-{
+  ConnectionObject *const connection_object
+  ) {
   connection_object->priority_timetick = *message_router_request->data++;
   connection_object->timeout_ticks = *message_router_request->data++;
   /* O_to_T Conn ID */
@@ -438,7 +460,8 @@ void ReadOutConnectionObjectFromMessage(
 }
 
 ForwardOpenConnectionType GetConnectionType(
-  EipUint16 network_connection_parameter) {
+  EipUint16 network_connection_parameter
+  ) {
   const EipUint16 kConnectionParameterMask = 0x6000;
 
   ForwardOpenConnectionType connection_type = network_connection_parameter
@@ -451,14 +474,16 @@ ForwardOpenConnectionType GetConnectionType(
   return connection_type;
 }
 
-ForwardOpenPriority GetPriorityForQos(
-  EipUint16 network_connection_parameter) {
+ForwardOpenPriority GetConnectionObjectTToOPriority(
+  const ConnectionObject *const connection_object
+  ) {
 
   const EipUint16 kConnectionParameterMask = 0xC00;
   CipUsint priority_value = 0x00;
 
-  ForwardOpenPriority priority = network_connection_parameter
-                                 & kConnectionParameterMask;
+  ForwardOpenPriority priority =
+    (connection_object->t_to_o_network_connection_parameter)
+    & kConnectionParameterMask;
 
   priority_value = GetPriorityForSocket(priority);
 
@@ -489,8 +514,8 @@ EipStatus HandleNullNonMatchingForwardOpenRequest(
   ConnectionObject *connection_object,
   CipInstance *instance,
   CipMessageRouterRequest *message_router_request,
-  CipMessageRouterResponse *message_router_response)
-{
+  CipMessageRouterResponse *message_router_response
+  ) {
   OPENER_TRACE_INFO("Right now we cannot handle Null requests\n");
   return AssembleForwardOpenResponse(
            connection_object,
@@ -515,8 +540,8 @@ EipStatus HandleNullMatchingForwardOpenRequest(
   ConnectionObject *connection_object,
   CipInstance *instance,
   CipMessageRouterRequest *message_router_request,
-  CipMessageRouterResponse *message_router_response)
-{
+  CipMessageRouterResponse *message_router_response
+  ) {
   OPENER_TRACE_INFO("Right now we cannot handle Null requests\n");
   return AssembleForwardOpenResponse(
            connection_object,
@@ -540,8 +565,8 @@ EipStatus HandleNonNullMatchingForwardOpenRequest(
   ConnectionObject *connection_object,
   CipInstance *instance,
   CipMessageRouterRequest *message_router_request,
-  CipMessageRouterResponse *message_router_response)
-{
+  CipMessageRouterResponse *message_router_response
+  ) {
   OPENER_TRACE_INFO("Right now we cannot handle reconfiguration requests\n");
   return AssembleForwardOpenResponse(
            connection_object,
@@ -564,8 +589,8 @@ EipStatus HandleNonNullNonMatchingForwardOpenRequest(
   ConnectionObject *connection_object,
   CipInstance *instance,
   CipMessageRouterRequest *message_router_request,
-  CipMessageRouterResponse *message_router_response)
-{
+  CipMessageRouterResponse *message_router_response
+  ) {
 
   EipUint16 connection_status = kConnectionManagerExtendedStatusCodeSuccess;
 
@@ -648,11 +673,12 @@ static const HandleForwardOpenRequestFunction
  *      @return >0 .. success, 0 .. no reply to send back
  *              -1 .. error
  */
-EipStatus ForwardOpen(CipInstance *instance,
-                      CipMessageRouterRequest *message_router_request,
-                      CipMessageRouterResponse *message_router_response,
-                      struct sockaddr *originator_address)
-{
+EipStatus ForwardOpen(
+  CipInstance *instance,
+  CipMessageRouterRequest *message_router_request,
+  CipMessageRouterResponse *message_router_response,
+  struct sockaddr *originator_address
+  ) {
   (void) instance; /*suppress compiler warning */
 
   uint8_t is_null_request = -1; /* 1 = Null Request, 0 =  Non-Null Request  */
@@ -712,7 +738,9 @@ EipStatus ForwardOpen(CipInstance *instance,
                           message_router_request, message_router_response);
 }
 
-void GeneralConnectionConfiguration(ConnectionObject *connection_object) {
+void GeneralConnectionConfiguration(
+  ConnectionObject *connection_object
+  ) {
   if ( kForwardOpenConnectionTypePointToPointConnection
        == (connection_object->o_to_t_network_connection_parameter
            & kForwardOpenConnectionTypePointToPointConnection) ) {
@@ -779,11 +807,12 @@ void GeneralConnectionConfiguration(ConnectionObject *connection_object) {
 
 }
 
-EipStatus ForwardClose(CipInstance *instance,
-                       CipMessageRouterRequest *message_router_request,
-                       CipMessageRouterResponse *message_router_response,
-                       struct sockaddr *originator_address)
-{
+EipStatus ForwardClose(
+  CipInstance *instance,
+  CipMessageRouterRequest *message_router_request,
+  CipMessageRouterResponse *message_router_response,
+  struct sockaddr *originator_address
+  ) {
   /*Suppress compiler warning*/
   (void) instance;
 
@@ -840,11 +869,12 @@ EipStatus ForwardClose(CipInstance *instance,
 }
 
 /* TODO: Not implemented */
-EipStatus GetConnectionOwner(CipInstance *instance,
-                             CipMessageRouterRequest *message_router_request,
-                             CipMessageRouterResponse *message_router_response,
-                             struct sockaddr *originator_address)
-{
+EipStatus GetConnectionOwner(
+  CipInstance *instance,
+  CipMessageRouterRequest *message_router_request,
+  CipMessageRouterResponse *message_router_response,
+  struct sockaddr *originator_address
+  ) {
   /* suppress compiler warnings */
   (void) instance;
   (void) message_router_request;
@@ -853,7 +883,9 @@ EipStatus GetConnectionOwner(CipInstance *instance,
   return kEipStatusOk;
 }
 
-EipStatus ManageConnections(MilliSeconds elapsed_time) {
+EipStatus ManageConnections(
+  MilliSeconds elapsed_time
+  ) {
   //OPENER_TRACE_INFO("Entering ManageConnections\n");
   /*Inform application that it can execute */
   HandleApplication();
@@ -939,8 +971,8 @@ EipStatus AssembleForwardOpenResponse(
   ConnectionObject *connection_object,
   CipMessageRouterResponse *message_router_response,
   EipUint8 general_status,
-  EipUint16 extended_status)
-{
+  EipUint16 extended_status
+  ) {
   /* write reply information in CPF struct dependent of pa_status */
   CipCommonPacketFormatData *cip_common_packet_format_data =
     &g_common_packet_format_data_item;
@@ -1041,7 +1073,8 @@ EipStatus AssembleForwardOpenResponse(
  * @param common_data_packet_format_data The CPF data packet where the Null Address Item shall be added
  */
 void AddNullAddressItem(
-  CipCommonPacketFormatData *common_data_packet_format_data) {
+  CipCommonPacketFormatData *common_data_packet_format_data
+  ) {
   /* Precondition: Null Address Item only valid in unconnected messages */
   assert(
     common_data_packet_format_data->data_item.type_id
@@ -1072,8 +1105,8 @@ EipStatus AssembleForwardCloseResponse(
   EipUint32 originator_serial_number,
   CipMessageRouterRequest *message_router_request,
   CipMessageRouterResponse *message_router_response,
-  EipUint16 extended_error_code)
-{
+  EipUint16 extended_error_code
+  ) {
   /* write reply information in CPF struct dependent of pa_status */
   CipCommonPacketFormatData *common_data_packet_format_data =
     &g_common_packet_format_data_item;
@@ -1114,7 +1147,9 @@ EipStatus AssembleForwardCloseResponse(
   return kEipStatusOkSend;
 }
 
-ConnectionObject *GetConnectedObject(EipUint32 connection_id) {
+ConnectionObject *GetConnectedObject(
+  EipUint32 connection_id
+  ) {
   ConnectionObject *active_connection_object_list_item =
     g_active_connection_list;
   while (NULL != active_connection_object_list_item) {
@@ -1131,7 +1166,9 @@ ConnectionObject *GetConnectedObject(EipUint32 connection_id) {
   return NULL;
 }
 
-ConnectionObject *GetConnectedOutputAssembly(EipUint32 output_assembly_id) {
+ConnectionObject *GetConnectedOutputAssembly(
+  EipUint32 output_assembly_id
+  ) {
   ConnectionObject *active_connection_object_list_item =
     g_active_connection_list;
 
@@ -1152,7 +1189,8 @@ ConnectionObject *GetConnectedOutputAssembly(EipUint32 output_assembly_id) {
 }
 
 ConnectionObject *CheckForExistingConnection(
-  ConnectionObject *connection_object) {
+  ConnectionObject *connection_object
+  ) {
   ConnectionObject *active_connection_object_list_item =
     g_active_connection_list;
 
@@ -1175,10 +1213,11 @@ ConnectionObject *CheckForExistingConnection(
   return NULL;
 }
 
-EipStatus CheckElectronicKeyData(EipUint8 key_format,
-                                 CipKeyData *key_data,
-                                 EipUint16 *extended_status)
-{
+EipStatus CheckElectronicKeyData(
+  EipUint8 key_format,
+  CipKeyData *key_data,
+  EipUint16 *extended_status
+  ) {
   EipByte compatiblity_mode = key_data->major_revision & 0x80;
 
   /* Remove compatibility bit */
@@ -1249,10 +1288,11 @@ EipStatus CheckElectronicKeyData(EipUint8 key_format,
     kEipStatusOk : kEipStatusError;
 }
 
-EipUint8 ParseConnectionPath(ConnectionObject *connection_object,
-                             CipMessageRouterRequest *message_router_request,
-                             EipUint16 *extended_error)
-{
+EipUint8 ParseConnectionPath(
+  ConnectionObject *connection_object,
+  CipMessageRouterRequest *message_router_request,
+  EipUint16 *extended_error
+  ) {
   const EipUint8 *message = message_router_request->data;
   unsigned int remaining_path_size = connection_object->connection_path_size =
                                        *message++; /* length in words */
@@ -1547,7 +1587,9 @@ EipUint8 ParseConnectionPath(ConnectionObject *connection_object,
   return kEipStatusOk;
 }
 
-void CloseConnection(ConnectionObject *RESTRICT connection_object) {
+void CloseConnection(
+  ConnectionObject *RESTRICT connection_object
+  ) {
   connection_object->state = kConnectionStateNonExistent;
   if ( 0x03 != (connection_object->transport_type_class_trigger & 0x03) ) {
     /* only close the UDP connection for not class 3 connections */
@@ -1563,13 +1605,16 @@ void CloseConnection(ConnectionObject *RESTRICT connection_object) {
   RemoveFromActiveConnections(connection_object);
 }
 
-void CopyConnectionData(ConnectionObject *RESTRICT destination,
-                        const ConnectionObject *RESTRICT const source)
-{
+void CopyConnectionData(
+  ConnectionObject *RESTRICT destination,
+  const ConnectionObject *RESTRICT const source
+  ) {
   memcpy( destination, source, sizeof(ConnectionObject) );
 }
 
-void AddNewActiveConnection(ConnectionObject *connection_object) {
+void AddNewActiveConnection(
+  ConnectionObject *connection_object
+  ) {
   connection_object->first_connection_object = NULL;
   connection_object->next_connection_object = g_active_connection_list;
   if (NULL != g_active_connection_list) {
@@ -1579,7 +1624,9 @@ void AddNewActiveConnection(ConnectionObject *connection_object) {
   g_active_connection_list->state = kConnectionStateEstablished;
 }
 
-void RemoveFromActiveConnections(ConnectionObject *connection_object) {
+void RemoveFromActiveConnections(
+  ConnectionObject *connection_object
+  ) {
 
   if (NULL != connection_object->first_connection_object) {
     connection_object->first_connection_object->next_connection_object =
@@ -1597,7 +1644,9 @@ void RemoveFromActiveConnections(ConnectionObject *connection_object) {
   connection_object->state = kConnectionStateNonExistent;
 }
 
-EipBool8 IsConnectedOutputAssembly(const EipUint32 instance_number) {
+EipBool8 IsConnectedOutputAssembly(
+  const EipUint32 instance_number
+  ) {
   EipBool8 is_connected = false;
 
   ConnectionObject *iterator = g_active_connection_list;
@@ -1612,9 +1661,10 @@ EipBool8 IsConnectedOutputAssembly(const EipUint32 instance_number) {
   return is_connected;
 }
 
-EipStatus AddConnectableObject(EipUint32 class_id,
-                               OpenConnectionFunction open_connection_function)
-{
+EipStatus AddConnectableObject(
+  EipUint32 class_id,
+  OpenConnectionFunction open_connection_function
+  ) {
   EipStatus status = kEipStatusError;
 
   /*parsing is now finished all data is available and check now establish the connection */
@@ -1633,7 +1683,9 @@ EipStatus AddConnectableObject(EipUint32 class_id,
 }
 
 ConnectionManagementHandling *
-GetConnectionManagementEntry(EipUint32 class_id) {
+GetConnectionManagementEntry(
+  EipUint32 class_id
+  ) {
 
   ConnectionManagementHandling *connection_management_entry = NULL;
 
@@ -1646,9 +1698,10 @@ GetConnectionManagementEntry(EipUint32 class_id) {
   return connection_management_entry;
 }
 
-EipStatus TriggerConnections(unsigned int output_assembly,
-                             unsigned int input_assembly)
-{
+EipStatus TriggerConnections(
+  unsigned int output_assembly,
+  unsigned int input_assembly
+  ) {
   EipStatus status = kEipStatusError;
 
   ConnectionObject *pstRunner = g_active_connection_list;

+ 36 - 21
source/src/cip/cipconnectionmanager.h

@@ -97,7 +97,9 @@ typedef enum {
     =
       0x0133,
   kConnectionManagerExtendedStatusCodeMismatchedTToONetworkConnectionFixVar =
-    0x135,
+    0x0135,
+  kConnectionManagerExtendedStatusCodeMismatchedTToONetworkConnectionPriority =
+    0x0136,
   kConnectionManagerExtendedStatusCodeConnectionTimedOut = 0x0203,
   kConnectionManagerExtendedStatusCodeUnconnectedRequestTimedOut = 0x0204,
   kConnectionManagerExtendedStatusCodeErrorParameterErrorInUnconnectedSendService
@@ -163,14 +165,16 @@ typedef enum ProductionTrigger {
 ProductionTrigger GetProductionTrigger(
   const ConnectionObject *const connection_object);
 
-void SetProductionTrigger(const ProductionTrigger production_trigger,
-                          ConnectionObject *connection_object);
+void SetProductionTrigger(
+  const ProductionTrigger production_trigger,
+  ConnectionObject *connection_object);
 
 CipUint GetProductionInhibitTime(
   const ConnectionObject *const connection_object);
 
-void SetProductionInhibitTime(const EipUint16 production_inhibit_time,
-                              ConnectionObject *const connection_object);
+void SetProductionInhibitTime(
+  const EipUint16 production_inhibit_time,
+  ConnectionObject *const connection_object);
 
 CipUdint GetTargetToOriginatorRequestedPackedInterval(
   const ConnectionObject *const connection_object);
@@ -361,7 +365,8 @@ static const int g_kCipConnectionManagerClassCode = 0x06;
  *  @param A unique connection id
  *  @return kEipStatusOk if successful, otherwise kEipStatusError
  */
-EipStatus ConnectionManagerInit(EipUint16 unique_connection_id);
+EipStatus ConnectionManagerInit(
+  EipUint16 unique_connection_id);
 
 /** @brief Get a connected object dependent on requested ConnectionID.
  *
@@ -369,7 +374,8 @@ EipStatus ConnectionManagerInit(EipUint16 unique_connection_id);
  *   @return pointer to connected Object
  *           0 .. connection not present in device
  */
-ConnectionObject *GetConnectedObject(EipUint32 connection_id);
+ConnectionObject *GetConnectedObject(
+  EipUint32 connection_id);
 
 /**  Get a connection object for a given output assembly.
  *
@@ -378,15 +384,17 @@ ConnectionObject *GetConnectedObject(EipUint32 connection_id);
  *   @return pointer to connected Object
  *           0 .. connection not present in device
  */
-ConnectionObject *GetConnectedOutputAssembly(EipUint32 output_assembly_id);
+ConnectionObject *GetConnectedOutputAssembly(
+  EipUint32 output_assembly_id);
 
 /** @brief Copy the given connection data from source to destination
  *
  * @param destination Destination of the copy operation
  * @param osurce Source of the copy operation
  */
-void CopyConnectionData(ConnectionObject *RESTRICT destination,
-                        const ConnectionObject *RESTRICT const source);
+void CopyConnectionData(
+  ConnectionObject *RESTRICT destination,
+  const ConnectionObject *RESTRICT const source);
 
 /** @brief Close the given connection
  *
@@ -395,10 +403,12 @@ void CopyConnectionData(ConnectionObject *RESTRICT destination,
  * @param connection_object pointer to the connection object structure to be
  * closed
  */
-void CloseConnection(ConnectionObject *RESTRICT connection_object);
+void CloseConnection(
+  ConnectionObject *RESTRICT connection_object);
 
 /* TODO: Missing documentation */
-EipBool8 IsConnectedOutputAssembly(const EipUint32 instance_number);
+EipBool8 IsConnectedOutputAssembly(
+  const EipUint32 instance_number);
 
 /** @brief Generate the ConnectionIDs and set the general configuration
  * parameter in the given connection object.
@@ -406,7 +416,8 @@ EipBool8 IsConnectedOutputAssembly(const EipUint32 instance_number);
  * @param connection_object pointer to the connection object that should be set
  * up.
  */
-void GeneralConnectionConfiguration(ConnectionObject *connection_object);
+void GeneralConnectionConfiguration(
+  ConnectionObject *connection_object);
 
 /** @brief Insert the given connection object to the list of currently active
  *  and managed connections.
@@ -417,13 +428,15 @@ void GeneralConnectionConfiguration(ConnectionObject *connection_object);
  *
  * @param connection_object pointer to the connection object to be added.
  */
-void AddNewActiveConnection(ConnectionObject *connection_object);
+void AddNewActiveConnection(
+  ConnectionObject *connection_object);
 
 /** @brief Removes connection from the list of active connections
  *
  * @param connection_object Connection object to be removed from the active connection list
  */
-void RemoveFromActiveConnections(ConnectionObject *connection_object);
+void RemoveFromActiveConnections(
+  ConnectionObject *connection_object);
 
 /** @brief returns the connection type of the supplied network connection parameter
  *
@@ -431,20 +444,22 @@ void RemoveFromActiveConnections(ConnectionObject *connection_object);
 ForwardOpenConnectionType GetConnectionType(
   EipUint16 network_connection_parameter);
 
-ForwardOpenPriority GetPriorityForQos(
-  EipUint16 network_connection_parameter);
+ForwardOpenPriority GetConnectionObjectTToOPriority(
+  const ConnectionObject *const connection_object);
 
 ProductionTrigger GetProductionTrigger(
   const ConnectionObject *const connection_object);
 
-void SetProductionTrigger(const ProductionTrigger production_trigger,
-                          ConnectionObject *connection_object);
+void SetProductionTrigger(
+  const ProductionTrigger production_trigger,
+  ConnectionObject *connection_object);
 
 CipUint GetProductionInhibitTime(
   const ConnectionObject *const connection_object);
 
-void SetProductionInhibitTime(const EipUint16 production_inhibit_time,
-                              ConnectionObject *const connection_object);
+void SetProductionInhibitTime(
+  const EipUint16 production_inhibit_time,
+  ConnectionObject *const connection_object);
 
 CipUdint GetTargetToOriginatorRequestedPackedInterval(
   const ConnectionObject *const RESTRICT connection_object);

+ 64 - 41
source/src/cip/cipioconnection.c

@@ -67,14 +67,17 @@ EipStatus OpenProducingPointToPointConnection(
   ConnectionObject *connection_object,
   CipCommonPacketFormatData *common_packet_format_data);
 
-EipUint16 HandleConfigData(ConnectionObject *connection_object);
+EipUint16 HandleConfigData(
+  ConnectionObject *connection_object);
 
 /* Regularly close the IO connection. If it is an exclusive owner or input only
  * connection and in charge of the connection a new owner will be searched
  */
-void CloseIoConnection(ConnectionObject *connection_object);
+void CloseIoConnection(
+  ConnectionObject *connection_object);
 
-void HandleIoConnectionTimeOut(ConnectionObject *connection_object);
+void HandleIoConnectionTimeOut(
+  ConnectionObject *connection_object);
 
 /** @brief  Send the data from the produced CIP Object of the connection via the socket of the connection object
  *   on UDP.
@@ -82,11 +85,13 @@ void HandleIoConnectionTimeOut(ConnectionObject *connection_object);
  *      @return status  EIP_OK .. success
  *                     EIP_ERROR .. error
  */
-EipStatus SendConnectedData(ConnectionObject *connection_object);
+EipStatus SendConnectedData(
+  ConnectionObject *connection_object);
 
-EipStatus HandleReceivedIoConnectionData(ConnectionObject *connection_object,
-                                         const EipUint8 *data,
-                                         EipUint16 data_length);
+EipStatus HandleReceivedIoConnectionData(
+  ConnectionObject *connection_object,
+  const EipUint8 *data,
+  EipUint16 data_length);
 
 /**** Global variables ****/
 EipUint8 *g_config_data_buffer = NULL; /**< buffers for the config data coming with a forward open request. */
@@ -94,8 +99,9 @@ unsigned int g_config_data_length = 0; /**< length of g_config_data_buffer. Init
 
 EipUint32 g_run_idle_state; /**< buffer for holding the run idle information. */
 
-EipUint16 ProcessProductionInhibitTime(ConnectionObject *io_connection_object)
-{
+EipUint16 ProcessProductionInhibitTime(
+  ConnectionObject *io_connection_object
+  ) {
   if ( kProductionTriggerCyclic
        == GetProductionTrigger(io_connection_object) ) {
     if ( 256 == GetProductionInhibitTime(io_connection_object) ) {
@@ -118,7 +124,8 @@ EipUint16 ProcessProductionInhibitTime(ConnectionObject *io_connection_object)
 }
 
 CipConnectionObjectTransportClassTriggerClass GetConnectionTransportClass(
-  const ConnectionObject *const connection_object) {
+  const ConnectionObject *const connection_object
+  ) {
   const unsigned int kTransportClassMask = 0x0F;
 
   switch(connection_object->transport_type_class_trigger &
@@ -134,7 +141,9 @@ CipConnectionObjectTransportClassTriggerClass GetConnectionTransportClass(
   return kCipConnectionObjectTransportClassTriggerClassInvalid;
 }
 
-void SetIoConnectionCallbacks(ConnectionObject *const io_connection_object) {
+void SetIoConnectionCallbacks(
+  ConnectionObject *const io_connection_object
+  ) {
   io_connection_object->connection_close_function = CloseIoConnection;
   io_connection_object->connection_timeout_function = HandleIoConnectionTimeOut;
   io_connection_object->connection_send_data_function = SendConnectedData;
@@ -144,8 +153,8 @@ void SetIoConnectionCallbacks(ConnectionObject *const io_connection_object) {
 
 EipUint16 SetupIoConnectionOriginatorToTargetConnectionPoint(
   ConnectionObject *const io_connection_object,
-  ConnectionObject *const RESTRICT connection_object)
-{
+  ConnectionObject *const RESTRICT connection_object
+  ) {
   CipClass *const assembly_class = GetCipClass(kCipAssemblyClassCode);
   CipInstance *instance = NULL;
   if ( NULL
@@ -198,8 +207,8 @@ EipUint16 SetupIoConnectionOriginatorToTargetConnectionPoint(
 
 EipUint16 SetupIoConnectionTargetToOriginatorConnectionPoint(
   ConnectionObject *const io_connection_object,
-  ConnectionObject *const RESTRICT connection_object)
-{
+  ConnectionObject *const RESTRICT connection_object
+  ) {
   ConnectionObject *iterator = g_active_connection_list;
   while (NULL != iterator) {
     if(io_connection_object->connection_path.connection_point[
@@ -217,6 +226,11 @@ EipUint16 SetupIoConnectionTargetToOriginatorConnectionPoint(
         return
           kConnectionManagerExtendedStatusCodeMismatchedTToONetworkConnectionFixVar;
       }
+      if ( GetConnectionObjectTToOPriority(io_connection_object) !=
+           GetConnectionObjectTToOPriority(iterator) ) {
+        return
+          kConnectionManagerExtendedStatusCodeMismatchedTToONetworkConnectionPriority;
+      }
 
     }
 
@@ -284,8 +298,8 @@ EipUint16 SetupIoConnectionTargetToOriginatorConnectionPoint(
  */
 EipStatus EstablishIoConnection(
   ConnectionObject *RESTRICT const connection_object,
-  EipUint16 *const extended_error)
-{
+  EipUint16 *const extended_error
+  ) {
   EipStatus eip_status = kEipStatusOk;
 
   ConnectionObject *io_connection_object = GetIoConnectionForConnectionData(
@@ -377,8 +391,8 @@ EipStatus EstablishIoConnection(
  */
 EipStatus OpenConsumingPointToPointConnection(
   ConnectionObject *const connection_object,
-  CipCommonPacketFormatData *const common_packet_format_data)
-{
+  CipCommonPacketFormatData *const common_packet_format_data
+  ) {
   /*static EIP_UINT16 nUDPPort = 2222; TODO think on improving the udp port assigment for point to point connections */
   int j = 0;
 
@@ -392,8 +406,7 @@ EipStatus OpenConsumingPointToPointConnection(
   { .sin_family = PF_INET, .sin_addr.s_addr = INADDR_ANY, .sin_port = htons(
       kOpenerEipIoUdpPort) };
 
-  CipUsint qos_for_socket = GetPriorityForQos (
-    connection_object->t_to_o_network_connection_parameter);
+  CipUsint qos_for_socket = GetConnectionObjectTToOPriority (connection_object);
   int socket = CreateUdpSocket(kUdpCommuncationDirectionConsuming,
                                &addr,
                                qos_for_socket);                                            /* the address is only needed for bind used if consuming */
@@ -423,8 +436,8 @@ EipStatus OpenConsumingPointToPointConnection(
 
 EipStatus OpenProducingPointToPointConnection(
   ConnectionObject *connection_object,
-  CipCommonPacketFormatData *common_packet_format_data)
-{
+  CipCommonPacketFormatData *common_packet_format_data
+  ) {
   in_port_t port = htons(kOpenerEipIoUdpPort); /* the default port to be used if no port information is part of the forward open request */
 
   if (kCipItemIdSocketAddressInfoTargetToOriginator
@@ -441,8 +454,7 @@ EipStatus OpenProducingPointToPointConnection(
   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_port = port;
 
-  CipUsint qos_for_socket = GetPriorityForQos (
-    connection_object->t_to_o_network_connection_parameter);
+  CipUsint qos_for_socket = GetConnectionObjectTToOPriority(connection_object);
   int socket = CreateUdpSocket(kUdpCommuncationDirectionProducing,
                                &connection_object->remote_address,
                                qos_for_socket);                                     /* the address is only needed for bind used if consuming */
@@ -459,8 +471,8 @@ EipStatus OpenProducingPointToPointConnection(
 
 EipStatus OpenProducingMulticastConnection(
   ConnectionObject *connection_object,
-  CipCommonPacketFormatData *common_packet_format_data)
-{
+  CipCommonPacketFormatData *common_packet_format_data
+  ) {
   ConnectionObject *existing_connection_object =
     GetExistingProducerMulticastConnection(
       connection_object->connection_path.connection_point[1]);
@@ -530,8 +542,8 @@ EipStatus OpenProducingMulticastConnection(
 EipStatus OpenMulticastConnection(
   UdpCommuncationDirection direction,
   ConnectionObject *connection_object,
-  CipCommonPacketFormatData *common_packet_format_data)
-{
+  CipCommonPacketFormatData *common_packet_format_data
+  ) {
   int j = -1;
 
   int address_info_item_which_contains_o_to_t = -1;
@@ -607,8 +619,7 @@ EipStatus OpenMulticastConnection(
   socket_address.sin_port = common_packet_format_data->address_info_item[j]
                             .sin_port;
 
-  CipUsint qos_for_socket = GetPriorityForQos (
-    connection_object->t_to_o_network_connection_parameter);
+  CipUsint qos_for_socket = GetConnectionObjectTToOPriority(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");
@@ -629,7 +640,9 @@ EipStatus OpenMulticastConnection(
   return kEipStatusOk;
 }
 
-EipUint16 HandleConfigData(ConnectionObject *connection_object) {
+EipUint16 HandleConfigData(
+  ConnectionObject *connection_object
+  ) {
 
   CipClass *const assembly_class = GetCipClass(kCipAssemblyClassCode);
   EipUint16 connection_manager_status = 0;
@@ -676,7 +689,9 @@ EipUint16 HandleConfigData(ConnectionObject *connection_object) {
   return connection_manager_status;
 }
 
-void CloseIoConnection(ConnectionObject *connection_object) {
+void CloseIoConnection(
+  ConnectionObject *connection_object
+  ) {
 
   CheckIoConnectionEvent(connection_object->connection_path.connection_point[
                            kConnectionPointConsumer],
@@ -725,7 +740,9 @@ void CloseIoConnection(ConnectionObject *connection_object) {
     connection_object);
 }
 
-void HandleIoConnectionTimeOut(ConnectionObject *connection_object) {
+void HandleIoConnectionTimeOut(
+  ConnectionObject *connection_object
+  ) {
   CheckIoConnectionEvent(connection_object->connection_path.connection_point[0],
                          connection_object->connection_path.connection_point[1],
                          kIoConnectionEventTimedOut);
@@ -772,7 +789,9 @@ void HandleIoConnectionTimeOut(ConnectionObject *connection_object) {
   connection_object->connection_close_function(connection_object);
 }
 
-EipStatus SendConnectedData(ConnectionObject *connection_object) {
+EipStatus SendConnectedData(
+  ConnectionObject *connection_object
+  ) {
 
   /* TODO think of adding an own send buffer to each connection object in order to preset up the whole message on connection opening and just change the variable data items e.g., sequence number */
 
@@ -851,10 +870,11 @@ EipStatus SendConnectedData(ConnectionObject *connection_object) {
            &g_message_data_reply_buffer[0], reply_length);
 }
 
-EipStatus HandleReceivedIoConnectionData(ConnectionObject *connection_object,
-                                         const EipUint8 *data,
-                                         EipUint16 data_length)
-{
+EipStatus HandleReceivedIoConnectionData(
+  ConnectionObject *connection_object,
+  const EipUint8 *data,
+  EipUint16 data_length
+  ) {
 
   /* check class 1 sequence number*/
   if ( (connection_object->transport_type_class_trigger & 0x0F) == 1 ) {
@@ -887,7 +907,9 @@ EipStatus HandleReceivedIoConnectionData(ConnectionObject *connection_object,
   return kEipStatusOk;
 }
 
-EipStatus OpenCommunicationChannels(ConnectionObject *connection_object) {
+EipStatus OpenCommunicationChannels(
+  ConnectionObject *connection_object
+  ) {
 
   EipStatus eip_status = kEipStatusOk;
   /*get pointer to the CPF data, currently we have just one global instance of the struct. This may change in the future*/
@@ -949,7 +971,8 @@ EipStatus OpenCommunicationChannels(ConnectionObject *connection_object) {
 }
 
 void CloseCommunicationChannelsAndRemoveFromActiveConnectionsList(
-  ConnectionObject *connection_object) {
+  ConnectionObject *connection_object
+  ) {
   IApp_CloseSocket_udp(
     connection_object->socket[kUdpCommuncationDirectionConsuming]);
 

+ 1 - 1
source/src/ports/POSIX/networkhandler.c

@@ -47,5 +47,5 @@ void SetQosOnSocket(int socket,
                     CipUsint qos_value) {
 
   int set_tos = qos_value;
-  setsockopt( socket, IPPROTO_IP, IP_TOS, &set_tos, sizeof(set_tos) );
+  setsockopt(socket, IPPROTO_IP, IP_TOS, &set_tos, sizeof(set_tos));
 }

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

@@ -48,5 +48,5 @@ int SetSocketToNonBlocking(int socket_handle) {
 void SetQosOnSocket(int socket,
                     CipUsint qos_value) {
   CipUsint set_tos = qos_value;
-  setsockopt( socket, IPPROTO_IP, IP_TOS, &set_tos, sizeof(set_tos) );
+  setsockopt(socket, IPPROTO_IP, IP_TOS, &set_tos, sizeof(set_tos));
 }

+ 0 - 1
uncrustify.cfg

@@ -133,4 +133,3 @@ mod_full_brace_for=add
 mod_full_brace_function=add
 mod_full_brace_if=add
 mod_full_brace_while=add
-