OpENer - Open Source EtherNet/IP(TM) I/O Target Stack
2.1
|
#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"
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 | |
EipUint8 * | g_config_data_buffer = NULL |
unsigned int | g_config_data_length = 0 |
EipUint32 | g_run_idle_state = 0 |
const int | kOpenerEipIoUdpPort = 0x08AE |
void CloseCommunicationChannelsAndRemoveFromActiveConnectionsList | ( | CipConnectionObject * | connection_object | ) |
close the communication channels of the given connection and remove it from the active connections list.
connection_object | pointer 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().
void CloseIoConnection | ( | CipConnectionObject * | connection_object | ) |
Definition at line 673 of file cipioconnection.c.
References CheckIoConnectionEvent(), CloseAllConnectionsForInputWithSameType(), CloseCommunicationChannelsAndRemoveFromActiveConnectionsList(), ConnectionObjectGetInstanceType(), ConnectionObjectGetTToOConnectionType(), ConnectionObjectSetState(), cip_connection_object::consumed_path, cip_connection_object::eip_level_sequence_count_producing, GetNextNonControlMasterConnection(), connection_path_epath::instance_id, kConnectionObjectConnectionTypeMulticast, kConnectionObjectInstanceTypeIOExclusiveOwner, kConnectionObjectInstanceTypeIOInputOnly, kConnectionObjectInstanceTypeIOListenOnly, kConnectionObjectStateNonExistent, kIoConnectionEventClosed, kUdpCommuncationDirectionProducing, OPENER_TRACE_INFO, cip_connection_object::produced_path, cip_connection_object::remote_address, cip_connection_object::sequence_count_producing, cip_connection_object::socket, and cip_connection_object::transmission_trigger_timer.
Referenced by SetIoConnectionCallbacks().
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
connection_object | pointer to the connection object structure holding the parsed data from the forward open request |
extended_error | the extended error code in case an error happened |
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().
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().
void HandleIoConnectionTimeOut | ( | CipConnectionObject * | connection_object | ) |
Definition at line 726 of file cipioconnection.c.
References CheckForTimedOutConnectionsAndCloseTCPConnections(), CheckIoConnectionEvent(), CloseAllConnectionsForInputWithSameType(), CloseEncapsulationSessionBySockAddr(), ConnectionObjectGetInstanceType(), ConnectionObjectGetTToOConnectionType(), ConnectionObjectSetState(), cip_connection_object::consumed_path, GetNextNonControlMasterConnection(), cip_connection_object::inactivity_watchdog_timer, connection_path_epath::instance_id, kConnectionObjectConnectionTypeMulticast, kConnectionObjectInstanceTypeIOExclusiveOwner, kConnectionObjectInstanceTypeIOInputOnly, kConnectionObjectInstanceTypeIOListenOnly, kConnectionObjectStateTimedOut, kIoConnectionEventTimedOut, kUdpCommuncationDirectionProducing, cip_connection_object::last_package_watchdog_timer, cip_connection_object::produced_path, cip_connection_object::socket, and cip_connection_object::transmission_trigger_timer.
Referenced by SetIoConnectionCallbacks().
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().
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!
connection_object | pointer to the connection object data |
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().
EipStatus OpenConsumingPointToPointConnection | ( | CipConnectionObject *const | connection_object, |
CipCommonPacketFormatData *const | common_packet_format_data | ||
) |
Open a Point2Point connection dependent on pa_direction.
connection_object | Pointer to registered Object in ConnectionManager. |
common_packet_format_data | Index of the connection object |
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().
EipStatus OpenMulticastConnection | ( | UdpCommuncationDirection | direction, |
CipConnectionObject * | connection_object, | ||
CipCommonPacketFormatData * | common_packet_format_data | ||
) |
Open a Multicast connection dependent on direction
.
direction | Flag to indicate if consuming or producing. |
connection_object | Pointer to registered Object in ConnectionManager. |
common_packet_format_data | Received CPF Data Item. |
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().
EipStatus OpenProducingMulticastConnection | ( | CipConnectionObject * | connection_object, |
CipCommonPacketFormatData * | common_packet_format_data | ||
) |
Definition at line 446 of file cipioconnection.c.
References CipCommonPacketFormatData::address_info_item, cip_connection_object::cip_produced_connection_id, g_common_packet_format_data_item, g_multicast_configuration, GetExistingProducerMulticastConnection(), connection_path_epath::instance_id, cip_connection_object::instance_type, kCipItemIdSocketAddressInfoTargetToOriginator, kConnectionObjectInstanceTypeIOExclusiveOwner, kEipStatusOk, kOpenerEipIoUdpPort, kUdpCommuncationDirectionProducing, SocketAddressInfoItem::length, SocketAddressInfoItem::nasin_zero, OpenMulticastConnection(), cip_connection_object::produced_path, cip_connection_object::remote_address, SocketAddressInfoItem::sin_family, SocketAddressInfoItem::sin_port, cip_connection_object::socket, and SocketAddressInfoItem::type_id.
Referenced by OpenCommunicationChannels().
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().
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().
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.
connection_object | pointer to the connection object |
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().
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().
EipUint16 SetupIoConnectionOriginatorToTargetConnectionPoint | ( | CipConnectionObject *const | io_connection_object, |
CipConnectionObject *const RESTRICT | connection_object | ||
) |
Definition at line 110 of file cipioconnection.c.
References connection_path_epath::attribute_id_or_connection_point, ConnectionObjectGetOToTConnectionSize(), ConnectionObjectGetTransportClassTriggerTransportClass(), cip_connection_object::consumed_connection_path_length, cip_connection_object::consumed_path, cip_connection_object::consuming_instance, CipAttributeStruct::data, GetCipAttribute(), GetCipClass(), GetCipInstance(), connection_path_epath::instance_id, kConnectionManagerExtendedStatusCodeErrorInvalidOToTConnectionSize, kConnectionManagerExtendedStatusCodeInvalidConsumingApplicationPath, kConnectionManagerExtendedStatusCodeSuccess, kConnectionObjectTransportClassTriggerTransportClass1, and OPENER_ASSERT.
Referenced by EstablishIoConnection().
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().
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().
const int kOpenerEipIoUdpPort = 0x08AE |
Definition at line 25 of file cipioconnection.c.
Referenced by OpenConsumingPointToPointConnection(), OpenMulticastConnection(), OpenProducingMulticastConnection(), and OpenProducingPointToPointConnection().