Browse Source

changed comments and the parse/convert function structure

FlorianPalm 11 years ago
parent
commit
34a16adfd2

+ 5 - 0
OPCUAServer/.cproject

@@ -501,4 +501,9 @@
 			</target>
 		</buildTargets>
 	</storageModule>
+	<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings">
+		<doc-comment-owner id="org.eclipse.cdt.ui.doxygen">
+			<path value=""/>
+		</doc-comment-owner>
+	</storageModule>
 </cproject>

+ 2 - 2
OPCUAServer/src/opcua_advancedDatatypes.h

@@ -693,13 +693,13 @@ struct BED_RelativePath
 */
 struct BED_RequestHeader
 {
-//ToDo	struct BED_SessionAuthenticationToken authenticationToken;		//ToDo
+	struct BED_SessionAuthenticationToken authenticationToken;		//ToDo
 	UA_DateTime timestamp;
 	BED_IntegerId requestHandle;
 	UInt32 returnDiagnostics;
 	UA_String auditEntryId;
 	UInt32 timeoutHint;
-//ToDo	struct BED_ExtensibleParameterAdditionalHeader additionalHeader;		//ToDo
+	T_ExtensibleParameter additionalHeader;
 };
 
 

+ 99 - 164
OPCUAServer/src/opcua_binaryEncDec.c

@@ -8,235 +8,170 @@
 #include "opcua_binaryEncDec.h"
 #include "opcua_types.h"
 
-
-
 /*
  * convert byte array to Byte
  */
-Byte convertToByte(const char *buf, int pos)
+Byte convertToByte(const char *buf, Int32 *pos)
 {
-	return (Byte)buf[pos];
+	*pos = (*pos) + 1;
+	return (Byte) buf[(*pos)-1];
+
 }
 /*
  * convert byte array to UInt16
  */
-UInt16 convertToUInt16(const char* buf, int pos)
+UInt16 convertToUInt16(const char* buf, Int32 *pos)
 {
 
-	Byte t1 = buf[pos];
-	Int32 t2 = (UInt16)(buf[pos+1] << 8);
-
+	Byte t1 = buf[*pos];
+	Int32 t2 = (UInt16) (buf[*pos + 1] << 8);
+	*pos += 2;
 	return t1 + t2;
 }
 /*
  * convert byte array to Int32
  */
-Int32 convertToInt32(const char* buf, int pos)
+Int32 convertToInt32(const char* buf, Int32 *pos)
 {
 
-	SByte t1 = buf[pos];
-	Int32 t2 = (UInt32)(buf[pos+1] << 8);
-	Int32 t3 = (UInt32)(buf[pos+2] << 16);
-	Int32 t4 = (UInt32)(buf[pos+3] << 24);
-
+	SByte t1 = buf[*pos];
+	Int32 t2 = (UInt32) (buf[*pos + 1] << 8);
+	Int32 t3 = (UInt32) (buf[*pos + 2] << 16);
+	Int32 t4 = (UInt32) (buf[*pos + 3] << 24);
+	*pos += 4;
 	return t1 + t2 + t3 + t4;
 }
 /*
  * convert byte array to UInt32
  */
-UInt32 convertToUInt32(const char* buf, int pos)
+UInt32 convertToUInt32(const char* buf, Int32 *pos)
 {
-	Byte t1 = buf[pos];
-	UInt32 t2 = (UInt32)(buf[pos+1] << 8);
-	UInt32 t3 = (UInt32)(buf[pos+2] << 16);
-	UInt32 t4 = (UInt32)(buf[pos+3] << 24);
-
+	Byte t1 = buf[*pos];
+	UInt32 t2 = (UInt32) (buf[*pos + 1] << 8);
+	UInt32 t3 = (UInt32) (buf[*pos + 2] << 16);
+	UInt32 t4 = (UInt32) (buf[*pos + 3] << 24);
+	*pos += 4;
 	return t1 + t2 + t3 + t4;
 }
 
