Bläddra i källkod

started with length calculation (encoding)
corrected decoding of diagnosticInfo

FlorianPalm 11 år sedan
förälder
incheckning
53a2288a42

+ 3 - 0
OPCUAServer/configure.ac

@@ -17,8 +17,11 @@ AM_CONDITIONAL([TARGET_LINUX],[test "${host_os}" = "linux-gnu" || test "${host_o
 #adding platform-dependent information to compile flags
 AM_COND_IF([TARGET_WIN],
     AC_DEFINE([WINDOWS])) #define WINDOWS is accessible from pre-processor
+
 AM_COND_IF([TARGET_LINUX],
     AC_DEFINE([LINUX]))
+    
+AC_LIBTOOL_WIN32_DLL
 AC_PROG_LIBTOOL
 AC_CONFIG_MACRO_DIR([m4])
 AC_CONFIG_FILES(Makefile src/Makefile tests/Makefile examples/src/Makefile)

+ 5 - 3
OPCUAServer/src/Makefile.am

@@ -20,12 +20,13 @@
 #					  opcua_transportLayer.h\
 #					  opcua_advancedDatatypes.h\
 #					  opcua_connectionHelper.h	
-noinst_LTLIBRARIES =$(top_builddir)/bin/libOpen62541.la
-__top_builddir__bin_libOpen62541_la_LDFLAGS = -no-undefined
-__top_builddir__bin_libOpen62541_la_SOURCES = 	opcua_builtInDatatypes.c\
+lib_LTLIBRARIES =libopen62541.la
+libopen62541_la_LDFLAGS = -avoid-version -no-undefined
+libopen62541_la_SOURCES = opcua_builtInDatatypes.c\
 						opcua_binaryEncDec.c\
 						opcua_transportLayer.c\
 						opcua_encodingLayer.c\
+						opcua_secureChannelLayer.c\
 						opcua_builtInDatatypes.h\
 						opcua_binaryEncDec.h\
 						opcua_transportLayer.h\
@@ -33,6 +34,7 @@ __top_builddir__bin_libOpen62541_la_SOURCES = 	opcua_builtInDatatypes.c\
 						opcua_types.h\
 						opcua_connectionHelper.h\
 						opcua_encodingLayer.h\
+						opcua_secureChannelLayer.h\
 						tcp_layer.h
 
 #bin_PROGRAMS= $(top_builddir)/bin/open62541.out

+ 2 - 2
OPCUAServer/src/opcua_advancedDatatypes.h

@@ -8,7 +8,7 @@
 #ifndef OPCUA_ADVANCEDDATATYPES_H_
 #define OPCUA_ADVANCEDDATATYPES_H_
 
-
+#include "opcua_builtInDatatypes.h"
 typedef struct AD_RawMessage_t AD_RawMessage;
 
 struct AD_RawMessage_t
@@ -139,7 +139,7 @@ struct BED_DiagnosticInfo
 	Int32 localizesText;
 	UA_String additionalInfo;
 	UA_StatusCode innerStatusCode;
-//	struct BED_DiagnosticInfo innerDiagnosticInfo;
+	struct BED_DiagnosticInfo *innerDiagnosticInfo;
 };
 
 

+ 136 - 8
OPCUAServer/src/opcua_binaryEncDec.c

@@ -8,11 +8,10 @@
 #include "opcua_binaryEncDec.h"
 #include "opcua_types.h"
 
-
 Byte decodeByte(const char *buf, Int32 *pos)
 {
 	*pos = (*pos) + 1;
-	return (Byte) buf[(*pos)-1];
+	return (Byte) buf[(*pos) - 1];
 
 }
 void encodeByte(Byte encodeByte, Int32 *pos, AD_RawMessage *dstBuf)
@@ -57,7 +56,6 @@ Int32 decodeInt32(const char* buf, Int32 *pos)
 	return t1 + t2 + t3 + t4;
 }
 
-
 UInt32 decodeUInt32(const char* buf, Int32 *pos)
 {
 	Byte t1 = buf[*pos];
@@ -75,7 +73,6 @@ void encodeUInt32(UInt32 value, char *dstBuf, Int32 *pos)
 
 }
 
