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

Go to the source code of this file.

Data Structures

struct  cip_message_router_object
 A class registry list node. More...
 

Typedefs

typedef struct
cip_message_router_object 
CipMessageRouterObject
 A class registry list node. More...
 

Functions

EipStatus CipMessageRouterInit ()
 Initialize the data structures of the message router. More...
 
CipError CreateMessageRouterRequestStructure (const EipUint8 *data, EipInt16 data_length, CipMessageRouterRequest *message_router_request)
 Create Message Router Request structure out of the received data. More...
 
void DeleteAllClasses (void)
 Free all data allocated by the classes created in the CIP stack. More...
 
CipClassGetCipClass (const EipUint32 class_id)
 Get a pointer to a CIP object with given class code. More...
 
CipInstanceGetCipInstance (const CipClass *RESTRICT const cip_class, EipUint32 instance_number)
 Get a pointer to an instance. More...
 
CipMessageRouterObjectGetRegisteredObject (EipUint32 class_id)
 Get the registered MessageRouter object corresponding to ClassID. given a class ID, return a pointer to the registration node for that object. More...
 
void InitializeCipMessageRouterClass (CipClass *cip_class)
 
EipStatus NotifyMessageRouter (EipUint8 *data, int data_length, const struct sockaddr *const originator_address, const int encapsulation_session)
 Notify the MessageRouter that an explicit message (connected or unconnected) has been received. This function will be called from the encapsulation layer. The CPF structure is already parsed an can be accessed via the global variable: g_stCPFDataItem. More...
 
EipStatus RegisterCipClass (CipClass *cip_class)
 Register a CIP Class to the message router. More...
 

Variables

CipMessageRouterObjectg_first_object = NULL
 Pointer to first registered object in MessageRouter. More...
 
CipMessageRouterRequest g_message_router_request
 
CipMessageRouterResponse g_message_router_response
 Structure for storing the Response generated by an explict message. More...
 

Typedef Documentation

A class registry list node.

A linked list of this object is the registry of classes known to the message router for small devices with very limited memory it could make sense to change this list into an array with a given max size for removing the need for having to dynamically allocate memory. The size of the array could be a parameter in the platform config file.

Function Documentation

EipStatus CipMessageRouterInit ( void  )

Initialize the data structures of the message router.

Returns
kEipStatusOk if class was initialized, otherwise kEipStatusError

Definition at line 78 of file cipmessagerouter.c.

References CreateCipClass(), CipMessageRouterResponse::data, g_message_data_reply_buffer, GetAttributeSingle(), InitializeCipMessageRouterClass(), InsertService(), kEipStatusError, kEipStatusOk, kGetAttributeSingle, and CipMessageRouterResponse::reserved.

Referenced by CipStackInit().

Here is the call graph for this function:

Here is the caller graph for this function:

CipError CreateMessageRouterRequestStructure ( const EipUint8 data,
EipInt16  data_length,
CipMessageRouterRequest message_router_request 
)

Create Message Router Request structure out of the received data.

Parses the UCMM header consisting of: service, IOI size, IOI, data into a request structure

Parameters
datapointer to the message data received
data_lengthnumber of bytes in the message
message_router_requestpointer to structure of MRRequest data item.
Returns
kEipStatusOk on success. otherwise kEipStatusError

Definition at line 245 of file cipmessagerouter.c.

References CipMessageRouterRequest::data, DecodePaddedEPath(), kCipErrorPathSegmentError, kCipErrorPathSizeInvalid, kCipErrorSuccess, CipMessageRouterRequest::request_path, CipMessageRouterRequest::request_path_size, and CipMessageRouterRequest::service.

Referenced by NotifyMessageRouter().

Here is the call graph for this function:

Here is the caller graph for this function:

void DeleteAllClasses ( void  )

Free all data allocated by the classes created in the CIP stack.

Definition at line 271 of file cipmessagerouter.c.

References cip_instance::attributes, cip_message_router_object::cip_class, cip_instance::cip_class, CipFree(), cip_class::class_instance, cip_class::class_name, g_first_object, cip_class::instances, cip_message_router_object::next, cip_instance::next, cip_class::number_of_attributes, and cip_class::services.

