OpENer - Open Source EtherNet/IP(TM) I/O Target Stack  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cipioconnection.c File Reference
#include <string.h>
#include <stdbool.h>
#include "cipioconnection.h"
#include "generic_networkhandler.h"
#include "cipconnectionmanager.h"
#include "cipassembly.h"
#include "cipidentity.h"
#include "ciptcpipinterface.h"
#include "cipcommon.h"
#include "appcontype.h"
#include "cpf.h"
#include "trace.h"
#include "endianconv.h"
Include dependency graph for cipioconnection.c:

Go to the source code of this file.

Functions

void CloseCommunicationChannelsAndRemoveFromActiveConnectionsList (CipConnectionObject *connection_object)
 close the communication channels of the given connection and remove it from the active connections list. More...
 
void CloseIoConnection (CipConnectionObject *connection_object)
 
EipStatus EstablishIoConnection (CipConnectionObject *RESTRICT const connection_object, EipUint16 *const extended_error)
 Establishes a new IO Type 1 Connection. More...
 
EipUint16 HandleConfigData (CipConnectionObject *connection_object)
 
void HandleIoConnectionTimeOut (CipConnectionObject *connection_object)
 
EipStatus HandleReceivedIoConnectionData (CipConnectionObject *connection_object, const EipUint8 *data, EipUint16 data_length)
 
EipStatus OpenCommunicationChannels (CipConnectionObject *connection_object)
 Take the data given in the connection object structure and open the necessary communication channels. More...
 
EipStatus OpenConsumingPointToPointConnection (CipConnectionObject *const connection_object, CipCommonPacketFormatData *const common_packet_format_data)
 Open a Point2Point connection dependent on pa_direction. More...
 
EipStatus OpenMulticastConnection (UdpCommuncationDirection direction, CipConnectionObject *connection_object, CipCommonPacketFormatData *common_packet_format_data)
 Open a Multicast connection dependent on direction. More...
 
EipStatus OpenProducingMulticastConnection (CipConnectionObject *connection_object, CipCommonPacketFormatData *common_packet_format_data)
 
EipStatus OpenProducingPointToPointConnection (CipConnectionObject *connection_object, CipCommonPacketFormatData *common_packet_format_data)
 
EipUint16 ProcessProductionInhibitTime (CipConnectionObject *io_connection_object)
 
EipStatus SendConnectedData (CipConnectionObject *connection_object)
 Send the data from the produced CIP Object of the connection via the socket of the connection object on UDP. More...
 
void SetIoConnectionCallbacks (CipConnectionObject *const io_connection_object)
 
EipUint16 SetupIoConnectionOriginatorToTargetConnectionPoint (CipConnectionObject *const io_connection_object, CipConnectionObject *const RESTRICT connection_object)
 
EipUint16 SetupIoConnectionTargetToOriginatorConnectionPoint (CipConnectionObject *const io_connection_object, CipConnectionObject *const RESTRICT connection_object)
 

Variables

EipUint8g_config_data_buffer = NULL
 
unsigned int g_config_data_length = 0
 
EipUint32 g_run_idle_state = 0
 
const int kOpenerEipIoUdpPort = 0x08AE
 

Function Documentation

void CloseCommunicationChannelsAndRemoveFromActiveConnectionsList ( CipConnectionObject connection_object)

close the communication channels of the given connection and remove it from the active connections list.

Parameters
connection_objectpointer to the connection object data

Definition at line 976 of file cipioconnection.c.

References CloseUdpSocket(), ConnectionObjectInitializeEmpty(), kUdpCommuncationDirectionConsuming, kUdpCommuncationDirectionProducing, RemoveFromActiveConnections(), and cip_connection_object::socket.

Referenced by CloseIoConnection().

Here is the call graph for this function:

Here is the caller graph for this function:

EipStatus EstablishIoConnection ( CipConnectionObject *RESTRICT const  connection_object,
EipUint16 *const  extended_error 
)

Establishes a new IO Type 1 Connection.

Setup all data in order to establish an IO connection.

This function needs the guarantee that no Null request will be passed to it. It will generate a new IO connection based on the data parsed in the Forward Open service

Parameters
connection_objectpointer to the connection object structure holding the parsed data from the forward open request
extended_errorthe extended error code in case an error happened
Returns
general status on the establishment
  • kEipStatusOk ... on success
  • On an error the general status code to be put into the response

Already handled by forward open

Definition at line 275 of file cipioconnection.c.

References AddNewActiveConnection(), CheckIoConnectionEvent(), ConnectionObjectGeneralConfiguration(), ConnectionObjectGetOToTConnectionType(), ConnectionObjectGetTToOConnectionType(), cip_connection_object::consumed_connection_path_length, cip_connection_object::consumed_path, cip_connection_object::consuming_instance, g_config_data_buffer, GetIoConnectionForConnectionData(), HandleConfigData(), connection_path_epath::instance_id, kCipErrorConnectionFailure, kConnectionManagerExtendedStatusCodeSuccess, kConnectionObjectConnectionTypeNull, kEipStatusOk, kIoConnectionEventOpened, OpenCommunicationChannels(), OPENER_ASSERT, ProcessProductionInhibitTime(), cip_connection_object::produced_connection_path_length, cip_connection_object::produced_path, cip_connection_object::producing_instance, SetIoConnectionCallbacks(), SetupIoConnectionOriginatorToTargetConnectionPoint(), and SetupIoConnectionTargetToOriginatorConnectionPoint().

Referenced by ConnectionManagerInit().

Here is the call graph for this function:

Here is the caller graph for this function:

EipUint16 HandleConfigData ( CipConnectionObject connection_object)

Definition at line 622 of file cipioconnection.c.

References cip_connection_object::configuration_path, ConnectionWithSameConfigPointExists(), CipByteArray::data, CipAttributeStruct::data, g_config_data_buffer, g_config_data_length, GetCipAttribute(), GetCipClass(), GetCipInstance(), connection_path_epath::instance_id, kConnectionManagerExtendedStatusCodeErrorOwnershipConflict, kConnectionManagerExtendedStatusCodeInvalidConfigurationApplicationPath, kEipStatusOk, CipByteArray::length, NotifyAssemblyConnectedDataReceived(), OPENER_ASSERT, OPENER_TRACE_INFO, and OPENER_TRACE_WARN.

Referenced by EstablishIoConnection().

Here is the call graph for this function:

Here is the caller graph for this function:

EipStatus HandleReceivedIoConnectionData ( CipConnectionObject connection_object,
const EipUint8 data,
EipUint16  data_length 
)

Definition at line 867 of file cipioconnection.c.

References CipIdentitySetExtendedDeviceStatus(), ConnectionObjectGetTransportClassTriggerTransportClass(), cip_connection_object::consuming_instance, g_run_idle_state, GetDintFromMessage(), GetIntFromMessage(), kAtLeastOneIoConnectionEstablishedAllInIdleMode, kAtLeastOneIoConnectionInRunMode, kConnectionObjectTransportClassTriggerTransportClass1, kEipStatusError, kEipStatusOk, NotifyAssemblyConnectedDataReceived(), OPENER_TRACE_INFO, RunIdleChanged(), SEQ_LEQ16, and cip_connection_object::sequence_count_consuming.

Referenced by SetIoConnectionCallbacks().

Here is the call graph for this function:

Here is the caller graph for this function:

EipStatus OpenCommunicationChannels ( CipConnectionObject connection_object)

Take the data given in the connection object structure and open the necessary communication channels.

This function will use the g_stCPFDataItem!

Parameters
connection_objectpointer to the connection object data
Returns
general status on the open process
  • EIP_OK ... on success
  • On an error the general status code to be put into the response

Definition at line 919 of file cipioconnection.c.

References ConnectionObjectGetOToTConnectionType(), ConnectionObjectGetTToOConnectionType(), g_common_packet_format_data_item, kCipErrorConnectionFailure, kConnectionObjectConnectionTypeMulticast, kConnectionObjectConnectionTypePointToPoint, kEipStatusError, kEipStatusOk, kUdpCommuncationDirectionConsuming, OpenConsumingPointToPointConnection(), OPENER_TRACE_ERR, OpenMulticastConnection(), OpenProducingMulticastConnection(), and OpenProducingPointToPointConnection().

Referenced by EstablishIoConnection().

Here is the call graph for this function:

Here is the caller graph for this function:

EipStatus OpenConsumingPointToPointConnection ( CipConnectionObject *const  connection_object,
CipCommonPacketFormatData *const  common_packet_format_data 
)

Open a Point2Point connection dependent on pa_direction.

Parameters
connection_objectPointer to registered Object in ConnectionManager.
common_packet_format_dataIndex of the connection object
Returns
kEipStatusOk on success, otherwise kEipStatusError

Definition at line 366 of file cipioconnection.c.

References CipCommonPacketFormatData::address_info_item, ConnectionObjectGetTToOPriority(), CreateUdpSocket(), kCipItemIdSocketAddressInfoOriginatorToTarget, kEipStatusError, kEipStatusOk, kOpenerEipIoUdpPort, kUdpCommuncationDirectionConsuming, SocketAddressInfoItem::length, SocketAddressInfoItem::nasin_zero, OPENER_TRACE_ERR, cip_connection_object::originator_address, SocketAddressInfoItem::sin_addr, SocketAddressInfoItem::sin_family, SocketAddressInfoItem::sin_port, cip_connection_object::socket, and SocketAddressInfoItem::type_id.

Referenced by OpenCommunicationChannels().

Here is the call graph for this function:

Here is the caller graph for this function:

EipStatus OpenMulticastConnection ( UdpCommuncationDirection  direction,
CipConnectionObject connection_object,
CipCommonPacketFormatData common_packet_format_data 
)

Open a Multicast connection dependent on direction.

Parameters
directionFlag to indicate if consuming or producing.
connection_objectPointer to registered Object in ConnectionManager.
common_packet_format_dataReceived CPF Data Item.
Returns
kEipStatusOk on success, otherwise kEipStatusError

Definition at line 523 of file cipioconnection.c.

References CipCommonPacketFormatData::address_info_item, ConnectionObjectGetTToOPriority(), CreateUdpSocket(), g_multicast_configuration, kCipItemIdSocketAddressInfoOriginatorToTarget, kCipItemIdSocketAddressInfoTargetToOriginator, kEipStatusError, kEipStatusOk, kOpenerEipIoUdpPort, kUdpCommuncationDirectionConsuming, kUdpCommuncationDirectionProducing, SocketAddressInfoItem::length, SocketAddressInfoItem::nasin_zero, OPENER_TRACE_ERR, OPENER_TRACE_INFO, cip_connection_object::originator_address, cip_connection_object::remote_address, SocketAddressInfoItem::sin_addr, SocketAddressInfoItem::sin_family, SocketAddressInfoItem::sin_port, cip_connection_object::socket, multicast_address_configuration::starting_multicast_address, and SocketAddressInfoItem::type_id.

Referenced by OpenCommunicationChannels(), and OpenProducingMulticastConnection().

Here is the call graph for this function:

Here is the caller graph for this function:

EipStatus OpenProducingPointToPointConnection ( CipConnectionObject connection_object,
CipCommonPacketFormatData common_packet_format_data 
)

Definition at line 411 of file cipioconnection.c.

References CipCommonPacketFormatData::address_info_item, ConnectionObjectGetTToOPriority(), CreateUdpSocket(), kCipErrorConnectionFailure, kCipItemIdSocketAddressInfoTargetToOriginator, kEipStatusOk, kOpenerEipIoUdpPort, kUdpCommuncationDirectionProducing, OPENER_TRACE_ERR, cip_connection_object::remote_address, SocketAddressInfoItem::sin_port, cip_connection_object::socket, and SocketAddressInfoItem::type_id.

Referenced by OpenCommunicationChannels().

Here is the call graph for this function:

Here is the caller graph for this function:

EipUint16 ProcessProductionInhibitTime ( CipConnectionObject io_connection_object)

< RPI not supported. Extended Error code deprecated

Definition at line 75 of file cipioconnection.c.

References ConnectionObjectGetProductionInhibitTime(), ConnectionObjectGetTransportClassTriggerProductionTrigger(), ConnectionObjectGetTToORequestedPacketInterval(), ConnectionObjectSetProductionInhibitTime(), kConnectionManagerExtendedStatusCodeRpiNotSupported, kConnectionManagerExtendedStatusCodeSuccess, kConnectionObjectTransportClassTriggerProductionTriggerCyclic, and OPENER_TRACE_INFO.

Referenced by EstablishIoConnection().

Here is the call graph for this function:

Here is the caller graph for this function:

EipStatus SendConnectedData ( CipConnectionObject connection_object)

Send the data from the produced CIP Object of the connection via the socket of the connection object on UDP.

Parameters
connection_objectpointer to the connection object
Returns
status EIP_OK .. success EIP_ERROR .. error

Definition at line 778 of file cipioconnection.c.