-
 Int64 decodeInt64(const char* buf, Int32 *pos)
 {
 
@@ -117,10 +114,11 @@ Int32 decodeUAGuid(const char *buf, Int32 *pos, UA_Guid *dstGUID)
 	return 0;
 }
 
-void decodeUAByteString(const char *buf, Int32* pos, UA_ByteString *dstBytestring)
+void decodeUAByteString(const char *buf, Int32* pos,
+		UA_ByteString *dstBytestring)
 {
 
-	decodeUAString(buf,pos,dstBytestring->Data);
+	decodeUAString(buf, pos, dstBytestring->Data);
 }
 
 UA_DateTime decodeUADateTime(const char *buf, Int32 *pos)
@@ -138,7 +136,6 @@ Int32 decodeUANodeId(const char* buf, Int32 *pos, UA_NodeId *dstNodeId)
 
 	dstNodeId->EncodingByte = decodeInt32(buf, pos);
 
-
 	switch (dstNodeId->EncodingByte)
 	{
 	case NIEVT_TWO_BYTE:
@@ -171,7 +168,7 @@ Int32 decodeUANodeId(const char* buf, Int32 *pos, UA_NodeId *dstNodeId)
 	case NIEVT_BYTESTRING:
 	{
 
-		decodeUAByteString(buf, pos,&(dstNodeId->Identifier.OPAQUE));
+		decodeUAByteString(buf, pos, &(dstNodeId->Identifier.OPAQUE));
 		break;
 	}
 	case NIEVT_NAMESPACE_URI_FLAG:
@@ -186,3 +183,134 @@ Int32 decodeUANodeId(const char* buf, Int32 *pos, UA_NodeId *dstNodeId)
 	return 0;
 }
 
+/**
+ * IntegerId
+ * Part: 4
+ * Chapter: 7.13
+ * Page: 118
+ */
+T_IntegerId decodeIntegerId(char* buf, Int32 *pos)
+{
+	return decodeUInt32(buf, pos);
+}
+
+/**
+ * DiagnosticInfo
+ * Part: 4
+ * Chapter: 7.9
+ * Page: 116
+ */
+enum encodingMask
+{
+	encodingMask_HasSymbolicId = 0x01,
+	encodingMask_HasNamespace = 0x02,
+	encodingMask_HasLocalizedText = 0x04,
+	encodingMask_HasLocale = 0x08,
+	encodingMask_HasAdditionalInfo = 0x10,
+	encodingMask_HasInnerStatusCode = 0x20,
+	encodingMask_HasInnerDiagnosticInfo= 0x40
+};
+Int32 decodeToDiagnosticInfo(char* buf, Int32 *pos,
+		T_DiagnosticInfo* dstDiagnosticInfo)
+{
+	Byte encodingByte =  (buf[*pos]);
+	Byte mask;
+	for(mask = 1; mask <= 0x40; mask << 2)
+	{
+		switch(mask && encodingByte)
+		{
+		DIEMT_SYMBOLIC_ID:
+			dstDiagnosticInfo->symbolicId = decodeInt32(buf, pos);
+			break;
+		DIEMT_NAMESPACE:
+
+			dstDiagnosticInfo->namespaceUri = decodeInt32(buf, pos);
+			break;
+		DIEMT_LOCALIZED_TEXT:
+			dstDiagnosticInfo->localizesText = decodeInt32(buf, pos);
+			break;
+		DIEMT_LOCALE:
+			dstDiagnosticInfo->locale = decodeInt32(buf, pos);
+			break;
+		DIEMT_ADDITIONAL_INFO:
+			decodeUAString(buf, pos, &dstDiagnosticInfo->additionalInfo);
+			break;
+		DIEMT_INNER_STATUS_CODE:
+
+			dstDiagnosticInfo->innerStatusCode = decodeUAStatusCode(buf, pos);
+			break;
+		DIEMT_INNER_DIAGNOSTIC_INFO:
+
+			dstDiagnosticInfo->innerDiagnosticInfo = opcua_malloc(sizeof(T_DiagnosticInfo));
+			decodeToDiagnosticInfo(buf, pos,
+				dstDiagnosticInfo->innerDiagnosticInfo);
+			break;
+		}
+	}
+	*pos += 1;
+	return 0;
+}
+Int32 DiagnosticInfo_calcSize(T_DiagnosticInfo *diagnosticInfo)
+{
+	Int32 minimumLength = 20;
+	Int32 length;
+	length += minimumLength;
+	length += diagnosticInfo->additionalInfo.Length;
+	length += sizeof(UInt32);
+	length += DiagnosticInfo_calcSize(diagnosticInfo->innerDiagnosticInfo);
+	return length;
+}
+/**
+ * RequestHeader
+ * Part: 4
+ * Chapter: 7.26
+ * Page: 132
+ */
+
+/** \copydoc decodeRequestHeader */
+Int32 decodeRequestHeader(const AD_RawMessage *srcRaw, Int32 *pos,
+		T_RequestHeader *dstRequestHeader)
+{
+
+	decodeUANodeId(srcRaw->message, pos,
+			&(dstRequestHeader->authenticationToken));
+	dstRequestHeader->timestamp = decodeUADateTime(srcRaw->message, pos);
+	dstRequestHeader->requestHandle = decodeIntegerId(srcRaw->message, pos);
+	dstRequestHeader->returnDiagnostics = decodeUInt32(srcRaw->message, pos);
+	decodeUAString(srcRaw->message, pos, &dstRequestHeader->auditEntryId);
+	dstRequestHeader->timeoutHint = decodeUInt32(srcRaw->message, pos);
+
+	// AdditionalHeader will stay empty, need to be changed if there is relevant information
+
+	return 0;
+}
+
+/**
+ * ResponseHeader
+ * Part: 4
+ * Chapter: 7.27
+ * Page: 133
+ */
+/** \copydoc encodeResponseHeader */
+/*Int32 encodeResponseHeader(const T_ResponseHeader *responseHeader, Int32 *pos,
+		AD_RawMessage *dstBuf)
+{
+
+	return 0;
+}*/
+
+Int32 ResponseHeader_calcSize(T_ResponseHeader *responseHeader)
+{
+	Int32 minimumLength = 24; // summation of all simple types
+	Int32 i, length;
+	length += minimumLength;
+
+	for (i = 0; i < responseHeader->noOfStringTable; i++)
+	{
+		length += responseHeader->stringTable[i].Length;
+		length += sizeof(UInt32); // length of the encoded length field
+	}
+//TODO
+	return 0;
+}
+

