From 6895d8214b7e13d29b10a36778674f5a86176672 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Fri, 20 Jan 2023 16:02:19 +0000 Subject: [PATCH] - MMS server: add function to ignore client requests (for test purposes) --- hal/memory/lib_memory.c | 3 --- src/iec61850/inc/iec61850_server.h | 10 ++++++- src/iec61850/server/impl/ied_server.c | 10 ++++++- src/mms/asn1/asn1_ber_primitive_value.c | 26 +++++++++---------- src/mms/asn1/ber_decode.c | 2 +- src/mms/asn1/ber_encoder.c | 25 ++++++++++++++++-- src/mms/asn1/ber_integer.c | 2 +- src/mms/inc/mms_server.h | 5 +++- src/mms/inc_private/mms_server_internal.h | 3 ++- src/mms/inc_private/mms_server_libinternal.h | 4 +-- src/mms/iso_mms/server/mms_server.c | 12 ++++++--- .../iso_mms/server/mms_server_connection.c | 3 +++ 12 files changed, 75 insertions(+), 30 deletions(-) diff --git a/hal/memory/lib_memory.c b/hal/memory/lib_memory.c index adeb105a..74fde5b4 100644 --- a/hal/memory/lib_memory.c +++ b/hal/memory/lib_memory.c @@ -38,7 +38,6 @@ Memory_malloc(size_t size) return memory; } - void* Memory_calloc(size_t nmemb, size_t size) { @@ -50,7 +49,6 @@ Memory_calloc(size_t nmemb, size_t size) return memory; } - void * Memory_realloc(void *ptr, size_t size) { @@ -67,4 +65,3 @@ Memory_free(void* memb) { free(memb); } - diff --git a/src/iec61850/inc/iec61850_server.h b/src/iec61850/inc/iec61850_server.h index d206b904..e3790011 100644 --- a/src/iec61850/inc/iec61850_server.h +++ b/src/iec61850/inc/iec61850_server.h @@ -3,7 +3,7 @@ * * IEC 61850 server API for libiec61850. * - * Copyright 2013-2022 Michael Zillgith + * Copyright 2013-2023 Michael Zillgith * * This file is part of libIEC61850. * @@ -783,6 +783,14 @@ typedef void (*IedConnectionIndicationHandler) (IedServer self, ClientConnection LIB61850_API void IedServer_setConnectionIndicationHandler(IedServer self, IedConnectionIndicationHandler handler, void* parameter); +/** + * \brief Ignore all requests from clients + * + * \param self the instance of IedServer to configure. + * \param enable when true all requests from clients will be ignored + */ +void +IedServer_ignoreClientRequests(IedServer self, bool enable); /**@}*/ diff --git a/src/iec61850/server/impl/ied_server.c b/src/iec61850/server/impl/ied_server.c index 9416d200..c543a41d 100644 --- a/src/iec61850/server/impl/ied_server.c +++ b/src/iec61850/server/impl/ied_server.c @@ -1,7 +1,7 @@ /* * ied_server.c * - * Copyright 2013-2022 Michael Zillgith + * Copyright 2013-2023 Michael Zillgith * * This file is part of libIEC61850. * @@ -1909,3 +1909,11 @@ IedServer_setTimeQuality(IedServer self, bool leapSecondKnown, bool clockFailure self->timeQuality = timeQuality; } + +void +IedServer_ignoreClientRequests(IedServer self, bool enable) +{ + if (self->mmsServer) { + MmsServer_ignoreClientRequests(self->mmsServer, enable); + } +} diff --git a/src/mms/asn1/asn1_ber_primitive_value.c b/src/mms/asn1/asn1_ber_primitive_value.c index 0dbd15bf..55cf626b 100644 --- a/src/mms/asn1/asn1_ber_primitive_value.c +++ b/src/mms/asn1/asn1_ber_primitive_value.c @@ -1,24 +1,24 @@ /* * asn1_ber_primitive_value.c * - * Copyright 2013-2020 Michael Zillgith + * Copyright 2013-2022 Michael Zillgith * - * This file is part of libIEC61850. + * This file is part of libIEC61850. * - * libIEC61850 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * libIEC61850 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * libIEC61850 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * libIEC61850 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with libIEC61850. If not, see . + * You should have received a copy of the GNU General Public License + * along with libIEC61850. If not, see . * - * See COPYING file for the complete license text. + * See COPYING file for the complete license text. */ #include "libiec61850_platform_includes.h" diff --git a/src/mms/asn1/ber_decode.c b/src/mms/asn1/ber_decode.c index 12078610..8a4866a8 100644 --- a/src/mms/asn1/ber_decode.c +++ b/src/mms/asn1/ber_decode.c @@ -1,7 +1,7 @@ /* * ber_decoder.c * - * Copyright 2013 Michael Zillgith + * Copyright 2013-2022 Michael Zillgith * * This file is part of libIEC61850. * diff --git a/src/mms/asn1/ber_encoder.c b/src/mms/asn1/ber_encoder.c index 63566f38..53a5d178 100644 --- a/src/mms/asn1/ber_encoder.c +++ b/src/mms/asn1/ber_encoder.c @@ -1,7 +1,7 @@ /* * ber_encoder.c * - * Copyright 2013 Michael Zillgith + * Copyright 2013-2022 Michael Zillgith * * This file is part of libIEC61850. * @@ -356,6 +356,28 @@ BerEncoder_UInt32determineEncodedSize(uint32_t value) return size; } +int +BerEncoder_Int32determineEncodedSize(int32_t value) +{ + uint8_t* valueArray = (uint8_t*) &value; + uint8_t valueBuffer[5]; + + valueBuffer[0] = 0; + + int i; + for (i = 0; i < 4; i++) { + valueBuffer[i + 1] = valueArray[i]; + } + +#if (ORDER_LITTLE_ENDIAN == 1) + BerEncoder_revertByteOrder(valueBuffer + 1, 4); +#endif + + int size = BerEncoder_compressInteger(valueBuffer, 5); + + return size; +} + int BerEncoder_determineLengthSize(uint32_t length) { @@ -457,7 +479,6 @@ BerEncoder_encodeOIDToBuffer(const char* oidString, uint8_t* buffer, int maxBufL requiredBytes--; } } - } return encodedBytes; diff --git a/src/mms/asn1/ber_integer.c b/src/mms/asn1/ber_integer.c index 9a7e8030..01281e3f 100644 --- a/src/mms/asn1/ber_integer.c +++ b/src/mms/asn1/ber_integer.c @@ -1,7 +1,7 @@ /* * ber_integer.c * - * Copyright 2013-2020 Michael Zillgith + * Copyright 2013-2022 Michael Zillgith * * This file is part of libIEC61850. * diff --git a/src/mms/inc/mms_server.h b/src/mms/inc/mms_server.h index 7e6118d0..98e4c796 100644 --- a/src/mms/inc/mms_server.h +++ b/src/mms/inc/mms_server.h @@ -1,7 +1,7 @@ /* * mms_server.h * - * Copyright 2013-2018 Michael Zillgith + * Copyright 2013-2023 Michael Zillgith * * This file is part of libIEC61850. * @@ -370,6 +370,9 @@ MmsServerConnection_getLocalAddress(MmsServerConnection self); LIB61850_INTERNAL void* MmsServerConnection_getSecurityToken(MmsServerConnection self); +LIB61850_INTERNAL void +MmsServer_ignoreClientRequests(MmsServer self, bool enable);; + /**@}*/ #ifdef __cplusplus diff --git a/src/mms/inc_private/mms_server_internal.h b/src/mms/inc_private/mms_server_internal.h index 780e1d74..727e97a3 100644 --- a/src/mms/inc_private/mms_server_internal.h +++ b/src/mms/inc_private/mms_server_internal.h @@ -135,7 +135,8 @@ struct sMmsServer { Map openConnections; Map valueCaches; - bool isLocked; + + bool blockRequests; ByteBuffer* transmitBuffer; /* global buffer for encoding reports, delayed responses... */ #if (CONFIG_MMS_THREADLESS_STACK != 1) diff --git a/src/mms/inc_private/mms_server_libinternal.h b/src/mms/inc_private/mms_server_libinternal.h index ac16e445..444989c9 100644 --- a/src/mms/inc_private/mms_server_libinternal.h +++ b/src/mms/inc_private/mms_server_libinternal.h @@ -1,7 +1,7 @@ /* * mms_server_libinternal.h * - * Copyright 2013-2022 Michael Zillgith + * Copyright 2013-2023 Michael Zillgith * * This file is part of libIEC61850. * @@ -196,7 +196,7 @@ MmsServer_getConnectionCounter(MmsServer self); LIB61850_INTERNAL void MmsServer_stopListeningThreadless(MmsServer self); -LIB61850_INTERNAL const char* +LIB61850_INTERNAL const char* MmsServer_getFilesystemBasepath(MmsServer self); #endif /* MMS_SERVER_LIBINTERNAL_H_ */ diff --git a/src/mms/iso_mms/server/mms_server.c b/src/mms/iso_mms/server/mms_server.c index 3905b52d..ed2cf725 100644 --- a/src/mms/iso_mms/server/mms_server.c +++ b/src/mms/iso_mms/server/mms_server.c @@ -1,7 +1,7 @@ /* * mms_server.c * - * Copyright 2013-2020 Michael Zillgith + * Copyright 2013-2023 Michael Zillgith * * This file is part of libIEC61850. * @@ -95,13 +95,13 @@ MmsServer_create(MmsDevice* device, TLSConfiguration tlsConfiguration) if (self->valueCaches == NULL) goto exit_error; - self->isLocked = false; - self->transmitBuffer = ByteBuffer_create(NULL, CONFIG_MMS_MAXIMUM_PDU_SIZE); if (self->transmitBuffer == NULL) goto exit_error; + self->blockRequests = false; + #if (CONFIG_MMS_SERVER_CONFIG_SERVICES_AT_RUNTIME == 1) self->fileServiceEnabled = true; self->dynamicVariableListServiceEnabled = true; @@ -820,4 +820,8 @@ MmsServer_getFilesystemBasepath(MmsServer self) #endif } - +void +MmsServer_ignoreClientRequests(MmsServer self, bool enable) +{ + self->blockRequests = enable; +} diff --git a/src/mms/iso_mms/server/mms_server_connection.c b/src/mms/iso_mms/server/mms_server_connection.c index b14ecc3a..4f914081 100644 --- a/src/mms/iso_mms/server/mms_server_connection.c +++ b/src/mms/iso_mms/server/mms_server_connection.c @@ -665,6 +665,9 @@ handleConfirmedResponsePdu( static inline void MmsServerConnection_parseMessage(MmsServerConnection self, ByteBuffer* message, ByteBuffer* response) { + if (self->server->blockRequests) + return; + uint8_t* buffer = message->buffer; if (message->size < 2)