OpENer - Open Source EtherNet/IP(TM) I/O Target Stack  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
encap.h File Reference

This file contains the public interface of the encapsulation layer. More...

#include "typedefs.h"
#include "cipconnectionobject.h"
Include dependency graph for encap.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  encapsulation_data
 
struct  encapsulation_interface_information
 

Macros

#define ENCAPSULATION_HEADER_LENGTH   24
 

Typedefs

typedef struct encapsulation_data EncapsulationData
 
typedef struct
encapsulation_interface_information 
EncapsulationInterfaceInformation
 
typedef struct enip_message ENIPMessage
 

Enumerations

enum  EncapsulationProtocolErrorCode {
  kEncapsulationProtocolSuccess = 0x0000, kEncapsulationProtocolInvalidCommand = 0x0001, kEncapsulationProtocolInsufficientMemory = 0x0002, kEncapsulationProtocolIncorrectData = 0x0003,
  kEncapsulationProtocolInvalidSessionHandle = 0x0064, kEncapsulationProtocolInvalidLength = 0x0065, kEncapsulationProtocolUnsupportedProtocol = 0x0069
}
 definition of status codes in encapsulation protocol All other codes are either legacy codes, or reserved for future use More...
 

Functions

void CloseClass3ConnectionBasedOnSession (size_t encapsulation_session_handle)
 
void CloseEncapsulationSessionBySockAddr (const CipConnectionObject *const connection_object)
 
void CloseSessionBySessionHandle (const CipConnectionObject *const connection_object)
 
EipInt16 CreateEncapsulationStructure (const EipUint8 *receive_buffer, int receive_buffer_length, EncapsulationData *const encapsulation_data)
 copy data from pa_buf in little endian to host in structure. More...
 
void EncapsulateListIdentityResponseMessage (const EncapsulationData *const receive_data, ENIPMessage *const outgoing_message)
 
void EncapsulationInit (void)
 Initialize the encapsulation layer. More...
 
void EncapsulationShutDown (void)
 Shutdown the encapsulation layer. More...
 
void GenerateEncapsulationHeader (const EncapsulationData *const receive_data, const size_t command_specific_data_length, const size_t session_handle, const EncapsulationProtocolErrorCode encapsulation_protocol_status, ENIPMessage *const outgoing_message)
 
size_t GetSessionFromSocket (const int socket_handle)
 
void HandleReceivedListInterfacesCommand (const EncapsulationData *const receive_data, ENIPMessage *const outgoing_message)
 
void HandleReceivedListServicesCommand (const EncapsulationData *const receive_data, ENIPMessage *const outgoing_message)
 generate reply with "Communications Services" + compatibility Flags. More...
 
void HandleReceivedRegisterSessionCommand (int socket, const EncapsulationData *const receive_data, ENIPMessage *const outgoing_message)
 
EipStatus HandleReceivedSendRequestResponseDataCommand (const EncapsulationData *const receive_data, const struct sockaddr *const originator_address, ENIPMessage *const outgoing_message)
 Call UCMM or Message Router if UCMM not implemented. More...
 
void ManageEncapsulationMessages (const MilliSeconds elapsed_time)
 Handle delayed encapsulation message responses. More...
 
void RemoveSession (const int socket)
 
void SkipEncapsulationHeader (ENIPMessage *const outgoing_message)
 

Detailed Description

This file contains the public interface of the encapsulation layer.

Definition in file encap.h.

Macro Definition Documentation

Typedef Documentation

typedef struct enip_message ENIPMessage

Definition at line 97 of file encap.h.

Enumeration Type Documentation

definition of status codes in encapsulation protocol All other codes are either legacy codes, or reserved for future use

Enumerator
kEncapsulationProtocolSuccess 
kEncapsulationProtocolInvalidCommand 
kEncapsulationProtocolInsufficientMemory 
kEncapsulationProtocolIncorrectData 
kEncapsulationProtocolInvalidSessionHandle 
kEncapsulationProtocolInvalidLength 
kEncapsulationProtocolUnsupportedProtocol 

Definition at line 30 of file encap.h.

Function Documentation

void CloseClass3ConnectionBasedOnSession ( size_t  encapsulation_session_handle)

