OpENer - Open Source EtherNet/IP(TM) I/O Target Stack  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
OpENer Ethernet encapsulation layer

Enumerations

enum  CipItemId {
  kCipItemIdNullAddress = 0x0000, kCipItemIdListIdentityResponse = 0x000C, kCipItemIdConnectionAddress = 0x00A1, kCipItemIdConnectedDataItem = 0x00B1,
  kCipItemIdUnconnectedDataItem = 0x00B2, kCipItemIdListServiceResponse = 0x0100, kCipItemIdSocketAddressInfoOriginatorToTarget = 0x8000, kCipItemIdSocketAddressInfoTargetToOriginator = 0x8001,
  kCipItemIdSequencedAddressItem = 0x8002
}
 CPF is Common Packet Format CPF packet := <number of items> {<items>} item := <TypeID> <Length> <data> <number of items> := two bytes <TypeID> := two bytes <Length> := two bytes <data> := <the number of bytes specified by Length> More...
 

Functions

int AddDintToMessage (const EipUint32 data, EipUint8 **const buffer)
 Write an 32Bit integer to the network buffer. More...
 
int AddIntToMessage (const EipUint16 data, EipUint8 **const buffer)
 Write an 16Bit integer to the network buffer. More...
 
int AddSintToMessage (const EipUint8 data, EipUint8 **const buffer)
 converts UINT8 data from host to little endian an writes it to buffer. More...
 
int AssembleIOMessage (const CipCommonPacketFormatData *const common_packet_format_data_item, ENIPMessage *const message)
 
int AssembleLinearMessage (const CipMessageRouterResponse *const message_router_response, const CipCommonPacketFormatData *const common_packet_format_data_item, ENIPMessage *const outgoing_message)
 Copy data from message_router_response struct and common_packet_format_data_item into ENIPMessage struct outgoing_message via encapsulation. More...
 
EipStatus CreateCommonPacketFormatStructure (const EipUint8 *data, size_t data_length, CipCommonPacketFormatData *common_packet_format_data)
 Creates Common Packet Format structure out of data. More...
 
void EncapsulationInit (void)
 Initialize the encapsulation layer. More...
 
void EncapsulationShutDown (void)
 Shutdown the encapsulation layer. More...
 
EipUint32 GetDintFromMessage (const EipUint8 **const buffer)
 Get an 32Bit integer from the network buffer. More...
 
EipUint16 GetIntFromMessage (const EipUint8 **const buffer)
 Get an 16Bit integer from the network buffer, and moves pointer beyond the 16 bit value. More...
 
EipUint8 GetSintFromMessage (const EipUint8 **const buffer)
 Reads EIP_UINT8 from *buffer and converts little endian to host. More...
 
void ManageEncapsulationMessages (const MilliSeconds elapsed_time)
 Handle delayed encapsulation message responses. More...
 
int NotifyCommonPacketFormat (EncapsulationData *const received_data, const struct sockaddr *const originator_address, ENIPMessage *const outgoing_message)
 
int NotifyConnectedCommonPacketFormat (const EncapsulationData *const received_data, const struct sockaddr *const originator_address, ENIPMessage *const outgoing_message)
 

Variables

CipCommonPacketFormatData g_common_packet_format_data_item
 Data storage for the any CPF data Currently we are single threaded and need only one CPF at the time. For future extensions towards multithreading maybe more CPF data items may be necessary. More...
 

Detailed Description

The Ethernet encapsulation layer handles provides the abstraction between the Ethernet and the CIP layer.

Enumeration Type Documentation

enum CipItemId

CPF is Common Packet Format CPF packet := <number of items> {<items>} item := <TypeID> <Length> <data> <number of items> := two bytes <TypeID> := two bytes <Length> := two bytes <data> := <the number of bytes specified by Length>

Definition of Item ID numbers used for address and data items in CPF structures

Enumerator
kCipItemIdNullAddress 

Type: Address; Indicates that encapsulation routing is not needed.

kCipItemIdListIdentityResponse 
kCipItemIdConnectionAddress 

Type: Address; Connection-based, used for connected messages, see Vol.2, p.42

kCipItemIdConnectedDataItem 

