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

Go to the source code of this file.

Functions

CipInstanceAddCIPInstance (CipClass *RESTRICT const class, const EipUint32 instance_id)
 Create one instance of a given class with a certain instance number. More...
 
CipInstanceAddCipInstances (CipClass *RESTRICT const cip_class, const int number_of_instances)
 Add a number of CIP instances to a given CIP class. More...
 
void AllocateAttributeMasks (CipClass *target_class)
 Allocates Attribute bitmasks. More...
 
size_t CalculateIndex (EipUint16 attribute_number)
 Calculates Byte-Index of Attribute. More...
 
void CipStackInit (const EipUint16 unique_connection_id)
 Initialize and setup the CIP-stack. More...
 
CipClassCreateCipClass (const EipUint32 class_id, const int number_of_class_attributes, const EipUint32 highest_class_attribute_number, const int number_of_class_services, const int number_of_instance_attributes, const EipUint32 highest_instance_attribute_number, const int number_of_instance_services, const int number_of_instances, char *name, const EipUint16 revision, void(*InitializeCipClass)(CipClass *))
 
int DecodeData (const EipUint8 cip_data_type, void *const cip_data, const EipUint8 **const cip_message)
 Retrieve the given data according to CIP encoding from the message buffer. More...
 
int DecodePaddedEPath (CipEpath *epath, const EipUint8 **message)
 Decodes padded EPath. More...
 
int EncodeData (const EipUint8 cip_type, const void *const cip_data, EipUint8 **cip_message)
 Produce the data according to CIP encoding onto the message buffer. More...
 
int EncodeEPath (CipEpath *epath, EipUint8 **message)
 
EipStatus GetAttributeAll (CipInstance *instance, CipMessageRouterRequest *message_router_request, CipMessageRouterResponse *message_router_response, struct sockaddr *originator_address, const int encapsulation_session)
 Generic implementation of the GetAttributeAll CIP service. More...
 
EipStatus GetAttributeSingle (CipInstance *RESTRICT const instance, CipMessageRouterRequest *const message_router_request, CipMessageRouterResponse *const message_router_response, struct sockaddr *originator_address, const int encapsulation_session)
 Generic implementation of the GetAttributeSingle CIP service. More...
 
CipAttributeStructGetCipAttribute (const CipInstance *const instance, const EipUint16 attribute_number)
 Get a pointer to an instance's attribute. More...
 
CipServiceStructGetCipService (const CipInstance *const instance, CipUsint service_number)
 
size_t GetSizeOfAttribute (const CipAttributeStruct *const attribute_struct)
 
void InsertAttribute (CipInstance *const instance, const EipUint16 attribute_number, const EipUint8 cip_type, void *const data, const EipByte cip_flags)
 Insert an attribute in an instance of a CIP class. More...
 
void InsertService (const CipClass *const class, const EipUint8 service_number, const CipServiceFunction service_function, char *const service_name)
 Insert a service in an instance of a CIP object. More...
 
EipStatus NotifyClass (const CipClass *RESTRICT const cip_class, CipMessageRouterRequest *const message_router_request, CipMessageRouterResponse *const message_router_response, struct sockaddr *originator_address, const int encapsulation_session)
 Check if requested service present in class/instance and call appropriate service. More...
 
void ShutdownCipStack (void)
 Shutdown of the CIP stack. More...
 

Variables

EipUint8 g_message_data_reply_buffer [OPENER_MESSAGE_DATA_REPLY_BUFFER]
 

Function Documentation

CipClass* CreateCipClass ( const EipUint32  class_id,
const int  number_of_class_attributes,
const EipUint32  highest_class_attribute_number,
const int  number_of_class_services,
const int  number_of_instance_attributes,
const EipUint32  highest_instance_attribute_number,
const int  number_of_instance_services,
const int  number_of_instances,
char *  name,
const EipUint16  revision,
void(*)(CipClass *)  InitializeCipClass 
)

Definition at line 189 of file cipcommon.c.

References AddCipInstances(), AllocateAttributeMasks(), CipCalloc(), cip_class::class_id, GetAttributeAll(), GetAttributeSingle(), GetCipClass(), InsertAttribute(), InsertService(), kCipUint, kEipStatusError, kGetableAll, kGetableSingle, kGetableSingleAndAll, kGetAttributeAll, kGetAttributeSingle, kNotSetOrGetable, OPENER_ASSERT, OPENER_TRACE_INFO, RegisterCipClass(), and cip_class::revision.

Referenced by CipEthernetLinkInit(), CipIdentityInit(), CipMessageRouterInit(), CipQoSInit(), CipTcpIpInterfaceInit(), ConnectionManagerInit(), and CreateAssemblyClass().

Here is the call graph for this function:

Here is the caller graph for this function:

int DecodePaddedEPath ( CipEpath epath,
const EipUint8 **  message 
)

Decodes padded EPath.

Parameters
epathEPath object to the receiving element
messagepointer to the message to decode
Returns
Number of decoded bytes

Definition at line 804 of file cipcommon.c.

References CipEpath::attribute_number, CipEpath::class_id, GetIntFromMessage(), CipEpath::instance_number, kEipStatusError, kSegmentTypeReserved, LOGICAL_SEGMENT_FORMAT_EIGHT_BIT, LOGICAL_SEGMENT_FORMAT_SIXTEEN_BIT, LOGICAL_SEGMENT_TYPE_ATTRIBUTE_ID, LOGICAL_SEGMENT_TYPE_CLASS_ID, LOGICAL_SEGMENT_TYPE_INSTANCE_ID, LOGICAL_SEGMENT_TYPE_MEMBER_ID, OPENER_TRACE_ERR, CipEpath::path_size, and SEGMENT_TYPE_LOGICAL_SEGMENT.