+ 47 - 0
OPCUAServer/src/opcua_binaryEncDec.h

@@ -11,6 +11,7 @@
 #include "opcua_builtInDatatypes.h"
 
 #include "opcua_advancedDatatypes.h"
+#include "opcua_types.h"
 
 
 
@@ -122,4 +123,50 @@ Int32 decodeUAString(const char* buf, Int32 *pos, UA_String *dstUAString);
  */
 void encodeUInt32(UInt32 value, char *dstBuf, Int32 *pos);
 
+
+/**
+ * \brief
+ * \param srcRaw             pointer to raw data which holds the encoded data
+ * \param pos
+ * \param dstRequestHeader   pointer to a structure which hold the encoded header
+ * \return                   0 = success
+ */
+Int32 decodeRequestHeader(const AD_RawMessage *srcRaw,Int32 *pos, T_RequestHeader *dstRequestHeader);
+
+
+
+/**
+ *
+ * @param srcHeader
+ * @param pos
+ * @param dstRaw
+ * @return
+ */
+Int32 encodeRequestHeader(const T_RequestHeader *srcHeader,Int32 *pos,AD_RawMessage *dstRaw);
+
+
+
+/**
+ *
+ * @param srcRaw
+ * @param pos
+ * @param dstResponseHeader
+ * @return
+ */
+Int32 decodeResponseHeader(const AD_RawMessage *srcRaw, Int32 *pos, T_ResponseHeader *dstResponseHeader);
+
+/**
+ *  @brief function to encode a secureChannelRequestHeader
+ *
+ * @param header   a open secure channel header structure which should be encoded to binary format
+ * @param dstBuf   pointer to a structure which hold the encoded header
+ * @return
+ */
+Int32 encodeResponseHeader(const T_ResponseHeader *responseHeader, Int32 *pos, AD_RawMessage *dstBuf);
+
+
+
+
+
+
 #endif /* OPCUA_BINARYENCDEC_NEU_H_ */

+ 2 - 1
OPCUAServer/src/opcua_builtInDatatypes.h

