|
|
@@ -23,18 +23,17 @@
|
|
|
#include "appcontype.h"
|
|
|
|
|
|
/* global public variables */
|
|
|
-EipUint8 g_message_data_reply_buffer[OPENER_MESSAGE_DATA_REPLY_BUFFER];
|
|
|
+EipUint8 g_message_data_reply_buffer[OPENER_MESSAGE_DATA_REPLY_BUFFER]; /**< Reply buffer */
|
|
|
|
|
|
-const EipUint16 kCipUintZero = 0;
|
|
|
+const EipUint16 kCipUintZero = 0; /**< Zero value for returning the UINT standard value */
|
|
|
|
|
|
/* private functions*/
|
|
|
int EncodeEPath(CipEpath *epath, EipUint8 **message);
|
|
|
|
|
|
-void CipStackInit(EipUint16 unique_connection_id) {
|
|
|
- EipStatus eip_status;
|
|
|
+void CipStackInit(const EipUint16 unique_connection_id) {
|
|
|
EncapsulationInit();
|
|
|
/* The message router is the first CIP object be initialized!!! */
|
|
|
- eip_status = CipMessageRouterInit();
|
|
|
+ EipStatus eip_status = CipMessageRouterInit();
|
|
|
OPENER_ASSERT(kEipStatusOk == eip_status);
|
|
|
eip_status = CipIdentityInit();
|
|
|
OPENER_ASSERT(kEipStatusOk == eip_status);
|
|
|
@@ -65,26 +64,22 @@ void ShutdownCipStack(void) {
|
|
|
DeleteAllClasses();
|
|
|
}
|
|
|
|
|
|
-EipStatus NotifyClass(CipClass *cip_class,
|
|
|
- CipMessageRouterRequest *message_router_request,
|
|
|
- CipMessageRouterResponse *message_router_response) {
|
|
|
- int i;
|
|
|
- CipInstance *instance;
|
|
|
- CipServiceStruct *service;
|
|
|
- unsigned instance_number; /* my instance number */
|
|
|
+EipStatus NotifyClass(const CipClass *restrict const cip_class,
|
|
|
+ CipMessageRouterRequest *const message_router_request,
|
|
|
+ CipMessageRouterResponse *const message_router_response) {
|
|
|
|
|
|
/* find the instance: if instNr==0, the class is addressed, else find the instance */
|
|
|
- instance_number = message_router_request->request_path.instance_number; /* get the instance number */
|
|
|
- instance = GetCipInstance(cip_class, instance_number); /* look up the instance (note that if inst==0 this will be the class itself) */
|
|
|
+ EipUint16 instance_number = message_router_request->request_path.instance_number; /* get the instance number */
|
|
|
+ CipInstance * instance = GetCipInstance(cip_class, instance_number); /* look up the instance (note that if inst==0 this will be the class itself) */
|
|
|
if (instance) /* if instance is found */
|
|
|
{
|
|
|
OPENER_TRACE_INFO("notify: found instance %d%s\n", instance_number,
|
|
|
instance_number == 0 ? " (class object)" : "");
|
|
|
|
|
|
- service = instance->cip_class->services; /* get pointer to array of services */
|
|
|
- if (service) /* if services are defined */
|
|
|
+ CipServiceStruct *service = instance->cip_class->services; /* get pointer to array of services */
|
|
|
+ if (NULL != service) /* if services are defined */
|
|
|
{
|
|
|
- for (i = 0; i < instance->cip_class->number_of_services; i++) /* seach the services list */
|
|
|
+ for (int i = 0; i < instance->cip_class->number_of_services; i++) /* seach the services list */
|
|
|
{
|
|
|
if (message_router_request->service == service->service_number) /* if match is found */
|
|
|
{
|
|
|
@@ -116,10 +111,9 @@ EipStatus NotifyClass(CipClass *cip_class,
|
|
|
return kEipStatusOkSend;
|
|
|
}
|
|
|
|
|
|
-CipInstance *AddCipInstances(CipClass *cip_class, int number_of_instances) {
|
|
|
- CipInstance *first_instance, *current_instance, **next_instance;
|
|
|
- int i;
|
|
|
- int instance_number = 1; /* the first instance is number 1 */
|
|
|
+CipInstance *AddCipInstances(CipClass *restrict const cip_class, const int number_of_instances) {
|
|
|
+ CipInstance **next_instance = NULL;
|
|
|
+ EipUint32 instance_number = 1; /* the first instance is number 1 */
|
|
|
|
|
|
OPENER_TRACE_INFO("adding %d instances to class %s\n", number_of_instances,
|
|
|
cip_class->class_name);
|
|
|
@@ -131,14 +125,16 @@ CipInstance *AddCipInstances(CipClass *cip_class, int number_of_instances) {
|
|
|
instance_number++; /* keep track of what the first new instance number will be */
|
|
|
}
|
|
|
|
|
|
- first_instance = current_instance = (CipInstance *) CipCalloc(
|
|
|
- number_of_instances, sizeof(CipInstance)); /* allocate a block of memory for all created instances*/
|
|
|
+ CipInstance *current_instance = current_instance = (CipInstance *) CipCalloc(
|
|
|
+ number_of_instances, sizeof(CipInstance)); /* allocate a block of memory for all created instances*/
|
|
|
+ CipInstance *first_instance = current_instance; /* allocate a block of memory for all created instances*/
|
|
|
+
|
|
|
OPENER_ASSERT(NULL != current_instance);
|
|
|
/* fail if run out of memory */
|
|
|
|
|
|
cip_class->number_of_instances += number_of_instances; /* add the number of instances just created to the total recorded by the class */
|
|
|
|
|
|
- for (i = 0; i < number_of_instances; i++) /* initialize all the new instances */
|
|
|
+ for (int i = 0; i < number_of_instances; i++) /* initialize all the new instances */
|
|
|
{
|
|
|
*next_instance = current_instance; /* link the previous pointer to this new node */
|
|
|
|
|
|
@@ -159,7 +155,7 @@ CipInstance *AddCipInstances(CipClass *cip_class, int number_of_instances) {
|
|
|
return first_instance;
|
|
|
}
|
|
|
|
|
|
-CipInstance *AddCIPInstance(CipClass *class, EipUint32 instance_id) {
|
|
|
+CipInstance *AddCIPInstance(CipClass *restrict const class, const EipUint32 instance_id) {
|
|
|
CipInstance *instance = GetCipInstance(class, instance_id);
|
|
|
|
|
|
if (0 == instance) { /*we have no instance with given id*/
|
|
|
@@ -169,22 +165,19 @@ CipInstance *AddCIPInstance(CipClass *class, EipUint32 instance_id) {
|
|
|
return instance;
|
|
|
}
|
|
|
|
|
|
-CipClass *CreateCipClass(EipUint32 class_id, int number_of_class_attributes,
|
|
|
- EipUint32 get_all_class_attributes_mask,
|
|
|
- int number_of_class_services,
|
|
|
- int number_of_instance_attributes,
|
|
|
- EipUint32 get_all_instance_attributes_mask,
|
|
|
- int number_of_instance_services,
|
|
|
- int number_of_instances, char *name,
|
|
|
- EipUint16 revision) {
|
|
|
- CipClass *class; /* pointer to the class struct */
|
|
|
- CipClass *meta_class; /* pointer to the metaclass struct */
|
|
|
+CipClass *CreateCipClass(const EipUint32 class_id, const int number_of_class_attributes,
|
|
|
+ const EipUint32 get_all_class_attributes_mask,
|
|
|
+ const int number_of_class_services,
|
|
|
+ const int number_of_instance_attributes,
|
|
|
+ const EipUint32 get_all_instance_attributes_mask,
|
|
|
+ const int number_of_instance_services,
|
|
|
+ const int number_of_instances, char *name,
|
|
|
+ const EipUint16 revision) {
|
|
|
|
|
|
OPENER_TRACE_INFO("creating class '%s' with id: 0x%"PRIX32"\n", name,
|
|
|
class_id);
|
|
|
|
|
|
- class = GetCipClass(class_id); /* check if an class with the ClassID already exists */
|
|
|
- OPENER_ASSERT(NULL == class);
|
|
|
+ OPENER_ASSERT(NULL == GetCipClass(class_id)); /* check if an class with the ClassID already exists */
|
|
|
/* should never try to redefine a class*/
|
|
|
|
|
|
/* a metaClass is a class that holds the class attributes and services
|
|
|
@@ -193,8 +186,8 @@ CipClass *CreateCipClass(EipUint32 class_id, int number_of_class_attributes,
|
|
|
and contains a pointer to a metaclass
|
|
|
CIP never explicitly addresses a metaclass*/
|
|
|
|
|
|
- class = (CipClass*) CipCalloc(1, sizeof(CipClass)); /* create the class object*/
|
|
|
- meta_class = (CipClass*) CipCalloc(1, sizeof(CipClass)); /* create the metaclass object*/
|
|
|
+ CipClass *const class = (CipClass*) CipCalloc(1, sizeof(CipClass)); /* create the class object*/
|
|
|
+ CipClass *const meta_class = (CipClass*) CipCalloc(1, sizeof(CipClass)); /* create the metaclass object*/
|
|
|
|
|
|
/* initialize the class-specific fields of the Class struct*/
|
|
|
class->class_id = class_id; /* the class remembers the class ID */
|
|
|
@@ -220,19 +213,19 @@ CipClass *CreateCipClass(EipUint32 class_id, int number_of_class_attributes,
|
|
|
strcat(meta_class->class_name, name);
|
|
|
|
|
|
/* initialize the instance-specific fields of the Class struct*/
|
|
|
- class->m_stSuper.instance_number = 0; /* the class object is instance zero of the class it describes (weird, but that's the spec)*/
|
|
|
- class->m_stSuper.attributes = 0; /* this will later point to the class attibutes*/
|
|
|
- class->m_stSuper.cip_class = meta_class; /* the class's class is the metaclass (like SmallTalk)*/
|
|
|
- class->m_stSuper.next = 0; /* the next link will always be zero, sinc there is only one instance of any particular class object */
|
|
|
+ class->class_instance.instance_number = 0; /* the class object is instance zero of the class it describes (weird, but that's the spec)*/
|
|
|
+ class->class_instance.attributes = 0; /* this will later point to the class attibutes*/
|
|
|
+ class->class_instance.cip_class = meta_class; /* the class's class is the metaclass (like SmallTalk)*/
|
|
|
+ class->class_instance.next = 0; /* the next link will always be zero, sinc there is only one instance of any particular class object */
|
|
|
|
|
|
- meta_class->m_stSuper.instance_number = 0xffffffff; /*the metaclass object does not really have a valid instance number*/
|
|
|
- meta_class->m_stSuper.attributes = 0; /* the metaclass has no attributes*/
|
|
|
- meta_class->m_stSuper.cip_class = 0; /* the metaclass has no class*/
|
|
|
- meta_class->m_stSuper.next = 0; /* the next link will always be zero, since there is only one instance of any particular metaclass object*/
|
|
|
+ meta_class->class_instance.instance_number = 0xffffffff; /*the metaclass object does not really have a valid instance number*/
|
|
|
+ meta_class->class_instance.attributes = 0; /* the metaclass has no attributes*/
|
|
|
+ meta_class->class_instance.cip_class = 0; /* the metaclass has no class*/
|
|
|
+ meta_class->class_instance.next = 0; /* the next link will always be zero, since there is only one instance of any particular metaclass object*/
|
|
|
|
|
|
/* further initialization of the class object*/
|
|
|
|
|
|
- class->m_stSuper.attributes = (CipAttributeStruct *) CipCalloc(
|
|
|
+ class->class_instance.attributes = (CipAttributeStruct *) CipCalloc(
|
|
|
meta_class->number_of_attributes, sizeof(CipAttributeStruct));
|
|
|
/* TODO -- check that we didn't run out of memory?*/
|
|
|
|
|
|
@@ -286,15 +279,13 @@ CipClass *CreateCipClass(EipUint32 class_id, int number_of_class_attributes,
|
|
|
return class;
|
|
|
}
|
|
|
|
|
|
-void InsertAttribute(CipInstance *instance, EipUint16 attribute_number,
|
|
|
- EipUint8 cip_type, void *data, EipByte cip_flags) {
|
|
|
- int i;
|
|
|
- CipAttributeStruct *attribute;
|
|
|
+void InsertAttribute(CipInstance *const instance, const EipUint16 attribute_number,
|
|
|
+ const EipUint8 cip_type, void *const data, const EipByte cip_flags) {
|
|
|
|
|
|
- attribute = instance->attributes;
|
|
|
+ CipAttributeStruct *attribute = instance->attributes;
|
|
|
OPENER_ASSERT(NULL != attribute);
|
|
|
/* adding a attribute to a class that was not declared to have any attributes is not allowed */
|
|
|
- for (i = 0; i < instance->cip_class->number_of_attributes; i++) {
|
|
|
+ for (int i = 0; i < instance->cip_class->number_of_attributes; i++) {
|
|
|
if (attribute->data == NULL) { /* found non set attribute */
|
|
|
attribute->attribute_number = attribute_number;
|
|
|
attribute->type = cip_type;
|
|
|
@@ -312,57 +303,55 @@ void InsertAttribute(CipInstance *instance, EipUint16 attribute_number,
|
|
|
|
|
|
OPENER_TRACE_ERR(
|
|
|
"Tried to insert to many attributes into class: %"PRIu32", instance %"PRIu32"\n",
|
|
|
- instance->cip_class->m_stSuper.instance_number,
|
|
|
+ instance->cip_class->class_instance.instance_number,
|
|
|
instance->instance_number);
|
|
|
OPENER_ASSERT(0);
|
|
|
/* trying to insert too many attributes*/
|
|
|
}
|
|
|
|
|
|
-void InsertService(CipClass * class, EipUint8 service_number,
|
|
|
- CipServiceFunction service_function, char *service_name) {
|
|
|
- int i;
|
|
|
- CipServiceStruct *p;
|
|
|
+void InsertService(const CipClass *const class, const EipUint8 service_number,
|
|
|
+ const CipServiceFunction service_function, char *const service_name) {
|
|
|
|
|
|
- p = class->services; /* get a pointer to the service array*/
|
|
|
- OPENER_ASSERT(p != 0);
|
|
|
+ CipServiceStruct *service = class->services; /* get a pointer to the service array*/
|
|
|
+ OPENER_ASSERT(service != 0);
|
|
|
/* adding a service to a class that was not declared to have services is not allowed*/
|
|
|
- for (i = 0; i < class->number_of_services; i++) /* Iterate over all service slots attached to the class */
|
|
|
+ for (int i = 0; i < class->number_of_services; i++) /* Iterate over all service slots attached to the class */
|
|
|
{
|
|
|
- if (p->service_number == service_number || p->service_function == NULL) /* found undefined service slot*/
|
|
|
+ if (service->service_number == service_number || service->service_function == NULL) /* found undefined service slot*/
|
|
|
{
|
|
|
- p->service_number = service_number; /* fill in service number*/
|
|
|
- p->service_function = service_function; /* fill in function address*/
|
|
|
- p->name = service_name;
|
|
|
+ service->service_number = service_number; /* fill in service number*/
|
|
|
+ service->service_function = service_function; /* fill in function address*/
|
|
|
+ service->name = service_name;
|
|
|
return;
|
|
|
}
|
|
|
- p++;
|
|
|
+ ++service;
|
|
|
}
|
|
|
OPENER_ASSERT(0);
|
|
|
/* adding more services than were declared is a no-no*/
|
|
|
}
|
|
|
|
|
|
-CipAttributeStruct *GetCipAttribute(CipInstance * instance,
|
|
|
- EipUint16 attribute_number) {
|
|
|
- int i;
|
|
|
+CipAttributeStruct *GetCipAttribute(const CipInstance *const instance,
|
|
|
+ const EipUint16 attribute_number) {
|
|
|
+
|
|
|
CipAttributeStruct *attribute = instance->attributes; /* init pointer to array of attributes*/
|
|
|
- for (i = 0; i < instance->cip_class->number_of_attributes; i++) {
|
|
|
+ for (int i = 0; i < instance->cip_class->number_of_attributes; i++) {
|
|
|
if (attribute_number == attribute->attribute_number)
|
|
|
return attribute;
|
|
|
else
|
|
|
- attribute++;
|
|
|
+ ++attribute;
|
|
|
}
|
|
|
|
|
|
OPENER_TRACE_WARN("attribute %d not defined\n", attribute_number);
|
|
|
|
|
|
- return 0;
|
|
|
+ return NULL;
|
|
|
}
|
|
|
|
|
|
/* TODO this needs to check for buffer overflow*/
|
|
|
-EipStatus GetAttributeSingle(CipInstance *instance,
|
|
|
- CipMessageRouterRequest *message_router_request,
|
|
|
- CipMessageRouterResponse *message_router_response) {
|
|
|
+EipStatus GetAttributeSingle(CipInstance *restrict const instance,
|
|
|
+ CipMessageRouterRequest *const message_router_request,
|
|
|
+ CipMessageRouterResponse *const message_router_response) {
|
|
|
/* Mask for filtering get-ability */
|
|
|
- EipByte get_mask;
|
|
|
+ EipByte get_mask = kNotSetOrGetable;
|
|
|
|
|
|
CipAttributeStruct *attribute = GetCipAttribute(
|
|
|
instance, message_router_request->request_path.attribute_number);
|
|
|
@@ -409,7 +398,7 @@ EipStatus GetAttributeSingle(CipInstance *instance,
|
|
|
return kEipStatusOkSend;
|
|
|
}
|
|
|
|
|
|
-int EncodeData(EipUint8 cip_type, void *data, EipUint8 **message) {
|
|
|
+int EncodeData(const EipUint8 cip_type, const void *const cip_data, EipUint8 **cip_message) {
|
|
|
int counter = 0;
|
|
|
|
|
|
switch (cip_type)
|
|
|
@@ -419,24 +408,20 @@ int EncodeData(EipUint8 cip_type, void *data, EipUint8 **message) {
|
|
|
case (kCipSint):
|
|
|
case (kCipUsint):
|
|
|
case (kCipByte):
|
|
|
- **message = *(EipUint8 *) (data);
|
|
|
- ++(*message);
|
|
|
- counter = 1;
|
|
|
+ counter = AddSintToMessage(*(EipUint8 *) (cip_data), cip_message);
|
|
|
break;
|
|
|
|
|
|
case (kCipInt):
|
|
|
case (kCipUint):
|
|
|
case (kCipWord):
|
|
|
- AddIntToMessage(*(EipUint16 *) (data), message);
|
|
|
- counter = 2;
|
|
|
+ counter = AddIntToMessage(*(EipUint16 *) (cip_data), cip_message);
|
|
|
break;
|
|
|
|
|
|
case (kCipDint):
|
|
|
case (kCipUdint):
|
|
|
case (kCipDword):
|
|
|
case (kCipReal):
|
|
|
- AddDintToMessage(*(EipUint32 *) (data), message);
|
|
|
- counter = 4;
|
|
|
+ counter = AddDintToMessage(*(EipUint32 *) (cip_data), cip_message);
|
|
|
break;
|
|
|
|
|
|
#ifdef OPENER_SUPPORT_64BIT_DATATYPES
|
|
|
@@ -444,8 +429,7 @@ int EncodeData(EipUint8 cip_type, void *data, EipUint8 **message) {
|
|
|
case (kCipUlint):
|
|
|
case (kCipLword):
|
|
|
case (kCipLreal):
|
|
|
- AddLintToMessage(*(EipUint64 *) (data), message);
|
|
|
- counter = 8;
|
|
|
+ counter = AddLintToMessage(*(EipUint64 *) (cip_data), cip_message);
|
|
|
break;
|
|
|
#endif
|
|
|
|
|
|
@@ -455,17 +439,17 @@ int EncodeData(EipUint8 cip_type, void *data, EipUint8 **message) {
|
|
|
case (kCipDateAndTime):
|
|
|
break;
|
|
|
case (kCipString): {
|
|
|
- CipString *string = (CipString *) data;
|
|
|
+ CipString *const string = (CipString *) cip_data;
|
|
|
|
|
|
- AddIntToMessage(*(EipUint16 *) &(string->length), message);
|
|
|
- memcpy(*message, string->string, string->length);
|
|
|
- *message += string->length;
|
|
|
+ AddIntToMessage(*(EipUint16 *) &(string->length), cip_message);
|
|
|
+ memcpy(*cip_message, string->string, string->length);
|
|
|
+ *cip_message += string->length;
|
|
|
|
|
|
counter = string->length + 2; /* we have a two byte length field */
|
|
|
if (counter & 0x01) {
|
|
|
/* we have an odd byte count */
|
|
|
- **message = 0;
|
|
|
- ++(*message);
|
|
|
+ **cip_message = 0;
|
|
|
+ ++(*cip_message);
|
|
|
counter++;
|
|
|
}
|
|
|
break;
|
|
|
@@ -478,13 +462,13 @@ int EncodeData(EipUint8 cip_type, void *data, EipUint8 **message) {
|
|
|
break;
|
|
|
|
|
|
case (kCipShortString): {
|
|
|
- CipShortString *short_string = (CipShortString *) data;
|
|
|
+ CipShortString *const short_string = (CipShortString *) cip_data;
|
|
|
|
|
|
- **message = short_string->length;
|
|
|
- ++(*message);
|
|
|
+ **cip_message = short_string->length;
|
|
|
+ ++(*cip_message);
|
|
|
|
|
|
- memcpy(*message, short_string->string, short_string->length);
|
|
|
- *message += short_string->length;
|
|
|
+ memcpy(*cip_message, short_string->string, short_string->length);
|
|
|
+ *cip_message += short_string->length;
|
|
|
|
|
|
counter = short_string->length + 1;
|
|
|
break;
|
|
|
@@ -494,19 +478,19 @@ int EncodeData(EipUint8 cip_type, void *data, EipUint8 **message) {
|
|
|
break;
|
|
|
|
|
|
case (kCipEpath):
|
|
|
- counter = EncodeEPath((CipEpath *) data, message);
|
|
|
+ counter = EncodeEPath((CipEpath *) cip_data, cip_message);
|
|
|
break;
|
|
|
|
|
|
case (kCipEngUnit):
|
|
|
break;
|
|
|
|
|
|
case (kCipUsintUsint): {
|
|
|
- CipRevision *revision = (CipRevision *) data;
|
|
|
+ CipRevision *revision = (CipRevision *) cip_data;
|
|
|
|
|
|
- **message = revision->major_revision;
|
|
|
- ++(*message);
|
|
|
- **message = revision->minor_revision;
|
|
|
- ++(*message);
|
|
|
+ **cip_message = revision->major_revision;
|
|
|
+ ++(*cip_message);
|
|
|
+ **cip_message = revision->minor_revision;
|
|
|
+ ++(*cip_message);
|
|
|
counter = 2;
|
|
|
break;
|
|
|
}
|
|
|
@@ -514,28 +498,27 @@ int EncodeData(EipUint8 cip_type, void *data, EipUint8 **message) {
|
|
|
case (kCipUdintUdintUdintUdintUdintString): {
|
|
|
/* TCP/IP attribute 5 */
|
|
|
CipTcpIpNetworkInterfaceConfiguration *tcp_ip_network_interface_configuration =
|
|
|
- (CipTcpIpNetworkInterfaceConfiguration *) data;
|
|
|
- AddDintToMessage(
|
|
|
- ntohl(tcp_ip_network_interface_configuration->ip_address), message);
|
|
|
- AddDintToMessage(
|
|
|
- ntohl(tcp_ip_network_interface_configuration->network_mask), message);
|
|
|
- AddDintToMessage(ntohl(tcp_ip_network_interface_configuration->gateway),
|
|
|
- message);
|
|
|
- AddDintToMessage(
|
|
|
- ntohl(tcp_ip_network_interface_configuration->name_server), message);
|
|
|
- AddDintToMessage(
|
|
|
+ (CipTcpIpNetworkInterfaceConfiguration *) cip_data;
|
|
|
+ counter += AddDintToMessage(
|
|
|
+ ntohl(tcp_ip_network_interface_configuration->ip_address), cip_message);
|
|
|
+ counter += AddDintToMessage(
|
|
|
+ ntohl(tcp_ip_network_interface_configuration->network_mask), cip_message);
|
|
|
+ counter += AddDintToMessage(ntohl(tcp_ip_network_interface_configuration->gateway),
|
|
|
+ cip_message);
|
|
|
+ counter += AddDintToMessage(
|
|
|
+ ntohl(tcp_ip_network_interface_configuration->name_server), cip_message);
|
|
|
+ counter += AddDintToMessage(
|
|
|
ntohl(tcp_ip_network_interface_configuration->name_server_2),
|
|
|
- message);
|
|
|
- counter = 20;
|
|
|
+ cip_message);
|
|
|
counter += EncodeData(
|
|
|
kCipString, &(tcp_ip_network_interface_configuration->domain_name),
|
|
|
- message);
|
|
|
+ cip_message);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case (kCip6Usint): {
|
|
|
- EipUint8 *p = (EipUint8 *) data;
|
|
|
- memcpy(*message, p, 6);
|
|
|
+ EipUint8 *p = (EipUint8 *) cip_data;
|
|
|
+ memcpy(*cip_message, p, 6);
|
|
|
counter = 6;
|
|
|
break;
|
|
|
}
|
|
|
@@ -544,25 +527,24 @@ int EncodeData(EipUint8 cip_type, void *data, EipUint8 **message) {
|
|
|
break;
|
|
|
|
|
|
case (kCipByteArray): {
|
|
|
- CipByteArray *cip_byte_array;
|
|
|
OPENER_TRACE_INFO(" -> get attribute byte array\r\n");
|
|
|
- cip_byte_array = (CipByteArray *) data;
|
|
|
- memcpy(*message, cip_byte_array->data, cip_byte_array->length);
|
|
|
- *message += cip_byte_array->length;
|
|
|
+ CipByteArray *cip_byte_array = (CipByteArray *) cip_data;
|
|
|
+ memcpy(*cip_message, cip_byte_array->data, cip_byte_array->length);
|
|
|
+ *cip_message += cip_byte_array->length;
|
|
|
counter = cip_byte_array->length;
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case (kInternalUint6): /* TODO for port class attribute 9, hopefully we can find a better way to do this*/
|
|
|
{
|
|
|
- EipUint16 *internal_unit16_6 = (EipUint16 *) data;
|
|
|
-
|
|
|
- AddIntToMessage(internal_unit16_6[0], message);
|
|
|
- AddIntToMessage(internal_unit16_6[1], message);
|
|
|
- AddIntToMessage(internal_unit16_6[2], message);
|
|
|
- AddIntToMessage(internal_unit16_6[3], message);
|
|
|
- AddIntToMessage(internal_unit16_6[4], message);
|
|
|
- AddIntToMessage(internal_unit16_6[5], message);
|
|
|
+ EipUint16 *internal_unit16_6 = (EipUint16 *) cip_data;
|
|
|
+
|
|
|
+ AddIntToMessage(internal_unit16_6[0], cip_message);
|
|
|
+ AddIntToMessage(internal_unit16_6[1], cip_message);
|
|
|
+ AddIntToMessage(internal_unit16_6[2], cip_message);
|
|
|
+ AddIntToMessage(internal_unit16_6[3], cip_message);
|
|
|
+ AddIntToMessage(internal_unit16_6[4], cip_message);
|
|
|
+ AddIntToMessage(internal_unit16_6[5], cip_message);
|
|
|
counter = 12;
|
|
|
break;
|
|
|
}
|
|
|
@@ -574,7 +556,7 @@ int EncodeData(EipUint8 cip_type, void *data, EipUint8 **message) {
|
|
|
return counter;
|
|
|
}
|
|
|
|
|
|
-int DecodeData(EipUint8 cip_type, void *data, EipUint8 **message) {
|
|
|
+int DecodeData(const EipUint8 cip_type, void *const data, const EipUint8 **const message) {
|
|
|
int number_of_decoded_bytes = -1;
|
|
|
|
|
|
switch (cip_type)
|
|
|
@@ -650,20 +632,16 @@ int DecodeData(EipUint8 cip_type, void *data, EipUint8 **message) {
|
|
|
EipStatus GetAttributeAll(CipInstance *instance,
|
|
|
CipMessageRouterRequest *message_router_request,
|
|
|
CipMessageRouterResponse *message_router_response) {
|
|
|
- int i, j;
|
|
|
- EipUint8 *reply;
|
|
|
- CipAttributeStruct *attribute;
|
|
|
- CipServiceStruct *service;
|
|
|
|
|
|
- reply = message_router_response->data; /* pointer into the reply */
|
|
|
- attribute = instance->attributes; /* pointer to list of attributes*/
|
|
|
- service = instance->cip_class->services; /* pointer to list of services*/
|
|
|
+ EipUint8 *reply = message_router_response->data; /* pointer into the reply */
|
|
|
+ CipAttributeStruct *attribute = instance->attributes; /* pointer to list of attributes*/
|
|
|
+ CipServiceStruct *service = instance->cip_class->services; /* pointer to list of services*/
|
|
|
|
|
|
if (instance->instance_number == 2) {
|
|
|
OPENER_TRACE_INFO("GetAttributeAll: instance number 2\n");
|
|
|
}
|
|
|
|
|
|
- for (i = 0; i < instance->cip_class->number_of_services; i++) /* hunt for the GET_ATTRIBUTE_SINGLE service*/
|
|
|
+ for (int i = 0; i < instance->cip_class->number_of_services; i++) /* hunt for the GET_ATTRIBUTE_SINGLE service*/
|
|
|
{
|
|
|
if (service->service_number == kGetAttributeSingle) /* found the service */
|
|
|
{
|
|
|
@@ -674,7 +652,7 @@ EipStatus GetAttributeAll(CipInstance *instance,
|
|
|
message_router_response->general_status = kCipErrorServiceNotSupported;
|
|
|
message_router_response->size_of_additional_status = 0;
|
|
|
} else {
|
|
|
- for (j = 0; j < instance->cip_class->number_of_attributes; j++) /* for each instance attribute of this class */
|
|
|
+ for (int j = 0; j < instance->cip_class->number_of_attributes; j++) /* for each instance attribute of this class */
|
|
|
{
|
|
|
int attrNum = attribute->attribute_number;
|
|
|
if (attrNum < 32
|
|
|
@@ -759,9 +737,9 @@ int EncodeEPath(CipEpath *epath, EipUint8 **message) {
|
|
|
return 2 + epath->path_size * 2; /* path size is in 16 bit chunks according to the specification */
|
|
|
}
|
|
|
|
|
|
-int DecodePaddedEPath(CipEpath *epath, EipUint8 **message) {
|
|
|
- unsigned int number_of_decoded_elements;
|
|
|
- EipUint8 *message_runner = *message;
|
|
|
+int DecodePaddedEPath(CipEpath *epath, const EipUint8 **message) {
|
|
|
+ unsigned int number_of_decoded_elements = 0;
|
|
|
+ const EipUint8 *message_runner = *message;
|
|
|
|
|
|
epath->path_size = *message_runner;
|
|
|
message_runner++;
|