Type: Data; Connected data item, see Vol.2, p.43

kCipItemIdUnconnectedDataItem 

Type: Data; Unconnected message

kCipItemIdListServiceResponse 
kCipItemIdSocketAddressInfoOriginatorToTarget 

Type: Data; Sockaddr info item originator to target

kCipItemIdSocketAddressInfoTargetToOriginator 

Type: Data; Sockaddr info item target to originator

kCipItemIdSequencedAddressItem 

Sequenced Address item

Definition at line 24 of file cpf.h.

Function Documentation

int AddDintToMessage ( const EipUint32  data,
EipUint8 **const  buffer 
)

Write an 32Bit integer to the network buffer.

Parameters
datavalue to write
bufferpointer to the network buffer array. This pointer will be incremented by 4!
Returns
Length in bytes of the encoded message

Write an 32Bit integer to the network buffer.

Parameters
datavalue to be written
bufferpointer where data should be written.

Definition at line 132 of file endianconv.c.

Referenced by AssembleForwardCloseResponse(), AssembleForwardOpenResponse(), AssembleLinearMessage(), CipEpathSetLogicalValue(), EncapsulateIpAddress(), EncapsulateListIdentityResponseMessage(), EncodeConnectedAddressItem(), EncodeData(), EncodeSequencedAddressItem(), GenerateEncapsulationHeader(), and SendConnectedData().

Here is the caller graph for this function:

int AddIntToMessage ( const EipUint16  data,
EipUint8 **const  buffer 
)

Write an 16Bit integer to the network buffer.

Parameters
datavalue to write
bufferpointer to the network buffer array. This pointer will be incremented by 2!
Returns
Length in bytes of the encoded message

Write an 16Bit integer to the network buffer.

Parameters
datavalue to be written
bufferpointer where data should be written.

Definition at line 117 of file endianconv.c.

Referenced by AssembleForwardCloseResponse(), AssembleForwardOpenResponse(), AssembleLinearMessage(), CipEpathSetLogicalValue(), EncapsulateIpAddress(), EncapsulateListIdentityResponseMessage(), EncapsulateRegisterSessionCommandResponseMessage(), EncodeConnectedAddressItem(), EncodeConnectedDataItemLength(), EncodeData(), EncodeDataItemLength(), EncodeDataItemType(), EncodeEPath(), EncodeExtendedStatusDataItems(), EncodeItemCount(), EncodeNullAddressItem(), EncodeSequencedAddressItem(), EncodeSequenceNumber(), EncodeSockaddrInfoItemTypeId(), EncodeSockaddrInfoLength(), EncodeUnconnectedDataItemLength(), GenerateEncapsulationHeader(), HandleReceivedListInterfacesCommand(), HandleReceivedListServicesCommand(), and SendConnectedData().

Here is the caller graph for this function:

int AddSintToMessage ( const EipUint8  data,
EipUint8 **const  buffer 
)

converts UINT8 data from host to little endian an writes it to buffer.

Parameters
datavalue to be written
bufferpointer where data should be written.

Definition at line 103 of file endianconv.c.

Referenced by CipEpathSetLogicalValue(), EncodeData(), EncodeDataItemData(), EncodeExtendedStatusLength(), EncodeGeneralStatus(), EncodeMessageRouterResponseData(), EncodeReplyService(), and EncodeReservedFieldOfLengthByte().

Here is the caller graph for this function:

int AssembleIOMessage ( const CipCommonPacketFormatData *const  common_packet_format_data_item,
ENIPMessage *const  message 
)

Copy data from CPFDataItem into linear memory in message for transmission over in encapsulation.

Parameters
common_packet_format_data_itempointer to CPF structure which has to be aligned into linear memory.
messageModified ENIP message struct
Returns
length of modification in bytes EIP_ERROR .. error

Definition at line 758 of file cpf.c.

References AssembleLinearMessage().

Referenced by SendConnectedData().

Here is the call graph for this function:

Here is the caller graph for this function:

int AssembleLinearMessage ( const CipMessageRouterResponse *const  message_router_response,
const CipCommonPacketFormatData *const  common_packet_format_data_item,
ENIPMessage *const  outgoing_message 
)

