Преглед изворни кода

Fixes wrong not enough data error

Signed-off-by: CapXilinx <melik-merkumians@acin.tuwien.ac.at>
CapXilinx пре 8 година
родитељ
комит
a1f99970e1

+ 3 - 1
source/src/cip/cipconnectionmanager.c

@@ -494,7 +494,7 @@ EipStatus ForwardOpen(
   bool is_matching_request = false; /* 1 = Matching Request, 0 = Non-Matching Request  */
 
   /*first check if we have already a connection with the given params */
-  ConnectionObjectInitializeFromMessage(message_router_request->data,
+  ConnectionObjectInitializeFromMessage(&(message_router_request->data),
                                      &g_dummy_connection_object);
 
   memcpy( &(g_dummy_connection_object.originator_address), originator_address,
@@ -1050,6 +1050,7 @@ EipUint8 ParseConnectionPath(
        > message_router_request->request_path_size ) {
     /*there is not enough data in received packet */
     *extended_error = 0;
+    OPENER_TRACE_INFO("Message not long enough for path\n");
     return kCipErrorNotEnoughData;
   }
 
@@ -1065,6 +1066,7 @@ EipUint8 ParseConnectionPath(
             /* Check if there is enough data for holding the electronic key segment */
             if (remaining_path < 5) {
               *extended_error = 0;
+              OPENER_TRACE_INFO("Message not long enough for electronic key\n");
               return kCipErrorNotEnoughData;
             }
             /* Electronic key format 4 found */

+ 15 - 15
source/src/cip/cipconnectionobject.c

@@ -95,20 +95,20 @@ CipConnectionObject *CipConnectionObjectCreate(const CipOctet *message) {
 }
 
 void ConnectionObjectInitializeFromMessage(
-  const CipOctet *message,
+  const CipOctet **message,
   CipConnectionObject *const connection_object) {
   /* For unconnected send - can be ignored by targets, and is ignored here */
-  CipByte priority_timetick = GetSintFromMessage(&message);
-  CipUsint timeout_ticks = GetSintFromMessage(&message);
+  CipByte priority_timetick = GetSintFromMessage(message);
+  CipUsint timeout_ticks = GetSintFromMessage(message);
 
   /* O_to_T Conn ID */
-  ConnectionObjectSetCipConsumedConnectionID(connection_object, GetDintFromMessage(&message));
+  ConnectionObjectSetCipConsumedConnectionID(connection_object, GetDintFromMessage(message));
   /* T_to_O Conn ID */
-  ConnectionObjectSetCipProducedConnectionID(connection_object, GetDintFromMessage(&message));
+  ConnectionObjectSetCipProducedConnectionID(connection_object, GetDintFromMessage(message));
 
-  ConnectionObjectSetConnectionSerialNumber(connection_object, GetIntFromMessage(&message));
-  ConnectionObjectSetOriginatorVendorId(connection_object, GetIntFromMessage(&message));
-  ConnectionObjectSetOriginatorSerialNumber(connection_object, GetDintFromMessage(&message));
+  ConnectionObjectSetConnectionSerialNumber(connection_object, GetIntFromMessage(message));
+  ConnectionObjectSetOriginatorVendorId(connection_object, GetIntFromMessage(message));
+  ConnectionObjectSetOriginatorSerialNumber(connection_object, GetDintFromMessage(message));
 
   /* keep it to none existent till the setup is done this eases error handling and
    * the state changes within the forward open request can not be detected from
@@ -118,9 +118,9 @@ void ConnectionObjectInitializeFromMessage(
   connection_object->sequence_count_producing = 0; /* set the sequence count to zero */
 
   ConnectionObjectSetConnectionTimeoutMultiplier(connection_object, GetSintFromMessage(
-    &message));
+    message));
 
-  MoveMessageNOctets(3, &message); /* 3 bytes reserved */
+  MoveMessageNOctets(3, message); /* 3 bytes reserved */
 
   /* the requested packet interval parameter needs to be a multiple of TIMERTICK from the header file */
   OPENER_TRACE_INFO(
@@ -131,21 +131,21 @@ void ConnectionObjectInitializeFromMessage(
     connection_object->connection_serial_number);
 
   ConnectionObjectSetOToTRequestedPacketInterval(connection_object, GetDintFromMessage(
-    &message));
+    message));
 
   ConnectionObjectSetInitialInactivityWatchdogTimerValue(connection_object);
 
   //TODO: introduce setter function
-  connection_object->o_to_t_network_connection_parameters = GetIntFromMessage(&message);
+  connection_object->o_to_t_network_connection_parameters = GetIntFromMessage(message);
 
-  connection_object->t_to_o_requested_packet_interval = GetDintFromMessage(&message);
+  connection_object->t_to_o_requested_packet_interval = GetDintFromMessage(message);
 
   ConnectionObjectSetExpectedPacketRate(connection_object,
       connection_object->t_to_o_requested_packet_interval);
 
-  connection_object->t_to_o_network_connection_parameters = GetIntFromMessage(&message);
+  connection_object->t_to_o_network_connection_parameters = GetIntFromMessage(message);
 
-  connection_object->transport_class_trigger = GetSintFromMessage(&message);
+  connection_object->transport_class_trigger = GetSintFromMessage(message);
 }
 
 ConnectionObjectState ConnectionObjectGetState(

+ 1 - 1
source/src/cip/cipconnectionobject.h

@@ -209,7 +209,7 @@ void ConnectionObjectInitializeEmpty(
   CipConnectionObject *const connection_object);
 
 void ConnectionObjectInitializeFromMessage(
-  const CipOctet *message,
+  const CipOctet **message,
   CipConnectionObject *const
   connection_object);
 

+ 1 - 0
source/src/cip/cipqos.c

@@ -69,6 +69,7 @@ EipStatus SetAttributeSingleQoS(
         message_router_response->general_status = kCipErrorSuccess;
       } else {
         message_router_response->general_status = kCipErrorNotEnoughData;
+        OPENER_TRACE_INFO("CIP QoS not enough data\n");
       }
     } else {
       message_router_response->general_status = kCipErrorInvalidAttributeValue;

+ 3 - 0
source/src/ports/POSIX/main.c

@@ -11,6 +11,8 @@
 #include "opener_api.h"
 #include "cipcommon.h"
 #include "trace.h"
+#include "doublylinkedlist.h"
+#include "cipconnectionobject.h"
 
 /******************************************************************************/
 /** @brief Signal handler function for ending stack execution
@@ -38,6 +40,7 @@ int main(int argc, char *arg[]) {
       "    e.g. ./OpENer 192.168.0.2 255.255.255.0 192.168.0.1 test.com testdevice 00 15 C5 BF D0 87\n");
     exit(0);
   } else {
+	  DoublyLinkedListInitialize(&connection_list, CipConnectionObjectListArrayAllocator, CipConnectionObjectListArrayFree);
     /* fetch Internet address info from the platform */
     ConfigureNetworkInterface(arg[1], arg[2], arg[3]);
     ConfigureDomainName(arg[4]);

+ 4 - 2
source/tests/cip/cipconnectionobjecttest.cpp

@@ -237,11 +237,13 @@ TEST(CipConnectionObject, ExpectedPacketRateZero) {
 
 TEST(CipConnectionObject, ParseConnectionData) {
   CipConnectionObject connection_object = { 0 };
-  CipOctet message[] = "\x06\x28\x00\x00\x00\x00\x00\x00\x00\x00\x98\xff\x18\x00\x78\x56" \
+  const CipOctet message[] = "\x06\x28\x00\x00\x00\x00\x00\x00\x00\x00\x98\xff\x18\x00\x78\x56" \
 "\x34\x12\x00\x00\x00\x00\xe0\x93\x04\x00\x02\x40\xa0\x86\x01\x00" \
 "\x22\x20\x01\x04\x20\x04\x24\x97\x2c\x98\x2c\x64";
 
-  ConnectionObjectInitializeFromMessage(message, &connection_object);
+  const CipOctet **message_runner = (const CipOctet **)&message;
+
+  ConnectionObjectInitializeFromMessage(message_runner, &connection_object);
   CipUdint o_to_t_network_connection_id = ConnectionObjectGetCipConsumedConnectionID(&connection_object);
   CHECK_EQUAL(0, o_to_t_network_connection_id);