FlorianPalm 11 роки тому
батько
коміт
e2b8953a30

+ 2 - 0
OPCUAServer/src/opcua_builtInDatatypes.h

@@ -479,6 +479,8 @@ typedef struct _UA_DataValue
 }
 UA_DataValue;
 
+typedef UInt32 IntegerId;
+
 
 /**
 * Duration

+ 15 - 14
OPCUAServer/src/opcua_encodingLayer.c

@@ -15,7 +15,7 @@
 * Chapter: 7.13
 * Page: 118
 */
-T_IntegerId convertToTIntegerId(char* buf, int pos){
+T_IntegerId convertToIntegerId(char* buf, int pos){
 	return convertToUInt32(buf, pos);
 }
 
@@ -25,7 +25,7 @@ T_IntegerId convertToTIntegerId(char* buf, int pos){
 * Chapter: 7.9
 * Page: 116
 */
-T_DiagnosticInfo convertToTDiagnosticInfo(char* buf, int pos){
+T_DiagnosticInfo convertToDiagnosticInfo(char* buf, int pos){
 	T_DiagnosticInfo tmpTDiagnosticInfo;
 	int counter = 0;
 	tmpTDiagnosticInfo.namespaceUri = convertToInt32(buf, counter);
@@ -55,7 +55,7 @@ T_DiagnosticInfo convertToTDiagnosticInfo(char* buf, int pos){
 * Chapter: 7.26
 * Page: 132
 */
-T_RequestHeader encodeRequestHeader(char* buf)
+T_RequestHeader decodeRequestHeader(char* buf)
 {
 	T_RequestHeader tmpRequestHeader;
 	int counter = 0;
@@ -95,19 +95,18 @@ T_RequestHeader encodeRequestHeader(char* buf)
 * Chapter: 7.27
 * Page: 133
 */
-T_ResponseHeader encodeTResponseHeader(char* buf){
-	T_ResponseHeader tmpResponseHeader;
-	int counter = 0;
-	tmpResponseHeader.timestamp = convertToUADateTime(buf, counter);
-	counter += sizeof(tmpResponseHeader.timestamp);
-	tmpResponseHeader.requestHandle = convertToTIntegerId(buf, counter);
-	counter += sizeof(tmpResponseHeader.requestHandle);
-	tmpResponseHeader.serviceResult = convertToUAStatusCode(buf, counter);
-	counter += sizeof(tmpResponseHeader.serviceResult);
-	tmpResponseHeader.serviceDiagnostics = convertToTDiagnosticInfo(buf, counter);
+decodeResponseHeader(const T_ResponseHeader *responseHeader, AD_RawMessage *buf)
+{
 
+	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);
 
-	return tmpResponseHeader;
 }
 
 void decodeMessage_test()
@@ -129,3 +128,5 @@ UA_ExtensionObject processMessage(AD_RawMessage *rawMessage)
 
 	//callServiceHandler(tmpNodeId,rawMessage);
 }
+
+

+ 26 - 0
OPCUAServer/src/opcua_encodingLayer.h

@@ -9,5 +9,31 @@
 #define OPCUA_ENCODINGLAYER_H_
 
 
+T_RequestHeader decodeRequestHeader(char *buf);
+
+Int32 encodeRequestHeader(T_RequestHeader *header,char *dstBuf, Int32 *outBufLen);
+
+
+
+T_ResponseHeader EL_decodeResponseHeader(AD_RawMessage *dstBuf);
+/**
+ *  \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 EL_encodeResponseHeader(T_ResponseHeader *header,AD_RawMessage* *dstBuf);
+
+/**
+ *  \brief function to encode a secureChannelRequest
+ *
+ * \param request   a open secure channel request structure which should be encoded to binary format
+ * \param dstBuf    pointer to a structure which hold the encoded request
+ * \return
+ */
+//Int32 EL_encodeOpenSecureChannelRequest(T_openSecureChannelRequest* request, AD_RawMessage* dstBuf;
+
 
 #endif /* OPCUA_ENCODINGLAYER_H_ */

+ 35 - 3
OPCUAServer/src/opcua_secureChannelLayer.c

@@ -13,10 +13,36 @@ Int32 SL_openSecureChannelRequest_check(const UA_connection *connection, secureC
 /*
  * respond the securechannel_open request
  */
-
-Int32 SL_secureChannel_respond(UA_connection *connection, SL_Response *response)
+Int32 SL_secureChannel_ResponseHeader_form(UA_connection *connection, T_ResponseHeader *responseHeader)
 {
+	responseHeader->timestamp = 0;//TODO getCurrentTime();
+	responseHeader->requestHandle = 0;
+	responseHeader->serviceResult = 0; // TODO insert service result code
+
+	responseHeader->serviceDiagnostics.EncodingMask = 0;
+	responseHeader->noOfStringTable = 0;
+
+	responseHeader->additionalHeader.Body = 0;
+	responseHeader->additionalHeader.Encoding = 0;
+	responseHeader->additionalHeader.Length = 0;
+
+	responseHeader->additionalHeader.TypeId.Namespace = 0;
+	responseHeader->additionalHeader.TypeId.Identifier = 0;
 
+
+	responseHeader->requestHandle = 0;
+}
+/*
+ *
+ */
+Int32 SL_secureChannel_Response_form(UA_connection *connection, SL_Response *response)
+{
+	response->ServerProtocolVersion = 0; //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
 }
 /*
  * opens a secureChannel (server side)
@@ -26,11 +52,17 @@ Int32 SL_secureChannel_open(const UA_connection *connection,
 		const SL_SecureConversationMessageHeader *SCM_Header,
 		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();
 	//client protocol Version
 
-connection->secureLayer.secureChannelId = AAS_Header->
+
 //connection->secureLayer.
 }
 /*

+ 22 - 6
OPCUAServer/src/opcua_secureChannelLayer.h

@@ -8,20 +8,25 @@
 #ifndef OPCUA_SECURECHANNELLAYER_H_
 #define OPCUA_SECURECHANNELLAYER_H_
 
+#include "opcua_advancedDatatypes.h"
 static const Int32 SL_HEADER_LENGTH = 0;
-typedef struct _SL_SecurityToken
+typedef struct _SL_ChannelSecurityToken
 {
 	UInt32 ChannelId;
 	UInt32 TokenId;
 	UA_DateTime CreatedAt;
 	Int32 RevisedLifeTime;
-}SL_SecurityToken;
+}SL_ChannelSecurityToken;
+
+
 typedef struct _SL_OpenSecureChannelResponse
 {
 	UInt32 ServerProtocolVersion;
-	SL_SecurityToken ChannelSecurityToken;
+	SL_ChannelSecurityToken SecurityToken;
 	UA_String ServerNonce;
 }SL_Response;
+
+
 typedef struct _SL_SecureConversationMessageHeader
 {
 	UInt32 MessageType;
@@ -29,6 +34,8 @@ typedef struct _SL_SecureConversationMessageHeader
 	UInt32 MessageSize;
 	UInt32 SecureChannelId;
 }SL_SecureConversationMessageHeader;
+
+
 typedef struct _SL_AsymmetricAlgorithmSecurityHeader
 {
 	UA_String SecurityPolicyUri;
@@ -54,8 +61,17 @@ typedef struct _SL_AsymmetricAlgorithmSecurityFooter
 	Byte *Signature;
 }SL_AsymmetricAlgorithmSecurityFooter;
 
-
-
-
+/*
+typedef struct _SL_ResponseHeader
+{
+	UA_DateTime timestamp;
+    IntegerId requestHandle;
+    UA_StatusCode serviceResult;
+    UA_DiagnosticInfo serviceDiagnostics;
+    UA_String *stringTable;
+    UInt32 stringTableLength;
+    UA_ExtensionObject additionalHeader;
+}SL_ResponseHeader;
+*/
 
 #endif /* OPCUA_SECURECHANNELLAYER_H_ */

+ 2 - 2
OPCUAServer/src/opcua_types.h

@@ -773,7 +773,7 @@ typedef struct _T_RequestHeader
 	UInt32 returnDiagnostics;
 	UA_String auditEntryId;
 	UInt32 timeoutHint;
-	UA_ExpandedNodeId additionalHeader;
+	UA_ExtensionObject additionalHeader;
 }
 T_RequestHeader;
 
@@ -808,7 +808,7 @@ typedef struct _T_ResponseHeader
 	UA_DiagnosticInfo serviceDiagnostics;
 	UInt16 noOfStringTable;
 	UA_String* stringTable;
-//ToDo	struct BED_ExtensibleParameterAdditionalHeader additionalHeader;		//ToDo
+	UA_ExtensionObject additionalHeader;
 }
 T_ResponseHeader;