@@ -127,6 +127,7 @@ typedef struct _UA_Guid
 	UInt16 Data2;
 	UInt16 Data3;
 	UA_ByteString Data4;
+
 }
 UA_Guid;
 /**
@@ -265,7 +266,7 @@ typedef enum _UA_DiagnosticInfoEncodingMaskType
 	DIEMT_SYMBOLIC_ID = 			0x01,
 	DIEMT_NAMESPACE = 				0x02,
 	DIEMT_LOCALIZED_TEXT = 			0x04,
-	DIEMT_LOCATE = 					0x08,
+	DIEMT_LOCALE = 					0x08,
 	DIEMT_ADDITIONAL_INFO = 		0x10,
 	DIEMT_INNER_STATUS_CODE = 		0x20,
 	DIEMT_INNER_DIAGNOSTIC_INFO = 	0x40

+ 12 - 5
OPCUAServer/src/opcua_connectionHelper.h

@@ -26,6 +26,15 @@ enum connectionState
 	connectionState_ESTABLISHED,
 
 };
+
+typedef struct
+{
+	UInt32 secureChannelId;
+	UInt32 tokenId;
+	UA_DateTime createdAt;
+	Int32 revisedLifetime;
+}SL_ChannelSecurityToken;
+
 typedef struct
 {
 	UInt32 recvBufferSize;
@@ -54,12 +63,10 @@ struct SL_connection
 	UA_String secureChannelId;
 	UInt32 UInt32_secureChannelId;
 	UInt32 securityMode;
-	UA_String clientNonce;
-	UA_Duration requestedLifetime; /// life time of the secure channel
-	UA_DateTime requestedAt; /// Point in time in which the secure channel was requested
+	UA_ByteString clientNonce;
 	UInt32 connectionState;
-	UInt32 tokenId;
-	UInt32 revisedLifetime;
+	SL_ChannelSecurityToken securityToken;
+
 };
 
 struct SS_connection

+ 0 - 79
OPCUAServer/src/opcua_encodingLayer.c

@@ -8,82 +8,3 @@
 #include "opcua_binaryEncDec.h"
 #include "opcua_types.h"
 #include "opcua_builtInDatatypes.h"
-
-/**
- * IntegerId
- * Part: 4
- * Chapter: 7.13
- * Page: 118
- */
-T_IntegerId decodeIntegerId(char* buf, Int32 *pos)
-{
-	return decodeUInt32(buf, pos);
-}
-
-/**
- * DiagnosticInfo
- * Part: 4
- * Chapter: 7.9
- * Page: 116
- */
-Int32 decodeToDiagnosticInfo(char* buf, Int32 *pos, T_DiagnosticInfo* dstDiagnosticInfo)
-{
-
-	dstDiagnosticInfo->namespaceUri = decodeInt32(buf,pos);
-	dstDiagnosticInfo->symbolicId = decodeInt32(buf, pos);
-	dstDiagnosticInfo->locale = decodeInt32(buf, pos);
-	dstDiagnosticInfo->localizesText = decodeInt32(buf, pos);
-
-	decodeUAByteString(buf, pos, dstDiagnosticInfo->additionalInfo);
-	dstDiagnosticInfo->innerStatusCode = decodeUAStatusCode(buf, pos);
-
-	//If the Flag InnerDiagnosticInfo is set, then the DiagnosticInfo will be encoded
-	if ((dstDiagnosticInfo->innerStatusCode & DIEMT_INNER_DIAGNOSTIC_INFO) == 1)
-	{
-		dstDiagnosticInfo->innerDiagnosticInfo = decodeTDiagnosticInfo(buf,
-				pos);
-	}
-
-	return 0;
-}
-
-/**
- * RequestHeader
- * Part: 4
- * Chapter: 7.26
- * Page: 132
- */
-
-/** \copydoc decodeRequestHeader */
-Int32 decodeRequestHeader(const AD_RawMessage *srcRaw, Int32 *pos,
-		T_RequestHeader *dstRequestHeader)
-{
-
-	decodeUANodeId(srcRaw->message, pos,&(dstRequestHeader->authenticationToken));
-	dstRequestHeader->timestamp = decodeUADateTime(srcRaw->message, pos);
-	dstRequestHeader->requestHandle = decodeIntegerId(srcRaw->message, pos);
-	dstRequestHeader->returnDiagnostics = decodeUInt32(srcRaw->message, pos);
-	decodeUAString(srcRaw->message, pos, &dstRequestHeader->auditEntryId);
-	dstRequestHeader->timeoutHint = decodeUInt32(srcRaw->message, pos);
-
-
-	// AdditionalHeader will stay empty, need to be changed if there is relevant information
-
-	return 0;
-}
-
-/**
- * ResponseHeader
- * Part: 4
- * Chapter: 7.27
- * Page: 133
- */
-/** \copydoc encodeResponseHeader */
-Int32 encodeResponseHeader(const T_ResponseHeader *responseHeader, Int32 *pos, AD_RawMessage *dstBuf)
-{
-
-	return 0;
-}
-
-
-

