Browse Source

added functionality to decode and encode packets (just structures + enc/dec..)

FlorianPalm 11 years ago
parent
commit
fe6cde5cca

+ 38 - 10
src/Makefile.am

@@ -1,5 +1,5 @@
 #optimization levels depending on debug
-AM_CFLAGS = $(GLOBAL_AM_CFLAGS) -I$(top_builddir)/include
+AM_CFLAGS = $(GLOBAL_AM_CFLAGS) -I$(top_builddir)/include -I$(top_builddir)/src -I. -I$(top_builddir)/src/util
 
 
 TOOL_DIR = ../tool
@@ -22,21 +22,49 @@ TOOL_DIR = ../tool
 #					  opcua_connectionHelper.h	
 lib_LTLIBRARIES = libopen62541.la
 libopen62541_la_LDFLAGS = -avoid-version -no-undefined
-libopen62541_la_SOURCES = 			opcua.c\
+#libopen62541_la_SOURCES = 			opcua.c\
+#						opcua_basictypes.c\
+#						opcua_namespace_0.c\
+#						opcua_transportLayer.c\
+#						opcua_secureLayer.c\
+#						tcp_layer.c\
+#						opcua_transportLayer.h\
+#						opcua_connectionHelper.h\
+#						opcua_encodingLayer.h\
+#						opcua_secureLayer.h\
+#						tcp_layer.h\
+#						util/UA_list.c\
+#						util/UA_indexedList.c\
+#						UA_stackInternalTypes.c\
+#						opcua_namespace.h\
+#						opcua_namespace.c
+						
+#libopen62541_ladir = $(top_builddir)/include . $(top_builddir)/src . $(top_builddir)/src/util					
+
+#libopen62541_la_HEADERS = opcua.h\
+#						opcua_basictypes.h\
+#						opcua_namespace.h\
+#						opcua_transportLayer.h\
+#						opcua_connectionHelper.h\
+#						opcua_encodingLayer.h\
+#						opcua_secureLayer.h\
+#						opcua_namespace.h\
+#						UA_connection.h\
+#						UA_stackInternalTypes.h\
+#						UA_list.h\
+#						UA_indexedList.h
+						
+libopen62541_la_SOURCES = opcua.c\
 						opcua_basictypes.c\
 						opcua_namespace_0.c\
+						UA_stackInternalTypes.c\
 						opcua_transportLayer.c\
-						opcua_secureChannelLayer.c\
-						tcp_layer.c\
-						opcua_transportLayer.h\
-						opcua_connectionHelper.h\
-						opcua_encodingLayer.h\
-						opcua_secureChannelLayer.h\
-						tcp_layer.h\
+						opcua_secureLayer.c\
 						util/UA_list.c\
 						util/UA_indexedList.c\
-						opcua_namespace.h\
 						opcua_namespace.c
+						
+						
 
 #bin_PROGRAMS= $(top_builddir)/bin/open62541.out
 #__top_builddir__bin_libOpen62541_out_SOURCES = opcuaServer.c

+ 6 - 6
src/UA_connection.h

