From 57656bdfb50e6380867a9982c1970f8c8b790ae4 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Thu, 21 Jan 2021 14:27:50 +0100 Subject: [PATCH] - IED server: reporting - implemented behavior according to tissue 1432 --- src/iec61850/server/mms_mapping/reporting.c | 64 ++++++++++++++++----- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/src/iec61850/server/mms_mapping/reporting.c b/src/iec61850/server/mms_mapping/reporting.c index 27261195..a3b40742 100644 --- a/src/iec61850/server/mms_mapping/reporting.c +++ b/src/iec61850/server/mms_mapping/reporting.c @@ -805,6 +805,11 @@ createUnbufferedReportControlBlock(ReportControlBlock* reportControlBlock, } } + /* check if there is a pre configured owner */ + if (reportControlBlock->clientReservation[0] > 0) { + MmsValue_setBoolean(mmsValue->value.structure.components[2], true); + } + reportControl->rcbValues = mmsValue; reportControl->timeOfEntry = MmsValue_newBinaryTime(false); @@ -1267,7 +1272,7 @@ increaseConfRev(ReportControl* self) static void checkReservationTimeout(ReportControl* rc) { - if (rc->enabled == false) { + if (rc->enabled == false && (rc->clientConnection == NULL)) { if (rc->reservationTimeout > 0) { if (Hal_getTimeInMs() > rc->reservationTimeout) { @@ -1307,6 +1312,9 @@ isIpAddressMatchingWithOwner(ReportControl* rc, const char* ipAddress) if (owner != NULL) { + if (MmsValue_getOctetStringSize(owner) == 0) + return true; + if (strchr(ipAddress, '.') != NULL) { uint8_t ipV4Addr[4]; @@ -1336,16 +1344,23 @@ reserveRcb(ReportControl* rc, MmsServerConnection connection) rc->reserved = true; rc->clientConnection = connection; + if (rc->buffered) { #if (CONFIG_IEC61850_BRCB_WITH_RESVTMS == 1) - MmsValue* resvTmsVal = ReportControl_getRCBValue(rc, "ResvTms"); - if (resvTmsVal) - MmsValue_setInt16(resvTmsVal, rc->resvTms); + MmsValue* resvTmsVal = ReportControl_getRCBValue(rc, "ResvTms"); + if (resvTmsVal) + MmsValue_setInt16(resvTmsVal, rc->resvTms); #endif + } + else { + MmsValue* resvVal = ReportControl_getRCBValue(rc, "Resv"); + if (resvVal) + MmsValue_setBoolean(resvVal, true); + } - rc->reservationTimeout = Hal_getTimeInMs() + (RESV_TMS_IMPLICIT_VALUE * 1000); updateOwner(rc, connection); } +#if 1 MmsDataAccessError Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, char* elementName, MmsValue* value, MmsServerConnection connection) @@ -1354,7 +1369,8 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, char* eleme ReportControl_lockNotify(rc); - bool resvTmsAccess = false; + bool resvTmsAccess = false; /* access is to RecvTms or Resv */ + bool dontUpdate = false; /* check reservation timeout for buffered RCBs */ if (rc->buffered) { @@ -1529,6 +1545,8 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, char* eleme } if (strcmp(elementName, "Resv") == 0) { + resvTmsAccess = true; + rc->reserved = value->value.boolean; if (rc->reserved == true) { @@ -1538,6 +1556,9 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, char* eleme else { updateOwner(rc, NULL); rc->clientConnection = NULL; + + if (rc->resvTms == -1) + dontUpdate = true; } } @@ -1717,8 +1738,11 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, char* eleme MmsValue* rcbValue = ReportControl_getRCBValue(rc, elementName); - if (rcbValue != NULL) - MmsValue_update(rcbValue, value); + if (rcbValue) { + if (dontUpdate == false) { + MmsValue_update(rcbValue, value); + } + } else { retVal = DATA_ACCESS_ERROR_OBJECT_VALUE_INVALID; goto exit_function; @@ -1732,13 +1756,20 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, char* eleme exit_function: /* every successful write access reserves the RCB */ - if ((rc->buffered) && (retVal == DATA_ACCESS_ERROR_SUCCESS) && (resvTmsAccess == false)) { - if (rc->resvTms == 0) { - rc->resvTms = RESV_TMS_IMPLICIT_VALUE; + if ((retVal == DATA_ACCESS_ERROR_SUCCESS) && (resvTmsAccess == false)) { + if (rc->buffered) { + rc->reservationTimeout = Hal_getTimeInMs() + (RESV_TMS_IMPLICIT_VALUE * 1000); - reserveRcb(rc, connection); + if (rc->resvTms == 0) { + rc->resvTms = RESV_TMS_IMPLICIT_VALUE; + + reserveRcb(rc, connection); + } + else if (rc->resvTms == -1) { + reserveRcb(rc, connection); + } } - else if (rc->resvTms == -1) { + else { reserveRcb(rc, connection); } } @@ -1747,6 +1778,7 @@ exit_function: return retVal; } +#endif void Reporting_deactivateReportsForConnection(MmsMapping* self, MmsServerConnection connection) @@ -1768,8 +1800,10 @@ Reporting_deactivateReportsForConnection(MmsMapping* self, MmsServerConnection c if (rc->buffered == false) { - MmsValue* resv = ReportControl_getRCBValue(rc, "Resv"); - MmsValue_setBoolean(resv, false); + if (rc->resvTms != -1) { + MmsValue* resv = ReportControl_getRCBValue(rc, "Resv"); + MmsValue_setBoolean(resv, false); + } if (rc->resvTms != -1) updateOwner(rc, NULL);