+ 0 - 45
OPCUAServer/src/opcua_encodingLayer.h

@@ -11,48 +11,3 @@
 #include "opcua_builtInDatatypes.h"
 #include "opcua_advancedDatatypes.h"
 #include "opcua_types.h"
-/**
- * \brief
- * \param srcRaw             pointer to raw data which holds the encoded data
- * \param pos
- * \param dstRequestHeader   pointer to a structure which hold the encoded header
- * \return                   0 = success
- */
-Int32 decodeRequestHeader(const AD_RawMessage *srcRaw,Int32 *pos, T_RequestHeader *dstRequestHeader);
-
-
-
-/**
- *
- * @param srcHeader
- * @param pos
- * @param dstRaw
- * @return
- */
-Int32 encodeRequestHeader(const T_RequestHeader *srcHeader,Int32 *pos,AD_RawMessage *dstRaw);
-
-
-
-/**
- *
- * @param srcRaw
- * @param pos
- * @param dstResponseHeader
- * @return
- */
-Int32 decodeResponseHeader(const AD_RawMessage *srcRaw, Int32 *pos, T_ResponseHeader *dstResponseHeader);
-
-/**
- *  @brief function to encode a secureChannelRequestHeader
- *
- * @param header   a open secure channel header structure which should be encoded to binary format
- * @param dstBuf   pointer to a structure which hold the encoded header
- * @return
- */
-Int32 encodeResponseHeader(const T_ResponseHeader *responseHeader, Int32 *pos, AD_RawMessage *dstBuf);
-
-
-
-
-
-#endif /* OPCUA_ENCODINGLAYER_H_ */

+ 60 - 98
OPCUAServer/src/opcua_secureChannelLayer.c

@@ -6,8 +6,10 @@
  */
 #include "opcua_secureChannelLayer.h"
 
+//memory calculation
 
-Int32 SL_openSecureChannelRequest_check(const UA_connection *connection, secureChannelMessage)
+
+Int32 SL_openSecureChannelRequest_check(const UA_connection *connection, AD_RawMessage *secureChannelMessage)
 {
 	return 0;
 }
@@ -30,59 +32,40 @@ Int32 SL_secureChannel_ResponseHeader_form(UA_connection *connection, T_Response
 	responseHeader->additionalHeader.Encoding = 0;
 	responseHeader->additionalHeader.Length = 0;
 
+
 	responseHeader->additionalHeader.TypeId.Namespace = 0;
-	responseHeader->additionalHeader.TypeId.Identifier = 0;
+	responseHeader->additionalHeader.TypeId.Identifier.Numeric = 0;
 
 
 	responseHeader->requestHandle = 0;
 	return 0;
 }
-/*
- *
- */
-Int32 SL_secureChannel_Response_form(UA_connection *connection, SL_Response *response)
-{
-	response->ServerProtocolVersion = connection->transportLayer//TODO must be set
-	response->SecurityToken.ChannelId = connection->secureLayer.UInt32_secureChannelId;
-	response->SecurityToken.CreatedAt = connection->secureLayer.requestedAt;
-	response->SecurityToken.TokenId = connection->secureLayer.tokenId; //TODO  must be generated;
-	response->SecurityToken.RevisedLifeTime = connection->secureLayer.revisedLifetime;
-	response->ServerNonce.Length = 0; // TODO
-	return 0;
-}
+
 /*
  * opens a secureChannel (server side)
  */
 Int32 SL_secureChannel_open(const UA_connection *connection,
 		const AD_RawMessage *secureChannelMessage,
-		const SL_SecureConversationMessageHeader *SCM_Header,
-		const SL_AsymmetricAlgorithmSecurityHeader *AAS_Header)
+		const SL_SecureConversationMessageHeader *SCMHeader,
+		const SL_AsymmetricAlgorithmSecurityHeader *AASHeader,
+		const SL_SequenceHeader *SequenceHeader)
 {
-	SL_Response response;
-
 
 
 
-	TL_send();
-	//client protocol Version
 
-return 0;
+	return 0;
 
 }
