Просмотр исходного кода

Fixes TCP/IP behavior

Several changes to fix TCP/IP object behavior

Signed-off-by: Martin Melik Merkumians <melik-merkumians@acin.tuwien.ac.at>
Martin Melik Merkumians 5 лет назад
Родитель
Сommit
ddfbff46d3

+ 9 - 7
source/src/cip/cipcommon.c

@@ -395,7 +395,7 @@ void InsertAttribute2(CipInstance *const instance,
         (cip_flags & kGetableSingle) ?
         1 << (attribute_number) % 8 : 0;
       cip_class->get_all_bit_mask[index] |=
-        (cip_flags & kGetableAll) ? 1 << (attribute_number) % 8 : 0;
+        (cip_flags & (kGetableAll | kGetableAllDummy)) ? 1 << (attribute_number) % 8 : 0;
       cip_class->set_bit_mask[index] |=
         ( (cip_flags & kSetable) ? 1 : 0 ) << ( (attribute_number) % 8 );
 
@@ -576,13 +576,15 @@ void EncodeCipString(const void *const data, ENIPMessage *const outgoing_message
     CipString *const string = (CipString *) data;
 
     AddIntToMessage(*(EipUint16 *) &(string->length), outgoing_message);
-    memcpy(outgoing_message->current_message_position, string->string, string->length);
-    outgoing_message->current_message_position += string->length;
-    outgoing_message->used_message_length += string->length;
+    if(0 != string->length) {
+      memcpy(outgoing_message->current_message_position, string->string, string->length);
+      outgoing_message->current_message_position += string->length;
+      outgoing_message->used_message_length += string->length;
 
-    if (outgoing_message->used_message_length & 0x01) {
-      /* we have an odd byte count */
-  	  AddSintToMessage(0, outgoing_message);
+      if (outgoing_message->used_message_length & 0x01) {
+        /* we have an odd byte count */
+  	    AddSintToMessage(0, outgoing_message);
+      }
     }
 }
 

+ 9 - 9
source/src/cip/cipmessagerouter.c

@@ -56,28 +56,28 @@ void InitializeCipMessageRouterClass(CipClass *cip_class) {
 
   CipClass *meta_class = cip_class->class_instance.cip_class;
 
-  InsertAttribute( (CipInstance *) cip_class, 1, kCipUint,
+  InsertAttribute2( (CipInstance *) cip_class, 1, kCipUint, EncodeCipUint,
                    (void *) &cip_class->revision, kGetableSingleAndAll );   /* revision */
-  InsertAttribute( (CipInstance *) cip_class, 2, kCipUint,
+  InsertAttribute2( (CipInstance *) cip_class, 2, kCipUint, EncodeCipUint,
                    (void *) &cip_class->number_of_instances,
                    kGetableSingle );                                       /*  largest instance number */
-  InsertAttribute( (CipInstance *) cip_class, 3, kCipUint,
+  InsertAttribute2( (CipInstance *) cip_class, 3, kCipUint, EncodeCipUint,
                    (void *) &cip_class->number_of_instances,
                    kGetableSingle );                                                           /* number of instances currently existing*/
-  InsertAttribute( (CipInstance *) cip_class, 4, kCipUint,
+  InsertAttribute2( (CipInstance *) cip_class, 4, kCipUint, EncodeCipUint,
                    (void *) &kCipUintZero,
                    kGetableAll );   /* optional attribute list - default = 0 */
-  InsertAttribute( (CipInstance *) cip_class, 5, kCipUint,
+  InsertAttribute2( (CipInstance *) cip_class, 5, kCipUint, EncodeCipUint,
                    (void *) &kCipUintZero,
                    kGetableAll ); /* optional service list - default = 0 */
-  InsertAttribute( (CipInstance *) cip_class, 6, kCipUint,
+  InsertAttribute2( (CipInstance *) cip_class, 6, kCipUint, EncodeCipUint,
                    (void *) &meta_class->highest_attribute_number,
                    kGetableSingleAndAll );                       /* max class attribute number*/
-  InsertAttribute( (CipInstance *) cip_class, 7, kCipUint,
+  InsertAttribute2( (CipInstance *) cip_class, 7, kCipUint, EncodeCipUint,
                    (void *) &cip_class->highest_attribute_number,
                    kGetableSingleAndAll );                       /* max instance attribute number*/
 
-  InsertService(meta_class, kGetAttributeAll, &GetAttributeAll,
+  InsertService(meta_class, kGetAttributeAll, &GetAttributeAll2,
                     "GetAttributeAll");                     /* bind instance services to the metaclass*/
   InsertService(meta_class, kGetAttributeSingle, &GetAttributeSingle,
                   "GetAttributeSingle");
@@ -86,7 +86,7 @@ void InitializeCipMessageRouterClass(CipClass *cip_class) {
 EipStatus CipMessageRouterInit() {
 
   CipClass *message_router = CreateCipClass(kCipMessageRouterClassCode, /* class code */
-                                            0, /* # of class attributes */
+                                            7, /* # of class attributes */
                                             7, /* # highest class attribute number */
                                             2, /* # of class services */
                                             0, /* # of instance attributes */

+ 11 - 8
source/src/cip/ciptcpipinterface.c

@@ -308,6 +308,8 @@ static bool IsIOConnectionActive(void)
 #endif /* defined (OPENER_TCPIP_IFACE_CFG_SETTABLE) && 0 != OPENER_TCPIP_IFACE_CFG_SETTABLE*/
 
 
+static CipUsint dummy_data_field = 0; /**< dummy data fiel to provide non-null data pointers for attributes without data fields */
+
 /************** Functions ****************************************/
 
 void EncoodeCipTcpIpInterfaceConfiguration(const void *const data, ENIPMessage *const outgoing_message) {
@@ -368,7 +370,7 @@ EipStatus SetAttributeSingleTcpIpInterface(
   EipUint16 attribute_number = message_router_request->request_path
                                .attribute_number;
 
-  if (NULL != attribute) {
+  if (NULL != attribute && !(kGetableAllDummy & attribute->attribute_flags)) {
     uint8_t set_bit_mask = (instance->cip_class->set_bit_mask[CalculateIndex(
                                                                 attribute_number)
                             ]);
@@ -564,7 +566,7 @@ EipStatus CipTcpIpInterfaceInit() {
                   kGetableSingleAndAll);
   InsertAttribute2(instance, 2, kCipDword, EncodeCipDword, &g_tcpip.config_capability,
                   kGetableSingleAndAll);
-  InsertAttribute2(instance, 3, kCipDword, EncodeCipDword, &g_tcpip.config_control,
+  InsertAttribute2(instance, 3 , kCipDword, EncodeCipDword, &g_tcpip.config_control,
                   kSetAndGetAble | kNvDataFunc | IFACE_CFG_SET_MODE );
   InsertAttribute2(instance, 4, kCipEpath, EncodeCipEPath, &g_tcpip.physical_link_object,
                   kGetableSingleAndAll);
@@ -573,17 +575,18 @@ EipStatus CipTcpIpInterfaceInit() {
                   kGetableSingleAndAll | kNvDataFunc | IFACE_CFG_SET_MODE);
   InsertAttribute2(instance, 6, kCipString, EncodeCipString, &g_tcpip.hostname,
                   kGetableSingleAndAll | kNvDataFunc | IFACE_CFG_SET_MODE);
-  InsertAttribute2(instance, 7, kCipAny, EncodeSafetyNetworkNumber, NULL,
-                    kGetableAll);
-
+  InsertAttribute2(instance, 7, kCipAny, EncodeSafetyNetworkNumber, &dummy_data_field,
+		  kGetableAllDummy);
   InsertAttribute2(instance, 8, kCipUsint, EncodeCipUsint, &g_tcpip.mcast_ttl_value,
                   kGetableSingleAndAll);
   InsertAttribute2(instance, 9, kCipAny, EncodeCipTcpIpMulticastConfiguration, &g_tcpip.mcast_config,
                   kGetableSingleAndAll);
   InsertAttribute2(instance, 10, kCipBool, EncodeCipBool, &g_tcpip.select_acd,
-                    kGetableSingleAndAll);
-  InsertAttribute2(instance, 11, kCipBool, EncodeCipLastConflictDetected, NULL,
-                      kGetableSingleAndAll);
+		  kGetableAllDummy);
+  InsertAttribute2(instance, 11, kCipBool, EncodeCipLastConflictDetected, &dummy_data_field,
+		  kGetableAllDummy);
+  InsertAttribute2(instance, 12, kCipBool, EncodeCipBool, &dummy_data_field,
+		  kGetableAllDummy);
   InsertAttribute2(instance,
                   13,
                   kCipUint,

+ 1 - 0
source/src/cip/ciptypes.h

@@ -113,6 +113,7 @@ typedef enum { /* TODO: Rework */
   kSetAndGetAble = 0x07, /**< both set and get-able */
   kGetableSingleAndAll = 0x03, /**< both single and all */
   /* Flags to control the usage of callbacks per attribute from the Get* and Set* services */
+  kGetableAllDummy = 0x08, /**< Get-able but a dummy Attribute */
   kPreGetFunc = 0x10, /**< enable pre get callback */
   kPostGetFunc = 0x20,  /**< enable post get callback */
   kPreSetFunc = 0x40, /**< enable pre set callback */

+ 1 - 0
source/src/enet_encap/cpf.c

@@ -525,6 +525,7 @@ void EncodeMessageRouterResponseData(
 //    AddSintToMessage( (message_router_response->message.message_buffer)[i], outgoing_message);
 //  }
   memcpy(outgoing_message->current_message_position, message_router_response->message.message_buffer, message_router_response->message.used_message_length);
+  outgoing_message->used_message_length += message_router_response->message.used_message_length;
 }
 
 /**

+ 2 - 1
source/src/enet_encap/encap.c

@@ -300,7 +300,8 @@ EipStatus HandleReceivedExplictUdpData
 }
 
 void SkipEncapsulationHeader(ENIPMessage *const outgoing_message) {
-  MoveMessageNOctets(ENCAPSULATION_HEADER_LENGTH, outgoing_message);
+  /* Move pointer over Header, but do not add to size */
+  outgoing_message->current_message_position += ENCAPSULATION_HEADER_LENGTH;
 }
 
 void GenerateEncapsulationHeader(const EncapsulationData *const receive_data,