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

Go to the source code of this file.

Functions

int AssembleIOMessage (const CipCommonPacketFormatData *const common_packet_format_data_item, ENIPMessage *const outgoing_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...
 
int EncodeConnectedAddressItem (const CipCommonPacketFormatData *const common_packet_format_data_item, ENIPMessage *const outgoing_message)
 
int EncodeConnectedDataItemLength (const CipMessageRouterResponse *const message_router_response, ENIPMessage *const outgoing_message)
 Encodes the Connected Data item length. More...
 
int EncodeDataItemData (const CipCommonPacketFormatData *const common_packet_format_data_item, ENIPMessage *const outgoing_message)
 
int EncodeDataItemLength (const CipCommonPacketFormatData *const common_packet_format_data_item, ENIPMessage *const outgoing_message)
 
int EncodeDataItemType (const CipCommonPacketFormatData *const common_packet_format_data_item, ENIPMessage *const outgoing_message)
 
int EncodeExtendedStatus (const CipMessageRouterResponse *const message_router_response, ENIPMessage *const outgoing_message)
 Encodes the extended status (length and data) into the message. More...
 
size_t EncodeExtendedStatusDataItems (const CipMessageRouterResponse *const message_router_response, ENIPMessage *const outgoing_message)
 Encodes the extended status data items. More...
 
int EncodeExtendedStatusLength (const CipMessageRouterResponse *const message_router_response, ENIPMessage *const outgoing_message)
 Encodes the length of the extended status data part. More...
 
int EncodeGeneralStatus (const CipMessageRouterResponse *const message_router_response, ENIPMessage *const outgoing_message)
 Encodes the general status of a Router Response. More...
 
int EncodeItemCount (const CipCommonPacketFormatData *const common_packet_format_data_item, ENIPMessage *const outgoing_message)
 Adds the item count to the message frame. More...
 
int EncodeMessageRouterResponseData (const CipMessageRouterResponse *const message_router_response, ENIPMessage *const outgoing_message)
 Encodes the Message Router Response data. More...
 
int EncodeNullAddressItem (ENIPMessage *const outgoing_message)
 Encodes a Null Address Item into the message frame. More...
 
int EncodeReplyService (const CipMessageRouterResponse *const message_router_response, ENIPMessage *const outgoing_message)
 Encodes the reply service code for the requested service. More...
 
int EncodeReservedFieldOfLengthByte (const CipMessageRouterResponse *const message_router_response, ENIPMessage *const outgoing_message)
 Encodes the reserved byte in the message router response. More...
 
int EncodeSequencedAddressItem (const CipCommonPacketFormatData *const common_packet_format_data_item, ENIPMessage *const outgoing_message)
 Encodes a sequenced address item into the message. More...
 
int EncodeSequenceNumber (const CipCommonPacketFormatData *const common_packet_format_data_item, ENIPMessage *const outgoing_message)
 Encodes a sequence number into the message. More...
 
int EncodeSockaddrInfoItemTypeId (int item_type, const CipCommonPacketFormatData *const common_packet_format_data_item, ENIPMessage *const outgoing_message)
 Encodes the sockaddr info type id into the message. More...
 
int EncodeSockaddrInfoLength (int item_type, const CipCommonPacketFormatData *const common_packet_format_data_item, ENIPMessage *const outgoing_message)
 Encodes the sockaddr info length into the message. More...
 
int EncodeUnconnectedDataItemLength (const CipMessageRouterResponse *const message_router_response, ENIPMessage *const outgoing_message)
 Encode the data item length of the unconnected data segment. 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...
 
const size_t item_count_field_size = 2
 
const size_t item_data_type_id_field_length = 2
 
const size_t sequenced_address_item_length = 8
 

Function Documentation

int EncodeConnectedAddressItem ( const CipCommonPacketFormatData *const  common_packet_format_data_item,
ENIPMessage *const  outgoing_message 
)

Encodes a Connected Address Item into the message frame

Parameters
common_packet_format_data_itemThe Common Packet Format data structure from which the message is constructed
outgoing_messageThe outgoing message object
Returns
The new size of the message frame after encoding

Definition at line 314 of file cpf.c.

References AddDintToMessage(), AddIntToMessage(), CipCommonPacketFormatData::address_item, AddressData::connection_identifier, enip_message::current_message_position, AddressItem::data, kCipItemIdConnectionAddress, and enip_message::used_message_length.

Referenced by AssembleLinearMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeConnectedDataItemLength ( const CipMessageRouterResponse *const  message_router_response,
ENIPMessage *const  outgoing_message 
)

Encodes the Connected Data item length.

Parameters
message_router_responseThe Router Response message which shall be answered
outgoing_messageThe outgoing message object
Returns
The new size of the message buffer

Definition at line 436 of file cpf.c.

References AddIntToMessage(), enip_message::current_message_position, CipMessageRouterResponse::data_length, CipMessageRouterResponse::size_of_additional_status, and enip_message::used_message_length.

Referenced by AssembleLinearMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeDataItemData ( const CipCommonPacketFormatData *const  common_packet_format_data_item,
ENIPMessage *const  outgoing_message 
)

Adds the data items to the message frame

Parameters
common_packet_format_data_itemThe Common Packet Format data structure from which the message is constructed
outgoing_messageThe outgoing message object
Returns
The new size of the message frame after encoding

Definition at line 415 of file cpf.c.

References AddSintToMessage(), enip_message::current_message_position, DataItem::data, CipCommonPacketFormatData::data_item, DataItem::length, and enip_message::used_message_length.

Referenced by AssembleLinearMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeDataItemLength ( const CipCommonPacketFormatData *const  common_packet_format_data_item,
ENIPMessage *const  outgoing_message 
)

Adds the data item section length to the message frame

Parameters
common_packet_format_data_itemThe Common Packet Format data structure from which the message is constructed
outgoing_messageThe outgoing message object
Returns
The new size of the message frame after encoding

Definition at line 398 of file cpf.c.

References AddIntToMessage(), enip_message::current_message_position, CipCommonPacketFormatData::data_item, DataItem::length, and enip_message::used_message_length.

Referenced by AssembleLinearMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeDataItemType ( const CipCommonPacketFormatData *const  common_packet_format_data_item,
ENIPMessage *const  outgoing_message 
)

Adds the data item type to the message frame

Parameters
common_packet_format_data_itemThe Common Packet Format data structure from which the message is constructed
outgoing_messageThe outgoing message object
Returns
The new size of the message frame after encoding

Definition at line 381 of file cpf.c.

References AddIntToMessage(), enip_message::current_message_position, CipCommonPacketFormatData::data_item, DataItem::type_id, and enip_message::used_message_length.

Referenced by AssembleLinearMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeExtendedStatus ( const CipMessageRouterResponse *const  message_router_response,
ENIPMessage *const  outgoing_message 
)

Encodes the extended status (length and data) into the message.

This function uses EncodeExtendedStatusLength and EncodeExtendedStatusDataItems to encode the complete extended status information into the message

Parameters
message_router_responseRouter Response message to be processed
outgoing_messageThe outgoing message object
Returns
New size of the message buffer

Definition at line 565 of file cpf.c.

References EncodeExtendedStatusDataItems(), EncodeExtendedStatusLength(), and enip_message::used_message_length.

Referenced by AssembleLinearMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

size_t EncodeExtendedStatusDataItems ( const CipMessageRouterResponse *const  message_router_response,
ENIPMessage *const  outgoing_message 
)

Encodes the extended status data items.

Parameters
message_router_responseRouter Response message to be processed
outgoing_messageThe outgoing message object
Returns
New size of the message buffer

Definition at line 542 of file cpf.c.

References AddIntToMessage(), CipMessageRouterResponse::additional_status, enip_message::current_message_position, MAX_SIZE_OF_ADD_STATUS, CipMessageRouterResponse::size_of_additional_status, and enip_message::used_message_length.

Referenced by EncodeExtendedStatus().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeExtendedStatusLength ( const CipMessageRouterResponse *const  message_router_response,
ENIPMessage *const  outgoing_message 
)

Encodes the length of the extended status data part.

Parameters
message_router_responseRouter Response message to be processed
outgoing_messageThe outgoing message object
Returns
New size of the message buffer

Definition at line 525 of file cpf.c.

References AddSintToMessage(), enip_message::current_message_position, CipMessageRouterResponse::size_of_additional_status, and enip_message::used_message_length.

Referenced by EncodeExtendedStatus().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeGeneralStatus ( const CipMessageRouterResponse *const  message_router_response,
ENIPMessage *const  outgoing_message 
)

Encodes the general status of a Router Response.

Parameters
message_router_responseRouter Response message to be processed
outgoing_messageThe outgoing message object
Returns
New size of the message buffer

Definition at line 507 of file cpf.c.

References AddSintToMessage(), enip_message::current_message_position, CipMessageRouterResponse::general_status, and enip_message::used_message_length.

Referenced by AssembleLinearMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeItemCount ( const CipCommonPacketFormatData *const  common_packet_format_data_item,
ENIPMessage *const  outgoing_message 
)

Adds the item count to the message frame.

Parameters
common_packet_format_data_itemThe Common Packet Format data structure from which the message is constructed
outgoing_messageThe outgoing message object
Returns
The new size of the message frame after encoding

Definition at line 364 of file cpf.c.

References AddIntToMessage(), enip_message::current_message_position, CipCommonPacketFormatData::item_count, and enip_message::used_message_length.

Referenced by AssembleLinearMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeMessageRouterResponseData ( const CipMessageRouterResponse *const  message_router_response,
ENIPMessage *const  outgoing_message 
)

Encodes the Message Router Response data.

Parameters
message_router_responseRouter Response message to be processed
outgoing_messageThe outgoing message object

Definition at line 598 of file cpf.c.

References AddSintToMessage(), enip_message::current_message_position, CipMessageRouterResponse::data, CipMessageRouterResponse::data_length, and enip_message::used_message_length.

Referenced by AssembleLinearMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeNullAddressItem ( ENIPMessage *const  outgoing_message)

Encodes a Null Address Item into the message frame.

Parameters
outgoing_messageThe outgoing message object
Returns
The new size of the message frame after encoding

Definition at line 297 of file cpf.c.

References AddIntToMessage(), enip_message::current_message_position, kCipItemIdNullAddress, and enip_message::used_message_length.

Referenced by AssembleLinearMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeReplyService ( const CipMessageRouterResponse *const  message_router_response,
ENIPMessage *const  outgoing_message 
)

Encodes the reply service code for the requested service.

Parameters
message_router_responseThe router response message data structure to be processed
outgoing_messageThe outgoing message object
Returns
The new size of the message buffer

Definition at line 473 of file cpf.c.

References AddSintToMessage(), enip_message::current_message_position, CipMessageRouterResponse::reply_service, and enip_message::used_message_length.

Referenced by AssembleLinearMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeReservedFieldOfLengthByte ( const CipMessageRouterResponse *const  message_router_response,
ENIPMessage *const  outgoing_message 
)

Encodes the reserved byte in the message router response.

Parameters
message_router_responseRouter Response message to be processed
outgoing_messageThe outgoing message object
Returns
New size of the message buffer

Definition at line 490 of file cpf.c.

References AddSintToMessage(), enip_message::current_message_position, CipMessageRouterResponse::reserved, and enip_message::used_message_length.

Referenced by AssembleLinearMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeSequencedAddressItem ( const CipCommonPacketFormatData *const  common_packet_format_data_item,
ENIPMessage *const  outgoing_message 
)

Encodes a sequenced address item into the message.

Parameters
common_packet_format_data_itemCommon Packet Format item which is used in the encoding
outgoing_messageThe outgoing message object
Returns
New message size after encoding

Definition at line 337 of file cpf.c.

References AddDintToMessage(), AddIntToMessage(), CipCommonPacketFormatData::address_item, AddressData::connection_identifier, enip_message::current_message_position, AddressItem::data, kCipItemIdSequencedAddressItem, AddressData::sequence_number, sequenced_address_item_length, and enip_message::used_message_length.

Referenced by AssembleLinearMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeSequenceNumber ( const CipCommonPacketFormatData *const  common_packet_format_data_item,
ENIPMessage *const  outgoing_message 
)

Encodes a sequence number into the message.

Parameters
common_packet_format_data_item
outgoing_messageThe outgoing message object
Returns
The new size of the message buffer

Definition at line 455 of file cpf.c.

References AddIntToMessage(), CipCommonPacketFormatData::address_item, enip_message::current_message_position, AddressItem::data, AddressData::sequence_number, and enip_message::used_message_length.

Referenced by AssembleLinearMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeSockaddrInfoItemTypeId ( int  item_type,
const CipCommonPacketFormatData *const  common_packet_format_data_item,
ENIPMessage *const  outgoing_message 
)

Encodes the sockaddr info type id into the message.

Parameters
item_type
common_packet_format_data_itemThe Common Packet Format data structure from which the message is constructed
outgoing_messageThe outgoing message object
Returns
New size of the message buffer

Definition at line 618 of file cpf.c.

References AddIntToMessage(), CipCommonPacketFormatData::address_info_item, enip_message::current_message_position, OPENER_ASSERT, SocketAddressInfoItem::type_id, and enip_message::used_message_length.

Referenced by AssembleLinearMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeSockaddrInfoLength ( int  item_type,
const CipCommonPacketFormatData *const  common_packet_format_data_item,
ENIPMessage *const  outgoing_message 
)

Encodes the sockaddr info length into the message.

Parameters
item_type
common_packet_format_data_itemThe Common Packet Format data structure from which the message is constructed
outgoing_messageThe outgoing message object
Returns
New size of the message buffer

Definition at line 639 of file cpf.c.

References AddIntToMessage(), CipCommonPacketFormatData::address_info_item, enip_message::current_message_position, SocketAddressInfoItem::length, and enip_message::used_message_length.

Referenced by AssembleLinearMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeUnconnectedDataItemLength ( const CipMessageRouterResponse *const  message_router_response,
ENIPMessage *const  outgoing_message 
)

Encode the data item length of the unconnected data segment.

Parameters
message_router_responseRouter Response message to be processed
outgoing_messageThe outgoing message object
Returns
New size of the message buffer

Definition at line 582 of file cpf.c.

References AddIntToMessage(), enip_message::current_message_position, CipMessageRouterResponse::data_length, CipMessageRouterResponse::size_of_additional_status, and enip_message::used_message_length.

Referenced by AssembleLinearMessage().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const size_t item_count_field_size = 2

The size of the item count field in the message

Definition at line 19 of file cpf.c.

const size_t item_data_type_id_field_length = 2

The size of the item count field in the message

Definition at line 20 of file cpf.c.

const size_t sequenced_address_item_length = 8

Definition at line 22 of file cpf.c.

Referenced by EncodeSequencedAddressItem().