-/*
- void SL_secureChannel_Request_get(AD_RawMessage        *secureChannelMessage,
- secureChannelRequest *SC_request)
- {
 
- }
+Int32 SL_openSecureChannel_responseMessage_getSize(SL_Response *response, Int32* sizeInOut)
+{
+
+}
 
 /*
  * closes a secureChannel (server side)
  */
-void SL_secureChannel_formResponse()
-{
-
-}
 void SL_secureChannel_close(UA_connection *connection)
 {
 
@@ -96,23 +79,32 @@ void SL_receive(UA_connection *connection, AD_RawMessage *serviceMessage)
 	AD_RawMessage* secureChannelMessage;
 	SL_SecureConversationMessageHeader SCM_Header;
 	SL_AsymmetricAlgorithmSecurityHeader AAS_Header;
+	SL_SequenceHeader SequenceHeader;
 
+	//TODO Error Handling, length checking
 	//get data from transport layer
-	TL_receive(UA_connection, secureChannelMessage);
+
+	TL_receive(connection, secureChannelMessage);
+
+	Int32 readPosition = 0;
 
 	//get the Secure Channel Message Header
-	UInt32 readPosition = SL_secureChannel_SCMHeader_get(connection,
-			secureChannelMessage, &SCM_Header);
+	SL_secureChannel_SCMHeader_get(connection,secureChannelMessage,
+			&readPosition, &SCM_Header);
 
 	//get the Secure Channel Asymmetric Algorithm Security Header
-	readPosition = SL_secureChannel_AASHeader_get(connection, secureChannelMessage,
-			readPosition, &AAS_Header);
+	SL_secureChannel_AASHeader_get(connection, secureChannelMessage,
+			&readPosition, &AAS_Header);
+
+	//get the Sequence Header
+	SL_secureChannel_SequenceHeader_get(connection,secureChannelMessage,
+			&readPosition,&SequenceHeader);
 
 	//get Secure Channel Message
-	SL_secureChannel_Message_get(connection, secureChannelMessage, readPosition,
-			serviceMessage);
+	SL_secureChannel_Message_get(connection, secureChannelMessage,
+			&readPosition,serviceMessage);
 
-	if (secureChannelMessage.length > 0)
+	if (secureChannelMessage->length > 0)
 	{
 		switch (SCM_Header.MessageType)
 		{
@@ -134,91 +126,61 @@ void SL_receive(UA_connection *connection, AD_RawMessage *serviceMessage)
 				//check if the request is valid
 				SL_openSecureChannelRequest_check(connection, secureChannelMessage);
 			}
-			SL_secureChannel_open(connection, serviceMessage);
-		}
-		else
-		{
-			//TODO send back Error Message
-		}
-
+			else
+			{
+				//TODO send back Error Message
+			}
 		//Client Handling
 
 		//TODO free memory for secureChannelMessage
 
 		break;
 		case packetType_CLO:
-			SL_secureChannel_close(connection, secureChannelMessage);
+
 
 		//TODO free memory for secureChannelMessage
 		break;
+		}
+
 	}
 
 }
 /*
  * get the secure channel message header
  */
