|
|
@@ -28,9 +28,9 @@
|
|
|
#include "appcontype.h"
|
|
|
#include "cipepath.h"
|
|
|
#include "stdlib.h"
|
|
|
+#include "ciptypes.h"
|
|
|
|
|
|
/* private functions*/
|
|
|
-void EncodeEPath(CipEpath *epath, ENIPMessage *message);
|
|
|
|
|
|
EipStatus CipStackInit(const EipUint16 unique_connection_id) {
|
|
|
/* The message router is the first CIP object be initialized!!! */
|
|
|
@@ -560,6 +560,7 @@ void EncodeCipByteArray(const CipByteArray *const data, ENIPMessage *const outgo
|
|
|
}
|
|
|
|
|
|
void EncodeCipEPath(const CipEpath *const data, ENIPMessage *const outgoing_message) {
|
|
|
+ AddIntToMessage(data->path_size, outgoing_message);
|
|
|
EncodeEPath((CipEpath*) data, outgoing_message);
|
|
|
}
|
|
|
|
|
|
@@ -905,10 +906,85 @@ EipStatus GetAttributeList(CipInstance *instance,
|
|
|
return kEipStatusOkSend;
|
|
|
}
|
|
|
|
|
|
-void EncodeEPath(CipEpath *epath, ENIPMessage *message) {
|
|
|
+EipStatus SetAttributeList(CipInstance *instance,
|
|
|
+ CipMessageRouterRequest *message_router_request,
|
|
|
+ CipMessageRouterResponse *message_router_response,
|
|
|
+ const struct sockaddr *originator_address,
|
|
|
+ const int encapsulation_session) {
|
|
|
+
|
|
|
+ InitializeENIPMessage(&message_router_response->message);
|
|
|
+ message_router_response->reply_service = (0x80
|
|
|
+ | message_router_request->service);
|
|
|
+ message_router_response->general_status = kCipErrorSuccess;
|
|
|
+ message_router_response->size_of_additional_status = 0;
|
|
|
+
|
|
|
+ CipUint attribute_count_request = GetUintFromMessage(
|
|
|
+ &message_router_request->data);
|
|
|
+
|
|
|
+ if (0 != attribute_count_request) {
|
|
|
+
|
|
|
+ EipUint16 attribute_number = 0;
|
|
|
+ CipAttributeStruct *attribute = NULL;
|
|
|
+
|
|
|
+ AddIntToMessage(attribute_count_request,
|
|
|
+ &message_router_response->message); // number of attributes in the response
|
|
|
+
|
|
|
+ for (size_t j = 0; j < attribute_count_request; j++) {
|
|
|
+
|
|
|
+ attribute_number = GetUintFromMessage(
|
|
|
+ &message_router_request->data);
|
|
|
+ attribute = GetCipAttribute(instance, attribute_number);
|
|
|
+
|
|
|
+ AddIntToMessage(attribute_number,
|
|
|
+ &message_router_response->message); // Attribute-ID
|
|
|
+
|
|
|
+ if (NULL != attribute) {
|
|
|
+
|
|
|
+ uint8_t set_bit_mask =
|
|
|
+ (instance->cip_class->set_bit_mask[CalculateIndex(
|
|
|
+ attribute_number)]);
|
|
|
+ if (0 != (set_bit_mask & (1 << (attribute_number % 8)))) { //check if attribute is settable
|
|
|
+ AddSintToMessage(kCipErrorSuccess,
|
|
|
+ &message_router_response->message); // Attribute status
|
|
|
+ AddSintToMessage(0, &message_router_response->message); // Reserved, shall be 0
|
|
|
+ attribute->decode(attribute->data, message_router_request,
|
|
|
+ message_router_response); // write data to attribute
|
|
|
+ } else {
|
|
|
+ AddSintToMessage(kCipErrorAttributeNotSetable,
|
|
|
+ &message_router_response->message); // Attribute status
|
|
|
+ AddSintToMessage(0, &message_router_response->message); // Reserved, shall be 0
|
|
|
+
|
|
|
+ //move request message pointer
|
|
|
+ int attribute_data_length = GetCipDataTypeLength(
|
|
|
+ attribute->type, message_router_request->data);
|
|
|
+ if (0 != attribute_data_length) {
|
|
|
+ message_router_request->data += attribute_data_length;
|
|
|
+ message_router_response->general_status =
|
|
|
+ kCipErrorAttributeListError;
|
|
|
+ } else {
|
|
|
+ message_router_response->general_status =
|
|
|
+ kCipErrorPartialTransfer;
|
|
|
+ return kEipStatusOkSend;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ AddSintToMessage(kCipErrorAttributeNotSupported,
|
|
|
+ &message_router_response->message); // status
|
|
|
+ AddSintToMessage(0, &message_router_response->message); // Reserved, shall be 0
|
|
|
+ message_router_response->general_status =
|
|
|
+ kCipErrorAttributeListError;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ message_router_response->general_status = kCipErrorAttributeListError;
|
|
|
+ }
|
|
|
+
|
|
|
+ return kEipStatusOkSend;
|
|
|
+}
|
|
|
+
|
|
|
+void EncodeEPath(const CipEpath *const epath, ENIPMessage *const message) {
|
|
|
unsigned int length = epath->path_size;
|
|
|
size_t start_length = message->used_message_length;
|
|
|
- AddIntToMessage(epath->path_size, message);
|
|
|
|
|
|
if(epath->class_id < 256) {
|
|
|
AddSintToMessage(0x20, message); /* 8 Bit Class Id */
|
|
|
@@ -947,7 +1023,7 @@ void EncodeEPath(CipEpath *epath, ENIPMessage *message) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- OPENER_ASSERT(2 + epath->path_size * 2 == message->used_message_length - start_length); /* path size is in 16 bit chunks according to the specification */
|
|
|
+ OPENER_ASSERT(epath->path_size * 2 == message->used_message_length - start_length); /* path size is in 16 bit chunks according to the specification */
|
|
|
}
|
|
|
|
|
|
int DecodePaddedEPath(CipEpath *epath, const EipUint8 **message) {
|