Quellcode durchsuchen

hel-ack-opn-opn-etc. game works again. session handling is missing

open62541 vor 11 Jahren
Ursprung
Commit
192ec3d80c

+ 1 - 1
examples/src/opcuaServerACPLT.c

@@ -120,7 +120,7 @@ void server_run() {
 				TL_Process(connection, &slMessage);
 			} else if (n <= 0) {
 				perror("ERROR reading from socket1");
-				exit(1);
+		//		exit(1);
 			}
 			UA_TL_Connection_getState(connection, &connectionState);
 		} while(connectionState != CONNECTIONSTATE_CLOSE);

+ 29 - 12
src/ua_stack_channel.c

@@ -15,10 +15,10 @@ typedef struct SL_Channel1 {
 
 	UA_TL_Connection1 connection;
 	UA_UInt32 requestId;
-	UA_UInt32 lastRequestId;
+	//UA_UInt32 lastRequestId;
 
 	UA_UInt32 sequenceNumber;
-	UA_UInt32 lastSequenceNumber;
+	//UA_UInt32 lastSequenceNumber;
 
 	UA_AsymmetricAlgorithmSecurityHeader remoteAsymAlgSettings;
 	UA_AsymmetricAlgorithmSecurityHeader localAsymAlgSettings;
@@ -185,7 +185,7 @@ _Bool SL_Channel_equal(void* channel1, void* channel2)
 	return (((SL_Channel1*)channel1)->channelId == ((SL_Channel1*)channel2)->channelId);
 }
 