@@ -11,12 +11,12 @@
 
 enum packetType
 {
-	packetType_HEL = 1,
-	packetType_ACK = 2,
-	packetType_ERR = 3,
-	packetType_OPN = 4,
-	packetType_MSG = 5,
-	packetType_CLO = 6
+	UA_MESSAGETYPE_HEL = 0x48454C, // H E L
+	UA_MESSAGETYPE_ACK = 0x41434B, // A C k
+	UA_MESSAGETYPE_ERR = 0x455151, // E R R
+	UA_MESSAGETYPE_OPN = 0x4F504E, // O P N
+	UA_MESSAGETYPE_MSG = 0x4D5347, // M S G
+	UA_MESSAGETYPE_CLO = 0x434C4F  // C L O
 };
 enum connectionState
 {

+ 372 - 0
src/UA_stackInternalTypes.c

@@ -0,0 +1,372 @@
+/*
+ * opcua_stackInternalTypes.c
+ *
+ *  Created on: Mar 24, 2014
+ *      Author: opcua
+ */
+
+
+#include "UA_stackInternalTypes.h"
+UA_Int32 UA_MessageType_calcSize(UA_MessageType const * ptr){
+	if(ptr==UA_NULL){return sizeof(UA_MessageType);}
+	return 0
+	 + 3 * sizeof(UA_Byte);
+}
+
+UA_Int32 UA_MessageType_encode(UA_MessageType const * src, UA_Int32* pos, char* dst){
+	UA_Int32 retval = UA_SUCCESS;
+	UA_Byte *tmpBuf;
+	tmpBuf = (UA_Byte*)&(src); //messageType to Byte representation
+	retval |= UA_Byte_encode(&(tmpBuf[0]),pos,dst);
+	retval |= UA_Byte_encode(&(tmpBuf[1]),pos,dst);
+	retval |= UA_Byte_encode(&(tmpBuf[2]),pos,dst);
+	return retval;
+}
+
+UA_Int32 UA_MessageType_decode(char const * src, UA_Int32* pos, UA_MessageType* dst){
+	UA_Int32 retval = UA_SUCCESS;
+	UA_Byte tmpBuf[3];
+	retval |= UA_Byte_decode(src,pos,&(tmpBuf[0]));//messageType to Byte representation
+	retval |= UA_Byte_decode(src,pos,&(tmpBuf[1]));
+	retval |= UA_Byte_decode(src,pos,&(tmpBuf[2]));
+	*dst = (UA_MessageType)((UA_Int32)(tmpBuf[0]<<16) + (UA_Int32)(tmpBuf[1]<<8) + (UA_Int32)(tmpBuf[2]));
+	return retval;
+}
+UA_TYPE_METHOD_DELETE_FREE(UA_MessageType)
+UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_MessageType)
+
+UA_Int32 UA_OPCUATcpMessageHeader_calcSize(UA_OPCUATcpMessageHeader const * ptr) {
+	if(ptr==UA_NULL){return sizeof(UA_OPCUATcpMessageHeader);}
+	return 0
+	 + UA_MessageType_calcSize(&(ptr->messageType))
+	 + sizeof(UA_Byte) // isFinal
+	 + sizeof(UA_UInt32) // messageSize
+	;
+}
+
+UA_Int32 UA_OPCUATcpMessageHeader_encode(UA_OPCUATcpMessageHeader const * src, UA_Int32* pos, char* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_MessageType_encode(&(src->messageType),pos,dst);
+	retval |= UA_Byte_encode(&(src->isFinal),pos,dst);
+	retval |= UA_UInt32_encode(&(src->messageSize),pos,dst);
+	return retval;
+}
+
+UA_Int32 UA_OPCUATcpMessageHeader_decode(char const * src, UA_Int32* pos, UA_OPCUATcpMessageHeader* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_MessageType_decode(src,pos,&(dst->messageType));
+	retval |= UA_Byte_decode(src,pos,&(dst->isFinal));
+	retval |= UA_UInt32_decode(src,pos,&(dst->messageSize));
+	return retval;
+}
+
+UA_Int32 UA_OPCUATcpMessageHeader_delete(UA_OPCUATcpMessageHeader* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_OPCUATcpMessageHeader_deleteMembers(p);
+	retval |= UA_free(p);
+	return retval;
+    }
+UA_Int32 UA_OPCUATcpMessageHeader_deleteMembers(UA_OPCUATcpMessageHeader* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	return retval;
+}
+
+UA_Int32 UA_OPCUATcpHelloMessage_calcSize(UA_OPCUATcpHelloMessage const * ptr) {
+	if(ptr==UA_NULL){return sizeof(UA_OPCUATcpHelloMessage);}
+	return 0
+	 + sizeof(UA_UInt32) // protocolVersion
+	 + sizeof(UA_UInt32) // receiveBufferSize
+	 + sizeof(UA_UInt32) // sendBufferSize
+	 + sizeof(UA_UInt32) // maxMessageSize
+	 + sizeof(UA_UInt32) // maxChunkCount
+	 + UA_String_calcSize(&(ptr->endpointUrl))
+	;
+}
+
+UA_Int32 UA_OPCUATcpHelloMessage_encode(UA_OPCUATcpHelloMessage const * src, UA_Int32* pos, char* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_UInt32_encode(&(src->protocolVersion),pos,dst);
+	retval |= UA_UInt32_encode(&(src->receiveBufferSize),pos,dst);
+	retval |= UA_UInt32_encode(&(src->sendBufferSize),pos,dst);
+	retval |= UA_UInt32_encode(&(src->maxMessageSize),pos,dst);
+	retval |= UA_UInt32_encode(&(src->maxChunkCount),pos,dst);
+	retval |= UA_String_encode(&(src->endpointUrl),pos,dst);
+	return retval;
+}
+
+UA_Int32 UA_OPCUATcpHelloMessage_decode(char const * src, UA_Int32* pos, UA_OPCUATcpHelloMessage* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_UInt32_decode(src,pos,&(dst->protocolVersion));
+	retval |= UA_UInt32_decode(src,pos,&(dst->receiveBufferSize));
+	retval |= UA_UInt32_decode(src,pos,&(dst->sendBufferSize));
+	retval |= UA_UInt32_decode(src,pos,&(dst->maxMessageSize));
+	retval |= UA_UInt32_decode(src,pos,&(dst->maxChunkCount));
+	retval |= UA_String_decode(src,pos,&(dst->endpointUrl));
+	return retval;
+}
+
+UA_Int32 UA_OPCUATcpHelloMessage_delete(UA_OPCUATcpHelloMessage* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_OPCUATcpHelloMessage_deleteMembers(p);
+	retval |= UA_free(p);
+	return retval;
+    }
+UA_Int32 UA_OPCUATcpHelloMessage_deleteMembers(UA_OPCUATcpHelloMessage* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_String_deleteMembers(&(p->endpointUrl));
+	return retval;
+}
+
+UA_Int32 UA_OPCUATcpAcknowledgeMessage_calcSize(UA_OPCUATcpAcknowledgeMessage const * ptr) {
+	if(ptr==UA_NULL){return sizeof(UA_OPCUATcpAcknowledgeMessage);}
+	return 0
+	 + sizeof(UA_UInt32) // protocolVersion
+	 + sizeof(UA_UInt32) // receiveBufferSize
+	 + sizeof(UA_UInt32) // sendBufferSize
+	 + sizeof(UA_UInt32) // maxMessageSize
+	 + sizeof(UA_UInt32) // maxChunkCount
+	;
+}
+
+UA_Int32 UA_OPCUATcpAcknowledgeMessage_encode(UA_OPCUATcpAcknowledgeMessage const * src, UA_Int32* pos, char* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_UInt32_encode(&(src->protocolVersion),pos,dst);
+	retval |= UA_UInt32_encode(&(src->receiveBufferSize),pos,dst);
+	retval |= UA_UInt32_encode(&(src->sendBufferSize),pos,dst);
+	retval |= UA_UInt32_encode(&(src->maxMessageSize),pos,dst);
+	retval |= UA_UInt32_encode(&(src->maxChunkCount),pos,dst);
+	return retval;
+}
+
+UA_Int32 UA_OPCUATcpAcknowledgeMessage_decode(char const * src, UA_Int32* pos, UA_OPCUATcpAcknowledgeMessage* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_UInt32_decode(src,pos,&(dst->protocolVersion));
+	retval |= UA_UInt32_decode(src,pos,&(dst->receiveBufferSize));
+	retval |= UA_UInt32_decode(src,pos,&(dst->sendBufferSize));
+	retval |= UA_UInt32_decode(src,pos,&(dst->maxMessageSize));
+	retval |= UA_UInt32_decode(src,pos,&(dst->maxChunkCount));
+	return retval;
+}
+
+UA_Int32 UA_OPCUATcpAcknowledgeMessage_delete(UA_OPCUATcpAcknowledgeMessage* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_OPCUATcpAcknowledgeMessage_deleteMembers(p);
+	retval |= UA_free(p);
+	return retval;
+    }
+UA_Int32 UA_OPCUATcpAcknowledgeMessage_deleteMembers(UA_OPCUATcpAcknowledgeMessage* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	return retval;
+}
+
+UA_Int32 UA_SecureConversationMessageHeader_calcSize(UA_SecureConversationMessageHeader const * ptr) {
+	if(ptr==UA_NULL){return sizeof(UA_SecureConversationMessageHeader);}
+	return 0
+	 + UA_OPCUATcpMessageHeader_calcSize(ptr->tcpMessageHeader)
+	 + sizeof(UA_UInt32) // secureChannelId
+	;
+}
+
+UA_Int32 UA_SecureConversationMessageHeader_encode(UA_SecureConversationMessageHeader const * src, UA_Int32* pos, char* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_OPCUATcpMessageHeader_encode(src->tcpMessageHeader,pos,dst);
+	retval |= UA_UInt32_encode(&(src->secureChannelId),pos,dst);
+	return retval;
+}
+
+UA_Int32 UA_SecureConversationMessageHeader_decode(char const * src, UA_Int32* pos, UA_SecureConversationMessageHeader* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_alloc((void**)&(dst->tcpMessageHeader),UA_OPCUATcpMessageHeader_calcSize(UA_NULL));
+	retval |= UA_OPCUATcpMessageHeader_decode(src,pos,dst->tcpMessageHeader);
+	retval |= UA_UInt32_decode(src,pos,&(dst->secureChannelId));
+	return retval;
+}
+
+UA_Int32 UA_SecureConversationMessageHeader_delete(UA_SecureConversationMessageHeader* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_SecureConversationMessageHeader_deleteMembers(p);
+	retval |= UA_free(p);
+	return retval;
+    }
+UA_Int32 UA_SecureConversationMessageHeader_deleteMembers(UA_SecureConversationMessageHeader* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_OPCUATcpMessageHeader_delete(p->tcpMessageHeader);
+	return retval;
+}
+
+UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_calcSize(UA_AsymmetricAlgorithmSecurityHeader const * ptr) {
+	if(ptr==UA_NULL){return sizeof(UA_AsymmetricAlgorithmSecurityHeader);}
+	return 0
+	 + UA_ByteString_calcSize(&(ptr->securityPolicyUri))
+	 + UA_ByteString_calcSize(&(ptr->senderCertificate))
+	 + UA_ByteString_calcSize(&(ptr->receiverCertificateThumbprint))
+	 + sizeof(UA_UInt32) // requestId
+	;
+}
+
+UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_encode(UA_AsymmetricAlgorithmSecurityHeader const * src, UA_Int32* pos, char* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_ByteString_encode(&(src->securityPolicyUri),pos,dst);
+	retval |= UA_ByteString_encode(&(src->senderCertificate),pos,dst);
+	retval |= UA_ByteString_encode(&(src->receiverCertificateThumbprint),pos,dst);
+	retval |= UA_UInt32_encode(&(src->requestId),pos,dst);
+	return retval;
+}
+
+UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_decode(char const * src, UA_Int32* pos, UA_AsymmetricAlgorithmSecurityHeader* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_ByteString_decode(src,pos,&(dst->securityPolicyUri));
+	retval |= UA_ByteString_decode(src,pos,&(dst->senderCertificate));
+	retval |= UA_ByteString_decode(src,pos,&(dst->receiverCertificateThumbprint));
+	retval |= UA_UInt32_decode(src,pos,&(dst->requestId));
+	return retval;
+}
+
+UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_delete(UA_AsymmetricAlgorithmSecurityHeader* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(p);
+	retval |= UA_free(p);
+	return retval;
+    }
+UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(UA_AsymmetricAlgorithmSecurityHeader* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_ByteString_deleteMembers(&(p->securityPolicyUri));
+	retval |= UA_ByteString_deleteMembers(&(p->senderCertificate));
+	retval |= UA_ByteString_deleteMembers(&(p->receiverCertificateThumbprint));
+	return retval;
+}
+
+UA_Int32 UA_SymmetricAlgorithmSecurityHeader_calcSize(UA_SymmetricAlgorithmSecurityHeader const * ptr) {
+	if(ptr==UA_NULL){return sizeof(UA_SymmetricAlgorithmSecurityHeader);}
+	return 0
+	 + sizeof(UA_UInt32) // tokenId
+	;
+}
+
+UA_Int32 UA_SymmetricAlgorithmSecurityHeader_encode(UA_SymmetricAlgorithmSecurityHeader const * src, UA_Int32* pos, char* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_UInt32_encode(&(src->tokenId),pos,dst);
+	return retval;
+}
+
+UA_Int32 UA_SymmetricAlgorithmSecurityHeader_decode(char const * src, UA_Int32* pos, UA_SymmetricAlgorithmSecurityHeader* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_UInt32_decode(src,pos,&(dst->tokenId));
+	return retval;
+}
+
+UA_Int32 UA_SymmetricAlgorithmSecurityHeader_delete(UA_SymmetricAlgorithmSecurityHeader* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_SymmetricAlgorithmSecurityHeader_deleteMembers(p);
+	retval |= UA_free(p);
+	return retval;
+    }
+UA_Int32 UA_SymmetricAlgorithmSecurityHeader_deleteMembers(UA_SymmetricAlgorithmSecurityHeader* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	return retval;
+}
+
+UA_Int32 UA_SequenceHeader_calcSize(UA_SequenceHeader const * ptr) {
+	if(ptr==UA_NULL){return sizeof(UA_SequenceHeader);}
+	return 0
+	 + sizeof(UA_UInt32) // sequenceNumber
+	 + sizeof(UA_UInt32) // requestId
+	;
+}
+
+UA_Int32 UA_SequenceHeader_encode(UA_SequenceHeader const * src, UA_Int32* pos, char* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_UInt32_encode(&(src->sequenceNumber),pos,dst);
+	retval |= UA_UInt32_encode(&(src->requestId),pos,dst);
+	return retval;
+}
+
+UA_Int32 UA_SequenceHeader_decode(char const * src, UA_Int32* pos, UA_SequenceHeader* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_UInt32_decode(src,pos,&(dst->sequenceNumber));
+	retval |= UA_UInt32_decode(src,pos,&(dst->requestId));
+	return retval;
+}
+
+UA_Int32 UA_SequenceHeader_delete(UA_SequenceHeader* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_SequenceHeader_deleteMembers(p);
+	retval |= UA_free(p);
+	return retval;
+    }
+UA_Int32 UA_SequenceHeader_deleteMembers(UA_SequenceHeader* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	return retval;
+}
+
+UA_Int32 UA_SecureConversationMessageFooter_calcSize(UA_SecureConversationMessageFooter const * ptr) {
+	if(ptr==UA_NULL){return sizeof(UA_SecureConversationMessageFooter);}
+	return 0
+	 + 0 //paddingSize is included in UA_Array_calcSize
+	 + UA_Array_calcSize(ptr->paddingSize, UA_BYTE, (void const**) ptr->padding)
+	 + sizeof(UA_Byte) // signature
+	;
+}
+
+UA_Int32 UA_SecureConversationMessageFooter_encode(UA_SecureConversationMessageFooter const * src, UA_Int32* pos, char* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_Int32_encode(&(src->paddingSize),pos,dst); // encode size
+	retval |= UA_Array_encode((void const**) (src->padding),src->paddingSize, UA_BYTE,pos,dst);
+	retval |= UA_Byte_encode(&(src->signature),pos,dst);
+	return retval;
+}
+
+UA_Int32 UA_SecureConversationMessageFooter_decode(char const * src, UA_Int32* pos, UA_SecureConversationMessageFooter* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_Int32_decode(src,pos,&(dst->paddingSize)); // decode size
+	retval |= UA_alloc((void**)&(dst->padding),dst->paddingSize*sizeof(void*));
+	retval |= UA_Array_decode(src,dst->paddingSize, UA_BYTE,pos,(void const**) (dst->padding));
+	retval |= UA_Byte_decode(src,pos,&(dst->signature));
+	return retval;
+}
+
+UA_Int32 UA_SecureConversationMessageFooter_delete(UA_SecureConversationMessageFooter* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_SecureConversationMessageFooter_deleteMembers(p);
+	retval |= UA_free(p);
+	return retval;
+    }
+UA_Int32 UA_SecureConversationMessageFooter_deleteMembers(UA_SecureConversationMessageFooter* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_Array_delete(p->padding,p->paddingSize);
+	return retval;
+}
+
+UA_Int32 UA_SecureConversationMessageAbortBody_calcSize(UA_SecureConversationMessageAbortBody const * ptr) {
+	if(ptr==UA_NULL){return sizeof(UA_SecureConversationMessageAbortBody);}
+	return 0
+	 + sizeof(UA_UInt32) // error
+	 + UA_String_calcSize(&(ptr->reason))
+	;
+}
+
+UA_Int32 UA_SecureConversationMessageAbortBody_encode(UA_SecureConversationMessageAbortBody const * src, UA_Int32* pos, char* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_UInt32_encode(&(src->error),pos,dst);
+	retval |= UA_String_encode(&(src->reason),pos,dst);
+	return retval;
+}
+
+UA_Int32 UA_SecureConversationMessageAbortBody_decode(char const * src, UA_Int32* pos, UA_SecureConversationMessageAbortBody* dst) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_UInt32_decode(src,pos,&(dst->error));
+	retval |= UA_String_decode(src,pos,&(dst->reason));
+	return retval;
+}
+
+UA_Int32 UA_SecureConversationMessageAbortBody_delete(UA_SecureConversationMessageAbortBody* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_SecureConversationMessageAbortBody_deleteMembers(p);
+	retval |= UA_free(p);
+	return retval;
+    }
+UA_Int32 UA_SecureConversationMessageAbortBody_deleteMembers(UA_SecureConversationMessageAbortBody* p) {
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_String_deleteMembers(&(p->reason));
+	return retval;
+}