-void convertUInt32ToByteArray(UInt32 value,char *buf,int pos)
+void convertUInt32ToByteArray(UInt32 value, char *dstBuf, Int32 *pos)
 {
-	memcpy(buf,&value,sizeof(value));
+	memcpy(&(dstBuf[*pos]), &value, sizeof(value));
+	pos += 4;
 	/*buf[pos] = (char)(value && 0xFF);
-	buf[pos + 1] = (char)((value >> 8) && 0xFF);
-	buf[pos + 2] = (char)((value >> 16) && 0xFF);
-	buf[pos + 3] = (char)((value >> 24) && 0xFF);
-	*/
+	 buf[pos + 1] = (char)((value >> 8) && 0xFF);
+	 buf[pos + 2] = (char)((value >> 16) && 0xFF);
+	 buf[pos + 3] = (char)((value >> 24) && 0xFF);
+	 */
 }
 /*
  * convert byte array to Int64
  */
-Int64 convertToInt64(const char* buf, int pos)
+Int64 convertToInt64(const char* buf, Int32 *pos)
 {
 
-	SByte t1 = buf[pos];
-	UInt64 t2 = (UInt64)(buf[pos+1] << 8);
-	UInt64 t3 = (UInt64)(buf[pos+2] << 16);
-	UInt64 t4 = (UInt64)(buf[pos+3] << 24);
-	UInt64 t5 = (UInt64)(buf[pos+4] << 32);
-	UInt64 t6 = (UInt64)(buf[pos+5] << 40);
-	UInt64 t7 = (UInt64)(buf[pos+6] << 48);
-	UInt64 t8 = (UInt64)(buf[pos+7] << 56);
-
+	SByte t1 = buf[*pos];
+	UInt64 t2 = (UInt64) (buf[*pos + 1] << 8);
+	UInt64 t3 = (UInt64) (buf[*pos + 2] << 16);
+	UInt64 t4 = (UInt64) (buf[*pos + 3] << 24);
+	UInt64 t5 = (UInt64) (buf[*pos + 4] << 32);
+	UInt64 t6 = (UInt64) (buf[*pos + 5] << 40);
+	UInt64 t7 = (UInt64) (buf[*pos + 6] << 48);
+	UInt64 t8 = (UInt64) (buf[*pos + 7] << 56);
+	pos += 8;
 	return t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8;
 }
 
-
-
-
-convertToUAString(const char* buf, int pos,UA_String *dstUAString)
+convertToUAString(const char* buf, Int32 *pos, UA_String *dstUAString)
 {
 
-	dstUAString->Length = convertToInt32(buf,pos);
-	if(dstUAString->Length > 0)
+	dstUAString->Length = convertToInt32(buf, pos);
+	if (dstUAString->Length > 0)
 	{
-		dstUAString->Data = &(buf[sizeof(UInt32)]);
+		dstUAString->Data = &(buf[*pos]);
 	}
 	else
 	{
 		dstUAString->Length = 0;
 		dstUAString->Data = NULL;
 	}
+	*pos += dstUAString->Length;
 }
 
-convertToUAGuid(const char* buf, int pos,UA_Guid* dstGUID)
+Int32 convertToUAGuid(const char *buf, Int32 *pos, UA_Guid *dstGUID)
 {
-
-	int counter = 0;
-	UInt32 i = 0;
-	for(i = 1; i <= 4; i++)
-	{
-
-		dstGUID->Data1[i] = convertToUInt32(*buf, pos+counter);
-
-		counter += sizeof(UInt32);
-	}
-	for(i = 1; i <= 2; i++)
-	{
-
-		dstGUID->Data2[i] = convertToUInt16(*buf, pos+counter);
-
-		counter += sizeof(UInt16);
-	}
-	for(i = 1; i <= 2; i++)
-	{
-
-		dstGUID->Data3[i] = convertToUInt16(*buf, pos+counter);
-
-		counter += sizeof(UInt16);
-	}
-	for(i = 1; i <= 8; i++)
-	{
-
-		dstGUID->Data4[i] = convertToByte(*buf, pos+counter);
-
-		counter += sizeof(Byte);
-	}
+	dstGUID->Data1 = convertToUInt32(buf, pos);
+	dstGUID->Data2 = convertToUInt16(buf, pos);
+	dstGUID->Data3 = convertToUInt16(buf, pos);
+	convertToUAByteString(buf, pos, &(dstGUID->Data4));
+	return 0;
 }
 
