OpENer - Open Source EtherNet/IP(TM) I/O Target Stack  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
opener_api.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (c) 2009, Rockwell Automation, Inc.
3  * All rights reserved.
4  *
5  ******************************************************************************/
6 #ifndef OPENER_OPENER_API_H_
7 #define OPENER_OPENER_API_H_
8 
9 #include <assert.h>
10 #include <stdbool.h>
11 
12 #include "typedefs.h"
13 #include "ciptypes.h"
14 #include "ciperror.h"
15 #include "opener_user_conf.h"
16 
34 ConfigureNetworkInterface(const char *const network_interface);
35 
41 void ConfigureMacAddress(const char *network_interface);
42 
47 void ConfigureDomainName(void);
52 void ConfigureHostName(void);
53 
59 void SetDeviceSerialNumber(const EipUint32 serial_number);
60 
66 void SetDeviceStatus(const EipUint16 device_status);
67 
74 void CipStackInit(const EipUint16 unique_connection_id);
75 
87 void ShutdownCipStack(void);
88 
96 CipClass *GetCipClass(const EipUint32 class_id);
97 
106 CipInstance *GetCipInstance(const CipClass *RESTRICT const cip_object,
107  const EipUint32 instance_number);
108 
120  const EipUint16 attribute_number);
121 
122 typedef void (*InitializeCipClass)(CipClass *);
145 CipClass *CreateCipClass( const EipUint32 class_id,
146  const int number_of_class_attributes,
147  const EipUint32 highest_class_attribute_number,
148  const int number_of_class_services,
149  const int number_of_instance_attributes,
150  const EipUint32 highest_instance_attribute_number,
151  const int number_of_instance_services,
152  const int number_of_instances,
153  char *name,
154  const EipUint16 revision,
155  InitializeCipClass initializer );
156 
176  CipClass *RESTRICT const cip_object_to_add_instances,
177  const int number_of_instances);
178 
189 CipInstance *AddCIPInstance(CipClass *RESTRICT const cip_class_to_add_instance,
190  const EipUint32 instance_id);
191 
209  const EipUint16 attribute_number,
210  const EipUint8 cip_data_type,
211  void *const cip_data,
212  const EipByte cip_flags);
219 void AllocateAttributeMasks(CipClass *target_class);
220 
227 size_t CalculateIndex(EipUint16 attribute_number);
228 
242 void InsertService(const CipClass *const cip_class_to_add_service,
243  const EipUint8 service_code,
244  const CipServiceFunction service_function,
245  char *const service_name);
246 
258 int EncodeData(const EipUint8 cip_data_type,
259  const void *const cip_data,
260  EipUint8 **cip_message);
261 
274 int DecodeData(const EipUint8 cip_data_type,
275  void *const cip_data,
276  const EipUint8 **const cip_message);
277 
295 CipInstance *CreateAssemblyObject(const EipUint32 instance_number,
296  EipByte *const data,
297  const EipUint16 data_length);
298 
300 
311  CipConnectionObject *RESTRICT const connection_object,
312  EipUint16 *const extended_error_code);
313 
320 typedef void (*ConnectionCloseFunction)(CipConnectionObject *connection_object);
321 
328  CipConnectionObject *connection_object);
329 
338  connection_object);
339 
350  CipConnectionObject *connection_object,
351  const EipUint8 *data,
352  const EipUint16 data_length);
353 
364 EipStatus
365 AddConnectableObject(const EipUint32 class_id,
366  OpenConnectionFunction open_connection_function);
367 
382  const unsigned int connection_number,
383  const unsigned int output_assembly_id,
384  const unsigned int input_assembly_id,
385  const unsigned int configuration_assembly_id);
386 
401  const unsigned int connection_number,
402  const unsigned int output_assembly_id,
403  const unsigned int input_assembly_id,
404  const unsigned int configuration_assembly_id);
405 
420  const unsigned int connection_number,
421  const unsigned int output_assembly_id,
422  const unsigned int input_assembly_id,
423  const unsigned int configuration_assembly_id);
424 
439 int HandleReceivedExplictTcpData(int socket_handle,
440  EipUint8 *buffer,
441  size_t length,
442  int *number_of_remaining_bytes,
443  struct sockaddr *originator_address,
444  ENIPMessage *const outgoing_message);
445 
461 int HandleReceivedExplictUdpData(const int socket_handle,
462  const struct sockaddr_in *from_address,
463  const EipUint8 *buffer,
464  const size_t buffer_length,
465  int *number_of_remaining_bytes,
466  bool unicast,
467  ENIPMessage *const outgoing_message);
468 
481 EipStatus
482 HandleReceivedConnectedData(const EipUint8 *const received_data,
483  int received_data_length,
484  struct sockaddr_in *from_address);
485 
499 EipStatus
500 ManageConnections(MilliSeconds elapsed_time);
501 
521 EipStatus
522 TriggerConnections(unsigned int output_assembly_id,
523  unsigned int input_assembly_id);
524 
533 void CloseSession(int socket_handle);
534 
555 EipStatus
557 
566 void HandleApplication(void);
567 
577 void CheckIoConnectionEvent(unsigned int output_assembly_id,
578  unsigned int input_assembly_id,
579  IoConnectionEvent io_connection_event);
580 
597 EipStatus
599 
612 EipBool8
614 
621 EipStatus
622 ResetDevice(void);
623 
631 EipStatus
633 
645 void *CipCalloc(size_t number_of_elements,
646  size_t size_of_element);
647 
654 void CipFree(void *data);
655 
663 void RunIdleChanged(EipUint32 run_idle_value);
664 
682 int CreateUdpSocket(UdpCommuncationDirection communication_direction,
683  struct sockaddr_in *socket_data,
684  CipUsint qos_for_socket);
685 
695 EipStatus
696 SendUdpData(struct sockaddr_in *socket_data,
697  int socket_handle,
698  EipUint8 *data,
699  EipUint16 data_length);
700 
706 void CloseSocket(const int socket_handle);
707 
889 #endif /*OPENER_OPENER_API_H_*/
EipStatus ApplicationInitialization(void)
Callback for the application initialization.
void InsertAttribute(CipInstance *const cip_instance, const EipUint16 attribute_number, const EipUint8 cip_data_type, void *const cip_data, const EipByte cip_flags)
Insert an attribute in an instance of a CIP class.
Definition: cipcommon.c:304
void CloseSession(int socket_handle)
Inform the encapsulation layer that the remote host has closed the connection.
Definition: encap.c:822
CipInstance * CreateAssemblyObject(const EipUint32 instance_number, EipByte *const data, const EipUint16 data_length)
Create an instance of an assembly object.
Definition: cipassembly.c:80
void(* ConnectionTimeoutFunction)(CipConnectionObject *connection_object)
Function prototype for handling the timeout of connections.
Definition: opener_api.h:327
EipStatus SendUdpData(struct sockaddr_in *socket_data, int socket_handle, EipUint8 *data, EipUint16 data_length)
Create a producing or consuming UDP socket.
void(* InitializeCipClass)(CipClass *)
Definition: opener_api.h:122
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, InitializeCipClass initializer)
Allocate memory for new CIP Class and attributes.
EipStatus(* CipServiceFunction)(CipInstance *const instance, CipMessageRouterRequest *const message_router_request, CipMessageRouterResponse *const message_router_response, struct sockaddr *originator_address, const int encapsulation_session)
Signature definition for the implementation of CIP services.
Definition: ciptypes.h:277
void SetDeviceSerialNumber(const EipUint32 serial_number)
Set the serial number of the device's identity object.
Definition: cipidentity.c:54
int HandleReceivedExplictUdpData(const int socket_handle, const struct sockaddr_in *from_address, const EipUint8 *buffer, const size_t buffer_length, int *number_of_remaining_bytes, bool unicast, ENIPMessage *const outgoing_message)
Notify the encapsulation layer that an explicit message has been received via UDP.
Definition: encap.c:237
Class is a subclass of Instance.
Definition: ciptypes.h:237
EipStatus(* OpenConnectionFunction)(CipConnectionObject *RESTRICT const connection_object, EipUint16 *const extended_error_code)
Function prototype for handling the opening of connections.
Definition: opener_api.h:310
UdpCommuncationDirection
Communication direction of an UDP socket; consuming is receiver, producing is sender.
Definition: typedefs.h:104
EipStatus AddConnectableObject(const EipUint32 class_id, OpenConnectionFunction open_connection_function)
register open functions for an specific object.
size_t CalculateIndex(EipUint16 attribute_number)
Calculates Byte-Index of Attribute.
Definition: cipcommon.c:895
CipInstance * AddCIPInstance(CipClass *RESTRICT const cip_class_to_add_instance, const EipUint32 instance_id)
Create one instance of a given class with a certain instance number.
Definition: cipcommon.c:178
void CheckIoConnectionEvent(unsigned int output_assembly_id, unsigned int input_assembly_id, IoConnectionEvent io_connection_event)
Inform the application on changes occurred for a connection.
void * CipCalloc(size_t number_of_elements, size_t size_of_element)
Allocate memory for the CIP stack.
void ConfigureListenOnlyConnectionPoint(const unsigned int connection_number, const unsigned int output_assembly_id, const unsigned int input_assembly_id, const unsigned int configuration_assembly_id)
Configures the connection point for a listen only connection.
Definition: appcontype.c:113
EipStatus
EIP stack status enum.
Definition: typedefs.h:93
uint8_t EipUint8
Definition: typedefs.h:32
void InsertService(const CipClass *const cip_class_to_add_service, const EipUint8 service_code, const CipServiceFunction service_function, char *const service_name)
Insert a service in an instance of a CIP object.
Definition: cipcommon.c:346
void HandleApplication(void)
Allow the device specific application to perform its execution.
uint32_t EipUint32
Definition: typedefs.h:34
EipStatus ResetDevice(void)
Emulate as close a possible a power cycle of the device.
IoConnectionEvent
Definition: ciptypes.h:113
void ConfigureMacAddress(const char *network_interface)
Configure the MAC address of the device.
Definition: networkconfig.c:31
void ConfigureInputOnlyConnectionPoint(const unsigned int connection_number, const unsigned int output_assembly_id, const unsigned int input_assembly_id, const unsigned int configuration_assembly_id)
Configures the connection point for an input only connection.
Definition: appcontype.c:100
EipStatus AfterAssemblyDataReceived(CipInstance *instance)
Call back function to inform application on received data for an assembly object. ...
EipStatus ManageConnections(MilliSeconds elapsed_time)
Check if any of the connection timers (TransmissionTrigger or WatchdogTimeout) have timed out...
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.
Definition: cipcommon.c:616
EipStatus TriggerConnections(unsigned int output_assembly_id, unsigned int input_assembly_id)
Trigger the production of an application triggered connection.
void CipFree(void *data)
Free memory allocated by the OpENer.
void ConfigureExclusiveOwnerConnectionPoint(const unsigned int connection_number, const unsigned int output_assembly_id, const unsigned int input_assembly_id, const unsigned int configuration_assembly_id)
Configures the connection point for an exclusive owner connection.
Definition: appcontype.c:85
int EncodeData(const EipUint8 cip_data_type, const void *const cip_data, EipUint8 **cip_message)
Produce the data according to CIP encoding onto the message buffer.
Definition: cipcommon.c:450
void CipStackInit(const EipUint16 unique_connection_id)
Initialize and setup the CIP-stack.
Definition: cipcommon.c:36
uint8_t CipUsint
Definition: typedefs.h:46
CipInstance * GetCipInstance(const CipClass *RESTRICT const cip_object, const EipUint32 instance_number)
Get a pointer to an instance.
EipStatus(* ConnectionSendDataFunction)(CipConnectionObject *connection_object)
Function prototype for sending data via a connection.
Definition: opener_api.h:337
CipClass * GetCipClass(const EipUint32 class_id)
Get a pointer to a CIP object with given class code.
CipAttributeStruct * GetCipAttribute(const CipInstance *const cip_instance, const EipUint16 attribute_number)
Get a pointer to an instance's attribute.
Definition: cipcommon.c:373
uint8_t EipByte
EIP Data type definitions.
Definition: typedefs.h:28
EipStatus ConfigureNetworkInterface(const char *const network_interface)
Configure the data of the network interface of the device.
Definition: networkconfig.c:27
EipStatus ResetDeviceToInitialConfiguration(void)
Reset the device to the initial configuration and emulate as close as possible a power cycle of the d...
uint8_t EipBool8
Definition: typedefs.h:37
void ShutdownCipStack(void)
Shutdown of the CIP stack.
Definition: cipcommon.c:61
void RunIdleChanged(EipUint32 run_idle_value)
Inform the application that the Run/Idle State has been changed by the originator.
unsigned long MilliSeconds
Definition: typedefs.h:68
int CreateUdpSocket(UdpCommuncationDirection communication_direction, struct sockaddr_in *socket_data, CipUsint qos_for_socket)
create a producing or consuming UDP socket
void SetDeviceStatus(const EipUint16 device_status)
Set the current status of the device.
Definition: cipidentity.c:61
void ConfigureDomainName(void)
Configure the domain name of the device.
Definition: networkconfig.c:87
EipStatus HandleReceivedConnectedData(const EipUint8 *const received_data, int received_data_length, struct sockaddr_in *from_address)
Notify the connection manager that data for a connection has been received.
void AllocateAttributeMasks(CipClass *target_class)
Allocates Attribute bitmasks.
Definition: cipcommon.c:885
void CloseSocket(const int socket_handle)
Close the given socket and clean up the stack.
CipInstance * AddCipInstances(CipClass *RESTRICT const cip_object_to_add_instances, const int number_of_instances)
Add a number of CIP instances to a given CIP class.
Definition: cipcommon.c:132
EipBool8 BeforeAssemblyDataSend(CipInstance *instance)
Inform the application that the data of an assembly object will be sent.
uint16_t EipUint16
Definition: typedefs.h:33
struct sockaddr_in originator_address
int HandleReceivedExplictTcpData(int socket_handle, EipUint8 *buffer, size_t length, int *number_of_remaining_bytes, struct sockaddr *originator_address, ENIPMessage *const outgoing_message)
Notify the encapsulation layer that an explicit message has been received via TCP.
Definition: encap.c:153
void(* ConnectionCloseFunction)(CipConnectionObject *connection_object)
Function prototype for handling the closing of connections.
Definition: opener_api.h:320
EipStatus(* ConnectionReceiveDataFunction)(CipConnectionObject *connection_object, const EipUint8 *data, const EipUint16 data_length)
Function prototype for receiving data via a connection.
Definition: opener_api.h:349
void ConfigureHostName(void)
Configure the host name of the device.