Copy data from message_router_response struct and common_packet_format_data_item into ENIPMessage struct outgoing_message via encapsulation.

Parameters
message_router_responsepointer to message router response which has to be aligned into linear memory.
common_packet_format_data_itempointer to CPF structure which has to be aligned into linear memory.
outgoing_messageModified ENIP message struct
Returns
length of modification in bytes kEipStatusError .. error

Definition at line 649 of file cpf.c.

References AddDintToMessage(), AddIntToMessage(), CipCommonPacketFormatData::address_info_item, CipCommonPacketFormatData::address_item, enip_message::current_message_position, CipCommonPacketFormatData::data_item, EncapsulateIpAddress(), EncodeConnectedAddressItem(), EncodeConnectedDataItemLength(), EncodeDataItemData(), EncodeDataItemLength(), EncodeDataItemType(), EncodeExtendedStatus(), EncodeGeneralStatus(), EncodeItemCount(), EncodeMessageRouterResponseData(), EncodeNullAddressItem(), EncodeReplyService(), EncodeReservedFieldOfLengthByte(), EncodeSequencedAddressItem(), EncodeSequenceNumber(), EncodeSockaddrInfoItemTypeId(), EncodeSockaddrInfoLength(), EncodeUnconnectedDataItemLength(), FillNextNMessageOctetsWithValueAndMoveToNextPosition(), kCipItemIdConnectedDataItem, kCipItemIdConnectionAddress, kCipItemIdNullAddress, kCipItemIdSequencedAddressItem, kCipItemIdSocketAddressInfoOriginatorToTarget, kCipItemIdSocketAddressInfoTargetToOriginator, kCipItemIdUnconnectedDataItem, kEipStatusError, OPENER_TRACE_INFO, SocketAddressInfoItem::sin_addr, SocketAddressInfoItem::sin_port, AddressItem::type_id, DataItem::type_id, SocketAddressInfoItem::type_id, and enip_message::used_message_length.

Referenced by AssembleIOMessage(), NotifyCommonPacketFormat(), and NotifyConnectedCommonPacketFormat().

Here is the call graph for this function:

Here is the caller graph for this function:

EipStatus CreateCommonPacketFormatStructure ( const EipUint8 data,
size_t  data_length,
CipCommonPacketFormatData common_packet_format_data 
)

Creates Common Packet Format structure out of data.

Create CPF structure out of the received data.

Parameters
datapointer to data which need to be structured.
data_lengthlength of data in pa_Data.
common_packet_format_datapointer to structure of CPF data item.
Returns
status EIP_OK .. success EIP_ERROR .. error
Parameters
dataPointer to data which need to be structured.
data_lengthLength of data in pa_Data.
common_packet_format_dataPointer to structure of CPF data item.
Returns
kEipStatusOk .. success kEipStatusError .. error

Definition at line 204 of file cpf.c.

References CipCommonPacketFormatData::address_info_item, CipCommonPacketFormatData::address_item, AddressData::connection_identifier, AddressItem::data, DataItem::data, CipCommonPacketFormatData::data_item, GetDintFromMessage(), GetIntFromMessage(), CipCommonPacketFormatData::item_count, kCipItemIdSocketAddressInfoOriginatorToTarget, kCipItemIdSocketAddressInfoTargetToOriginator, kEipStatusError, kEipStatusOk, AddressItem::length, DataItem::length, SocketAddressInfoItem::length, SocketAddressInfoItem::nasin_zero, OPENER_ASSERT, OPENER_TRACE_INFO, OPENER_TRACE_WARN, AddressData::sequence_number, SocketAddressInfoItem::sin_addr, SocketAddressInfoItem::sin_family, SocketAddressInfoItem::sin_port, AddressItem::type_id, DataItem::type_id, and SocketAddressInfoItem::type_id.

Referenced by HandleReceivedConnectedData(), NotifyCommonPacketFormat(), and NotifyConnectedCommonPacketFormat().

Here is the call graph for this function:

Here is the caller graph for this function:

void EncapsulationInit ( void  )

Initialize the encapsulation layer.