-
-UA_ByteString convertToUAByteString(const char* buf, int pos){
-	UA_ByteString tmpUAByteString;
-	int counter = sizeof(Int32);
-	int i = 0;
-
-	tmpUAByteString.Length = convertToInt32(buf, pos);
-	Byte byteStringData[tmpUAByteString.Length];
-
-	if(tmpUAByteString.Length == -1){
-		return tmpUAByteString;
-	}else{
-		for(i = 0; i < tmpUAByteString.Length; i++)
-		{
-			byteStringData[i] = convertToByte(buf, pos+counter);
-			counter += sizeof(Byte);
-		}
-	}
-
-	tmpUAByteString.Data = byteStringData;
-
-	return tmpUAByteString;
+convertToUAByteString(const char *buf, Int32* pos, UA_ByteString *dstBytestring)
+{
+	convertToUAString(buf,pos,dstBytestring);
 }
 
-UA_DateTime convertToUADateTime(const char* buf, int pos){
-	UA_DateTime tmpUADateTime;
-	tmpUADateTime = convertToInt64(buf, pos);
-	return tmpUADateTime;
+UA_DateTime convertToUADateTime(const char *buf, Int32 *pos)
+{
+	return convertToInt64(buf, pos);
 }
 
-UA_StatusCode convertToUAStatusCode(const char* buf, int pos){
+UA_StatusCode convertToUAStatusCode(const char* buf, Int32 *pos)
+{
 	return convertToUInt32(buf, pos);
 }
 
+Int32 convertToUANodeId(const char* buf, Int32 *pos, UA_NodeId *dstNodeId)
+{
 
-void convertToUANodeId(const char* buf, int pos, UA_NodeId* dstNodeId){
+	dstNodeId->EncodingByte = convertToInt32(buf, pos);
 
-	dstNodeId->EncodingByte = convertToInt32(buf, 0);
 
-	int counter = sizeof(UInt32);
+	switch (dstNodeId->EncodingByte)
+	{
+	case NIEVT_TWO_BYTE:
+	{
 
-	UA_NodeIdEncodingValuesType encodingType = dstNodeId->EncodingByte;
+		dstNodeId->Identifier.Numeric = convertToByte(buf, pos);
+		break;
+	}
+	case NIEVT_FOUR_BYTE:
+	{
+		dstNodeId->Identifier.Numeric = convertToInt16(buf, pos);
+		break;
+	}
+	case NIEVT_NUMERIC:
+	{
 
-	switch(encodingType)
+		dstNodeId->Identifier.Numeric = convertToInt32(buf, pos);
+		break;
+	}
+	case NIEVT_STRING:
 	{
-		case NIEVT_TWO_BYTE:
-		{
-
-			dstNodeId->Identifier.Numeric = convertToInt32(buf, counter);
-
-			counter += sizeof(UInt16);
-			break;
-		}
-		case NIEVT_FOUR_BYTE:
-		{
-
-			dstNodeId->Identifier.Numeric = convertToInt32(buf, counter);
-
-			counter += sizeof(Int64);
-			break;
-		}
-		case NIEVT_NUMERIC:
-		{
-
-			dstNodeId->Identifier.Numeric = convertToInt32(buf, counter);
-
-			counter += sizeof(UInt32);
-			break;
-		}
-		case NIEVT_STRING:
-		{
-
-
-			convertToUAString(buf, counter,&dstNodeId->Identifier.String);
-			counter += sizeof(sizeof(UInt32) + dstNodeId->Identifier.String.Length);
-
-			break;
-		}
-		case NIEVT_GUID:
-		{
-
-
-			convertToUAGuid(buf, counter,&dstNodeId->Identifier.Guid);
-
-			counter += sizeof(UA_Guid);
-			break;
-		}
-		case NIEVT_BYTESTRING:
-		{
-			dstNodeId->Identifier.OPAQUE = convertToUAByteString(buf, counter);
-			//If Length == -1 then the ByteString is null
-			if(dstNodeId->Identifier.OPAQUE.Length == -1)
-			{
-				counter += sizeof(Int32);
-			}else{
-				counter += sizeof(Int32)+sizeof(Byte)*dstNodeId->Identifier.OPAQUE.Length;
-			}
-			break;
-		}
-		default:
-			break;
+		convertToUAString(buf, pos, &dstNodeId->Identifier.String);
+		break;
 	}
-}
+	case NIEVT_GUID:
+	{
+		convertToUAGuid(buf, pos, &(dstNodeId->Identifier.Guid));
+		break;
+	}
+	case NIEVT_BYTESTRING:
+	{
 
+		convertToUAByteString(buf, pos,&(dstNodeId->Identifier.OPAQUE));
+		break;
+	}
+	case NIEVT_NAMESPACE_URI_FLAG:
+	{
+		//TODO implement
+		break;
+	}
+	default:
 
+		break;
+	}
+	return 0;
+}
 

+ 31 - 3
OPCUAServer/src/opcua_binaryEncDec.h

@@ -13,8 +13,36 @@
 
 
 //functions
-Byte convertToByte(const char* buf, int pos);
-Int32 convertToInt32(const char* buf,int pos);
-UInt32 convertToUInt32(const char* buf, int pos);
+/**
+ *
+ * @param buf  			binary encoded message
+ * @param pos  			position at which the data is located in/out, parser position after the conversion
+ * @return
+ */
+Byte convertToByte(const char* buf, Int32 *pos);
+/**
+ *
+ * @param buf  			binary encoded message
+ * @param pos  			position at which the data is located in/out, parser position after the conversion
+ * @return
+ */
+Int32 convertToInt32(const char* buf, Int32 *pos);
+
+/**
+ *
+ * @param buf  			binary encoded message
+ * @param pos  			position at which the data is located in/out, parser position after the conversion
+ * @return				encoded data
+ */
+UInt32 convertToUInt32(const char* buf, Int32 *pos);
+
+/**
+ *
+ * @param buf  			binary encoded message
+ * @param pos  			position at which the data is located in/out, parser position after the conversion
+ * @param dstNodeId		receiver of the nodeid structure
+ * @param return		success = 0
+ */
+Int32 convertToUANodeId(const char* buf, Int32 *pos, UA_NodeId *dstNodeId);
 
 #endif /* OPCUA_BINARYENCDEC_NEU_H_ */

+ 16 - 16
OPCUAServer/src/opcua_builtInDatatypes.h

@@ -99,23 +99,11 @@ typedef Int64 UA_DateTime; //100 nanosecond resolution
 			      //start Date: 1601-01-01 12:00 AM
 
 
-/**
-* GuidType
-* Part: 6
-* Chapter: 5.2.2.6
-* Page: 17
-*/
-typedef struct _UA_Guid
-{
-	UInt32 Data1[4];
-	UInt16 Data2[2];
-	UInt16 Data3[2];
-	Byte Data4[8];
-}
-UA_Guid;
 
 
-/**
+
+
+/*
 * ByteString
 * Part: 6
 * Chapter: 5.2.2.7
@@ -128,7 +116,19 @@ typedef struct _UA_ByteString
 }
 UA_ByteString;
 
-
+/* GuidType
+* Part: 6
+* Chapter: 5.2.2.6
+* Page: 17
+*/
+typedef struct _UA_Guid
+{
+	UInt32 Data1;
+	UInt16 Data2;
+	UInt16 Data3;
+	UA_ByteString Data4;
+}
+UA_Guid;
 /**
 * XmlElement
 * Part: 6

+ 58 - 97
OPCUAServer/src/opcua_encodingLayer.c

@@ -10,123 +10,84 @@
 #include "opcua_builtInDatatypes.h"
 
 /**
-* IntegerId
-* Part: 4
-* Chapter: 7.13
-* Page: 118
-*/
-T_IntegerId convertToIntegerId(char* buf, int pos){
+ * IntegerId
+ * Part: 4
+ * Chapter: 7.13
+ * Page: 118
+ */
+T_IntegerId convertToIntegerId(char* buf, Int32 *pos)
+{
 	return convertToUInt32(buf, pos);
 }
 
 /**
-* DiagnosticInfo
-* Part: 4
-* Chapter: 7.9
-* Page: 116
-*/
-T_DiagnosticInfo convertToDiagnosticInfo(char* buf, int pos){
-	T_DiagnosticInfo tmpTDiagnosticInfo;
-	int counter = 0;
-	tmpTDiagnosticInfo.namespaceUri = convertToInt32(buf, counter);
-	counter += sizeof(tmpTDiagnosticInfo.namespaceUri);
-	tmpTDiagnosticInfo.symbolicId = convertToInt32(buf, counter);
-	counter += sizeof(tmpTDiagnosticInfo.symbolicId);
-	tmpTDiagnosticInfo.locale = convertToInt32(buf, counter);
-	counter += sizeof(tmpTDiagnosticInfo.locale);
-	tmpTDiagnosticInfo.localizesText = convertToInt32(buf, counter);
-	counter += sizeof(tmpTDiagnosticInfo.localizesText);
-	tmpTDiagnosticInfo.additionalInfo = convertToUAString(buf, counter);
-	counter += sizeof(tmpTDiagnosticInfo.additionalInfo);
-	tmpTDiagnosticInfo.innerStatusCode = convertToUAStatusCode(buf, pos);
-	counter += sizeof(tmpTDiagnosticInfo.innerStatusCode);
+ * DiagnosticInfo
+ * Part: 4
+ * Chapter: 7.9
+ * Page: 116
+ */
+Int32 convertToDiagnosticInfo(char* buf, Int32 *pos, T_DiagnosticInfo* dstDiagnosticInfo)
+{
 
-	//If the Flag InnerDiagnosticInfo is set, then the DiagnosticInfo will be encoded
-	if((tmpTDiagnosticInfo.innerStatusCode & DIEMT_INNER_DIAGNOSTIC_INFO) == 1){
-		tmpTDiagnosticInfo.innerDiagnosticInfo = convertToTDiagnosticInfo(buf, counter);
-	}
+	dstDiagnosticInfo->namespaceUri = convertToInt32(buf,pos);
+	dstDiagnosticInfo->symbolicId = convertToInt32(buf, pos);
+	dstDiagnosticInfo->locale = convertToInt32(buf, pos);
+	dstDiagnosticInfo->localizesText = convertToInt32(buf, pos);
+	dstDiagnosticInfo->additionalInfo = convertToUAString(buf, pos);
+	dstDiagnosticInfo->innerStatusCode = convertToUAStatusCode(buf, pos);
 
-	return tmpTDiagnosticInfo;
-}
-
-/**
-* RequestHeader
-* Part: 4
-* Chapter: 7.26
-* Page: 132
-*/
-T_RequestHeader decodeRequestHeader(char* buf)
-{
-	T_RequestHeader tmpRequestHeader;
-	int counter = 0;
-	//ToDo: counter needs the length of the buffer,
-	//		strings have in this type just the size of the pointer not of the content
-	tmpRequestHeader.authenticationToken = convertToUANodeId(buf, counter);
-	if (tmpRequestHeader.authenticationToken.EncodingByte == NIEVT_STRING)
-	{
-		counter =
-				sizeof(tmpRequestHeader.authenticationToken.EncodingByte)
-						+ sizeof(tmpRequestHeader.authenticationToken.Namespace)
-						+ sizeof(tmpRequestHeader.authenticationToken.Identifier.String.Length)
-						+ sizeof(tmpRequestHeader.authenticationToken.Identifier.String.Data);
-	}
-	else
+	//If the Flag InnerDiagnosticInfo is set, then the DiagnosticInfo will be encoded
+	if ((dstDiagnosticInfo->innerStatusCode & DIEMT_INNER_DIAGNOSTIC_INFO) == 1)
 	{
-		counter = sizeof(tmpRequestHeader.authenticationToken);
+		dstDiagnosticInfo->innerDiagnosticInfo = convertToTDiagnosticInfo(buf,
+				pos);
 	}
-	tmpRequestHeader.timestamp = convertToUADateTime(buf, counter);
-	counter += sizeof(tmpRequestHeader.timestamp);
-	tmpRequestHeader.requestHandle = convertToTIntegerId(buf, counter);
-	counter += sizeof(tmpRequestHeader.requestHandle);
-	tmpRequestHeader.returnDiagnostics = convertToUInt32(buf, counter);
-	counter += sizeof(tmpRequestHeader.returnDiagnostics);
-	tmpRequestHeader.auditEntryId = convertToUAString(buf, counter);
-	counter += sizeof(tmpRequestHeader.auditEntryId);
-	tmpRequestHeader.timeoutHint = convertToUInt32(buf, counter);
-	counter += sizeof(tmpRequestHeader.timeoutHint);
-	// AdditionalHeader will stay empty, need to be changed if there is relevant information
 
-	return tmpRequestHeader;
+	return 0;
 }
 
 /**
-* ResponseHeader
-* Part: 4
-* Chapter: 7.27
-* Page: 133
-*/
-decodeResponseHeader(const T_ResponseHeader *responseHeader, AD_RawMessage *buf)
-{
+ * RequestHeader
+ * Part: 4
+ * Chapter: 7.26
+ * Page: 132
+ */
 
-	int counter = 0;
-	responseHeader->timestamp = convertToUADateTime(buf->message, counter);
-	counter += sizeof(responseHeader->timestamp);
-	responseHeader->requestHandle = convertToTIntegerId(buf->message, counter);
-	counter += sizeof(responseHeader->requestHandle);
-	responseHeader->serviceResult = convertToUAStatusCode(buf->message, counter);
-	counter += sizeof(responseHeader->serviceResult);
-	responseHeader->serviceDiagnostics = convertToTDiagnosticInfo(buf->message, counter);
+/** \copydoc decodeRequestHeader */
+Int32 decodeRequestHeader(const AD_RawMessage *srcRaw, Int32 *pos,
+		T_RequestHeader *dstRequestHeader)
+{
 
-}
+	convertToUANodeId(srcRaw->message, pos,&(dstRequestHeader->authenticationToken));
+	dstRequestHeader->timestamp = convertToUADateTime(srcRaw->message, pos);
+	dstRequestHeader->requestHandle = convertToIntegerId(srcRaw->message, pos);
+	dstRequestHeader->returnDiagnostics = convertToUInt32(srcRaw->message, pos);
+	convertToUAString(srcRaw->message, pos, &dstRequestHeader->auditEntryId);
+	dstRequestHeader->timeoutHint = convertToUInt32(srcRaw->message, pos);
 
-void decodeMessage_test()
-{
+	// AdditionalHeader will stay empty, need to be changed if there is relevant information
 
-	char testMessage = {01,0x20,0xbe,0x01,0x20,0x20,0xf2,0xd6,0xd6,0xc9,0x01,0x00,0xbe,0x01,0x00,0x00,0xf2,0xd6,0xd6,0xc9,0x87,0x0b,0xcf,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0xe0,0x93,0x04,0x00,0x,0x};
-	AD_RawMessage rawMessage;
-	rawMessage.message = testMessage;
-	rawMessage.length = 64;
-	decodeMessage(testMessage);
+	return 0;
 }
-/*
- * builds a message structure by decoding a byte stream
+
+/**
+ * ResponseHeader
+ * Part: 4
+ * Chapter: 7.27
+ * Page: 133
  */
-UA_ExtensionObject processMessage(AD_RawMessage *rawMessage)
+/** \copydoc decodeResponseHeader */
+Int32 decodeResponseHeader(const T_ResponseHeader *responseHeader, Int32 *pos, AD_RawMessage *buf)
 {
-	UA_NodeId tmpNodeId = convertToUANodeId(rawMessage,0);
-
+	responseHeader->timestamp = convertToUADateTime(buf->message, pos);
+	responseHeader->requestHandle = convertToTIntegerId(buf->message, pos);
+	responseHeader->serviceResult = convertToUAStatusCode(buf->message,
+			pos);
 
-	//callServiceHandler(tmpNodeId,rawMessage);
+	responseHeader->serviceDiagnostics = convertToTDiagnosticInfo(buf->message,
+			pos);
+	return 0;
 }
 
 
+

+ 61 - 59
OPCUAServer/src/opcua_secureChannelLayer.c

@@ -6,10 +6,14 @@
  */
 #include "opcua_secureChannelLayer.h"
 
+
 Int32 SL_openSecureChannelRequest_check(const UA_connection *connection, secureChannelMessage)
 {
-
+	return 0;
 }
+
+
+
 /*
  * respond the securechannel_open request
  */
@@ -53,10 +57,8 @@ Int32 SL_secureChannel_open(const UA_connection *connection,
 		const SL_AsymmetricAlgorithmSecurityHeader *AAS_Header)
 {
 	SL_Response response;
-	T_ResponseHeader responseHeader;
 
-	SL_secureChannel_Response_form(connection,&response);
-	SL_secureChannel_ResponseHeader_form(connection,&responseHeader);
+
 
 
 	TL_send();
@@ -71,7 +73,7 @@ Int32 SL_secureChannel_open(const UA_connection *connection,
  {
 
  }
- */
+
 /*
  * closes a secureChannel (server side)
  */
@@ -89,65 +91,65 @@ void SL_secureChannel_close(UA_connection *connection)
  */
 void SL_receive(UA_connection *connection, AD_RawMessage *serviceMessage)
 {
-AD_RawMessage* secureChannelMessage;
-SL_SecureConversationMessageHeader SCM_Header;
-SL_AsymmetricAlgorithmSecurityHeader AAS_Header;
+	AD_RawMessage* secureChannelMessage;
+	SL_SecureConversationMessageHeader SCM_Header;
+	SL_AsymmetricAlgorithmSecurityHeader AAS_Header;
 
-//get data from transport layer
-TL_receive(UA_connection, secureChannelMessage);
+	//get data from transport layer
+	TL_receive(UA_connection, secureChannelMessage);
 
-//get the Secure Channel Message Header
-UInt32 readPosition = SL_secureChannel_SCMHeader_get(connection,
-		secureChannelMessage, &SCM_Header);
+	//get the Secure Channel Message Header
+	UInt32 readPosition = SL_secureChannel_SCMHeader_get(connection,
+			secureChannelMessage, &SCM_Header);
 
-//get the Secure Channel Asymmetric Algorithm Security Header
-readPosition = SL_secureChannel_AASHeader_get(connection, secureChannelMessage,
-		readPosition, &AAS_Header);
+	//get the Secure Channel Asymmetric Algorithm Security Header
+	readPosition = SL_secureChannel_AASHeader_get(connection, secureChannelMessage,
+			readPosition, &AAS_Header);
 
-//get Secure Channel Message
-SL_secureChannel_Message_get(connection, secureChannelMessage, readPosition,
-		serviceMessage);
+	//get Secure Channel Message
+	SL_secureChannel_Message_get(connection, secureChannelMessage, readPosition,
+			serviceMessage);
 
-if (secureChannelMessage.length > 0)
-{
-	switch (SCM_Header.MessageType)
+	if (secureChannelMessage.length > 0)
 	{
-	case packetType_MSG:
-		if (connection->secureLayer.connectionState
-				== connectionState_ESTABLISHED)
+		switch (SCM_Header.MessageType)
 		{
-
+		case packetType_MSG:
+			if (connection->secureLayer.connectionState
+					== connectionState_ESTABLISHED)
+			{
+
+			}
+			else //receiving message, without secure channel
+			{
+				//TODO send back Error Message
+			}
+			break;
+		case packetType_OPN:
+			//Server Handling
+			if (openSecureChannelHeader_check(connection, secureChannelMessage))
+			{
+				//check if the request is valid
+				SL_openSecureChannelRequest_check(connection, secureChannelMessage);
+			}
+			SL_secureChannel_open(connection, serviceMessage);
 		}
-		else //receiving message, without secure channel
+		else
 		{
 			//TODO send back Error Message
 		}
-		break;
-	case packetType_OPN:
-		//Server Handling
-		if (openSecureChannelHeader_check(connection, secureChannelMessage))
-		{
-			//check if the request is valid
-			SL_openSecureChannelRequest_check(connection, secureChannelMessage);
-		}
-		SL_secureChannel_open(connection, serviceMessage);
-	}
-	else
-	{
-		//TODO send back Error Message
-	}
 
-	//Client Handling
+		//Client Handling
 
-	//TODO free memory for secureChannelMessage
+		//TODO free memory for secureChannelMessage
 
-	break;
-	case packetType_CLO:
-	SL_secureChannel_close(connection, secureChannelMessage);
+		break;
+		case packetType_CLO:
+		SL_secureChannel_close(connection, secureChannelMessage);
 
-	//TODO free memory for secureChannelMessage
-	break;
-}
+		//TODO free memory for secureChannelMessage
+		break;
+	}
 
 }
 /*
@@ -156,16 +158,16 @@ if (secureChannelMessage.length > 0)
 UInt32 SL_secureChannel_SCMHeader_get(UA_connection *connection,
 	AD_RawMessage *rawMessage, 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 = convertToUInt32(rawMessage, pos);
-pos += sizeof(UInt32);
-SC_Header->SecureChannelId = convertToUInt32(rawMessage, pos);
-pos += sizeof(UInt32);
-return pos;
+	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 = convertToUInt32(rawMessage, pos);
+	pos += sizeof(UInt32);
+	SC_Header->SecureChannelId = convertToUInt32(rawMessage, pos);
+	pos += sizeof(UInt32);
+	return pos;
 
 }
 /*

+ 1 - 0
OPCUAServer/src/opcua_secureChannelLayer.h

@@ -9,6 +9,7 @@
 #define OPCUA_SECURECHANNELLAYER_H_
 
 #include "opcua_advancedDatatypes.h"
+#include "opcua_encodingLayer.h"
 static const Int32 SL_HEADER_LENGTH = 0;
 typedef struct _SL_ChannelSecurityToken
 {

+ 66 - 3
OPCUAServer/tests/check_stack.c

@@ -13,7 +13,7 @@
 #include "../src/opcua_transportLayer.h"
 #include "check.h"
 
-START_TEST(test_getPacketType_correctArgument)
+START_TEST(test_getPacketType_validParameter)
 {
 
 	char buf[] = {'C','L','O'};
@@ -23,25 +23,88 @@ START_TEST(test_getPacketType_correctArgument)
 
 	ck_assert_int_eq(TL_getPacketType(&rawMessage),packetType_CLO);
 
-}END_TEST
+}
+END_TEST
+
+
+START_TEST(test_decodeRequestHeader_validParameter)
+{
+		char testMessage = {0x00,0x00,0x72,0xf1,0xdc,0xc9,0x87,0x0b,
+							0xcf,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
+							0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,
+							0x00,0x00,0x00,0x00,0x00};
+		AD_RawMessage rawMessage;
+		rawMessage.message = testMessage;
+		rawMessage.length = 29;
+		Int32 position = 0;
+		T_RequestHeader requestHeader;
+		decodeRequestHeader(rawMessage,&position,requestHeader);
+
+		ck_assert_int_eq(requestHeader.authenticationToken.EncodingByte,0);
+
+		ck_assert_int_eq(requestHeader.returnDiagnostics,0);
+
+		ck_assert_int_eq(requestHeader.authenticationToken.EncodingByte,0);
+}
+END_TEST
+
 
 Suite* TL_testSuite_getPacketType(void)
 {
 	Suite *s = suite_create("getPacketType");
 	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core,test_getPacketType_correctArgument);
+	tcase_add_test(tc_core,test_getPacketType_validParameter);
 	suite_add_tcase(s,tc_core);
 	return s;
 }
 
+
+Suite* EC_testSuite_encodeRequestHeader()
+{
+	Suite *s = suite_create("");
+	TCase *tc_core = tcase_create("Core");
+	tcase_add_test(tc_core,<TEST_NAME>);
+	suite_add_tcase(s,tc_core);
+	return s;
+}
+/*
+Suite* TL_<TESTSUITENAME>(void)
+{
+	Suite *s = suite_create("<TESTSUITENAME>");
+	TCase *tc_core = tcase_create("Core");
+	tcase_add_test(tc_core,<TEST_NAME>);
+	suite_add_tcase(s,tc_core);
+	return s;
+}
+*/
+
 int main (void)
 {
 	int number_failed;
+
+
 	Suite *s = TL_testSuite_getPacketType();
 	SRunner *sr = srunner_create(s);
 	srunner_run_all(sr,CK_NORMAL);
 	number_failed = srunner_ntests_failed(sr);
 	srunner_free(sr);
 
+
+	s =  EC_testSuite_encodeRequestHeader();
+	sr = srunner_create(s);
+	srunner_run_all(sr,CK_NORMAL);
+	number_failed += srunner_ntests_failed(sr);
+	srunner_free(sr);
+
+
+	/* <TESTSUITE_TEMPLATE>
+	s =  <TESTSUITENAME>;
+	sr = srunner_create(s);
+	srunner_run_all(sr,CK_NORMAL);
+	number_failed += srunner_ntests_failed(sr);
+	srunner_free(sr);
+	*/
 	return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 }
+
+