Referenced by CreateMessageRouterRequestStructure().

Here is the call graph for this function:

Here is the caller graph for this function:

int EncodeEPath ( CipEpath epath,
EipUint8 **  message 
)

Definition at line 747 of file cipcommon.c.

References AddIntToMessage(), CipEpath::attribute_number, CipEpath::class_id, CipEpath::instance_number, and CipEpath::path_size.

Referenced by EncodeData().

Here is the call graph for this function:

Here is the caller graph for this function:

EipStatus GetAttributeAll ( CipInstance instance,
CipMessageRouterRequest message_router_request,
CipMessageRouterResponse message_router_response,
struct sockaddr *  originator_address,
const int  encapsulation_session 
)

Generic implementation of the GetAttributeAll CIP service.

Copy all attributes from Object into the global message buffer.

Parameters
instancepointer to object instance with data.
message_router_requestpointer to MR request.
message_router_responsepointer for MR response.
originator_addressaddress struct of the originator as received
encapsulation_sessionassociated encapsulation session of the explicit message
Returns
length of data stream >0 .. success 0 .. no reply to send

Definition at line 704 of file cipcommon.c.

References CipEpath::attribute_number, CipAttributeStruct::attribute_number, cip_instance::attributes, CalculateIndex(), cip_instance::cip_class, CipMessageRouterResponse::data, CipMessageRouterResponse::data_length, CipMessageRouterResponse::general_status, cip_class::get_all_bit_mask, GetCipService(), kCipErrorServiceNotSupported, kEipStatusError, kEipStatusOk, kEipStatusOkSend, kGetAttributeSingle, cip_class::number_of_attributes, CipMessageRouterResponse::reply_service, CipMessageRouterRequest::request_path, CipMessageRouterRequest::service, cip_service_struct::service_function, and CipMessageRouterResponse::size_of_additional_status.

Referenced by CipEthernetLinkInit(), CipIdentityInit(), ConnectionManagerInit(), and CreateCipClass().

Here is the call graph for this function:

Here is the caller graph for this function:

EipStatus GetAttributeSingle ( CipInstance *RESTRICT const  instance,
CipMessageRouterRequest *const  message_router_request,
CipMessageRouterResponse *const  message_router_response,
struct sockaddr *  originator_address,
const int  encapsulation_session 
)

Generic implementation of the GetAttributeSingle CIP service.

Check from classID which Object requests an attribute, search if object has the appropriate attribute implemented.

Parameters
instancepointer to instance.
message_router_requestpointer to request.
message_router_responsepointer to response.
originator_addressaddress struct of the originator as received
encapsulation_sessionassociated encapsulation session of the explicit message
Returns
status >0 .. success -1 .. requested attribute not available

Definition at line 391 of file cipcommon.c.

References CipEpath::attribute_number, BeforeAssemblyDataSend(), CalculateIndex(), CipMessageRouterResponse::data, CipAttributeStruct::data, CipMessageRouterResponse::data_length, EncodeData(), CipMessageRouterResponse::general_status, GetCipAttribute(), kCipByteArray, kCipErrorAttributeNotSupported, kCipErrorSuccess, kEipStatusOkSend, kGetAttributeAll, OPENER_ASSERT, OPENER_TRACE_INFO, CipMessageRouterResponse::reply_service, CipMessageRouterRequest::request_path, CipMessageRouterRequest::service, CipMessageRouterResponse::size_of_additional_status, and CipAttributeStruct::type.

Referenced by CipIdentityInit(), CipMessageRouterInit(), ConnectionManagerInit(), CreateAssemblyClass(), CreateCipClass(), GetAttributeSingleEthernetLink(), and GetAttributeSingleQoS().

Here is the call graph for this function:

Here is the caller graph for this function:

CipServiceStruct* GetCipService ( const CipInstance *const  instance,
CipUsint  service_number 
)

Definition at line 692 of file cipcommon.c.

References cip_instance::cip_class, cip_class::number_of_services, cip_service_struct::service_number, and cip_class::services.

Referenced by GetAttributeAll().

Here is the caller graph for this function:

EipStatus NotifyClass ( const CipClass *const RESTRICT  cip_class,
CipMessageRouterRequest *const  message_router_request,
CipMessageRouterResponse *const  message_router_response,
struct sockaddr *  originator_address,
const int  encapsulation_session 
)

Check if requested service present in class/instance and call appropriate service.

Parameters
cip_classclass receiving the message
message_router_requestrequest message
message_router_responsereply message
originator_addressaddress struct of the originator as received
encapsulation_sessionassociated encapsulation session of the explicit message
Returns
  • kEipStatusOkSend ... success
  • kEipStatusOk ... no reply to send back
  • kEipStatusError ... error

Definition at line 75 of file cipcommon.c.

References cip_instance::cip_class, CipMessageRouterResponse::data_length, CipMessageRouterResponse::general_status, GetCipInstance(), CipEpath::instance_number, kCipErrorPathDestinationUnknown, kCipErrorServiceNotSupported, kEipStatusOkSend, cip_service_struct::name, cip_class::number_of_services, OPENER_ASSERT, OPENER_TRACE_INFO, OPENER_TRACE_WARN, CipMessageRouterResponse::reply_service, CipMessageRouterRequest::request_path, CipMessageRouterRequest::service, cip_service_struct::service_function, cip_service_struct::service_number, cip_class::services, and CipMessageRouterResponse::size_of_additional_status.

Referenced by NotifyMessageRouter().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

EipUint8 g_message_data_reply_buffer[OPENER_MESSAGE_DATA_REPLY_BUFFER]

Reply buffer

Definition at line 30 of file cipcommon.c.

Referenced by CipMessageRouterInit(), and NotifyMessageRouter().