Referenced by ShutdownCipStack().

Here is the call graph for this function:

Here is the caller graph for this function:

CipMessageRouterObject* GetRegisteredObject ( EipUint32  class_id)

Get the registered MessageRouter object corresponding to ClassID. given a class ID, return a pointer to the registration node for that object.

Parameters
class_idClass code to be searched for.
Returns
Pointer to registered message router object NULL .. Class not registered

Definition at line 111 of file cipmessagerouter.c.

References cip_message_router_object::cip_class, cip_class::class_id, g_first_object, cip_message_router_object::next, and OPENER_ASSERT.

Referenced by GetCipClass(), and NotifyMessageRouter().

Here is the caller graph for this function:

void InitializeCipMessageRouterClass ( CipClass cip_class)

Definition at line 52 of file cipmessagerouter.c.

References cip_instance::cip_class, cip_class::class_instance, cip_class::highest_attribute_number, InsertAttribute(), kCipUint, kGetableAll, kGetableSingle, kGetableSingleAndAll, cip_class::number_of_instances, and cip_class::revision.

Referenced by CipMessageRouterInit().

Here is the call graph for this function:

Here is the caller graph for this function:

EipStatus NotifyMessageRouter ( EipUint8 data,
int  data_length,
const struct sockaddr *const  originator_address,
const int  encapsulation_session 
)

Notify the MessageRouter that an explicit message (connected or unconnected) has been received. This function will be called from the encapsulation layer. The CPF structure is already parsed an can be accessed via the global variable: g_stCPFDataItem.

Parameters
datapointer to the data buffer of the message directly at the beginning of the CIP part.
data_lengthnumber of bytes in the data buffer
originator_addressThe address of the originator as received
encapsulation_sessionThe associated encapsulation session of the explicit message
Returns
kEipStatusError on fault kEipStatusOk on success

Definition at line 173 of file cipmessagerouter.c.

References cip_message_router_object::cip_class, CipEpath::class_id, cip_class::class_name, CreateMessageRouterRequestStructure(), CipMessageRouterResponse::data, CipMessageRouterResponse::data_length, g_message_data_reply_buffer, CipMessageRouterResponse::general_status, GetRegisteredObject(), kCipErrorPathDestinationUnknown, kCipErrorSuccess, kEipStatusError, kEipStatusOk, kEipStatusOkSend, NotifyClass(), OPENER_ASSERT, OPENER_TRACE_ERR, OPENER_TRACE_INFO, CipMessageRouterResponse::reply_service, CipMessageRouterRequest::request_path, CipMessageRouterResponse::reserved, and CipMessageRouterResponse::size_of_additional_status.

Referenced by NotifyCommonPacketFormat(), and NotifyConnectedCommonPacketFormat().

Here is the call graph for this function:

Here is the caller graph for this function:

EipStatus RegisterCipClass ( CipClass cip_class)

Register a CIP Class to the message router.

Parameters
cip_classPointer to a class object to be registered.
Returns
kEipStatusOk on success kEipStatusError on no memory available to register more objects

Definition at line 154 of file cipmessagerouter.c.

References cip_message_router_object::cip_class, CipCalloc(), g_first_object, kEipStatusError, kEipStatusOk, and cip_message_router_object::next.

Referenced by CreateCipClass().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

CipMessageRouterObject* g_first_object = NULL

Pointer to first registered object in MessageRouter.

Definition at line 29 of file cipmessagerouter.c.

Referenced by DeleteAllClasses(), GetRegisteredObject(), and RegisterCipClass().

CipMessageRouterRequest g_message_router_request

Definition at line 13 of file cipmessagerouter.c.

CipMessageRouterResponse g_message_router_response

Structure for storing the Response generated by an explict message.

This buffer will be used for storing the result. The response message will be generated by assembleLinearMsg.

Definition at line 14 of file cipmessagerouter.c.

Referenced by NotifyCommonPacketFormat(), and NotifyConnectedCommonPacketFormat().