Definition at line 123 of file encap.c.

References encapsulation_interface_information::capability_flags, DetermineEndianess(), ENCAP_NUMBER_OF_SUPPORTED_DELAYED_ENCAP_MESSAGES, encapsulation_interface_information::encapsulation_protocol_version, g_interface_information, g_registered_sessions, CipTcpIpNetworkInterfaceConfiguration::ip_address, kCapabilityFlagsCipTcp, kCapabilityFlagsCipUdpClass0or1, kCipItemIdListServiceResponse, encapsulation_interface_information::length, encapsulation_interface_information::name_of_service, OPENER_NUMBER_OF_SUPPORTED_SESSIONS, DelayedEncapsulationMessage::socket, and encapsulation_interface_information::type_code.

Referenced by CipStackInit().

Here is the call graph for this function:

Here is the caller graph for this function:

void EncapsulationShutDown ( void  )

Shutdown the encapsulation layer.

This means that all open sessions including their sockets are closed.

Definition at line 847 of file encap.c.

References CloseTcpSocket(), g_registered_sessions, OPENER_NUMBER_OF_SUPPORTED_SESSIONS, and OPENER_TRACE_INFO.

Referenced by ShutdownCipStack().

Here is the call graph for this function:

Here is the caller graph for this function:

EipUint32 GetDintFromMessage ( const EipUint8 **const  buffer)

Get an 32Bit integer from the network buffer.

Parameters
bufferpointer to the network buffer array. This pointer will be incremented by 4!
Returns
Extracted 32 bit integer value

Get an 32Bit integer from the network buffer.

Parameters
bufferpointer where data should be reed.
Returns
EIP_UNÍT32 value

Definition at line 83 of file endianconv.c.

Referenced by CipEpathGetLogicalValue(), ConnectionObjectInitializeFromMessage(), CreateCommonPacketFormatStructure(), CreateEncapsulationStructure(), DecodeData(), ForwardClose(), GetPathNetworkSegmentProductionInhibitTimeInMicroseconds(), HandleReceivedIoConnectionData(), HandleReceivedSendRequestResponseDataCommand(), HandleReceivedSendUnitDataCommand(), SetAttributeSingleQoS(), and SetAttributeSingleTcp().

Here is the caller graph for this function:

EipUint16 GetIntFromMessage ( const EipUint8 **const  buffer)

Get an 16Bit integer from the network buffer, and moves pointer beyond the 16 bit value.

Parameters
bufferPointer to the network buffer array. This pointer will be incremented by 2!
Returns
Extracted 16 bit integer value

Get an 16Bit integer from the network buffer, and moves pointer beyond the 16 bit value.

Parameters
bufferpointer where data should be reed.
Returns
EIP_UINT16 data value

Definition at line 57 of file endianconv.c.

Referenced by CipEpathGetLogicalValue(), ConnectionObjectInitializeFromMessage(), CreateCommonPacketFormatStructure(), CreateEncapsulationStructure(), DecodeData(), DecodePaddedEPath(), DetermineDelayTime(), ForwardClose(), GetElectronicKeyFormat4FromMessage(), HandleDataOnTcpSocket(), HandleReceivedIoConnectionData(), HandleReceivedRegisterSessionCommand(), HandleReceivedSendRequestResponseDataCommand(), HandleReceivedSendUnitDataCommand(), NotifyConnectedCommonPacketFormat(), and SetAttributeSingleTcp().

Here is the caller graph for this function:

EipUint8 GetSintFromMessage ( const EipUint8 **const  buffer)

Reads EIP_UINT8 from *buffer and converts little endian to host.

Parameters
bufferpointer where data should be reed.
Returns
EIP_UINT8 data value

Definition at line 29 of file endianconv.c.

Referenced by CipEpathGetLogicalValue(), ConnectionObjectInitializeFromMessage(), GetElectronicKeyFormat4FromMessage(), GetPathDataSegmentSimpleDataWordLength(), and ParseConnectionPath().

Here is the caller graph for this function:

void ManageEncapsulationMessages ( const MilliSeconds  elapsed_time)

Handle delayed encapsulation message responses.

Certain encapsulation message requests require a delayed sending of the response message. This functions checks if messages need to be sent and performs the sending.

Definition at line 857 of file encap.c.

References ENCAP_NUMBER_OF_SUPPORTED_DELAYED_ENCAP_MESSAGES, SendUdpData(), DelayedEncapsulationMessage::socket, and DelayedEncapsulationMessage::time_out.

Referenced by ManageConnections().

Here is the call graph for this function:

Here is the caller graph for this function:

int NotifyCommonPacketFormat ( EncapsulationData *const  received_data,
const struct sockaddr *const  originator_address,
ENIPMessage *const  outgoing_message 
)

Parse the CPF data from a received unconnected explicit message and hand the data on to the message router

Parameters
received_datapointer to the encapsulation structure with the received message
originator_addressAddress struct of the originator
outgoing_messageThe outgoing ENIP message struct
Returns
number of bytes to be sent back. < 0 if nothing should be sent

Definition at line 26 of file cpf.c.

References CipCommonPacketFormatData::address_item, AssembleLinearMessage(), CreateCommonPacketFormatStructure(), enip_message::current_message_position, DataItem::data, CipCommonPacketFormatData::data_item, encapsulation_data::data_length, g_message_router_response, GenerateEncapsulationHeader(), kCipItemIdNullAddress, kCipItemIdUnconnectedDataItem, kEipStatusError, kEipStatusOk, kEncapsulationProtocolIncorrectData, kEncapsulationProtocolSuccess, DataItem::length, enip_message::message_buffer, NotifyMessageRouter(), OPENER_TRACE_ERR, encapsulation_data::session_handle, SkipEncapsulationHeader(), AddressItem::type_id, DataItem::type_id, and enip_message::used_message_length.

Referenced by HandleReceivedSendRequestResponseDataCommand().

Here is the call graph for this function:

Here is the caller graph for this function:

int NotifyConnectedCommonPacketFormat ( const EncapsulationData *const  received_data,
const struct sockaddr *const  originator_address,
ENIPMessage *const  outgoing_message 
)

Parse the CPF data from a received connected explicit message, check the connection status, update any timers, and hand the data on to the message router

Parameters
received_datapointer to the encapsulation structure with the received message
originator_addressAddress struct of the originator
outgoing_messageThe outgoing ENIP message struct
Returns
number of bytes to be sent back. < 0 if nothing should be sent

Definition at line 91 of file cpf.c.

References CipCommonPacketFormatData::address_item, AssembleLinearMessage(), cip_connection_object::cip_produced_connection_id, AddressData::connection_identifier, ConnectionObjectResetInactivityWatchdogTimerValue(), CreateCommonPacketFormatStructure(), encapsulation_data::current_communication_buffer_position, enip_message::current_message_position, AddressItem::data, DataItem::data, CipCommonPacketFormatData::data_item, encapsulation_data::data_length, ENCAPSULATION_HEADER_LENGTH, g_message_router_response, GenerateEncapsulationHeader(), GetConnectedObject(), GetIntFromMessage(), kCipItemIdConnectedDataItem, kCipItemIdConnectionAddress, kEipStatusError, kEncapsulationProtocolSuccess, cip_connection_object::last_reply_sent, DataItem::length, enip_message::message_buffer, NotifyMessageRouter(), OPENER_TRACE_ERR, OPENER_TRACE_INFO, cip_connection_object::sequence_count_consuming, AddressData::sequence_number, encapsulation_data::session_handle, SkipEncapsulationHeader(), AddressItem::type_id, DataItem::type_id, and enip_message::used_message_length.

Referenced by HandleReceivedSendUnitDataCommand().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

CipCommonPacketFormatData g_common_packet_format_data_item

Data storage for the any CPF data Currently we are single threaded and need only one CPF at the time. For future extensions towards multithreading maybe more CPF data items may be necessary.

CPF global data items

Definition at line 24 of file cpf.c.

Referenced by AssembleForwardCloseResponse(), AssembleForwardOpenResponse(), ForwardClose(), HandleReceivedConnectedData(), OpenCommunicationChannels(), OpenProducingMulticastConnection(), and SendConnectedData().