+ 36 - 28
src/opcua_secureChannelLayer.h

@@ -1,16 +1,18 @@
 /*
- * opcua_secureChannelLayer.h
+ * opcua_stackInternalTypes.h
  *
- *  Created on: Dec 19, 2013
+ *  Created on: Mar 24, 2014
  *      Author: opcua
  */
 
-#ifndef OPCUA_SECURECHANNELLAYER_H_
-#define OPCUA_SECURECHANNELLAYER_H_
 
+#ifndef OPCUA_STACKINTERNALTYPES_H_
+#define OPCUA_STACKINTERNALTYPES_H_
+
+#include "UA_config.h"
 #include "opcua.h"
 #include "UA_connection.h"
-#include "../include/UA_config.h"
+
 
 static const UA_Int32 SL_HEADER_LENGTH = 0;
 /* Enums */
@@ -36,17 +38,27 @@ typedef struct T_SL_Response
 }UA_SL_Response;
 UA_TYPE_METHOD_PROTOTYPES(UA_SL_Response)
 
+/* MessageType */
+typedef UA_Int32 UA_MessageType;
+UA_Int32 UA_MessageType_calcSize(UA_MessageType const * ptr);
+UA_Int32 UA_MessageType_encode(UA_MessageType const * src, UA_Int32* pos, char* dst);
+UA_Int32 UA_MessageType_decode(char const * src, UA_Int32* pos, UA_MessageType* dst);
+UA_Int32 UA_MessageType_delete(UA_MessageType* p);
+UA_Int32 UA_MessageType_deleteMembers(UA_MessageType* p);
+
 
 /*** UA_OPCUATcpMessageHeader ***/
 /* TCP Header */
 typedef struct T_UA_OPCUATcpMessageHeader {
-	UA_UInt32 messageType;
+	UA_MessageType messageType;
 	UA_Byte isFinal;
 	UA_UInt32 messageSize;
 } UA_OPCUATcpMessageHeader;
 UA_Int32 UA_OPCUATcpMessageHeader_calcSize(UA_OPCUATcpMessageHeader const * ptr);
 UA_Int32 UA_OPCUATcpMessageHeader_encode(UA_OPCUATcpMessageHeader const * src, UA_Int32* pos, char* dst);
 UA_Int32 UA_OPCUATcpMessageHeader_decode(char const * src, UA_Int32* pos, UA_OPCUATcpMessageHeader* dst);
