瀏覽代碼

bugfix: decoding of NodeID

Leon Urbas 11 年之前
父節點
當前提交
b2c7dbf8f1
共有 4 個文件被更改,包括 43 次插入6 次删除
  1. 4 0
      src/opcua_binaryEncDec.c
  2. 30 1
      src/opcua_builtInDatatypes.c
  3. 7 2
      src/opcua_secureChannelLayer.c
  4. 2 3
      src/opcua_transportLayer.c

+ 4 - 0
src/opcua_binaryEncDec.c

@@ -810,6 +810,10 @@ Int32 UAByteString_calcSize(UA_ByteString *byteString)
 /* See 62541-6 §5.2.2.9 */
 Int32 decodeUANodeId(char const * buf, Int32 *pos, UA_NodeId *dstNodeId)
 {
+	// LU: Initialize dstNodeId to gain repeatable results
+	dstNodeId->Namespace = 0;
+	dstNodeId->Identifier.Numeric = 0;
+
 	decoder_decodeBuiltInDatatype(buf, BYTE, pos, &(dstNodeId->EncodingByte));
 
 	switch (dstNodeId->EncodingByte)

+ 30 - 1
src/opcua_builtInDatatypes.c

@@ -40,5 +40,34 @@ Int32 UA_ByteString_compare(UA_ByteString *string1,UA_ByteString *string2)
 }
 
 void UA_String_printf(char* label, UA_ByteString* string) {
-	printf("%s %.*s\n", label, string->Length, (char*) string->Data);
+	printf("%s {Length=%d, Data=%.*s}\n", label, string->Length, string->Length, (char*) string->Data);
 }
+
+void UA_NodeId_printf(char* label, UA_NodeId* node) {
+	printf("%s {EncodingByte=%d, Namespace=%d, ", label, (int) node->EncodingByte, (int) node->Namespace);
+	switch (node->EncodingByte)
+	{
+	case NIEVT_TWO_BYTE:
+	case NIEVT_FOUR_BYTE:
+	case NIEVT_NUMERIC:
+		printf("Identifier=%d", node->Identifier.Numeric);
+		break;
+	case NIEVT_STRING:
+	case NIEVT_BYTESTRING:
+		// TODO: This implementation does not distinguish between String and Bytestring. Error?
+		printf("Identifier={Length=%d, Data=%.*s}", node->Identifier.String.Length, node->Identifier.String.Length, (char*) (node->Identifier.String.Data));
+		break;
+	case NIEVT_GUID:
+		printf("guid={Data1=%d, Data2=%d, Data3=%d, Data4=={Length=%d, Data=%.*s}}",
+				node->Identifier.Guid.Data1,
+				node->Identifier.Guid.Data2,
+				node->Identifier.Guid.Data3,
+				node->Identifier.Guid.Data4.Length, node->Identifier.Guid.Data4.Length, (char*) (node->Identifier.Guid.Data4.Data));
+		break;
+	default:
+		printf("ups! shit happens");
+		break;
+	}
+	printf("}\n");
+}
+

+ 7 - 2
src/opcua_secureChannelLayer.c

@@ -82,12 +82,16 @@ Int32 SL_processMessage(UA_connection *connection, UA_ByteString message)
 	Int32 requestedLifetime;
 
 	decoder_decodeBuiltInDatatype(message.Data,NODE_ID,&pos,&ServiceRequestType);
+	UA_NodeId_printf("serviceRequestType=",&ServiceRequestType);
 
 	if(ServiceRequestType.EncodingByte == NIEVT_FOUR_BYTE)
 	{
 		if(ServiceRequestType.Identifier.Numeric == 446) // OpensecureChannelRequest
 		{
 			decoder_decodeRequestHeader(message.Data, &pos, &requestHeader);
+			UA_String_printf("requestHeader.auditEntryId=",&requestHeader.auditEntryId);
+			UA_NodeId_printf("requestHeader.authenticationToken=", &requestHeader.authenticationToken);
+
 			decoder_decodeBuiltInDatatype(message.Data,UINT32, &pos, &clientProtocolVersion);
 
 			if(clientProtocolVersion != connection->transportLayer.remoteConf.protocolVersion)
@@ -187,11 +191,9 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage)
 
 		case packetType_OPN : /* openSecureChannel Message received */
 				decodeAASHeader(&secureChannelPacket,&pos,&AAS_Header);
-#if DEBUG
 				UA_String_printf("AAS_Header.ReceiverThumbprint=", &(AAS_Header.ReceiverThumbprint));
 				UA_String_printf("AAS_Header.SecurityPolicyUri=", &(AAS_Header.SecurityPolicyUri));
 				UA_String_printf("AAS_Header.SenderCertificate=", &(AAS_Header.SenderCertificate));
-#endif
 				if(SCM_Header.SecureChannelId != 0)
 				{
 
@@ -205,6 +207,9 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage)
 				}
 
 				decodeSequenceHeader(&secureChannelPacket,&pos,&SequenceHeader);
+				printf("SequenceHeader.RequestId=%d\n",SequenceHeader.RequestId);
+				printf("SequenceHeader.SequenceNr=%d\n",SequenceHeader.SequenceNumber);
+
 				//TODO check that the sequence number is smaller than MaxUInt32 - 1024
 				connection->secureLayer.sequenceNumber = SequenceHeader.SequenceNumber;
 

+ 2 - 3
src/opcua_transportLayer.c

@@ -118,9 +118,8 @@ Int32 TL_receive(UA_connection *connection, UA_ByteString *packet)
 Int32 TL_getPacketType(UA_ByteString *packet, Int32 *pos)
 {
 	Int32 retVal = -1;
-	printf("TL_getPacketType - entered \n");
-	printf("TL_getPacketType - pos = %d \n",*pos);
-	//printf(packet->Data[*pos]);
+	// printf("TL_getPacketType - entered \n");
+	// printf("TL_getPacketType - pos = %d \n",*pos);
 
 	if(packet->Data[*pos] == 'H' &&
 	   packet->Data[*pos+1] == 'E' &&