-UA_Int32 SL_Channel_new(SL_secureChannel *channel,
+UA_Int32 SL_Channel_new(SL_secureChannel **channel,
 		SL_ChannelIdProvider channelIdProvider,
 		SL_ChannelSecurityTokenProvider tokenProvider,
 		UA_ByteString *receiverCertificateThumbprint,
@@ -195,10 +195,11 @@ UA_Int32 SL_Channel_new(SL_secureChannel *channel,
 
 {
 	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_alloc((void**)&channel,sizeof(SL_secureChannel));
-	retval |= UA_alloc((void**)channel,sizeof(SL_Channel1));
 
-	SL_Channel1 *thisChannel = (SL_Channel1*)(*channel);
+	retval |= UA_alloc((void**)channel,sizeof(SL_secureChannel));
+
+	SL_Channel1 *thisChannel = UA_NULL;
+	retval |= UA_alloc((void**)&thisChannel,sizeof(SL_Channel1));
 
 	thisChannel->channelIdProvider = channelIdProvider;
 	thisChannel->tokenProvider = tokenProvider;
@@ -216,6 +217,7 @@ UA_Int32 SL_Channel_new(SL_secureChannel *channel,
 
 	thisChannel->state = UA_SL_CHANNEL_CLOSED;
 
+	**channel = (SL_secureChannel)thisChannel;
 
 	return UA_SUCCESS;
 }
@@ -254,11 +256,11 @@ UA_Int32 SL_Channel_initByRequest(SL_secureChannel channel,
 
 	//init last requestId and sequenceNumber
 
-	channel->lastRequestId = sequenceHeader->requestId;
-	channel->lastSequenceNumber = sequenceHeader->sequenceNumber;
+	//channel->lastRequestId = sequenceHeader->requestId;
+	//channel->lastSequenceNumber = sequenceHeader->sequenceNumber;
 
-	channel->requestId = channel->lastRequestId;
-	channel->sequenceNumber = channel->lastSequenceNumber;
+	channel->requestId = sequenceHeader->requestId;//channel->lastRequestId;
+	channel->sequenceNumber = sequenceHeader->sequenceNumber;//channel->lastSequenceNumber;
 
 	channel->state = UA_SL_CHANNEL_CLOSED;
 
@@ -296,11 +298,26 @@ UA_Int32 SL_Channel_renewToken(SL_secureChannel channel, UA_UInt32 tokenId,UA_Da
 
 UA_Int32 SL_Channel_checkSequenceNumber(SL_secureChannel channel, UA_UInt32 sequenceNumber)
 {
-	if(((SL_Channel1*)channel)->sequenceNumber == sequenceNumber){
+	if(((SL_Channel1*)channel)->sequenceNumber+1 == sequenceNumber){
+		((SL_Channel1*)channel)->sequenceNumber++;
+
 		return UA_SUCCESS;
 	}
 	printf("SL_Channel_checkSequenceNumber - ERROR, wrong SequenceNumber expected: %i, received: %i",
-			((SL_Channel1*)channel)->sequenceNumber,sequenceNumber);
+			((SL_Channel1*)channel)->sequenceNumber+1,sequenceNumber);
+	return UA_ERROR;
+
+}
+
+UA_Int32 SL_Channel_checkRequestId(SL_secureChannel channel, UA_UInt32 requestId)
+{
+	if(((SL_Channel1*)channel)->requestId+1 == requestId){
+		((SL_Channel1*)channel)->requestId++;
+
+		return UA_SUCCESS;
+	}
+	printf("SL_Channel_requestId - ERROR, wrong requestId expected: %i, received: %i",
+			((SL_Channel1*)channel)->requestId+1,requestId);
 	return UA_ERROR;
 
 }

+ 3 - 1
src/ua_stack_channel.h

@@ -26,7 +26,7 @@ typedef UA_Int32 (*SL_ChannelIdProvider)(UA_UInt32*);
 
 
 
-UA_Int32 SL_Channel_new(SL_secureChannel *channel,
+UA_Int32 SL_Channel_new(SL_secureChannel **channel,
 		SL_ChannelIdProvider channelIdProvider,
 		SL_ChannelSecurityTokenProvider tokenProvider,
 		UA_ByteString *receiverCertificateThumbprint,
@@ -63,6 +63,8 @@ UA_Int32 SL_Channel_processCloseRequest(SL_secureChannel channel,
 		const UA_CloseSecureChannelRequest* request);
 UA_Int32 SL_Channel_registerTokenProvider(SL_secureChannel channel,SL_ChannelSecurityTokenProvider provider);
 UA_Int32 SL_Channel_registerChannelIdProvider(SL_ChannelIdProvider provider);
+UA_Int32 SL_Channel_checkRequestId(SL_secureChannel channel, UA_UInt32 requestId);
+
 UA_Int32 SL_Channel_checkSequenceNumber(SL_secureChannel channel, UA_UInt32 sequenceNumber);
 _Bool SL_Channel_equal(void* channel1, void* channel2);
 //getters

+ 5 - 2
src/ua_transport_binary.c

@@ -119,7 +119,7 @@ static UA_Int32 TL_handleHello(TL_Connection* connection, const UA_ByteString* m
 static UA_Int32 TL_handleOpen(UA_TL_Connection1 connection, const UA_ByteString* msg, UA_Int32* pos) {
 	UA_Int32 state;
 	UA_TL_Connection_getState(connection,&state);
-	SL_secureChannel *channel = UA_NULL;
+	SL_secureChannel *channel;
 
 
 
@@ -143,7 +143,7 @@ static UA_Int32 TL_handleOpen(UA_TL_Connection1 connection, const UA_ByteString*
 		senderCertificate.data = UA_NULL;
 		senderCertificate.length = 0;
 
-		SL_Channel_new(channel,
+		SL_Channel_new(&channel,
 				SL_ChannelManager_generateChannelId,
 				SL_ChannelManager_generateToken,
 				&receiverCertificateThumbprint,
@@ -185,6 +185,9 @@ static UA_Int32 TL_handleClo(UA_TL_Connection1 connection, const UA_ByteString*
 	retval |= SL_ChannelManager_removeChannel(header->secureChannelId);
 
 	retval |= UA_SecureConversationMessageHeader_delete(header);
+
+//TODO remove that
+	UA_TL_Connection_close(connection);
 	return retval;
 }
 

+ 1 - 2
src/ua_transport_binary_secure.c

@@ -237,7 +237,6 @@ UA_Int32 SL_handleRequest(SL_secureChannel channel, const UA_ByteString* msg,
 		UA_ResponseHeader_encodeBinary(&r, pos, &response_msg);
 		responsetype = UA_RESPONSEHEADER_NS0;
 	}
-
 	SL_Send(channel, &response_msg, responsetype);
 	UA_ByteString_deleteMembers(&response_msg);
 
@@ -326,7 +325,7 @@ UA_Int32 SL_Process(const UA_ByteString* msg,
 		UA_SequenceHeader_decodeBinary(msg, pos,
 				&sequenceHeader);
 		SL_Channel_checkSequenceNumber(channel,sequenceHeader.sequenceNumber);
-
+		SL_Channel_checkRequestId(channel,sequenceHeader.requestId);
 		//request id processing
 
 

+ 1 - 1
src/ua_transport_connection.c

@@ -44,7 +44,7 @@ UA_Int32 UA_TL_Connection_delete(UA_TL_Connection1 connection)
 }
 UA_Int32 UA_TL_Connection_close(UA_TL_Connection1 connection)
 {
-	((TL_Connection*)connection)->state = CONNECTIONSTATE_CLOSED;
+	((TL_Connection*)connection)->state = CONNECTIONSTATE_CLOSE;
 	return UA_SUCCESS;
 }
 UA_Int32 UA_TL_Connection_configByHello(UA_TL_Connection1 connection, UA_OPCUATcpHelloMessage *helloMessage)