-UInt32 SL_secureChannel_SCMHeader_get(UA_connection *connection,
-	AD_RawMessage *rawMessage, SL_SecureConversationMessageHeader* SC_Header)
+Int32 SL_secureChannel_SCMHeader_get(UA_connection *connection,
+	AD_RawMessage *rawMessage,Int32 *pos, SL_SecureConversationMessageHeader* SC_Header)
 {
-	Int32 pos = 0;
 	SC_Header->MessageType = TL_getPacketType(rawMessage);
-	pos += TL_MESSAGE_TYPE_LEN;
-	SC_Header->IsFinal = rawMessage[pos];
-	pos += sizeof(Byte);
-	SC_Header->MessageSize = decodeUInt32(rawMessage, pos);
-	pos += sizeof(UInt32);
-	SC_Header->SecureChannelId = decodeUInt32(rawMessage, pos);
-	pos += sizeof(UInt32);
-	return pos;
+	*pos += 3;//TL_MESSAGE_TYPE_LEN;
+	SC_Header->IsFinal = rawMessage->message[*pos];
+	SC_Header->MessageSize = decodeUInt32(rawMessage, *pos);
+	SC_Header->SecureChannelId = decodeUInt32(rawMessage, *pos);
+	return 0;
 
 }
+Int32 SL_secureChannel_SequenceHeader_get(UA_connection *connection,
+		AD_RawMessage *rawMessage, Int32 *pos,
+		SL_SequenceHeader *SequenceHeader)
+{
+	SequenceHeader->RequestId = decodeUInt32(rawMessage->message, pos);
+	SequenceHeader->SequenceNumber = decodeUInt32(rawMessage->message, pos);
+	return 0;
+}
 /*
  * get the asymmetric algorithm security header
  */
-UInt32 SL_secureChannel_AASHeader_get(UA_connection *connection,
-	AD_RawMessage *rawMessage, UInt32 pos,
+Int32 SL_secureChannel_AASHeader_get(UA_connection *connection,
+	AD_RawMessage *rawMessage, Int32 *pos,
 	SL_AsymmetricAlgorithmSecurityHeader* AAS_Header)
 {
-
-	AAS_Header->SecurityPolicyUri.Length = decodeInt32(rawMessage, pos);
-
-	pos += sizeof(Int32);
-	AAS_Header->SecurityPolicyUri.Data = rawMessage[pos];
-
-	if (AAS_Header->SecurityPolicyUri.Length < 0)
-	{
-		AAS_Header->SecurityPolicyUri.Length = 0;
-	}
-	pos += AAS_Header->SecurityPolicyUri.Length;
-
-	AAS_Header->SenderCertificate.Length = decodeInt32(rawMessage, pos);
-	pos += sizeof(Int32);
-	if (AAS_Header->SenderCertificate.Length < 0)
-	{
-		AAS_Header->SenderCertificate.Length = 0;
-	}
-	AAS_Header->SenderCertificate.Data = rawMessage[pos];
-
-	pos += AAS_Header->SenderCertificate.Length;
-
-	AAS_Header->ReceiverThumbprint.Length = decodeInt32(rawMessage, pos);
-	pos += sizeof(Int32);
-
-	if (AAS_Header->ReceiverThumbprint.Length < 0)
-	{
-		AAS_Header->ReceiverThumbprint.Length = 0;
-	}
-	AAS_Header->ReceiverThumbprint.Data = rawMessage[pos];
-
-	pos += AAS_Header->ReceiverThumbprint.Length;
-	return pos;
+	Int32 err = 0;
+	err += decodeUAByteString(rawMessage->message,pos,AAS_Header->SecurityPolicyUri);
+	err += decodeUAByteString(rawMessage->message,pos,AAS_Header->SenderCertificate);
+	err += decodeUAByteString(rawMessage->message,pos,AAS_Header->ReceiverThumbprint);
+	return err;
 }
 void SL_secureChannel_Footer_get()
 {
 
 }
-void SL_secureChannel_Message_get(UA_connection *connection,
-	AD_RawMessage *rawMessage, UInt32 pos, AD_RawMessage *message)
-{
-
-}

+ 3 - 7
OPCUAServer/src/opcua_secureChannelLayer.h

@@ -10,14 +10,10 @@
 
 #include "opcua_advancedDatatypes.h"
 #include "opcua_encodingLayer.h"
+#include "opcua_connectionHelper.h"
+
 static const Int32 SL_HEADER_LENGTH = 0;
-typedef struct _SL_ChannelSecurityToken
-{
-	UInt32 ChannelId;
-	UInt32 TokenId;
-	UA_DateTime CreatedAt;
-	Int32 RevisedLifeTime;
-}SL_ChannelSecurityToken;
+
 
 
 typedef struct _SL_OpenSecureChannelResponse