Definition at line 906 of file encap.c.

References cip_connection_object::associated_encapsulation_session, cip_connection_object::connection_close_function, connection_list, ConnectionObjectGetTransportClassTriggerTransportClass(), doubly_linked_list_node::data, DoublyLinkedList::first, kConnectionObjectTransportClassTriggerTransportClass3, and doubly_linked_list_node::next.

Referenced by CheckEncapsulationInactivity(), CloseSession(), HandleReceivedUnregisterSessionCommand(), and RemoveSession().

Here is the call graph for this function:

Here is the caller graph for this function:

void CloseEncapsulationSessionBySockAddr ( const CipConnectionObject *const  connection_object)

Definition at line 874 of file encap.c.

References CloseSession(), FreeErrorMessage(), g_registered_sessions, GetErrorMessage(), GetSocketErrorNumber(), OPENER_NUMBER_OF_SUPPORTED_SESSIONS, OPENER_TRACE_ERR, and cip_connection_object::originator_address.

Referenced by HandleIoConnectionTimeOut().

Here is the call graph for this function:

Here is the caller graph for this function:

void CloseSessionBySessionHandle ( const CipConnectionObject *const  connection_object)

Definition at line 813 of file encap.c.

References cip_connection_object::associated_encapsulation_session, CloseTcpSocket(), g_registered_sessions, and OPENER_TRACE_INFO.

Referenced by Class3ConnectionTimeoutHandler().

Here is the call graph for this function:

Here is the caller graph for this function:

EipInt16 CreateEncapsulationStructure ( const EipUint8 receive_buffer,
int  receive_buffer_length,
EncapsulationData *const  encapsulation_data 
)

copy data from pa_buf in little endian to host in structure.

Parameters
receive_bufferReceived message
receive_buffer_lengthLength of the data in receive_buffer. Might be more than one message
encapsulation_datastructure to which data shall be copied
Returns
return difference between bytes in pa_buf an data_length 0 .. full package received >0 .. more than one packet received <0 .. only fragment of data portion received

Definition at line 774 of file encap.c.

References encapsulation_data::command_code, encapsulation_data::communication_buffer_start, encapsulation_data::current_communication_buffer_position, encapsulation_data::data_length, ENCAPSULATION_HEADER_LENGTH, GetDintFromMessage(), GetIntFromMessage(), kSenderContextSize, encapsulation_data::options, encapsulation_data::sender_context, encapsulation_data::session_handle, and encapsulation_data::status.

Referenced by HandleReceivedExplictTcpData(), and HandleReceivedExplictUdpData().

Here is the call graph for this function:

Here is the caller graph for this function:

void EncapsulateListIdentityResponseMessage ( const EncapsulationData *const  receive_data,
ENIPMessage *const  outgoing_message 
)

Array of USINT - length 8 shall be set to zero

Definition at line 436 of file encap.c.

References AddDintToMessage(), AddIntToMessage(), enip_message::current_message_position, device_type_, EncapsulateIpAddress(), GenerateEncapsulationHeader(), CipTcpIpNetworkInterfaceConfiguration::ip_address, kEncapsulationProtocolSuccess, kSupportedProtocolVersion, CipShortString::length, CipRevision::major_revision, CipRevision::minor_revision, MoveMessageNOctets(), product_code_, serial_number_, status_, CipShortString::string, enip_message::used_message_length, and vendor_id_.

Referenced by HandleReceivedListIdentityCommandTcp(), and HandleReceivedListIdentityCommandUdp().

Here is the call graph for this function:

Here is the caller graph for this function:

void GenerateEncapsulationHeader ( const EncapsulationData *const  receive_data,
const size_t  command_specific_data_length,
const size_t  session_handle,
const EncapsulationProtocolErrorCode  encapsulation_protocol_status,
ENIPMessage *const  outgoing_message 
)
size_t GetSessionFromSocket ( const int  socket_handle)

Definition at line 897 of file encap.c.

References g_registered_sessions, and OPENER_NUMBER_OF_SUPPORTED_SESSIONS.

Referenced by CheckEncapsulationInactivity().

Here is the caller graph for this function:

void HandleReceivedListInterfacesCommand ( const EncapsulationData *const  receive_data,
ENIPMessage *const  outgoing_message 
)

Definition at line 381 of file encap.c.

References AddIntToMessage(), enip_message::current_message_position, GenerateEncapsulationHeader(), kEncapsulationProtocolSuccess, and enip_message::used_message_length.

Referenced by HandleReceivedExplictTcpData(), and HandleReceivedExplictUdpData().

Here is the call graph for this function:

Here is the caller graph for this function:

void HandleReceivedListServicesCommand ( const EncapsulationData *const  receive_data,
ENIPMessage *const  outgoing_message 
)

generate reply with "Communications Services" + compatibility Flags.

Parameters
receive_datapointer to structure with received data
outgoing_messageThe outgoing ENIP message

Definition at line 345 of file encap.c.

References AddIntToMessage(), encapsulation_interface_information::capability_flags, enip_message::current_message_position, encapsulation_interface_information::encapsulation_protocol_version, GenerateEncapsulationHeader(), kEncapsulationProtocolSuccess, encapsulation_interface_information::length, encapsulation_interface_information::name_of_service, encapsulation_interface_information::type_code, and enip_message::used_message_length.

Referenced by HandleReceivedExplictTcpData(), and HandleReceivedExplictUdpData().

Here is the call graph for this function:

Here is the caller graph for this function:

void HandleReceivedRegisterSessionCommand ( int  socket,
const EncapsulationData *const  receive_data,
ENIPMessage *const  outgoing_message 
)

Definition at line 556 of file encap.c.

References encapsulation_data::current_communication_buffer_position, EncapsulateRegisterSessionCommandResponseMessage(), g_actual_time, g_registered_sessions, g_timestamps, GetFreeSessionIndex(), GetIntFromMessage(), kEncapsulationProtocolInsufficientMemory, kEncapsulationProtocolInvalidCommand, kEncapsulationProtocolSuccess, kEncapsulationProtocolUnsupportedProtocol, kSessionStatusInvalid, kSupportedProtocolVersion, OPENER_NUMBER_OF_SUPPORTED_SESSIONS, OPENER_TRACE_INFO, SocketTimerArrayGetEmptySocketTimer(), SocketTimerSetLastUpdate(), and SocketTimerSetSocket().

Referenced by HandleReceivedExplictTcpData().

Here is the call graph for this function:

Here is the caller graph for this function:

EipStatus HandleReceivedSendRequestResponseDataCommand ( const EncapsulationData *const  receive_data,
const struct sockaddr *const  originator_address,
ENIPMessage *const  outgoing_message 
)

Call UCMM or Message Router if UCMM not implemented.

Parameters
receive_dataPointer to structure with data and header information.
originator_addressAddress of the originator as received from socket
outgoing_messageThe outgoing ENIP message
Returns
status kEipStatusOk .. success. kEipStatusError .. error

Definition at line 698 of file encap.c.

References CheckRegisteredSessions(), encapsulation_data::current_communication_buffer_position, encapsulation_data::data_length, GenerateEncapsulationHeader(), GetDintFromMessage(), GetIntFromMessage(), InitializeENIPMessage(), kEipStatusError, kEipStatusOkSend, kEncapsulationProtocolInvalidSessionHandle, kSessionStatusValid, NotifyCommonPacketFormat(), and encapsulation_data::session_handle.

Referenced by HandleReceivedExplictTcpData().

Here is the call graph for this function:

Here is the caller graph for this function:

void RemoveSession ( const int  socket)

Definition at line 835 of file encap.c.

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

Referenced by CheckEncapsulationInactivity(), HandleDataOnTcpSocket(), and NetworkHandlerProcessOnce().

Here is the call graph for this function:

Here is the caller graph for this function:

void SkipEncapsulationHeader ( ENIPMessage *const  outgoing_message)

Definition at line 312 of file encap.c.

References enip_message::current_message_position, ENCAPSULATION_HEADER_LENGTH, and MoveMessageNOctets().

Referenced by NotifyCommonPacketFormat(), and NotifyConnectedCommonPacketFormat().

Here is the call graph for this function:

Here is the caller graph for this function: