OpENer - Open Source EtherNet/IP(TM) I/O Target Stack
2.1
|
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... | |
The Ethernet encapsulation layer handles provides the abstraction between the Ethernet and the CIP layer.
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
Write an 32Bit integer to the network buffer.
data | value to write |
buffer | pointer to the network buffer array. This pointer will be incremented by 4! |
Write an 32Bit integer to the network buffer.
data | value to be written |
buffer | pointer 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().
Write an 16Bit integer to the network buffer.
data | value to write |
buffer | pointer to the network buffer array. This pointer will be incremented by 2! |
Write an 16Bit integer to the network buffer.
data | value to be written |
buffer | pointer 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().
converts UINT8 data from host to little endian an writes it to buffer.
data | value to be written |
buffer | pointer where data should be written. |
Definition at line 103 of file endianconv.c.
Referenced by CipEpathSetLogicalValue(), EncodeData(), EncodeDataItemData(), EncodeExtendedStatusLength(), EncodeGeneralStatus(), EncodeMessageRouterResponseData(), EncodeReplyService(), and EncodeReservedFieldOfLengthByte().
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.
common_packet_format_data_item | pointer to CPF structure which has to be aligned into linear memory. |
message | Modified ENIP message struct |
Definition at line 758 of file cpf.c.
References AssembleLinearMessage().
Referenced by SendConnectedData().
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.
message_router_response | pointer to message router response which has to be aligned into linear memory. |
common_packet_format_data_item | pointer to CPF structure which has to be aligned into linear memory. |
outgoing_message | Modified ENIP message struct |
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().
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.
data | pointer to data which need to be structured. |
data_length | length of data in pa_Data. |
common_packet_format_data | pointer to structure of CPF data item. |
data | Pointer to data which need to be structured. |
data_length | Length of data in pa_Data. |
common_packet_format_data | Pointer to structure of CPF data item. |
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().
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().
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().
Get an 32Bit integer from the network buffer.
buffer | pointer to the network buffer array. This pointer will be incremented by 4! |
Get an 32Bit integer from the network buffer.
buffer | pointer where data should be reed. |
Definition at line 83 of file endianconv.c.
Referenced by CipEpathGetLogicalValue(), ConnectionObjectInitializeFromMessage(), CreateCommonPacketFormatStructure(), CreateEncapsulationStructure(), DecodeData(), ForwardClose(), GetPathNetworkSegmentProductionInhibitTimeInMicroseconds(), HandleReceivedIoConnectionData(), HandleReceivedSendRequestResponseDataCommand(), HandleReceivedSendUnitDataCommand(), SetAttributeSingleQoS(), and SetAttributeSingleTcp().
Get an 16Bit integer from the network buffer, and moves pointer beyond the 16 bit value.
buffer | Pointer to the network buffer array. This pointer will be incremented by 2! |
Get an 16Bit integer from the network buffer, and moves pointer beyond the 16 bit value.
buffer | pointer where data should be reed. |
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().
Reads EIP_UINT8 from *buffer and converts little endian to host.
buffer | pointer where data should be reed. |
Definition at line 29 of file endianconv.c.
Referenced by CipEpathGetLogicalValue(), ConnectionObjectInitializeFromMessage(), GetElectronicKeyFormat4FromMessage(), GetPathDataSegmentSimpleDataWordLength(), and ParseConnectionPath().
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().
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
received_data | pointer to the encapsulation structure with the received message |
originator_address | Address struct of the originator |
outgoing_message | The outgoing ENIP message struct |
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().
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
received_data | pointer to the encapsulation structure with the received message |
originator_address | Address struct of the originator |
outgoing_message | The outgoing ENIP message struct |
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().
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().