|
|
@@ -44,40 +44,38 @@ EipStatus RegisterCipClass(CipClass *cip_class);
|
|
|
* @param message_router_request pointer to structure of MRRequest data item.
|
|
|
* @return kEipStatusOk on success. otherwise kEipStatusError
|
|
|
*/
|
|
|
-CipError CreateMessageRouterRequestStructure(
|
|
|
- const EipUint8 *data,
|
|
|
- EipInt16 data_length,
|
|
|
- CipMessageRouterRequest *message_router_request);
|
|
|
-
|
|
|
+CipError CreateMessageRouterRequestStructure(const EipUint8 *data,
|
|
|
+ EipInt16 data_length,
|
|
|
+ CipMessageRouterRequest *message_router_request);
|
|
|
|
|
|
void InitializeCipMessageRouterClass(CipClass *cip_class) {
|
|
|
|
|
|
CipClass *meta_class = cip_class->class_instance.cip_class;
|
|
|
|
|
|
InsertAttribute( (CipInstance *) cip_class, 1, kCipUint, EncodeCipUint, NULL,
|
|
|
- (void *) &cip_class->revision, kGetableSingleAndAll ); /* revision */
|
|
|
+ (void *) &cip_class->revision, kGetableSingleAndAll ); /* revision */
|
|
|
InsertAttribute( (CipInstance *) cip_class, 2, kCipUint, EncodeCipUint, NULL,
|
|
|
- (void *) &cip_class->number_of_instances,
|
|
|
- kGetableSingle ); /* largest instance number */
|
|
|
+ (void *) &cip_class->number_of_instances, kGetableSingle ); /* largest instance number */
|
|
|
InsertAttribute( (CipInstance *) cip_class, 3, kCipUint, EncodeCipUint, NULL,
|
|
|
- (void *) &cip_class->number_of_instances,
|
|
|
- kGetableSingle ); /* number of instances currently existing*/
|
|
|
+ (void *) &cip_class->number_of_instances, kGetableSingle ); /* number of instances currently existing*/
|
|
|
InsertAttribute( (CipInstance *) cip_class, 4, kCipUint, EncodeCipUint, NULL,
|
|
|
- (void *) &kCipUintZero,
|
|
|
- kGetableAll ); /* optional attribute list - default = 0 */
|
|
|
+ (void *) &kCipUintZero, kGetableAll ); /* optional attribute list - default = 0 */
|
|
|
InsertAttribute( (CipInstance *) cip_class, 5, kCipUint, EncodeCipUint, NULL,
|
|
|
- (void *) &kCipUintZero,
|
|
|
- kGetableAll ); /* optional service list - default = 0 */
|
|
|
+ (void *) &kCipUintZero, kGetableAll ); /* optional service list - default = 0 */
|
|
|
InsertAttribute( (CipInstance *) cip_class, 6, kCipUint, EncodeCipUint, NULL,
|
|
|
(void *) &meta_class->highest_attribute_number,
|
|
|
- kGetableSingleAndAll ); /* max class attribute number*/
|
|
|
+ kGetableSingleAndAll ); /* max class attribute number*/
|
|
|
InsertAttribute( (CipInstance *) cip_class, 7, kCipUint, EncodeCipUint, NULL,
|
|
|
(void *) &cip_class->highest_attribute_number,
|
|
|
- kGetableSingleAndAll ); /* max instance attribute number*/
|
|
|
-
|
|
|
- InsertService(meta_class, kGetAttributeAll, &GetAttributeAll,
|
|
|
- "GetAttributeAll"); /* bind instance services to the metaclass*/
|
|
|
- InsertService(meta_class, kGetAttributeSingle, &GetAttributeSingle,
|
|
|
+ kGetableSingleAndAll ); /* max instance attribute number*/
|
|
|
+
|
|
|
+ InsertService(meta_class,
|
|
|
+ kGetAttributeAll,
|
|
|
+ &GetAttributeAll,
|
|
|
+ "GetAttributeAll"); /* bind instance services to the metaclass*/
|
|
|
+ InsertService(meta_class,
|
|
|
+ kGetAttributeSingle,
|
|
|
+ &GetAttributeSingle,
|
|
|
"GetAttributeSingle");
|
|
|
}
|
|
|
|
|
|
@@ -94,10 +92,12 @@ EipStatus CipMessageRouterInit() {
|
|
|
"message router", /* class name */
|
|
|
1, /* # class revision*/
|
|
|
InitializeCipMessageRouterClass); /* # function pointer for initialization*/
|
|
|
- if (NULL == message_router) {
|
|
|
+ if(NULL == message_router) {
|
|
|
return kEipStatusError;
|
|
|
}
|
|
|
- InsertService(message_router, kGetAttributeSingle, &GetAttributeSingle,
|
|
|
+ InsertService(message_router,
|
|
|
+ kGetAttributeSingle,
|
|
|
+ &GetAttributeSingle,
|
|
|
"GetAttributeSingle");
|
|
|
|
|
|
/* reserved for future use -> set to zero */
|
|
|
@@ -114,10 +114,10 @@ EipStatus CipMessageRouterInit() {
|
|
|
CipMessageRouterObject *GetRegisteredObject(EipUint32 class_id) {
|
|
|
CipMessageRouterObject *object = g_first_object; /* get pointer to head of class registration list */
|
|
|
|
|
|
- while (NULL != object) /* for each entry in list*/
|
|
|
+ while(NULL != object) /* for each entry in list*/
|
|
|
{
|
|
|
OPENER_ASSERT(NULL != object->cip_class);
|
|
|
- if (object->cip_class->class_code == class_id) {
|
|
|
+ if(object->cip_class->class_code == class_id) {
|
|
|
return object; /* return registration node if it matches class ID*/
|
|
|
}
|
|
|
object = object->next;
|
|
|
@@ -129,7 +129,7 @@ CipClass *GetCipClass(const CipUdint class_code) {
|
|
|
CipMessageRouterObject *message_router_object =
|
|
|
GetRegisteredObject(class_code);
|
|
|
|
|
|
- if (message_router_object) {
|
|
|
+ if(message_router_object) {
|
|
|
return message_router_object->cip_class;
|
|
|
} else {
|
|
|
return NULL;
|
|
|
@@ -139,15 +139,15 @@ CipClass *GetCipClass(const CipUdint class_code) {
|
|
|
CipInstance *GetCipInstance(const CipClass *RESTRICT const cip_class,
|
|
|
const EipUint32 instance_number) {
|
|
|
|
|
|
- if (instance_number == 0) {
|
|
|
+ if(instance_number == 0) {
|
|
|
return (CipInstance *) cip_class; /* if the instance number is zero, return the class object itself*/
|
|
|
|
|
|
}
|
|
|
/* pointer to linked list of instances from the class object*/
|
|
|
- for (CipInstance *instance = cip_class->instances; instance; instance =
|
|
|
- instance->next) /* follow the list*/
|
|
|
+ for(CipInstance *instance = cip_class->instances; instance;
|
|
|
+ instance = instance->next) /* follow the list*/
|
|
|
{
|
|
|
- if (instance->instance_number == instance_number) {
|
|
|
+ if(instance->instance_number == instance_number) {
|
|
|
return instance; /* if the number matches, return the instance*/
|
|
|
}
|
|
|
}
|
|
|
@@ -158,13 +158,13 @@ CipInstance *GetCipInstance(const CipClass *RESTRICT const cip_class,
|
|
|
EipStatus RegisterCipClass(CipClass *cip_class) {
|
|
|
CipMessageRouterObject **message_router_object = &g_first_object;
|
|
|
|
|
|
- while (*message_router_object) {
|
|
|
+ while(*message_router_object) {
|
|
|
message_router_object = &(*message_router_object)->next; /* follow the list until p points to an empty link (list end)*/
|
|
|
|
|
|
}
|
|
|
- *message_router_object = (CipMessageRouterObject *) CipCalloc(
|
|
|
- 1, sizeof(CipMessageRouterObject) ); /* create a new node at the end of the list*/
|
|
|
- if (*message_router_object == 0) {
|
|
|
+ *message_router_object =
|
|
|
+ (CipMessageRouterObject *) CipCalloc(1, sizeof(CipMessageRouterObject) ); /* create a new node at the end of the list*/
|
|
|
+ if(*message_router_object == 0) {
|
|
|
return kEipStatusError; /* check for memory error*/
|
|
|
|
|
|
}
|
|
|
@@ -183,38 +183,35 @@ EipStatus NotifyMessageRouter(EipUint8 *data,
|
|
|
CipError status = kCipErrorSuccess;
|
|
|
|
|
|
OPENER_TRACE_INFO("NotifyMessageRouter: routing unconnected message\n");
|
|
|
- if ( kCipErrorSuccess
|
|
|
- != ( status = CreateMessageRouterRequestStructure(
|
|
|
- data, data_length, &g_message_router_request) ) ) { /* error from create MR structure*/
|
|
|
+ if(kCipErrorSuccess !=
|
|
|
+ (status =
|
|
|
+ CreateMessageRouterRequestStructure(data, data_length,
|
|
|
+ &g_message_router_request) ) ) { /* error from create MR structure*/
|
|
|
OPENER_TRACE_ERR(
|
|
|
"NotifyMessageRouter: error from createMRRequeststructure\n");
|
|
|
message_router_response->general_status = status;
|
|
|
message_router_response->size_of_additional_status = 0;
|
|
|
message_router_response->reserved = 0;
|
|
|
- message_router_response->reply_service = (0x80
|
|
|
- | g_message_router_request.
|
|
|
- service);
|
|
|
+ message_router_response->reply_service =
|
|
|
+ (0x80 | g_message_router_request.service);
|
|
|
} else {
|
|
|
/* forward request to appropriate Object if it is registered*/
|
|
|
CipMessageRouterObject *registered_object = GetRegisteredObject(
|
|
|
g_message_router_request.request_path.class_id);
|
|
|
- if (registered_object == 0) {
|
|
|
+ if(registered_object == 0) {
|
|
|
OPENER_TRACE_ERR(
|
|
|
"NotifyMessageRouter: sending CIP_ERROR_OBJECT_DOES_NOT_EXIST reply, class id 0x%x is not registered\n",
|
|
|
(unsigned ) g_message_router_request.request_path.class_id);
|
|
|
- message_router_response->general_status =
|
|
|
- kCipErrorPathDestinationUnknown; /*according to the test tool this should be the correct error flag instead of CIP_ERROR_OBJECT_DOES_NOT_EXIST;*/
|
|
|
+ message_router_response->general_status = kCipErrorPathDestinationUnknown; /*according to the test tool this should be the correct error flag instead of CIP_ERROR_OBJECT_DOES_NOT_EXIST;*/
|
|
|
message_router_response->size_of_additional_status = 0;
|
|
|
message_router_response->reserved = 0;
|
|
|
- message_router_response->reply_service = (0x80
|
|
|
- | g_message_router_request.
|
|
|
- service);
|
|
|
+ message_router_response->reply_service =
|
|
|
+ (0x80 | g_message_router_request.service);
|
|
|
} else {
|
|
|
/* call notify function from Object with ClassID (gMRRequest.RequestPath.ClassID)
|
|
|
object will or will not make an reply into gMRResponse*/
|
|
|
message_router_response->reserved = 0;
|
|
|
- OPENER_ASSERT(NULL != registered_object->cip_class);
|
|
|
- OPENER_TRACE_INFO(
|
|
|
+ OPENER_ASSERT(NULL != registered_object->cip_class); OPENER_TRACE_INFO(
|
|
|
"NotifyMessageRouter: calling notify function of class '%s'\n",
|
|
|
registered_object->cip_class->class_name);
|
|
|
eip_status = NotifyClass(registered_object->cip_class,
|
|
|
@@ -243,26 +240,26 @@ EipStatus NotifyMessageRouter(EipUint8 *data,
|
|
|
return eip_status;
|
|
|
}
|
|
|
|
|
|
-CipError CreateMessageRouterRequestStructure(
|
|
|
- const EipUint8 *data,
|
|
|
- EipInt16 data_length,
|
|
|
- CipMessageRouterRequest *message_router_request) {
|
|
|
+CipError CreateMessageRouterRequestStructure(const EipUint8 *data,
|
|
|
+ EipInt16 data_length,
|
|
|
+ CipMessageRouterRequest *message_router_request)
|
|
|
+{
|
|
|
|
|
|
message_router_request->service = *data;
|
|
|
data++;
|
|
|
data_length--;
|
|
|
|
|
|
- int number_of_decoded_bytes = DecodePaddedEPath(
|
|
|
- &(message_router_request->request_path), &data);
|
|
|
- if (number_of_decoded_bytes < 0) {
|
|
|
+ int number_of_decoded_bytes =
|
|
|
+ DecodePaddedEPath(&(message_router_request->request_path), &data);
|
|
|
+ if(number_of_decoded_bytes < 0) {
|
|
|
return kCipErrorPathSegmentError;
|
|
|
}
|
|
|
|
|
|
message_router_request->data = data;
|
|
|
- message_router_request->request_path_size = data_length
|
|
|
- - number_of_decoded_bytes;
|
|
|
+ message_router_request->request_data_size = data_length -
|
|
|
+ number_of_decoded_bytes;
|
|
|
|
|
|
- if (message_router_request->request_path_size < 0) {
|
|
|
+ if(message_router_request->request_data_size < 0) {
|
|
|
return kCipErrorPathSizeInvalid;
|
|
|
} else {
|
|
|
return kCipErrorSuccess;
|
|
|
@@ -275,15 +272,15 @@ void DeleteAllClasses(void) {
|
|
|
CipInstance *instance = NULL;
|
|
|
CipInstance *instance_to_delete = NULL;
|
|
|
|
|
|
- while (NULL != message_router_object) {
|
|
|
+ while(NULL != message_router_object) {
|
|
|
message_router_object_to_delete = message_router_object;
|
|
|
message_router_object = message_router_object->next;
|
|
|
|
|
|
instance = message_router_object_to_delete->cip_class->instances;
|
|
|
- while (NULL != instance) {
|
|
|
+ while(NULL != instance) {
|
|
|
instance_to_delete = instance;
|
|
|
instance = instance->next;
|
|
|
- if (message_router_object_to_delete->cip_class->number_of_attributes) /* if the class has instance attributes */
|
|
|
+ if(message_router_object_to_delete->cip_class->number_of_attributes) /* if the class has instance attributes */
|
|
|
{ /* then free storage for the attribute array */
|
|
|
CipFree(instance_to_delete->attributes);
|
|
|
}
|