References AddDintToMessage(), AddIntToMessage(), CipCommonPacketFormatData::address_info_item, CipCommonPacketFormatData::address_item, AssembleIOMessage(), cip_instance::attributes, BeforeAssemblyDataSend(), cip_connection_object::cip_produced_connection_id, AddressData::connection_identifier, ConnectionObjectGetTransportClassTriggerTransportClass(), enip_message::current_message_position, AddressItem::data, CipByteArray::data, CipAttributeStruct::data, CipCommonPacketFormatData::data_item, cip_connection_object::eip_level_sequence_count_producing, g_common_packet_format_data_item, g_run_idle_state, InitializeENIPMessage(), CipCommonPacketFormatData::item_count, kCipItemIdConnectedDataItem, kCipItemIdConnectionAddress, kCipItemIdSequencedAddressItem, kConnectionObjectTransportClassTriggerTransportClass0, kConnectionObjectTransportClassTriggerTransportClass1, kUdpCommuncationDirectionProducing, AddressItem::length, DataItem::length, CipByteArray::length, enip_message::message_buffer, cip_connection_object::producing_instance, cip_connection_object::remote_address, SendUdpData(), cip_connection_object::sequence_count_producing, AddressData::sequence_number, cip_connection_object::socket, AddressItem::type_id, DataItem::type_id, SocketAddressInfoItem::type_id, and enip_message::used_message_length.

Referenced by SetIoConnectionCallbacks().

Here is the call graph for this function:

Here is the caller graph for this function:

void SetIoConnectionCallbacks ( CipConnectionObject *const  io_connection_object)

Definition at line 102 of file cipioconnection.c.

References CloseIoConnection(), cip_connection_object::connection_close_function, cip_connection_object::connection_receive_data_function, cip_connection_object::connection_send_data_function, cip_connection_object::connection_timeout_function, HandleIoConnectionTimeOut(), HandleReceivedIoConnectionData(), and SendConnectedData().

Referenced by EstablishIoConnection().

Here is the call graph for this function:

Here is the caller graph for this function:

EipUint16 SetupIoConnectionOriginatorToTargetConnectionPoint ( CipConnectionObject *const  io_connection_object,
CipConnectionObject *const RESTRICT  connection_object 
)
EipUint16 SetupIoConnectionTargetToOriginatorConnectionPoint ( CipConnectionObject *const  io_connection_object,
CipConnectionObject *const RESTRICT  connection_object 
)

Definition at line 164 of file cipioconnection.c.

References connection_path_epath::attribute_id_or_connection_point, connection_list, ConnectionObjectGetProductionInhibitTime(), ConnectionObjectGetTransportClassTriggerProductionTrigger(), ConnectionObjectGetTransportClassTriggerTransportClass(), ConnectionObjectGetTToOConnectionSize(), ConnectionObjectGetTToOConnectionSizeType(), ConnectionObjectGetTToOConnectionType(), ConnectionObjectGetTToOPriority(), ConnectionObjectGetTToORequestedPacketInterval(), doubly_linked_list_node::data, CipAttributeStruct::data, DoublyLinkedList::first, GetCipAttribute(), GetCipClass(), GetCipInstance(), connection_path_epath::instance_id, kConnectionManagerExtendedStatusCodeErrorInvalidTToOConnectionSize, kConnectionManagerExtendedStatusCodeErrorRpiValuesNotAcceptable, kConnectionManagerExtendedStatusCodeInvalidProducingApplicationPath, kConnectionManagerExtendedStatusCodeMismatchedTransportClass, kConnectionManagerExtendedStatusCodeMismatchedTToONetworkConnectionFixVar, kConnectionManagerExtendedStatusCodeMismatchedTToONetworkConnectionPriority, kConnectionManagerExtendedStatusCodeMismatchedTToOProductionInhibitTimeSegment, kConnectionManagerExtendedStatusCodeMismatchedTToOProductionTrigger, kConnectionManagerExtendedStatusCodeSuccess, kConnectionObjectConnectionTypeMulticast, kConnectionObjectTransportClassTriggerTransportClass1, doubly_linked_list_node::next, OPENER_ASSERT, cip_connection_object::produced_path, and cip_connection_object::producing_instance.

Referenced by EstablishIoConnection().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

EipUint8* g_config_data_buffer = NULL

buffers for the config data coming with a forward open request.

Definition at line 70 of file cipioconnection.c.

Referenced by EstablishIoConnection(), HandleConfigData(), and ParseConnectionPath().

unsigned int g_config_data_length = 0

length of g_config_data_buffer. Initialized with 0

Definition at line 71 of file cipioconnection.c.

Referenced by HandleConfigData(), and ParseConnectionPath().

EipUint32 g_run_idle_state = 0

buffer for holding the run idle information.

Definition at line 73 of file cipioconnection.c.

Referenced by HandleReceivedIoConnectionData(), and SendConnectedData().