+UA_Int32 UA_OPCUATcpMessageHeader_delete(UA_OPCUATcpMessageHeader* p);
+UA_Int32 UA_OPCUATcpMessageHeader_deleteMembers(UA_OPCUATcpMessageHeader* p);
 
 /*** UA_OPCUATcpHelloMessage ***/
 /* Hello Message */
@@ -61,6 +73,8 @@ typedef struct T_UA_OPCUATcpHelloMessage {
 UA_Int32 UA_OPCUATcpHelloMessage_calcSize(UA_OPCUATcpHelloMessage const * ptr);
 UA_Int32 UA_OPCUATcpHelloMessage_encode(UA_OPCUATcpHelloMessage const * src, UA_Int32* pos, char* dst);
 UA_Int32 UA_OPCUATcpHelloMessage_decode(char const * src, UA_Int32* pos, UA_OPCUATcpHelloMessage* dst);
+UA_Int32 UA_OPCUATcpHelloMessage_delete(UA_OPCUATcpHelloMessage* p);
+UA_Int32 UA_OPCUATcpHelloMessage_deleteMembers(UA_OPCUATcpHelloMessage* p);
 
 /*** UA_OPCUATcpAcknowledgeMessage ***/
 /* Acknowledge Message */
@@ -74,18 +88,20 @@ typedef struct T_UA_OPCUATcpAcknowledgeMessage {
 UA_Int32 UA_OPCUATcpAcknowledgeMessage_calcSize(UA_OPCUATcpAcknowledgeMessage const * ptr);
 UA_Int32 UA_OPCUATcpAcknowledgeMessage_encode(UA_OPCUATcpAcknowledgeMessage const * src, UA_Int32* pos, char* dst);
 UA_Int32 UA_OPCUATcpAcknowledgeMessage_decode(char const * src, UA_Int32* pos, UA_OPCUATcpAcknowledgeMessage* dst);
+UA_Int32 UA_OPCUATcpAcknowledgeMessage_delete(UA_OPCUATcpAcknowledgeMessage* p);
+UA_Int32 UA_OPCUATcpAcknowledgeMessage_deleteMembers(UA_OPCUATcpAcknowledgeMessage* p);
 
 /*** UA_SecureConversationMessageHeader ***/
 /* Secure Layer Sequence Header */
 typedef struct T_UA_SecureConversationMessageHeader {
-	UA_UInt32 messageType;
-	UA_Byte isFinal;
-	UA_UInt32 messageSize;
+	UA_OPCUATcpMessageHeader* tcpMessageHeader;
 	UA_UInt32 secureChannelId;
 } UA_SecureConversationMessageHeader;
 UA_Int32 UA_SecureConversationMessageHeader_calcSize(UA_SecureConversationMessageHeader const * ptr);
 UA_Int32 UA_SecureConversationMessageHeader_encode(UA_SecureConversationMessageHeader const * src, UA_Int32* pos, char* dst);
 UA_Int32 UA_SecureConversationMessageHeader_decode(char const * src, UA_Int32* pos, UA_SecureConversationMessageHeader* dst);
+UA_Int32 UA_SecureConversationMessageHeader_delete(UA_SecureConversationMessageHeader* p);
+UA_Int32 UA_SecureConversationMessageHeader_deleteMembers(UA_SecureConversationMessageHeader* p);
 
 /*** UA_AsymmetricAlgorithmSecurityHeader ***/
 /* Security Header> */
@@ -98,6 +114,8 @@ typedef struct T_UA_AsymmetricAlgorithmSecurityHeader {
 UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_calcSize(UA_AsymmetricAlgorithmSecurityHeader const * ptr);
 UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_encode(UA_AsymmetricAlgorithmSecurityHeader const * src, UA_Int32* pos, char* dst);
 UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_decode(char const * src, UA_Int32* pos, UA_AsymmetricAlgorithmSecurityHeader* dst);
+UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_delete(UA_AsymmetricAlgorithmSecurityHeader* p);
+UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(UA_AsymmetricAlgorithmSecurityHeader* p);
 
 /*** UA_SymmetricAlgorithmSecurityHeader ***/
 /* Secure Layer Symmetric Algorithm Header */
@@ -107,6 +125,8 @@ typedef struct T_UA_SymmetricAlgorithmSecurityHeader {
 UA_Int32 UA_SymmetricAlgorithmSecurityHeader_calcSize(UA_SymmetricAlgorithmSecurityHeader const * ptr);
 UA_Int32 UA_SymmetricAlgorithmSecurityHeader_encode(UA_SymmetricAlgorithmSecurityHeader const * src, UA_Int32* pos, char* dst);
 UA_Int32 UA_SymmetricAlgorithmSecurityHeader_decode(char const * src, UA_Int32* pos, UA_SymmetricAlgorithmSecurityHeader* dst);
+UA_Int32 UA_SymmetricAlgorithmSecurityHeader_delete(UA_SymmetricAlgorithmSecurityHeader* p);
+UA_Int32 UA_SymmetricAlgorithmSecurityHeader_deleteMembers(UA_SymmetricAlgorithmSecurityHeader* p);
 
 /*** UA_SequenceHeader ***/
 /* Secure Layer Sequence Header */
@@ -117,6 +137,8 @@ typedef struct T_UA_SequenceHeader {
 UA_Int32 UA_SequenceHeader_calcSize(UA_SequenceHeader const * ptr);
 UA_Int32 UA_SequenceHeader_encode(UA_SequenceHeader const * src, UA_Int32* pos, char* dst);
 UA_Int32 UA_SequenceHeader_decode(char const * src, UA_Int32* pos, UA_SequenceHeader* dst);
+UA_Int32 UA_SequenceHeader_delete(UA_SequenceHeader* p);
+UA_Int32 UA_SequenceHeader_deleteMembers(UA_SequenceHeader* p);
 
 /*** UA_SecureConversationMessageFooter ***/
 /* Secure Conversation Message Footer */
@@ -128,6 +150,8 @@ typedef struct T_UA_SecureConversationMessageFooter {
 UA_Int32 UA_SecureConversationMessageFooter_calcSize(UA_SecureConversationMessageFooter const * ptr);
 UA_Int32 UA_SecureConversationMessageFooter_encode(UA_SecureConversationMessageFooter const * src, UA_Int32* pos, char* dst);
 UA_Int32 UA_SecureConversationMessageFooter_decode(char const * src, UA_Int32* pos, UA_SecureConversationMessageFooter* dst);
+UA_Int32 UA_SecureConversationMessageFooter_delete(UA_SecureConversationMessageFooter* p);
+UA_Int32 UA_SecureConversationMessageFooter_deleteMembers(UA_SecureConversationMessageFooter* p);
 
 /*** UA_SecureConversationMessageAbortBody ***/
 /* Secure Conversation Message Abort Body */
@@ -138,24 +162,8 @@ typedef struct T_UA_SecureConversationMessageAbortBody {
 UA_Int32 UA_SecureConversationMessageAbortBody_calcSize(UA_SecureConversationMessageAbortBody const * ptr);
 UA_Int32 UA_SecureConversationMessageAbortBody_encode(UA_SecureConversationMessageAbortBody const * src, UA_Int32* pos, char* dst);
 UA_Int32 UA_SecureConversationMessageAbortBody_decode(char const * src, UA_Int32* pos, UA_SecureConversationMessageAbortBody* dst);
+UA_Int32 UA_SecureConversationMessageAbortBody_delete(UA_SecureConversationMessageAbortBody* p);
+UA_Int32 UA_SecureConversationMessageAbortBody_deleteMembers(UA_SecureConversationMessageAbortBody* p);
 
-/**
- *
- * @param connection
- * @return
- */
-UA_Int32 SL_initConnectionObject(UA_connection *connection);
-
-/**
- *
- * @param connection
- * @param response
- * @param sizeInOut
- * @return
- */
-UA_Int32 SL_openSecureChannel_responseMessage_get(UA_connection *connection,
-		UA_SL_Response *response, UA_Int32* sizeInOut);
-
-void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage);
 
-#endif /* OPCUA_SECURECHANNELLAYER_H_ */
+#endif

+ 6 - 280
src/opcua_secureChannelLayer.c

@@ -7,7 +7,7 @@
 #include <stdio.h>
 #include <memory.h> // memcpy
 #include "opcua_transportLayer.h"
-#include "opcua_secureChannelLayer.h"
+#include "opcua_secureLayer.h"
 
 #define SIZE_SECURECHANNEL_HEADER 12
 #define SIZE_SEQHEADER_HEADER 8
@@ -470,7 +470,6 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage) {
 	UA_SecureConversationMessageHeader secureConvHeader;
 	UA_AsymmetricAlgorithmSecurityHeader asymAlgSecHeader;
 	UA_SequenceHeader sequenceHeader;
-	UA_Int32 packetType = 0;
 	UA_Int32 pos = 0;
 	UA_Int32 iTmp;
 	//TODO Error Handling, length checking
@@ -482,13 +481,13 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage) {
 	if (secureChannelPacket.length > 0 && secureChannelPacket.data != NULL) {
 
 		printf("SL_receive - data received \n");
-		packetType = TL_getPacketType(&secureChannelPacket, &pos);
+		//packetType = TL_getPacketType(&secureChannelPacket, &pos);
 
 		UA_SecureConversationMessageHeader_decode(secureChannelPacket.data, &pos, &secureConvHeader);
 
-		switch (secureConvHeader.messageType) {
+		switch (secureConvHeader.tcpMessageHeader->messageType) {
 
-		case packetType_OPN: /* openSecureChannel Message received */
+		case UA_MESSAGETYPE_OPN: /* openSecureChannel Message received */
 			UA_AsymmetricAlgorithmSecurityHeader_encode(secureChannelPacket.data, &pos, &asymAlgSecHeader);
 			UA_ByteString_printf("SL_receive - AAS_Header.ReceiverThumbprint=",
 					&(asymAlgSecHeader.receiverCertificateThumbprint));
@@ -531,7 +530,7 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage) {
 			SL_processMessage(connection, message);
 
 			break;
-		case packetType_MSG: /* secure Channel Message received */
+		case UA_MESSAGETYPE_MSG: /* secure Channel Message received */
 			if (connection->secureLayer.connectionState
 					== connectionState_ESTABLISHED) {
 
@@ -544,7 +543,7 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage) {
 			}
 
 			break;
-		case packetType_CLO: /* closeSecureChannel Message received */
+		case UA_MESSAGETYPE_CLO: /* closeSecureChannel Message received */
 			if (SL_check(connection, secureChannelPacket) == UA_NO_ERROR) {
 
 			}
@@ -616,276 +615,3 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage) {
 }
 
 
-UA_Int32 UA_OPCUATcpMessageHeader_calcSize(UA_OPCUATcpMessageHeader const * ptr) {
-	return 0
-	 + sizeof(UA_UInt32) // messageType
-	 + sizeof(UA_Byte) // isFinal
-	 + sizeof(UA_UInt32) // messageSize
-	;
-}
-
-UA_Int32 UA_OPCUATcpMessageHeader_encode(UA_OPCUATcpMessageHeader const * src, UA_Int32* pos, char* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_encode(&(src->messageType),pos,dst);
-	retval |= UA_Byte_encode(&(src->isFinal),pos,dst);
-	retval |= UA_UInt32_encode(&(src->messageSize),pos,dst);
-	return retval;
-}
-
-UA_Int32 UA_OPCUATcpMessageHeader_decode(char const * src, UA_Int32* pos, UA_OPCUATcpMessageHeader* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_decode(src,pos,&(dst->messageType));
-	retval |= UA_Byte_decode(src,pos,&(dst->isFinal));
-	retval |= UA_UInt32_decode(src,pos,&(dst->messageSize));
-	return retval;
-}
-
-UA_Int32 UA_OPCUATcpHelloMessage_calcSize(UA_OPCUATcpHelloMessage const * ptr) {
-	return 0
-	 + sizeof(UA_UInt32) // protocolVersion
-	 + sizeof(UA_UInt32) // receiveBufferSize
-	 + sizeof(UA_UInt32) // sendBufferSize
-	 + sizeof(UA_UInt32) // maxMessageSize
-	 + sizeof(UA_UInt32) // maxChunkCount
-	 + UA_String_calcSize(&(ptr->endpointUrl))
-	;
-}
-
-UA_Int32 UA_OPCUATcpHelloMessage_encode(UA_OPCUATcpHelloMessage const * src, UA_Int32* pos, char* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_encode(&(src->protocolVersion),pos,dst);
-	retval |= UA_UInt32_encode(&(src->receiveBufferSize),pos,dst);
-	retval |= UA_UInt32_encode(&(src->sendBufferSize),pos,dst);
-	retval |= UA_UInt32_encode(&(src->maxMessageSize),pos,dst);
-	retval |= UA_UInt32_encode(&(src->maxChunkCount),pos,dst);
-	retval |= UA_String_encode(&(src->endpointUrl),pos,dst);
-	return retval;
-}
-
-UA_Int32 UA_OPCUATcpHelloMessage_decode(char const * src, UA_Int32* pos, UA_OPCUATcpHelloMessage* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_decode(src,pos,&(dst->protocolVersion));
-	retval |= UA_UInt32_decode(src,pos,&(dst->receiveBufferSize));
-	retval |= UA_UInt32_decode(src,pos,&(dst->sendBufferSize));
-	retval |= UA_UInt32_decode(src,pos,&(dst->maxMessageSize));
-	retval |= UA_UInt32_decode(src,pos,&(dst->maxChunkCount));
-	retval |= UA_String_decode(src,pos,&(dst->endpointUrl));
-	return retval;
-}
-
-UA_Int32 UA_OPCUATcpAcknowledgeMessage_calcSize(UA_OPCUATcpAcknowledgeMessage const * ptr) {
-	return 0
-	 + sizeof(UA_UInt32) // protocolVersion
-	 + sizeof(UA_UInt32) // receiveBufferSize
-	 + sizeof(UA_UInt32) // sendBufferSize
-	 + sizeof(UA_UInt32) // maxMessageSize
-	 + sizeof(UA_UInt32) // maxChunkCount
-	;
-}
-
-UA_Int32 UA_OPCUATcpAcknowledgeMessage_encode(UA_OPCUATcpAcknowledgeMessage const * src, UA_Int32* pos, char* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_encode(&(src->protocolVersion),pos,dst);
-	retval |= UA_UInt32_encode(&(src->receiveBufferSize),pos,dst);
-	retval |= UA_UInt32_encode(&(src->sendBufferSize),pos,dst);
-	retval |= UA_UInt32_encode(&(src->maxMessageSize),pos,dst);
-	retval |= UA_UInt32_encode(&(src->maxChunkCount),pos,dst);
-	return retval;
-}
-
-UA_Int32 UA_OPCUATcpAcknowledgeMessage_decode(char const * src, UA_Int32* pos, UA_OPCUATcpAcknowledgeMessage* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_decode(src,pos,&(dst->protocolVersion));
-	retval |= UA_UInt32_decode(src,pos,&(dst->receiveBufferSize));
-	retval |= UA_UInt32_decode(src,pos,&(dst->sendBufferSize));
-	retval |= UA_UInt32_decode(src,pos,&(dst->maxMessageSize));
-	retval |= UA_UInt32_decode(src,pos,&(dst->maxChunkCount));
-	return retval;
-}
-
-UA_Int32 UA_SecureConversationMessageHeader_calcSize(UA_SecureConversationMessageHeader const * ptr) {
-	return 0
-	 + sizeof(UA_UInt32) // messageType
-	 + sizeof(UA_Byte) // isFinal
-	 + sizeof(UA_UInt32) // messageSize
-	 + sizeof(UA_UInt32) // secureChannelId
-	;
-}
-
-UA_Int32 UA_SecureConversationMessageHeader_encode(UA_SecureConversationMessageHeader const * src, UA_Int32* pos, char* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_encode(&(src->messageType),pos,dst);
-	retval |= UA_Byte_encode(&(src->isFinal),pos,dst);
-	retval |= UA_UInt32_encode(&(src->messageSize),pos,dst);
-	retval |= UA_UInt32_encode(&(src->secureChannelId),pos,dst);
-	return retval;
-}
-
-UA_Int32 UA_SecureConversationMessageHeader_decode(char const * src, UA_Int32* pos, UA_SecureConversationMessageHeader* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_decode(src,pos,&(dst->messageType));
-	retval |= UA_Byte_decode(src,pos,&(dst->isFinal));
-	retval |= UA_UInt32_decode(src,pos,&(dst->messageSize));
-	retval |= UA_UInt32_decode(src,pos,&(dst->secureChannelId));
-	return retval;
-}
-
-UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_calcSize(UA_AsymmetricAlgorithmSecurityHeader const * ptr) {
-	return 0
-	 + UA_ByteString_calcSize(&(ptr->securityPolicyUri))
-	 + UA_ByteString_calcSize(&(ptr->senderCertificate))
-	 + UA_ByteString_calcSize(&(ptr->receiverCertificateThumbprint))
-	 + sizeof(UA_UInt32) // requestId
-	;
-}
-
-UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_encode(UA_AsymmetricAlgorithmSecurityHeader const * src, UA_Int32* pos, char* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_ByteString_encode(&(src->securityPolicyUri),pos,dst);
-	retval |= UA_ByteString_encode(&(src->senderCertificate),pos,dst);
-	retval |= UA_ByteString_encode(&(src->receiverCertificateThumbprint),pos,dst);
-	retval |= UA_UInt32_encode(&(src->requestId),pos,dst);
-	return retval;
-}
-
-UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_decode(char const * src, UA_Int32* pos, UA_AsymmetricAlgorithmSecurityHeader* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_ByteString_decode(src,pos,&(dst->securityPolicyUri));
-	retval |= UA_ByteString_decode(src,pos,&(dst->senderCertificate));
-	retval |= UA_ByteString_decode(src,pos,&(dst->receiverCertificateThumbprint));
-	retval |= UA_UInt32_decode(src,pos,&(dst->requestId));
-	return retval;
-}
-
-UA_Int32 UA_SymmetricAlgorithmSecurityHeader_calcSize(UA_SymmetricAlgorithmSecurityHeader const * ptr) {
-	return 0
-	 + sizeof(UA_UInt32) // tokenId
-	;
-}
-
-UA_Int32 UA_SymmetricAlgorithmSecurityHeader_encode(UA_SymmetricAlgorithmSecurityHeader const * src, UA_Int32* pos, char* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_encode(&(src->tokenId),pos,dst);
-	return retval;
-}
-
-UA_Int32 UA_SymmetricAlgorithmSecurityHeader_decode(char const * src, UA_Int32* pos, UA_SymmetricAlgorithmSecurityHeader* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_decode(src,pos,&(dst->tokenId));
-	return retval;
-}
-
-UA_Int32 UA_SequenceHeader_calcSize(UA_SequenceHeader const * ptr) {
-	return 0
-	 + sizeof(UA_UInt32) // sequenceNumber
-	 + sizeof(UA_UInt32) // requestId
-	;
-}
-
-UA_Int32 UA_SequenceHeader_encode(UA_SequenceHeader const * src, UA_Int32* pos, char* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_encode(&(src->sequenceNumber),pos,dst);
-	retval |= UA_UInt32_encode(&(src->requestId),pos,dst);
-	return retval;
-}
-
-UA_Int32 UA_SequenceHeader_decode(char const * src, UA_Int32* pos, UA_SequenceHeader* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_decode(src,pos,&(dst->sequenceNumber));
-	retval |= UA_UInt32_decode(src,pos,&(dst->requestId));
-	return retval;
-}
-
-UA_Int32 UA_SecureConversationMessageFooter_calcSize(UA_SecureConversationMessageFooter const * ptr) {
-	return 0
-	 + 0 //paddingSize is included in UA_Array_calcSize
-	 + UA_Array_calcSize(ptr->paddingSize, UA_BYTE, (void const**) ptr->padding)
-	 + sizeof(UA_Byte) // signature
-	;
-}
-
-UA_Int32 UA_SecureConversationMessageFooter_encode(UA_SecureConversationMessageFooter const * src, UA_Int32* pos, char* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_Int32_encode(&(src->paddingSize),pos,dst); // encode size
-	retval |= UA_Array_encode((void const**) (src->padding),src->paddingSize, UA_BYTE,pos,dst);
-	retval |= UA_Byte_encode(&(src->signature),pos,dst);
-	return retval;
-}
-
-UA_Int32 UA_SecureConversationMessageFooter_decode(char const * src, UA_Int32* pos, UA_SecureConversationMessageFooter* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_Int32_decode(src,pos,&(dst->paddingSize)); // decode size
-	retval |= UA_Array_decode(src,dst->paddingSize, UA_BYTE,pos,(void const**) (dst->padding));
-	retval |= UA_Byte_decode(src,pos,&(dst->signature));
-	return retval;
-}
-
-UA_Int32 UA_SecureConversationMessageAbortBody_calcSize(UA_SecureConversationMessageAbortBody const * ptr) {
-	return 0
-	 + sizeof(UA_UInt32) // error
-	 + UA_String_calcSize(&(ptr->reason))
-	;
-}
-
-UA_Int32 UA_SecureConversationMessageAbortBody_encode(UA_SecureConversationMessageAbortBody const * src, UA_Int32* pos, char* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_encode(&(src->error),pos,dst);
-	retval |= UA_String_encode(&(src->reason),pos,dst);
-	return retval;
-}
-
-UA_Int32 UA_SecureConversationMessageAbortBody_decode(char const * src, UA_Int32* pos, UA_SecureConversationMessageAbortBody* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_decode(src,pos,&(dst->error));
-	retval |= UA_String_decode(src,pos,&(dst->reason));
-	return retval;
-}
-
-/*
-UA_Int32 UA_SL_SequenceHeader_calcSize(UA_SL_SequenceHeader const * ptr);\
-UA_Int32 UA_SL_SequenceHeader_delete(UA_SL_SequenceHeader * p);\
-UA_Int32 UA_SL_SequenceHeader_deleteMembers(UA_SL_SequenceHeader * p);
-
-UA_Int32 UA_SL_SequenceHeader_decode(char const * src, UA_Int32* pos, UA_SL_SequenceHeader * dst){
-	UA_Int32 retVal = 0;
-	retVal |= UA_UInt32_decode(src, pos, &(dst->sequenceNumber));
-	retVal |= UA_UInt32_decode(src, pos, &(dst->requestId));
-	return UA_SUCCESS;
-}
-UA_Int32 UA_SL_SequenceHeader_encode(UA_SL_SequenceHeader const * src, UA_Int32* pos, char * dst){
-	UA_Int32 retVal = 0;
-	retVal |= UA_UInt32_encode(&(src->requestId),pos,dst);
-	retVal |= UA_UInt32_encode(&(src->sequenceNumber),pos,dst);
-	return retVal;
-
-}
-/*
- * get the asymmetric algorithm security header
- */
-/*
-UA_Int32 UA_SL_AsymmetricAlgorithmSecurityHeader_decode(char * const src, UA_Int32 *pos,
-		UA_SL_AsymmetricAlgorithmSecurityHeader *dst){
-	UA_Int32 retVal = 0;
-	retVal |= UA_String_decode(src, pos,
-			&(dst->securityPolicyUri));
-	retVal |= UA_ByteString_decode(src, pos,
-			&(dst->senderCertificate));
-	retVal |= UA_String_decode(src, pos,
-			&(dst->receiverThumbprint));
-	return retVal;
-
-}
-
-UA_Int32 UA_SL_AsymetricAlgorithmSecurityHeader_encode(UA_SL_AsymmetricAlgorithmSecurityHeader *const src,
-		UA_Int32 *pos, char * dst) {
-	UA_Int32 retVal = 0;
-	retVal |= UA_String_encode(&(src->securityPolicyUri), pos,
-			dst);
-	retVal |= UA_ByteString_encode(&(src->senderCertificate), pos,
-			dst);
-	retVal |= UA_String_encode(&(src->receiverThumbprint), pos,
-			dst);
-	return UA_SUCCESS;
-}
-
-*/

+ 32 - 0
src/opcua_secureLayer.h

@@ -0,0 +1,32 @@
+/*
+ * opcua_secureChannelLayer.h
+ *
+ *  Created on: Dec 19, 2013
+ *      Author: opcua
+ */
+#ifndef OPCUA_SECURECHANNELLAYER_H_
+#define OPCUA_SECURECHANNELLAYER_H_
+#include "opcua.h"
+#include "UA_connection.h"
+#include "../include/UA_config.h"
+#include "UA_stackInternalTypes.h"
+/*
+*
+* @param connection
+* @return
+*/
+UA_Int32 SL_initConnectionObject(UA_connection *connection);
+
+/**
+*
+* @param connection
+* @param response
+* @param sizeInOut
+* @return
+*/
+UA_Int32 SL_openSecureChannel_responseMessage_get(UA_connection *connection,
+UA_SL_Response *response, UA_Int32* sizeInOut);
+
+void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage);
+
+#endif /* OPCUA_SECURECHANNELLAYER_H_ */

+ 35 - 29
src/opcua_transportLayer.c

@@ -51,21 +51,26 @@ UA_Int32 TL_check(UA_connection *connection)
 
 UA_Int32 TL_receive(UA_connection *connection, UA_ByteString *packet)
 {
-	UA_UInt32 length = 0;
+
 	UA_Int32 pos = 0;
+	UA_OPCUATcpMessageHeader *tcpMessageHeader;
+
+	UA_alloc((void**)&tcpMessageHeader,UA_OPCUATcpMessageHeader_calcSize(UA_NULL));
 
-	struct TL_header tmpHeader;
 	printf("TL_receive - entered \n");
 
 	packet->data = NULL;
 	packet->length = 0;
 
+
+	UA_OPCUATcpMessageHeader_decode(connection->readData.data, &pos,tcpMessageHeader);
+
 	if(TL_check(connection) == UA_NO_ERROR)
 	{
 
 		printf("TL_receive - no error \n");
 		printf("TL_receive - connection->readData.length %d \n",connection->readData.length);
-		UA_Int32 packetType = TL_getPacketType(&(connection->readData),&pos);
+
 
 		//is final chunk or not
 		//TODO process chunks
@@ -73,12 +78,12 @@ UA_Int32 TL_receive(UA_connection *connection, UA_ByteString *packet)
 		//save the message size if needed
 		pos += sizeof(UA_UInt32);
 
-		printf("TL_receive - packetType = %d \n",packetType);
-		switch(packetType)
+		printf("TL_receive - MessageType = %d \n",tcpMessageHeader->messageType);
+		switch(tcpMessageHeader->messageType)
 		{
-		case packetType_MSG:
-		case packetType_OPN:
-		case packetType_CLO:
+		case UA_MESSAGETYPE_MSG:
+		case UA_MESSAGETYPE_OPN:
+		case UA_MESSAGETYPE_CLO:
 		{
 			packet->data = connection->readData.data;
 			packet->length = connection->readData.length;
@@ -86,14 +91,14 @@ UA_Int32 TL_receive(UA_connection *connection, UA_ByteString *packet)
 			printf("TL_receive - received MSG or OPN or CLO message\n");
 			break;
 		}
-		case packetType_HEL:
-		case packetType_ACK:
+		case UA_MESSAGETYPE_HEL:
+		case UA_MESSAGETYPE_ACK:
 		{
 			printf("TL_receive - received HEL or ACK message\n");
-			TL_process(connection, packetType, &pos);
+			TL_process(connection, tcpMessageHeader->messageType, &pos);
 			break;
 		}
-		case packetType_ERR:
+		case UA_MESSAGETYPE_ERR:
 		{
 			printf("TL_receive - received ERR message\n");
 
@@ -126,42 +131,42 @@ UA_Int32 TL_getPacketType(UA_ByteString *packet, UA_Int32 *pos)
 	   packet->data[*pos+2] == 'L')
 	{
 		*pos += 3 * sizeof(UA_Byte);
-		retVal = packetType_HEL;
+		retVal = UA_MESSAGETYPE_HEL;
 	}
 	else if(packet->data[*pos] == 'A' &&
 	        packet->data[*pos+1] == 'C' &&
 	        packet->data[*pos+2] == 'K')
 	{
 		*pos += 3 * sizeof(UA_Byte);
-		retVal = packetType_ACK;
+		retVal = UA_MESSAGETYPE_ACK;
 	}
 	else if(packet->data[*pos] == 'E' &&
 			packet->data[*pos+1] == 'R' &&
 			packet->data[*pos+2] == 'R')
 	{
 		*pos += 3 * sizeof(UA_Byte);
-		retVal =  packetType_ERR;
+		retVal =  UA_MESSAGETYPE_ERR;
 	}
 	else if(packet->data[*pos] == 'O' &&
 	        packet->data[*pos+1] == 'P' &&
 	        packet->data[*pos+2] == 'N')
 	{
 		*pos += 3 * sizeof(UA_Byte);
-		retVal =  packetType_OPN;
+		retVal =  UA_MESSAGETYPE_OPN;
 	}
 	else if(packet->data[*pos] == 'C' &&
 	        packet->data[*pos+1] == 'L' &&
 	        packet->data[*pos+2] == 'O')
 	{
 		*pos += 3 * sizeof(UA_Byte);
-		retVal =  packetType_CLO;
+		retVal =  UA_MESSAGETYPE_CLO;
 	}
 	else if(packet->data[*pos] == 'M' &&
 			packet->data[*pos+1] == 'S' &&
 			packet->data[*pos+2] == 'G')
 	{
 		*pos += 3 * sizeof(UA_Byte);
-		retVal =  packetType_MSG;
+		retVal =  UA_MESSAGETYPE_MSG;
 	}
 	//TODO retVal == -1 -- ERROR no valid message received
 	return retVal;
@@ -174,37 +179,38 @@ UA_Int32 TL_process(UA_connection *connection,UA_Int32 packetType, UA_Int32 *pos
 	UA_ByteString tmpMessage;
 	UA_Byte reserved;
 	UA_UInt32 messageSize;
+	UA_OPCUATcpHelloMessage *helloMessage;
+	UA_alloc((void**)(&helloMessage),UA_OPCUATcpHelloMessage_calcSize(UA_NULL));
 	printf("TL_process - entered \n");
 	struct TL_header tmpHeader;
 	switch(packetType)
 	{
-	case packetType_HEL :
+	case UA_MESSAGETYPE_HEL :
 		if(connection->transportLayer.connectionState == connectionState_CLOSED)
 		{
 			printf("TL_process - extracting header information \n");
 			printf("TL_process - pos = %d \n",*pos);
 
-			/* extract information from received header */
-			UA_UInt32_decode(connection->readData.data,pos,(&(connection->transportLayer.remoteConf.protocolVersion)));
+			UA_OPCUATcpHelloMessage_decode(connection->readData.data,pos,helloMessage);
 
+			/* extract information from received header */
+			//UA_UInt32_decode(connection->readData.data,pos,(&(connection->transportLayer.remoteConf.protocolVersion)));
+			connection->transportLayer.remoteConf.protocolVersion = helloMessage->protocolVersion;
 			printf("TL_process - protocolVersion = %d \n",connection->transportLayer.remoteConf.protocolVersion);
 
-			UA_UInt32_decode(connection->readData.data,pos,(&(connection->transportLayer.remoteConf.recvBufferSize)));
-
+			connection->transportLayer.remoteConf.recvBufferSize = helloMessage->receiveBufferSize;
 			printf("TL_process - recvBufferSize = %d \n",connection->transportLayer.remoteConf.recvBufferSize);
 
-			UA_UInt32_decode(connection->readData.data,pos,(&(connection->transportLayer.remoteConf.sendBufferSize)));
-
+			connection->transportLayer.remoteConf.sendBufferSize = helloMessage->sendBufferSize;
 			printf("TL_process - sendBufferSize = %d \n",connection->transportLayer.remoteConf.sendBufferSize);
 
-			UA_UInt32_decode(connection->readData.data,pos,(&(connection->transportLayer.remoteConf.maxMessageSize)));
-
+			connection->transportLayer.remoteConf.maxMessageSize = helloMessage->maxMessageSize;
 			printf("TL_process - maxMessageSize = %d \n",connection->transportLayer.remoteConf.maxMessageSize);
 
-			UA_UInt32_decode(connection->readData.data,pos,(&(connection->transportLayer.remoteConf.maxChunkCount)));
-
+			connection->transportLayer.remoteConf.maxChunkCount = helloMessage->maxChunkCount;
 			printf("TL_process - maxChunkCount = %d \n",connection->transportLayer.remoteConf.maxChunkCount);
 
+
 			UA_String_decode(connection->readData.data,pos,(&(connection->transportLayer.endpointURL)));
 
 			/* send back acknowledge */

+ 2 - 1
src/opcua_transportLayer.h

@@ -11,7 +11,7 @@
 
 #include "opcua.h"
 #include "UA_connection.h"
-
+#include "UA_stackInternalTypes.h"
 
 //TODO : Implement this interface
 #include "tcp_layer.h"
@@ -98,6 +98,7 @@ UA_Int32 TL_check(UA_connection *connection);
 UA_Int32 TL_receive(UA_connection *connection,UA_ByteString *packet);
 UA_Int32 TL_send(UA_connection *connection, UA_ByteString *packet);
 UA_Int32 TL_getPacketType(UA_ByteString *packet, UA_Int32 *pos);
+UA_Int32 TL_process(UA_connection *connection,UA_Int32 packetType, UA_Int32 *pos);
 
 
 #endif /* OPCUA_TRANSPORTLAYER_H_ */

+ 3 - 0
tool/Opc.Ua.Types.bsd

@@ -10,6 +10,9 @@
 
   <opc:Import Namespace="http://opcfoundation.org/BinarySchema/" />
  
+ 
+ 
+
   <opc:StructuredType Name="XmlElement">
     <opc:Documentation>An XML element encoded as a UTF-8 string.</opc:Documentation>
     <opc:Field Name="Length" TypeName="opc:Int32" />

+ 1 - 3
tool/UA_stackInternalTypes

@@ -28,9 +28,7 @@
   
   <opc:StructuredType Name="SecureConversationMessageHeader">
     <opc:Documentation>Secure Layer Sequence Header</opc:Documentation>
-    <opc:Field Name="MessageType" TypeName="opc:UInt32" />
-    <opc:Field Name="IsFinal" TypeName="opc:Byte" />
-    <opc:Field Name="MessageSize" TypeName="opc:UInt32" />
+    <opc:Field Name="MessageHeader" TypeName="opc:OPCUATcpMessageHeader" />
     <opc:Field Name="SecureChannelId" TypeName="opc:UInt32" />
   </opc:StructuredType>