From c05c72f544dd87d121ed5fbb1865daf8f9c4313a Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Tue, 29 Oct 2024 18:35:30 +0000 Subject: [PATCH] - some code format updates --- src/iec61850/server/mms_mapping/reporting.c | 1608 ++++++++++++------- src/iec61850/server/model/model.c | 1 - 2 files changed, 995 insertions(+), 614 deletions(-) diff --git a/src/iec61850/server/mms_mapping/reporting.c b/src/iec61850/server/mms_mapping/reporting.c index 3e21116a..ab04e846 100644 --- a/src/iec61850/server/mms_mapping/reporting.c +++ b/src/iec61850/server/mms_mapping/reporting.c @@ -21,22 +21,22 @@ * See COPYING file for the complete license text. */ +#include "hal_thread.h" #include "libiec61850_platform_includes.h" -#include "mms_mapping.h" #include "linked_list.h" +#include "mms_mapping.h" #include "stack_config.h" -#include "hal_thread.h" -#include "simple_allocator.h" -#include "mem_alloc_linked_list.h" #include "ber_encoder.h" +#include "mem_alloc_linked_list.h" +#include "simple_allocator.h" +#include "conversions.h" +#include "ied_server_private.h" #include "mms_mapping_internal.h" -#include "mms_value_internal.h" #include "mms_server_internal.h" -#include "conversions.h" +#include "mms_value_internal.h" #include "reporting.h" -#include "ied_server_private.h" #include /* if not explicitly set by client "ResvTms" will be set to this value */ @@ -55,9 +55,10 @@ static ReportBuffer* ReportBuffer_create(int bufferSize) { - ReportBuffer* self = (ReportBuffer*) GLOBAL_MALLOC(sizeof(ReportBuffer)); + ReportBuffer* self = (ReportBuffer*)GLOBAL_MALLOC(sizeof(ReportBuffer)); - if (self) { + if (self) + { self->lastEnqueuedReport = NULL; self->oldestReport = NULL; self->nextToTransmit = NULL; @@ -65,13 +66,15 @@ ReportBuffer_create(int bufferSize) self->isOverflow = true; self->memoryBlockSize = bufferSize; - self->memoryBlock = (uint8_t*) GLOBAL_MALLOC(self->memoryBlockSize); + self->memoryBlock = (uint8_t*)GLOBAL_MALLOC(self->memoryBlockSize); - if (self->memoryBlock == NULL) { + if (self->memoryBlock == NULL) + { GLOBAL_FREEMEM(self); self = NULL; } - else { + else + { #if (CONFIG_MMS_THREADLESS_STACK != 1) self->lock = Semaphore_create(1); #endif @@ -84,7 +87,8 @@ ReportBuffer_create(int bufferSize) static void ReportBuffer_destroy(ReportBuffer* self) { - if (self) { + if (self) + { GLOBAL_FREEMEM(self->memoryBlock); #if (CONFIG_MMS_THREADLESS_STACK != 1) @@ -98,9 +102,10 @@ ReportBuffer_destroy(ReportBuffer* self) ReportControl* ReportControl_create(bool buffered, LogicalNode* parentLN, int reportBufferSize, IedServer iedServer) { - ReportControl* self = (ReportControl*) GLOBAL_MALLOC(sizeof(ReportControl)); + ReportControl* self = (ReportControl*)GLOBAL_MALLOC(sizeof(ReportControl)); - if (self) { + if (self) + { self->name = NULL; self->domain = NULL; self->parentLN = parentLN; @@ -169,7 +174,8 @@ ReportControl_unlockNotify(ReportControl* self) static void purgeBuf(ReportControl* rc) { - if (DEBUG_IED_SERVER) printf("IED_SERVER: RCB %s purgeBuf\n", rc->name); + if (DEBUG_IED_SERVER) + printf("IED_SERVER: RCB %s purgeBuf\n", rc->name); /* reset trigger */ rc->triggered = false; @@ -193,7 +199,8 @@ deleteDataSetValuesShadowBuffer(ReportControl* self) int i; - for (i = 0; i < dataSetSize; i++) { + for (i = 0; i < dataSetSize; i++) + { if (self->bufferedDataSetValues[i] != NULL) MmsValue_delete(self->bufferedDataSetValues[i]); } @@ -210,8 +217,9 @@ deleteDataSetValuesShadowBuffer(ReportControl* self) void ReportControl_destroy(ReportControl* self) { - if (self) { - if (self->rcbValues != NULL ) + if (self) + { + if (self->rcbValues != NULL) MmsValue_delete(self->rcbValues); if (self->inclusionFlags != NULL) @@ -227,8 +235,10 @@ ReportControl_destroy(ReportControl* self) deleteDataSetValuesShadowBuffer(self); - if (self->isDynamicDataSet) { - if (self->dataSet != NULL) { + if (self->isDynamicDataSet) + { + if (self->dataSet != NULL) + { MmsMapping_freeDynamicallyCreatedDataSet(self->dataSet); self->isDynamicDataSet = false; self->dataSet = NULL; @@ -255,7 +265,8 @@ ReportControl_destroy(ReportControl* self) MmsValue* ReportControl_getRCBValue(ReportControl* rc, const char* elementName) { - if (rc->buffered) { + if (rc->buffered) + { if (strcmp(elementName, "RptID") == 0) return MmsValue_getElement(rc->rcbValues, 0); else if (strcmp(elementName, "RptEna") == 0) @@ -283,15 +294,18 @@ ReportControl_getRCBValue(ReportControl* rc, const char* elementName) else if (strcmp(elementName, "TimeofEntry") == 0) return MmsValue_getElement(rc->rcbValues, 12); - if (rc->server->edition >= IEC_61850_EDITION_2) { + if (rc->server->edition >= IEC_61850_EDITION_2) + { #if (CONFIG_IEC61850_BRCB_WITH_RESVTMS == 1) - if (rc->server->enableBRCBResvTms) { + if (rc->server->enableBRCBResvTms) + { if (strcmp(elementName, "ResvTms") == 0) return MmsValue_getElement(rc->rcbValues, 13); if (strcmp(elementName, "Owner") == 0) return MmsValue_getElement(rc->rcbValues, 14); } - else { + else + { if (strcmp(elementName, "Owner") == 0) return MmsValue_getElement(rc->rcbValues, 13); } @@ -300,8 +314,9 @@ ReportControl_getRCBValue(ReportControl* rc, const char* elementName) return MmsValue_getElement(rc->rcbValues, 13); #endif } - - } else { + } + else + { if (strcmp(elementName, "RptID") == 0) return MmsValue_getElement(rc->rcbValues, 0); else if (strcmp(elementName, "RptEna") == 0) @@ -328,7 +343,7 @@ ReportControl_getRCBValue(ReportControl* rc, const char* elementName) return MmsValue_getElement(rc->rcbValues, 11); } - return NULL ; + return NULL; } #if (CONFIG_IEC61850_SERVICE_TRACKING == 1) @@ -340,8 +355,10 @@ copyRCBValuesToTrackingObject(MmsMapping* self, ReportControl* rc) Semaphore_wait(rc->rcbValuesLock); #endif - if (rc->buffered) { - if (self->brcbTrk) { + if (rc->buffered) + { + if (self->brcbTrk) + { BrcbTrkInstance trkInst = self->brcbTrk; if (trkInst->rptID) @@ -350,11 +367,13 @@ copyRCBValuesToTrackingObject(MmsMapping* self, ReportControl* rc) if (trkInst->rptEna) MmsValue_update(trkInst->rptEna->mmsValue, ReportControl_getRCBValue(rc, "RptEna")); - if (trkInst->datSet) { + if (trkInst->datSet) + { char datSet[130]; const char* datSetStr = MmsValue_toString(ReportControl_getRCBValue(rc, "DatSet")); - if (datSetStr) { + if (datSetStr) + { StringUtils_copyStringMax(datSet, 130, datSetStr); StringUtils_replace(datSet, '$', '.'); @@ -390,15 +409,16 @@ copyRCBValuesToTrackingObject(MmsMapping* self, ReportControl* rc) if (trkInst->entryID) MmsValue_update(trkInst->entryID->mmsValue, ReportControl_getRCBValue(rc, "EntryID")); - if (trkInst->timeOfEntry) { + if (trkInst->timeOfEntry) + { MmsValue* timeofEntryValue = ReportControl_getRCBValue(rc, "TimeofEntry"); if (timeofEntryValue) MmsValue_update(trkInst->timeOfEntry->mmsValue, timeofEntryValue); } - - if (trkInst->resvTms) { + if (trkInst->resvTms) + { MmsValue* resvTmsValue = ReportControl_getRCBValue(rc, "ResvTms"); if (resvTmsValue) @@ -406,8 +426,10 @@ copyRCBValuesToTrackingObject(MmsMapping* self, ReportControl* rc) } } } - else { - if (self->urcbTrk) { + else + { + if (self->urcbTrk) + { UrcbTrkInstance trkInst = self->urcbTrk; if (trkInst->rptID) @@ -419,11 +441,13 @@ copyRCBValuesToTrackingObject(MmsMapping* self, ReportControl* rc) if (trkInst->resv) MmsValue_update(trkInst->rptEna->mmsValue, ReportControl_getRCBValue(rc, "Resv")); - if (trkInst->datSet) { + if (trkInst->datSet) + { char datSet[130]; const char* datSetStr = MmsValue_toString(ReportControl_getRCBValue(rc, "DatSet")); - if (datSetStr) { + if (datSetStr) + { StringUtils_copyStringMax(datSet, 130, datSetStr); StringUtils_replace(datSet, '$', '.'); @@ -463,8 +487,10 @@ copyRCBValuesToTrackingObject(MmsMapping* self, ReportControl* rc) static void updateSingleTrackingValue(MmsMapping* self, ReportControl* rc, const char* name, MmsValue* newValue) { - if (rc->buffered) { - if (self->brcbTrk) { + if (rc->buffered) + { + if (self->brcbTrk) + { BrcbTrkInstance trkInst = self->brcbTrk; DataAttribute* attributeToUpdate = NULL; @@ -473,12 +499,14 @@ updateSingleTrackingValue(MmsMapping* self, ReportControl* rc, const char* name, attributeToUpdate = trkInst->rptID; else if (!strcmp(name, "RptEna")) attributeToUpdate = trkInst->rptEna; - else if (!strcmp(name, "DatSet")) { + else if (!strcmp(name, "DatSet")) + { char datSet[130]; const char* datSetStr = MmsValue_toString(newValue); - if (datSetStr) { + if (datSetStr) + { StringUtils_copyStringMax(datSet, 130, datSetStr); StringUtils_replace(datSet, '$', '.'); @@ -513,8 +541,10 @@ updateSingleTrackingValue(MmsMapping* self, ReportControl* rc, const char* name, MmsValue_update(attributeToUpdate->mmsValue, newValue); } } - else { - if (self->urcbTrk) { + else + { + if (self->urcbTrk) + { UrcbTrkInstance trkInst = self->urcbTrk; DataAttribute* attributeToUpdate = NULL; @@ -525,12 +555,14 @@ updateSingleTrackingValue(MmsMapping* self, ReportControl* rc, const char* name, attributeToUpdate = trkInst->rptEna; else if (!strcmp(name, "Resv")) attributeToUpdate = trkInst->resv; - else if (!strcmp(name, "DatSet")) { + else if (!strcmp(name, "DatSet")) + { char datSet[130]; const char* datSetStr = MmsValue_toString(newValue); - if (datSetStr) { + if (datSetStr) + { StringUtils_copyStringMax(datSet, 130, datSetStr); StringUtils_replace(datSet, '$', '.'); @@ -560,37 +592,43 @@ updateSingleTrackingValue(MmsMapping* self, ReportControl* rc, const char* name, } static void -updateGenericTrackingObjectValues(MmsMapping* self, ReportControl* rc, IEC61850_ServiceType serviceType, MmsDataAccessError errVal) +updateGenericTrackingObjectValues(MmsMapping* self, ReportControl* rc, IEC61850_ServiceType serviceType, + MmsDataAccessError errVal) { ServiceTrkInstance trkInst = NULL; - if (rc->buffered) { - if (self->brcbTrk) { - trkInst = (ServiceTrkInstance) self->brcbTrk; + if (rc->buffered) + { + if (self->brcbTrk) + { + trkInst = (ServiceTrkInstance)self->brcbTrk; } } - else { - if (self->urcbTrk) { - trkInst = (ServiceTrkInstance) self->urcbTrk; + else + { + if (self->urcbTrk) + { + trkInst = (ServiceTrkInstance)self->urcbTrk; } } - if (trkInst) { + if (trkInst) + { if (trkInst->serviceType) - MmsValue_setInt32(trkInst->serviceType->mmsValue, (int) serviceType); + MmsValue_setInt32(trkInst->serviceType->mmsValue, (int)serviceType); if (trkInst->t) MmsValue_setUtcTimeMsEx(trkInst->t->mmsValue, Hal_getTimeInMs(), self->iedServer->timeQuality); if (trkInst->errorCode) MmsValue_setInt32(trkInst->errorCode->mmsValue, - private_IedServer_convertMmsDataAccessErrorToServiceError(errVal)); + private_IedServer_convertMmsDataAccessErrorToServiceError(errVal)); char objRef[130]; /* create object reference */ - LogicalNode* ln = (LogicalNode*) rc->parentLN; - LogicalDevice* ld = (LogicalDevice*) ln->parent; + LogicalNode* ln = (LogicalNode*)rc->parentLN; + LogicalDevice* ld = (LogicalDevice*)ln->parent; char* iedName = self->iedServer->mmsDevice->deviceName; @@ -599,19 +637,24 @@ updateGenericTrackingObjectValues(MmsMapping* self, ReportControl* rc, IEC61850_ /* convert MMS name to ACSI object reference */ int pos = 0; bool replace = false; - do { - if (replace) { + do + { + if (replace) + { objRef[pos] = objRef[pos + 3]; } - else { - if (objRef[pos] == '$') { + else + { + if (objRef[pos] == '$') + { objRef[pos] = '.'; replace = true; } } } while (objRef[pos++]); - if (trkInst->objRef) { + if (trkInst->objRef) + { IedServer_updateVisibleStringAttributeValue(self->iedServer, trkInst->objRef, objRef); } } @@ -639,7 +682,8 @@ getDataSetEntryWithIndex(DataSetEntry* dataSet, int index) { int i = 0; - while (dataSet) { + while (dataSet) + { if (i == index) return dataSet; @@ -656,16 +700,17 @@ createDataSetValuesShadowBuffer(ReportControl* rc) { int dataSetSize = DataSet_getSize(rc->dataSet); - MmsValue** dataSetValues = (MmsValue**) GLOBAL_CALLOC(dataSetSize, sizeof(MmsValue*)); + MmsValue** dataSetValues = (MmsValue**)GLOBAL_CALLOC(dataSetSize, sizeof(MmsValue*)); rc->bufferedDataSetValues = dataSetValues; - rc->valueReferences = (MmsValue**) GLOBAL_MALLOC(dataSetSize * sizeof(MmsValue*)); + rc->valueReferences = (MmsValue**)GLOBAL_MALLOC(dataSetSize * sizeof(MmsValue*)); DataSetEntry* dataSetEntry = rc->dataSet->fcdas; int i; - for (i = 0; i < dataSetSize; i++) { + for (i = 0; i < dataSetSize; i++) + { assert(dataSetEntry != NULL); rc->valueReferences[i] = dataSetEntry->value; @@ -675,28 +720,35 @@ createDataSetValuesShadowBuffer(ReportControl* rc) } static bool -checkIfClientHasAccessToDataSetEntries(MmsMapping* mapping, MmsServerConnection connection, MmsNamedVariableList mmsVariableList) +checkIfClientHasAccessToDataSetEntries(MmsMapping* mapping, MmsServerConnection connection, + MmsNamedVariableList mmsVariableList) { bool accessAllowed = true; - if (connection) { + if (connection) + { LinkedList entryElem = LinkedList_getNext(mmsVariableList->listOfVariables); - while (entryElem) { + while (entryElem) + { MmsNamedVariableListEntry entry = (MmsNamedVariableListEntry)LinkedList_getData(entryElem); - MmsValue* entryValue = mmsServer_getValue(mapping->mmsServer, entry->domain, entry->variableName, connection, true); + MmsValue* entryValue = + mmsServer_getValue(mapping->mmsServer, entry->domain, entry->variableName, connection, true); - if (entryValue) { + if (entryValue) + { - if (MmsValue_getType(entryValue) == MMS_DATA_ACCESS_ERROR) { + if (MmsValue_getType(entryValue) == MMS_DATA_ACCESS_ERROR) + { accessAllowed = false; } MmsValue_deleteConditional(entryValue); } - else { + else + { accessAllowed = false; } @@ -705,7 +757,6 @@ checkIfClientHasAccessToDataSetEntries(MmsMapping* mapping, MmsServerConnection entryElem = LinkedList_getNext(entryElem); } - } return accessAllowed; @@ -720,13 +771,17 @@ updateReportDataset(MmsMapping* mapping, ReportControl* rc, MmsValue* newDatSet, bool isUsedDataSetDynamic = rc->isDynamicDataSet; - if (newDatSet != NULL) { - if (strcmp(MmsValue_toString(newDatSet), "") == 0) { + if (newDatSet != NULL) + { + if (strcmp(MmsValue_toString(newDatSet), "") == 0) + { success = true; dataSetValue = NULL; - if (rc->dataSet) { - if (rc->buffered) { + if (rc->dataSet) + { + if (rc->buffered) + { rc->isBuffering = false; purgeBuf(rc); } @@ -734,8 +789,10 @@ updateReportDataset(MmsMapping* mapping, ReportControl* rc, MmsValue* newDatSet, /* delete pending events */ deleteDataSetValuesShadowBuffer(rc); - if (isUsedDataSetDynamic) { - if (rc->dataSet) { + if (isUsedDataSetDynamic) + { + if (rc->dataSet) + { MmsMapping_freeDynamicallyCreatedDataSet(rc->dataSet); } } @@ -753,23 +810,30 @@ updateReportDataset(MmsMapping* mapping, ReportControl* rc, MmsValue* newDatSet, bool dataSetChanged = true; /* check if old and new data sets are the same */ - if (rc->dataSet && dataSetValue) { + if (rc->dataSet && dataSetValue) + { const char* dataSetLdName = rc->dataSet->logicalDeviceName; const char* dataSetName = rc->dataSet->name; const char* newDataSetName = MmsValue_toString(dataSetValue); - if (newDataSetName[0] == '@') { - if ((dataSetLdName == NULL) && (!strcmp(dataSetName, newDataSetName + 1))) { + if (newDataSetName[0] == '@') + { + if ((dataSetLdName == NULL) && (!strcmp(dataSetName, newDataSetName + 1))) + { dataSetChanged = false; } } - else if (newDataSetName[0] == '/') { - if ((dataSetLdName == NULL) && (!strcmp(dataSetName, newDataSetName + 1))) { + else if (newDataSetName[0] == '/') + { + if ((dataSetLdName == NULL) && (!strcmp(dataSetName, newDataSetName + 1))) + { dataSetChanged = false; } } - else { - if (dataSetLdName && dataSetName) { + else + { + if (dataSetLdName && dataSetName) + { char externalVisibleName[256]; @@ -777,28 +841,33 @@ updateReportDataset(MmsMapping* mapping, ReportControl* rc, MmsValue* newDatSet, LogicalDevice* ld = IedModel_getDeviceByInst(mapping->model, dataSetLdName); - if (ld == NULL) { + if (ld == NULL) + { success = false; goto exit_function; } - if (ld->ldName) { + if (ld->ldName) + { StringUtils_copyStringMax(externalVisibleName, 256, ld->ldName); } - else { + else + { StringUtils_concatString(externalVisibleName, 256, mapping->model->name, dataSetLdName); } StringUtils_appendString(externalVisibleName, 256, "/"); StringUtils_appendString(externalVisibleName, 256, dataSetName); - if (!(strcmp(externalVisibleName, newDataSetName))) { + if (!(strcmp(externalVisibleName, newDataSetName))) + { dataSetChanged = false; } } } - if (rc->buffered) { + if (rc->buffered) + { if (dataSetChanged) purgeBuf(rc); } @@ -810,7 +879,8 @@ updateReportDataset(MmsMapping* mapping, ReportControl* rc, MmsValue* newDatSet, DataSet* dataSet = IedModel_lookupDataSet(mapping->model, dataSetName); - if (dataSet) { + if (dataSet) + { char domainNameBuf[130]; @@ -818,35 +888,44 @@ updateReportDataset(MmsMapping* mapping, ReportControl* rc, MmsValue* newDatSet, MmsDomain* dsDomain = MmsDevice_getDomain(mapping->mmsDevice, domainNameBuf); - if (dsDomain) { + if (dsDomain) + { MmsNamedVariableList namedVariableList = MmsDomain_getNamedVariableList(dsDomain, dataSet->name); - if (namedVariableList) { - if (checkIfClientHasAccessToDataSetEntries(mapping, connection, namedVariableList) == false) { + if (namedVariableList) + { + if (checkIfClientHasAccessToDataSetEntries(mapping, connection, namedVariableList) == false) + { goto exit_function; } } - } - } #if (MMS_DYNAMIC_DATA_SETS == 1) - if (dataSet == NULL) { + if (dataSet == NULL) + { dataSet = MmsMapping_getDomainSpecificDataSet(mapping, dataSetName); - if (dataSet == NULL) { + if (dataSet == NULL) + { /* check if association specific data set is requested */ - if (dataSetName[0] == '@') { - - if (rc->buffered == false) { /* for buffered report non-permanent datasets are not allowed */ - if (connection != NULL) { - MmsNamedVariableList mmsVariableList - = MmsServerConnection_getNamedVariableList(connection, dataSetName + 1); + if (dataSetName[0] == '@') + { - if (mmsVariableList) { - if (checkIfClientHasAccessToDataSetEntries(mapping, connection, mmsVariableList) == false) { + if (rc->buffered == false) + { /* for buffered report non-permanent datasets are not allowed */ + if (connection != NULL) + { + MmsNamedVariableList mmsVariableList = + MmsServerConnection_getNamedVariableList(connection, dataSetName + 1); + + if (mmsVariableList) + { + if (checkIfClientHasAccessToDataSetEntries(mapping, connection, mmsVariableList) == + false) + { goto exit_function; } @@ -857,11 +936,15 @@ updateReportDataset(MmsMapping* mapping, ReportControl* rc, MmsValue* newDatSet, } /* check for VMD specific data set */ - else if (dataSetName[0] == '/') { - MmsNamedVariableList mmsVariableList = MmsDevice_getNamedVariableListWithName(mapping->mmsDevice, dataSetName + 1); + else if (dataSetName[0] == '/') + { + MmsNamedVariableList mmsVariableList = + MmsDevice_getNamedVariableListWithName(mapping->mmsDevice, dataSetName + 1); - if (mmsVariableList) { - if (checkIfClientHasAccessToDataSetEntries(mapping, connection, mmsVariableList) == false) { + if (mmsVariableList) + { + if (checkIfClientHasAccessToDataSetEntries(mapping, connection, mmsVariableList) == false) + { goto exit_function; } @@ -874,7 +957,6 @@ updateReportDataset(MmsMapping* mapping, ReportControl* rc, MmsValue* newDatSet, goto exit_function; rc->isDynamicDataSet = true; - } else rc->isDynamicDataSet = false; @@ -888,13 +970,16 @@ updateReportDataset(MmsMapping* mapping, ReportControl* rc, MmsValue* newDatSet, if (rc->dataSet && rc->dataSet != dataSet) dataSetChanged = true; - if (dataSetChanged) { + if (dataSetChanged) + { /* delete pending event and create buffer for new data set */ deleteDataSetValuesShadowBuffer(rc); - if (isUsedDataSetDynamic) { - if (rc->dataSet) { + if (isUsedDataSetDynamic) + { + if (rc->dataSet) + { MmsMapping_freeDynamicallyCreatedDataSet(rc->dataSet); } } @@ -913,7 +998,7 @@ updateReportDataset(MmsMapping* mapping, ReportControl* rc, MmsValue* newDatSet, if (rc->inclusionFlags != NULL) GLOBAL_FREEMEM(rc->inclusionFlags); - rc->inclusionFlags = (uint8_t*) GLOBAL_CALLOC(dataSet->elementCount, sizeof(uint8_t)); + rc->inclusionFlags = (uint8_t*)GLOBAL_CALLOC(dataSet->elementCount, sizeof(uint8_t)); } success = true; @@ -923,7 +1008,8 @@ updateReportDataset(MmsMapping* mapping, ReportControl* rc, MmsValue* newDatSet, goto exit_function; } - else { + else + { success = true; } @@ -972,7 +1058,8 @@ createOptFlds(ReportControlBlock* reportControlBlock) } static MmsValue* -createTrgOps(ReportControlBlock* reportControlBlock) { +createTrgOps(ReportControlBlock* reportControlBlock) +{ MmsValue* trgOps = MmsValue_newBitString(-6); uint8_t triggerOps = reportControlBlock->trgOps; @@ -1026,7 +1113,8 @@ getNextRoundedStartTime(uint64_t currentTime, uint64_t intgPd) uint64_t modTime = currentTime % intgPd; uint64_t delta = intgPd; - if (modTime != 0) { + if (modTime != 0) + { delta = intgPd - modTime; } @@ -1049,16 +1137,21 @@ refreshIntegrityPeriod(ReportControl* rc) Semaphore_post(rc->rcbValuesLock); #endif - if (rc->buffered == false) { + if (rc->buffered == false) + { - if (rc->triggerOps & TRG_OPT_INTEGRITY) { + if (rc->triggerOps & TRG_OPT_INTEGRITY) + { - if (rc->intgPd > 0) { + if (rc->intgPd > 0) + { - if (rc->server->syncIntegrityReportTimes) { + if (rc->server->syncIntegrityReportTimes) + { rc->nextIntgReportTime = getNextRoundedStartTime(Hal_getTimeInMs(), rc->intgPd); } - else { + else + { rc->nextIntgReportTime = Hal_getTimeInMs() + rc->intgPd; } } @@ -1085,13 +1178,15 @@ static void composeDefaultRptIdString(char* rptIdString, ReportControl* reportControl) { int bufPos = 0; - while (reportControl->domain->domainName[bufPos] != 0) { + while (reportControl->domain->domainName[bufPos] != 0) + { rptIdString[bufPos] = reportControl->domain->domainName[bufPos]; bufPos++; } rptIdString[bufPos++] = '/'; int i = 0; - while (reportControl->name[i] != 0) { + while (reportControl->name[i] != 0) + { rptIdString[bufPos] = reportControl->name[i]; bufPos++; i++; @@ -1120,146 +1215,150 @@ updateWithDefaultRptId(ReportControl* reportControl, MmsValue* rptId) } static MmsVariableSpecification* -createUnbufferedReportControlBlock(ReportControlBlock* reportControlBlock, - ReportControl* reportControl) +createUnbufferedReportControlBlock(ReportControlBlock* reportControlBlock, ReportControl* reportControl) { - MmsVariableSpecification* rcb = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + MmsVariableSpecification* rcb = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); rcb->name = StringUtils_copyString(reportControlBlock->name); rcb->type = MMS_STRUCTURE; - MmsValue* mmsValue = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); + MmsValue* mmsValue = (MmsValue*)GLOBAL_CALLOC(1, sizeof(MmsValue)); mmsValue->deleteValue = false; mmsValue->type = MMS_STRUCTURE; int structSize = 11; - if (reportControl->server->edition >= IEC_61850_EDITION_2) { + if (reportControl->server->edition >= IEC_61850_EDITION_2) + { if (reportControl->hasOwner) structSize = 12; } mmsValue->value.structure.size = structSize; - mmsValue->value.structure.components = (MmsValue**) GLOBAL_CALLOC(structSize, sizeof(MmsValue*)); + mmsValue->value.structure.components = (MmsValue**)GLOBAL_CALLOC(structSize, sizeof(MmsValue*)); rcb->typeSpec.structure.elementCount = structSize; - rcb->typeSpec.structure.elements = (MmsVariableSpecification**) GLOBAL_CALLOC(structSize, - sizeof(MmsVariableSpecification*)); + rcb->typeSpec.structure.elements = + (MmsVariableSpecification**)GLOBAL_CALLOC(structSize, sizeof(MmsVariableSpecification*)); - MmsVariableSpecification* namedVariable = - (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + MmsVariableSpecification* namedVariable = + (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("RptID"); namedVariable->typeSpec.visibleString = -129; namedVariable->type = MMS_VISIBLE_STRING; rcb->typeSpec.structure.elements[0] = namedVariable; if ((reportControlBlock->rptId != NULL) && (strlen(reportControlBlock->rptId) > 0)) - mmsValue->value.structure.components[0] = MmsValue_newVisibleString( - reportControlBlock->rptId); + mmsValue->value.structure.components[0] = MmsValue_newVisibleString(reportControlBlock->rptId); else mmsValue->value.structure.components[0] = createDefaultRptId(reportControl); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("RptEna"); namedVariable->type = MMS_BOOLEAN; rcb->typeSpec.structure.elements[1] = namedVariable; mmsValue->value.structure.components[1] = MmsValue_newBoolean(false); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("Resv"); namedVariable->type = MMS_BOOLEAN; rcb->typeSpec.structure.elements[2] = namedVariable; mmsValue->value.structure.components[2] = MmsValue_newBoolean(false); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("DatSet"); namedVariable->typeSpec.visibleString = -129; namedVariable->type = MMS_VISIBLE_STRING; rcb->typeSpec.structure.elements[3] = namedVariable; - if (reportControlBlock->dataSetName != NULL) { - char* dataSetReference = createDataSetReferenceForDefaultDataSet(reportControlBlock, - reportControl); - mmsValue->value.structure.components[3] = MmsValue_newVisibleString(dataSetReference); - GLOBAL_FREEMEM(dataSetReference); + if (reportControlBlock->dataSetName != NULL) + { + char* dataSetReference = createDataSetReferenceForDefaultDataSet(reportControlBlock, reportControl); + mmsValue->value.structure.components[3] = MmsValue_newVisibleString(dataSetReference); + GLOBAL_FREEMEM(dataSetReference); } else - mmsValue->value.structure.components[3] = MmsValue_newVisibleString(""); + mmsValue->value.structure.components[3] = MmsValue_newVisibleString(""); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("ConfRev"); namedVariable->type = MMS_UNSIGNED; namedVariable->typeSpec.unsignedInteger = 32; rcb->typeSpec.structure.elements[4] = namedVariable; - mmsValue->value.structure.components[4] = - MmsValue_newUnsignedFromUint32(reportControlBlock->confRef); + mmsValue->value.structure.components[4] = MmsValue_newUnsignedFromUint32(reportControlBlock->confRef); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("OptFlds"); namedVariable->type = MMS_BIT_STRING; namedVariable->typeSpec.bitString = -10; rcb->typeSpec.structure.elements[5] = namedVariable; mmsValue->value.structure.components[5] = createOptFlds(reportControlBlock); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("BufTm"); namedVariable->type = MMS_UNSIGNED; namedVariable->typeSpec.unsignedInteger = 32; rcb->typeSpec.structure.elements[6] = namedVariable; - mmsValue->value.structure.components[6] = - MmsValue_newUnsignedFromUint32(reportControlBlock->bufferTime); + mmsValue->value.structure.components[6] = MmsValue_newUnsignedFromUint32(reportControlBlock->bufferTime); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("SqNum"); namedVariable->type = MMS_UNSIGNED; namedVariable->typeSpec.unsignedInteger = 8; rcb->typeSpec.structure.elements[7] = namedVariable; mmsValue->value.structure.components[7] = MmsValue_newUnsigned(8); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("TrgOps"); namedVariable->type = MMS_BIT_STRING; namedVariable->typeSpec.bitString = -6; rcb->typeSpec.structure.elements[8] = namedVariable; mmsValue->value.structure.components[8] = createTrgOps(reportControlBlock); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("IntgPd"); namedVariable->type = MMS_UNSIGNED; namedVariable->typeSpec.unsignedInteger = 32; rcb->typeSpec.structure.elements[9] = namedVariable; - mmsValue->value.structure.components[9] = - MmsValue_newUnsignedFromUint32(reportControlBlock->intPeriod); + mmsValue->value.structure.components[9] = MmsValue_newUnsignedFromUint32(reportControlBlock->intPeriod); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("GI"); namedVariable->type = MMS_BOOLEAN; rcb->typeSpec.structure.elements[10] = namedVariable; mmsValue->value.structure.components[10] = MmsValue_newBoolean(false); - if (reportControl->server->edition >= IEC_61850_EDITION_2) { + if (reportControl->server->edition >= IEC_61850_EDITION_2) + { - if (reportControl->hasOwner) { - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + if (reportControl->hasOwner) + { + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("Owner"); namedVariable->type = MMS_OCTET_STRING; namedVariable->typeSpec.octetString = -64; rcb->typeSpec.structure.elements[11] = namedVariable; - mmsValue->value.structure.components[11] = MmsValue_newOctetString(0, 16); /* size 16 is enough to store client IPv6 address */ + mmsValue->value.structure.components[11] = + MmsValue_newOctetString(0, 16); /* size 16 is enough to store client IPv6 address */ /* initialize pre configured owner */ - if (reportControlBlock->clientReservation[0] == 4) { + if (reportControlBlock->clientReservation[0] == 4) + { reportControl->resvTms = -1; - MmsValue_setOctetString(mmsValue->value.structure.components[11], reportControlBlock->clientReservation + 1, 4); + MmsValue_setOctetString(mmsValue->value.structure.components[11], + reportControlBlock->clientReservation + 1, 4); } - else if (reportControlBlock->clientReservation[0] == 6) { + else if (reportControlBlock->clientReservation[0] == 6) + { reportControl->resvTms = -1; - MmsValue_setOctetString(mmsValue->value.structure.components[11], reportControlBlock->clientReservation + 1, 16); + MmsValue_setOctetString(mmsValue->value.structure.components[11], + reportControlBlock->clientReservation + 1, 16); } } } /* check if there is a pre configured owner */ - if (reportControlBlock->clientReservation[0] > 0) { + if (reportControlBlock->clientReservation[0] > 0) + { MmsValue_setBoolean(mmsValue->value.structure.components[2], true); } @@ -1275,16 +1374,16 @@ createUnbufferedReportControlBlock(ReportControlBlock* reportControlBlock, } static MmsVariableSpecification* -createBufferedReportControlBlock(ReportControlBlock* reportControlBlock, - ReportControl* reportControl) +createBufferedReportControlBlock(ReportControlBlock* reportControlBlock, ReportControl* reportControl) { - MmsVariableSpecification* rcb = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + MmsVariableSpecification* rcb = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); rcb->name = StringUtils_copyString(reportControlBlock->name); rcb->type = MMS_STRUCTURE; int brcbElementCount = 13; - if (reportControl->server->edition >= IEC_61850_EDITION_2) { + if (reportControl->server->edition >= IEC_61850_EDITION_2) + { #if (CONFIG_IEC61850_BRCB_WITH_RESVTMS == 1) if (reportControl->server->enableBRCBResvTms) @@ -1295,116 +1394,112 @@ createBufferedReportControlBlock(ReportControlBlock* reportControlBlock, brcbElementCount++; } - MmsValue* mmsValue = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); + MmsValue* mmsValue = (MmsValue*)GLOBAL_CALLOC(1, sizeof(MmsValue)); mmsValue->deleteValue = false; mmsValue->type = MMS_STRUCTURE; mmsValue->value.structure.size = brcbElementCount; - mmsValue->value.structure.components = (MmsValue**) GLOBAL_CALLOC(brcbElementCount, sizeof(MmsValue*)); + mmsValue->value.structure.components = (MmsValue**)GLOBAL_CALLOC(brcbElementCount, sizeof(MmsValue*)); rcb->typeSpec.structure.elementCount = brcbElementCount; - rcb->typeSpec.structure.elements = (MmsVariableSpecification**) GLOBAL_CALLOC(brcbElementCount, - sizeof(MmsVariableSpecification*)); + rcb->typeSpec.structure.elements = + (MmsVariableSpecification**)GLOBAL_CALLOC(brcbElementCount, sizeof(MmsVariableSpecification*)); - MmsVariableSpecification* namedVariable = - (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + MmsVariableSpecification* namedVariable = + (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("RptID"); namedVariable->typeSpec.visibleString = -129; namedVariable->type = MMS_VISIBLE_STRING; rcb->typeSpec.structure.elements[0] = namedVariable; if ((reportControlBlock->rptId != NULL) && (strlen(reportControlBlock->rptId) > 0)) - mmsValue->value.structure.components[0] = MmsValue_newVisibleString( - reportControlBlock->rptId); + mmsValue->value.structure.components[0] = MmsValue_newVisibleString(reportControlBlock->rptId); else mmsValue->value.structure.components[0] = createDefaultRptId(reportControl); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("RptEna"); namedVariable->type = MMS_BOOLEAN; rcb->typeSpec.structure.elements[1] = namedVariable; mmsValue->value.structure.components[1] = MmsValue_newBoolean(false); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("DatSet"); namedVariable->typeSpec.visibleString = -129; namedVariable->type = MMS_VISIBLE_STRING; rcb->typeSpec.structure.elements[2] = namedVariable; - if (reportControlBlock->dataSetName != NULL) { - char* dataSetReference = createDataSetReferenceForDefaultDataSet(reportControlBlock, - reportControl); + if (reportControlBlock->dataSetName != NULL) + { + char* dataSetReference = createDataSetReferenceForDefaultDataSet(reportControlBlock, reportControl); - mmsValue->value.structure.components[2] = MmsValue_newVisibleString(dataSetReference); - GLOBAL_FREEMEM(dataSetReference); + mmsValue->value.structure.components[2] = MmsValue_newVisibleString(dataSetReference); + GLOBAL_FREEMEM(dataSetReference); } else - mmsValue->value.structure.components[2] = MmsValue_newVisibleString(""); + mmsValue->value.structure.components[2] = MmsValue_newVisibleString(""); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("ConfRev"); namedVariable->type = MMS_UNSIGNED; namedVariable->typeSpec.unsignedInteger = 32; rcb->typeSpec.structure.elements[3] = namedVariable; - mmsValue->value.structure.components[3] = - MmsValue_newUnsignedFromUint32(reportControlBlock->confRef); + mmsValue->value.structure.components[3] = MmsValue_newUnsignedFromUint32(reportControlBlock->confRef); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("OptFlds"); namedVariable->type = MMS_BIT_STRING; namedVariable->typeSpec.bitString = -10; rcb->typeSpec.structure.elements[4] = namedVariable; mmsValue->value.structure.components[4] = createOptFlds(reportControlBlock); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("BufTm"); namedVariable->type = MMS_UNSIGNED; namedVariable->typeSpec.unsignedInteger = 32; rcb->typeSpec.structure.elements[5] = namedVariable; - mmsValue->value.structure.components[5] = - MmsValue_newUnsignedFromUint32(reportControlBlock->bufferTime); + mmsValue->value.structure.components[5] = MmsValue_newUnsignedFromUint32(reportControlBlock->bufferTime); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("SqNum"); namedVariable->type = MMS_UNSIGNED; namedVariable->typeSpec.unsignedInteger = 16; rcb->typeSpec.structure.elements[6] = namedVariable; mmsValue->value.structure.components[6] = MmsValue_newUnsigned(16); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("TrgOps"); namedVariable->type = MMS_BIT_STRING; namedVariable->typeSpec.bitString = -6; rcb->typeSpec.structure.elements[7] = namedVariable; mmsValue->value.structure.components[7] = createTrgOps(reportControlBlock); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("IntgPd"); namedVariable->type = MMS_UNSIGNED; namedVariable->typeSpec.unsignedInteger = 32; rcb->typeSpec.structure.elements[8] = namedVariable; - mmsValue->value.structure.components[8] = - MmsValue_newUnsignedFromUint32(reportControlBlock->intPeriod); + mmsValue->value.structure.components[8] = MmsValue_newUnsignedFromUint32(reportControlBlock->intPeriod); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("GI"); namedVariable->type = MMS_BOOLEAN; rcb->typeSpec.structure.elements[9] = namedVariable; mmsValue->value.structure.components[9] = MmsValue_newBoolean(false); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("PurgeBuf"); namedVariable->type = MMS_BOOLEAN; rcb->typeSpec.structure.elements[10] = namedVariable; mmsValue->value.structure.components[10] = MmsValue_newBoolean(false); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("EntryID"); namedVariable->type = MMS_OCTET_STRING; namedVariable->typeSpec.octetString = 8; rcb->typeSpec.structure.elements[11] = namedVariable; mmsValue->value.structure.components[11] = MmsValue_newOctetString(8, 8); - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("TimeofEntry"); namedVariable->type = MMS_BINARY_TIME; namedVariable->typeSpec.binaryTime = 6; @@ -1413,14 +1508,16 @@ createBufferedReportControlBlock(ReportControlBlock* reportControlBlock, reportControl->timeOfEntry = mmsValue->value.structure.components[12]; - if (reportControl->server->edition >= IEC_61850_EDITION_2) { + if (reportControl->server->edition >= IEC_61850_EDITION_2) + { int currentIndex = 13; #if (CONFIG_IEC61850_BRCB_WITH_RESVTMS == 1) int resvTmsIndex = currentIndex; - if (reportControl->server->enableBRCBResvTms) { - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + if (reportControl->server->enableBRCBResvTms) + { + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("ResvTms"); namedVariable->type = MMS_INTEGER; namedVariable->typeSpec.integer = 16; @@ -1430,27 +1527,34 @@ createBufferedReportControlBlock(ReportControlBlock* reportControlBlock, } #endif /* (CONFIG_IEC61850_BRCB_WITH_RESVTMS == 1) */ - if (reportControl->hasOwner) { - namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); + if (reportControl->hasOwner) + { + namedVariable = (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("Owner"); namedVariable->type = MMS_OCTET_STRING; namedVariable->typeSpec.octetString = -64; rcb->typeSpec.structure.elements[currentIndex] = namedVariable; - mmsValue->value.structure.components[currentIndex] = MmsValue_newOctetString(0, 16); /* size 16 is enough to store client IPv6 address */ + mmsValue->value.structure.components[currentIndex] = + MmsValue_newOctetString(0, 16); /* size 16 is enough to store client IPv6 address */ /* initialize pre configured owner */ - if (reportControlBlock->clientReservation[0] == 4) { + if (reportControlBlock->clientReservation[0] == 4) + { reportControl->resvTms = -1; - MmsValue_setOctetString(mmsValue->value.structure.components[currentIndex], reportControlBlock->clientReservation + 1, 4); + MmsValue_setOctetString(mmsValue->value.structure.components[currentIndex], + reportControlBlock->clientReservation + 1, 4); } - else if (reportControlBlock->clientReservation[0] == 6) { + else if (reportControlBlock->clientReservation[0] == 6) + { reportControl->resvTms = -1; - MmsValue_setOctetString(mmsValue->value.structure.components[currentIndex], reportControlBlock->clientReservation + 1, 16); + MmsValue_setOctetString(mmsValue->value.structure.components[currentIndex], + reportControlBlock->clientReservation + 1, 16); } } #if (CONFIG_IEC61850_BRCB_WITH_RESVTMS == 1) - if (reportControl->server->enableBRCBResvTms) { + if (reportControl->server->enableBRCBResvTms) + { MmsValue_setInt16(mmsValue->value.structure.components[resvTmsIndex], reportControl->resvTms); } #endif @@ -1467,63 +1571,63 @@ createBufferedReportControlBlock(ReportControlBlock* reportControlBlock, } /* createBufferedReportControlBlock() */ static ReportControlBlock* -getRCBForLogicalNodeWithIndex(MmsMapping* self, LogicalNode* logicalNode, - int index, bool buffered) +getRCBForLogicalNodeWithIndex(MmsMapping* self, LogicalNode* logicalNode, int index, bool buffered) { int rcbCount = 0; ReportControlBlock* nextRcb = self->model->rcbs; - while (nextRcb != NULL ) { - if (nextRcb->parent == logicalNode) { + while (nextRcb != NULL) + { + if (nextRcb->parent == logicalNode) + { - if (nextRcb->buffered == buffered) { + if (nextRcb->buffered == buffered) + { if (rcbCount == index) return nextRcb; rcbCount++; } - } nextRcb = nextRcb->sibling; } - return NULL ; + return NULL; } MmsVariableSpecification* -Reporting_createMmsBufferedRCBs(MmsMapping* self, MmsDomain* domain, - LogicalNode* logicalNode, int reportsCount) +Reporting_createMmsBufferedRCBs(MmsMapping* self, MmsDomain* domain, LogicalNode* logicalNode, int reportsCount) { - MmsVariableSpecification* namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, - sizeof(MmsVariableSpecification)); + MmsVariableSpecification* namedVariable = + (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("BR"); namedVariable->type = MMS_STRUCTURE; namedVariable->typeSpec.structure.elementCount = reportsCount; - namedVariable->typeSpec.structure.elements = (MmsVariableSpecification**) GLOBAL_CALLOC(reportsCount, - sizeof(MmsVariableSpecification*)); + namedVariable->typeSpec.structure.elements = + (MmsVariableSpecification**)GLOBAL_CALLOC(reportsCount, sizeof(MmsVariableSpecification*)); int currentReport = 0; - while (currentReport < reportsCount) { - ReportControl* rc = ReportControl_create(true, logicalNode, self->iedServer->reportBufferSizeBRCBs, self->iedServer); + while (currentReport < reportsCount) + { + ReportControl* rc = + ReportControl_create(true, logicalNode, self->iedServer->reportBufferSizeBRCBs, self->iedServer); rc->domain = domain; - ReportControlBlock* reportControlBlock = getRCBForLogicalNodeWithIndex( - self, logicalNode, currentReport, true); + ReportControlBlock* reportControlBlock = getRCBForLogicalNodeWithIndex(self, logicalNode, currentReport, true); rc->hasOwner = self->iedServer->enableOwnerForRCB; - rc->name = StringUtils_createString(3, logicalNode->name, "$BR$", - reportControlBlock->name); + rc->name = StringUtils_createString(3, logicalNode->name, "$BR$", reportControlBlock->name); rc->rcb = reportControlBlock; namedVariable->typeSpec.structure.elements[currentReport] = - createBufferedReportControlBlock(reportControlBlock, rc); + createBufferedReportControlBlock(reportControlBlock, rc); LinkedList_add(self->reportControls, rc); @@ -1534,37 +1638,36 @@ Reporting_createMmsBufferedRCBs(MmsMapping* self, MmsDomain* domain, } MmsVariableSpecification* -Reporting_createMmsUnbufferedRCBs(MmsMapping* self, MmsDomain* domain, - LogicalNode* logicalNode, int reportsCount) +Reporting_createMmsUnbufferedRCBs(MmsMapping* self, MmsDomain* domain, LogicalNode* logicalNode, int reportsCount) { - MmsVariableSpecification* namedVariable = (MmsVariableSpecification*) GLOBAL_CALLOC(1, - sizeof(MmsVariableSpecification)); + MmsVariableSpecification* namedVariable = + (MmsVariableSpecification*)GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); namedVariable->name = StringUtils_copyString("RP"); namedVariable->type = MMS_STRUCTURE; namedVariable->typeSpec.structure.elementCount = reportsCount; - namedVariable->typeSpec.structure.elements = (MmsVariableSpecification**) GLOBAL_CALLOC(reportsCount, - sizeof(MmsVariableSpecification*)); + namedVariable->typeSpec.structure.elements = + (MmsVariableSpecification**)GLOBAL_CALLOC(reportsCount, sizeof(MmsVariableSpecification*)); int currentReport = 0; - while (currentReport < reportsCount) { - ReportControl* rc = ReportControl_create(false, logicalNode, self->iedServer->reportBufferSizeURCBs, self->iedServer); + while (currentReport < reportsCount) + { + ReportControl* rc = + ReportControl_create(false, logicalNode, self->iedServer->reportBufferSizeURCBs, self->iedServer); rc->domain = domain; - ReportControlBlock* reportControlBlock = getRCBForLogicalNodeWithIndex( - self, logicalNode, currentReport, false); + ReportControlBlock* reportControlBlock = getRCBForLogicalNodeWithIndex(self, logicalNode, currentReport, false); rc->hasOwner = self->iedServer->enableOwnerForRCB; - rc->name = StringUtils_createString(3, logicalNode->name, "$RP$", - reportControlBlock->name); + rc->name = StringUtils_createString(3, logicalNode->name, "$RP$", reportControlBlock->name); rc->rcb = reportControlBlock; namedVariable->typeSpec.structure.elements[currentReport] = - createUnbufferedReportControlBlock(reportControlBlock, rc); + createUnbufferedReportControlBlock(reportControlBlock, rc); LinkedList_add(self->reportControls, rc); @@ -1581,7 +1684,8 @@ convertIPv4AddressStringToByteArray(const char* clientAddressString, uint8_t ipV const char* separator = clientAddressString; - while (separator != NULL && addrElementCount < 4) { + while (separator != NULL && addrElementCount < 4) + { int intVal = atoi(separator); ipV4Addr[addrElementCount] = intVal; @@ -1591,7 +1695,7 @@ convertIPv4AddressStringToByteArray(const char* clientAddressString, uint8_t ipV if (separator != NULL) separator++; /* skip '.' character */ - addrElementCount ++; + addrElementCount++; } if (addrElementCount == 4) @@ -1609,18 +1713,23 @@ updateOwner(ReportControl* rc, MmsServerConnection connection) Semaphore_wait(rc->rcbValuesLock); #endif - if (rc->server->edition >= IEC_61850_EDITION_2 && rc->hasOwner) { + if (rc->server->edition >= IEC_61850_EDITION_2 && rc->hasOwner) + { MmsValue* owner = ReportControl_getRCBValue(rc, "Owner"); - if (owner != NULL) { + if (owner != NULL) + { - if (connection != NULL) { + if (connection != NULL) + { char* clientAddressString = MmsServerConnection_getClientAddress(connection); - if (DEBUG_IED_SERVER) printf("IED_SERVER: reporting.c: set owner to %s\n", clientAddressString); + if (DEBUG_IED_SERVER) + printf("IED_SERVER: reporting.c: set owner to %s\n", clientAddressString); - if (strchr(clientAddressString, '.') != NULL) { + if (strchr(clientAddressString, '.') != NULL) + { if (DEBUG_IED_SERVER) printf("IED_SERVER: reporting.c: client address is IPv4 address\n"); @@ -1632,20 +1741,22 @@ updateOwner(ReportControl* rc, MmsServerConnection connection) MmsValue_setOctetString(owner, ipV4Addr, 4); else MmsValue_setOctetString(owner, ipV4Addr, 0); - } - else { + else + { uint8_t ipV6Addr[16]; bool valid = StringUtils_convertIPv6AdddressStringToByteArray(clientAddressString, ipV6Addr); - if (valid) { + if (valid) + { if (DEBUG_IED_SERVER) printf("IED_SERVER: reporting.c: client address is IPv6 address\n"); MmsValue_setOctetString(owner, ipV6Addr, 16); } - else { + else + { if (DEBUG_IED_SERVER) printf("IED_SERVER: reporting.c: not a valid IPv6 address\n"); @@ -1653,17 +1764,22 @@ updateOwner(ReportControl* rc, MmsServerConnection connection) } } } - else { - if (rc->resvTms != -1) { + else + { + if (rc->resvTms != -1) + { uint8_t emptyAddr[1]; MmsValue_setOctetString(owner, emptyAddr, 0); } - else { + else + { /* Set to pre-configured owner */ - if (rc->rcb->clientReservation[0] == 4) { + if (rc->rcb->clientReservation[0] == 4) + { MmsValue_setOctetString(owner, rc->rcb->clientReservation + 1, 4); } - else if (rc->rcb->clientReservation[0] == 6) { + else if (rc->rcb->clientReservation[0] == 6) + { MmsValue_setOctetString(owner, rc->rcb->clientReservation + 1, 16); } } @@ -1683,7 +1799,8 @@ checkForZeroEntryID(MmsValue* value) int i = 0; - while (i < 8) { + while (i < 8) + { if (buffer[i] != 0) return false; @@ -1700,8 +1817,10 @@ checkReportBufferForEntryID(ReportControl* rc, MmsValue* value) ReportBufferEntry* entry = rc->reportBuffer->oldestReport; - while (entry != NULL) { - if (memcmp(entry->entryId, value->value.octetString.buf, 8) == 0) { + while (entry != NULL) + { + if (memcmp(entry->entryId, value->value.octetString.buf, 8) == 0) + { ReportBufferEntry* nextEntryForResync = entry->next; rc->reportBuffer->nextToTransmit = nextEntryForResync; @@ -1735,9 +1854,12 @@ increaseConfRev(ReportControl* self) static void checkReservationTimeout(MmsMapping* self, ReportControl* rc) { - if (rc->enabled == false && (rc->clientConnection == NULL)) { - if (rc->reservationTimeout > 0) { - if (Hal_getTimeInMs() > rc->reservationTimeout) { + if (rc->enabled == false && (rc->clientConnection == NULL)) + { + if (rc->reservationTimeout > 0) + { + if (Hal_getTimeInMs() > rc->reservationTimeout) + { if (rc->resvTms != -1) rc->resvTms = 0; @@ -1746,7 +1868,8 @@ checkReservationTimeout(MmsMapping* self, ReportControl* rc) printf("IED_SERVER: reservation timeout expired for %s.%s\n", rc->parentLN->name, rc->name); #if (CONFIG_IEC61850_BRCB_WITH_RESVTMS == 1) - if (self->iedServer->enableBRCBResvTms) { + if (self->iedServer->enableBRCBResvTms) + { #if (CONFIG_MMS_THREADLESS_STACK != 1) Semaphore_wait(rc->rcbValuesLock); #endif @@ -1766,13 +1889,17 @@ checkReservationTimeout(MmsMapping* self, ReportControl* rc) #if (CONFIG_IEC61850_SERVICE_TRACKING == 1) copyRCBValuesToTrackingObject(self, rc); - updateGenericTrackingObjectValues(self, rc, IEC61850_SERVICE_TYPE_INTERNAL_CHANGE, DATA_ACCESS_ERROR_SUCCESS); + updateGenericTrackingObjectValues(self, rc, IEC61850_SERVICE_TYPE_INTERNAL_CHANGE, + DATA_ACCESS_ERROR_SUCCESS); #endif /* (CONFIG_IEC61850_SERVICE_TRACKING == 1) */ - if (self->rcbEventHandler) { - ClientConnection clientConnection = private_IedServer_getClientConnectionByHandle(self->iedServer, rc->clientConnection); + if (self->rcbEventHandler) + { + ClientConnection clientConnection = + private_IedServer_getClientConnectionByHandle(self->iedServer, rc->clientConnection); - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_UNRESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_UNRESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); } } } @@ -1786,13 +1913,15 @@ ReportControl_readAccess(ReportControl* rc, MmsMapping* mmsMapping, MmsServerCon MmsDataAccessError accessError = DATA_ACCESS_ERROR_SUCCESS; /* check reservation timeout */ - if (rc->buffered) { + if (rc->buffered) + { checkReservationTimeout(mmsMapping, rc); } ClientConnection clientConnection = NULL; - if (mmsMapping->controlBlockAccessHandler || mmsMapping->rcbEventHandler) { + if (mmsMapping->controlBlockAccessHandler || mmsMapping->rcbEventHandler) + { clientConnection = private_IedServer_getClientConnectionByHandle(mmsMapping->iedServer, connection); } @@ -1809,14 +1938,19 @@ ReportControl_readAccess(ReportControl* rc, MmsMapping* mmsMapping, MmsServerCon LogicalDevice* ld = (LogicalDevice*)ln->parent; - if (mmsMapping->controlBlockAccessHandler(mmsMapping->controlBlockAccessHandlerParameter, clientConnection, acsiClass, ld, ln, rc->rcb->name, elementName, IEC61850_CB_ACCESS_TYPE_READ) == false) { + if (mmsMapping->controlBlockAccessHandler(mmsMapping->controlBlockAccessHandlerParameter, clientConnection, + acsiClass, ld, ln, rc->rcb->name, elementName, + IEC61850_CB_ACCESS_TYPE_READ) == false) + { accessError = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED; accessAllowed = false; } } - if (mmsMapping->rcbEventHandler) { - mmsMapping->rcbEventHandler(mmsMapping->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_GET_PARAMETER, elementName, accessError); + if (mmsMapping->rcbEventHandler) + { + mmsMapping->rcbEventHandler(mmsMapping->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_GET_PARAMETER, elementName, accessError); } return accessAllowed; @@ -1833,33 +1967,42 @@ isIpAddressMatchingWithOwner(ReportControl* rc, const char* ipAddress) MmsValue* owner = ReportControl_getRCBValue(rc, "Owner"); - if (owner != NULL) { + if (owner != NULL) + { - if (MmsValue_getOctetStringSize(owner) == 0) { + if (MmsValue_getOctetStringSize(owner) == 0) + { retVal = true; goto exit_function; } - if (strchr(ipAddress, '.') != NULL) { + if (strchr(ipAddress, '.') != NULL) + { uint8_t ipV4Addr[4]; - if (convertIPv4AddressStringToByteArray(ipAddress, ipV4Addr)) { - if (memcmp(ipV4Addr, MmsValue_getOctetStringBuffer(owner), 4) == 0) { + if (convertIPv4AddressStringToByteArray(ipAddress, ipV4Addr)) + { + if (memcmp(ipV4Addr, MmsValue_getOctetStringBuffer(owner), 4) == 0) + { retVal = true; goto exit_function; } } } - else { + else + { uint8_t ipV6Addr[16]; - if (StringUtils_convertIPv6AdddressStringToByteArray(ipAddress, ipV6Addr)) { - if (memcmp(ipV6Addr, MmsValue_getOctetStringBuffer(owner), 16) == 0) { + if (StringUtils_convertIPv6AdddressStringToByteArray(ipAddress, ipV6Addr)) + { + if (memcmp(ipV6Addr, MmsValue_getOctetStringBuffer(owner), 16) == 0) + { retVal = true; goto exit_function; } } - else { + else + { goto exit_function; } } @@ -1875,7 +2018,7 @@ exit_function: } static void -reserveRcb(ReportControl* rc, MmsServerConnection connection) +reserveRcb(ReportControl* rc, MmsServerConnection connection) { rc->reserved = true; rc->clientConnection = connection; @@ -1884,16 +2027,19 @@ reserveRcb(ReportControl* rc, MmsServerConnection connection) Semaphore_wait(rc->rcbValuesLock); #endif - if (rc->buffered) { + if (rc->buffered) + { #if (CONFIG_IEC61850_BRCB_WITH_RESVTMS == 1) - if (rc->server->enableBRCBResvTms) { + if (rc->server->enableBRCBResvTms) + { MmsValue* resvTmsVal = ReportControl_getRCBValue(rc, "ResvTms"); if (resvTmsVal) MmsValue_setInt16(resvTmsVal, rc->resvTms); } #endif } - else { + else + { MmsValue* resvVal = ReportControl_getRCBValue(rc, "Resv"); if (resvVal) MmsValue_setBoolean(resvVal, true); @@ -1908,7 +2054,7 @@ reserveRcb(ReportControl* rc, MmsServerConnection connection) MmsDataAccessError Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* elementName, MmsValue* value, - MmsServerConnection connection) + MmsServerConnection connection) { MmsDataAccessError retVal = DATA_ACCESS_ERROR_SUCCESS; @@ -1931,7 +2077,9 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* LogicalDevice* ld = (LogicalDevice*)ln->parent; - if (self->controlBlockAccessHandler(self->controlBlockAccessHandlerParameter, clientConnection, acsiClass, ld, ln, rc->rcb->name, elementName, IEC61850_CB_ACCESS_TYPE_WRITE) == false) { + if (self->controlBlockAccessHandler(self->controlBlockAccessHandlerParameter, clientConnection, acsiClass, ld, + ln, rc->rcb->name, elementName, IEC61850_CB_ACCESS_TYPE_WRITE) == false) + { retVal = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED; goto exit_function_only_tracking; @@ -1939,29 +2087,38 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* } /* check reservation timeout for buffered RCBs */ - if (rc->buffered) { + if (rc->buffered) + { checkReservationTimeout(self, rc); - if (rc->resvTms == 0) { + if (rc->resvTms == 0) + { /* nothing to to */ } - else if (rc->resvTms == -1) { + else if (rc->resvTms == -1) + { - if (rc->reserved == false) { + if (rc->reserved == false) + { - if (self->iedServer->edition < IEC_61850_EDITION_2_1) { + if (self->iedServer->edition < IEC_61850_EDITION_2_1) + { #if (CONFIG_IEC61850_RCB_ALLOW_ONLY_PRECONFIGURED_CLIENT == 1) - if (isIpAddressMatchingWithOwner(rc, MmsServerConnection_getClientAddress(connection))) { + if (isIpAddressMatchingWithOwner(rc, MmsServerConnection_getClientAddress(connection))) + { rc->reserved = true; rc->clientConnection = connection; - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); } } - else { + else + { if (DEBUG_IED_SERVER) printf("IED_SERVER: client IP not matching with pre-assigned owner\n"); } @@ -1969,34 +2126,42 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* rc->reserved = true; rc->clientConnection = connection; - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); } #endif - } } } - else if (rc->resvTms > 0) { - if (rc->reserved == false) { + else if (rc->resvTms > 0) + { + if (rc->reserved == false) + { - if (isIpAddressMatchingWithOwner(rc, MmsServerConnection_getClientAddress(connection))) { + if (isIpAddressMatchingWithOwner(rc, MmsServerConnection_getClientAddress(connection))) + { rc->reserved = true; rc->clientConnection = connection; rc->reservationTimeout = Hal_getTimeInMs() + (rc->resvTms * 1000); - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); } } - else { + else + { if (DEBUG_IED_SERVER) printf("IED_SERVER: client IP not matching with owner\n"); } - } - else { - if (rc->clientConnection == connection) { + else + { + if (rc->clientConnection == connection) + { rc->reservationTimeout = Hal_getTimeInMs() + (rc->resvTms * 1000); } } @@ -2006,9 +2171,12 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* ReportControl_lockNotify(rc); /* for edition 2.1 don't allow implicit RCB reservation */ - if (self->iedServer->edition == IEC_61850_EDITION_2_1) { - if (rc->reserved == false) { - if ((strcmp(elementName, "Resv")) && (strcmp(elementName, "ResvTms"))) { + if (self->iedServer->edition == IEC_61850_EDITION_2_1) + { + if (rc->reserved == false) + { + if ((strcmp(elementName, "Resv")) && (strcmp(elementName, "ResvTms"))) + { retVal = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED; goto exit_function; @@ -2016,15 +2184,18 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* } } - if ((rc->reserved) && (rc->clientConnection != connection)) { + if ((rc->reserved) && (rc->clientConnection != connection)) + { retVal = DATA_ACCESS_ERROR_TEMPORARILY_UNAVAILABLE; goto exit_function; } #if (CONFIG_IEC61850_RCB_ALLOW_ONLY_PRECONFIGURED_CLIENT == 1) - if (rc->resvTms == -1) { - if (isIpAddressMatchingWithOwner(rc, MmsServerConnection_getClientAddress(connection)) == false) { + if (rc->resvTms == -1) + { + if (isIpAddressMatchingWithOwner(rc, MmsServerConnection_getClientAddress(connection)) == false) + { retVal = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED; if (DEBUG_IED_SERVER) @@ -2035,30 +2206,36 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* } #endif - if (strcmp(elementName, "RptEna") == 0) { + if (strcmp(elementName, "RptEna") == 0) + { - if (value->value.boolean == true) { + if (value->value.boolean == true) + { - if (rc->enabled == true) { + if (rc->enabled == true) + { retVal = DATA_ACCESS_ERROR_TEMPORARILY_UNAVAILABLE; goto exit_function; } if (DEBUG_IED_SERVER) - printf("IED_SERVER: Activate report for client %s\n", - MmsServerConnection_getClientAddress(connection)); + printf("IED_SERVER: Activate report for client %s\n", MmsServerConnection_getClientAddress(connection)); - if (updateReportDataset(self, rc, NULL, connection)) { + if (updateReportDataset(self, rc, NULL, connection)) + { - if (rc->reserved == false) { + if (rc->reserved == false) + { rc->resvTms = RESV_TMS_IMPLICIT_VALUE; reserveRcb(rc, connection); - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); } } @@ -2075,9 +2252,11 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* Semaphore_post(rc->rcbValuesLock); #endif - if (rc->buffered) { + if (rc->buffered) + { - if (rc->isResync == false) { + if (rc->isResync == false) + { rc->reportBuffer->nextToTransmit = rc->reportBuffer->oldestReport; rc->reportBuffer->isOverflow = true; } @@ -2108,22 +2287,27 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* retVal = DATA_ACCESS_ERROR_SUCCESS; - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_ENABLE, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_ENABLE, + NULL, DATA_ACCESS_ERROR_SUCCESS); } goto exit_function; } - else { + else + { retVal = DATA_ACCESS_ERROR_TEMPORARILY_UNAVAILABLE; goto exit_function; } } - else { + else + { if (rc->enabled == false) goto exit_function; - if (((rc->enabled) || (rc->reserved)) && (rc->clientConnection != connection)) { + if (((rc->enabled) || (rc->reserved)) && (rc->clientConnection != connection)) + { retVal = DATA_ACCESS_ERROR_TEMPORARILY_UNAVAILABLE; goto exit_function; @@ -2131,108 +2315,132 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* if (DEBUG_IED_SERVER) printf("IED_SERVER: Deactivate report for client %s\n", - MmsServerConnection_getClientAddress(connection)); + MmsServerConnection_getClientAddress(connection)); - if (rc->buffered) { + if (rc->buffered) + { rc->reportBuffer->isOverflow = true; rc->isResync = false; } - else { + else + { if (rc->dataSet) clearInclusionFlags(rc); /* clear report buffer */ purgeBuf(rc); - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_PURGEBUF, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_PURGEBUF, + NULL, DATA_ACCESS_ERROR_SUCCESS); } } - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_DISABLE, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_DISABLE, + NULL, DATA_ACCESS_ERROR_SUCCESS); } rc->enabled = false; } - } - if (strcmp(elementName, "GI") == 0) { - if ((rc->enabled) && (rc->clientConnection == connection)) { + if (strcmp(elementName, "GI") == 0) + { + if ((rc->enabled) && (rc->clientConnection == connection)) + { - if (MmsValue_getBoolean(value)) { + if (MmsValue_getBoolean(value)) + { if (rc->triggerOps & TRG_OPT_GI) rc->gi = true; } retVal = DATA_ACCESS_ERROR_SUCCESS; - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_GI, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_GI, NULL, + DATA_ACCESS_ERROR_SUCCESS); } goto exit_function; } - else { + else + { retVal = DATA_ACCESS_ERROR_TEMPORARILY_UNAVAILABLE; goto exit_function; } } - if (rc->enabled == false) { + if (rc->enabled == false) + { - if ((rc->reserved) && (rc->clientConnection != connection)) { + if ((rc->reserved) && (rc->clientConnection != connection)) + { retVal = DATA_ACCESS_ERROR_TEMPORARILY_UNAVAILABLE; goto exit_function; } - if (strcmp(elementName, "Resv") == 0) { + if (strcmp(elementName, "Resv") == 0) + { resvTmsAccess = true; rc->reserved = value->value.boolean; - if (rc->reserved == true) { + if (rc->reserved == true) + { - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_RESERVED, + NULL, DATA_ACCESS_ERROR_SUCCESS); } updateOwner(rc, connection); rc->clientConnection = connection; } - else { + else + { updateOwner(rc, NULL); rc->clientConnection = NULL; if (rc->resvTms == -1) dontUpdate = true; - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_UNRESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_UNRESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); } } - } - else if (strcmp(elementName, "PurgeBuf") == 0) { - if (MmsValue_getType(value) == MMS_BOOLEAN) { + else if (strcmp(elementName, "PurgeBuf") == 0) + { + if (MmsValue_getType(value) == MMS_BOOLEAN) + { - if (MmsValue_getBoolean(value) == true) { + if (MmsValue_getBoolean(value) == true) + { purgeBuf(rc); retVal = DATA_ACCESS_ERROR_SUCCESS; - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_PURGEBUF, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_PURGEBUF, NULL, DATA_ACCESS_ERROR_SUCCESS); } goto exit_function; } } - } - else if (strcmp(elementName, "DatSet") == 0) { + else if (strcmp(elementName, "DatSet") == 0) + { if (!(self->iedServer->rcbSettingsWritable & IEC61850_REPORTSETTINGS_DATSET)) { @@ -2246,9 +2454,11 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* MmsValue* datSet = ReportControl_getRCBValue(rc, "DatSet"); - if (!MmsValue_equals(datSet, value)) { + if (!MmsValue_equals(datSet, value)) + { - if (updateReportDataset(self, rc, value, connection)) { + if (updateReportDataset(self, rc, value, connection)) + { MmsValue_update(datSet, value); @@ -2258,15 +2468,19 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* Semaphore_post(rc->rcbValuesLock); #endif - if (rc->buffered) { + if (rc->buffered) + { purgeBuf(rc); - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_PURGEBUF, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_PURGEBUF, NULL, DATA_ACCESS_ERROR_SUCCESS); } } } - else { + else + { #if (CONFIG_MMS_THREADLESS_STACK != 1) Semaphore_post(rc->rcbValuesLock); #endif @@ -2276,7 +2490,8 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* goto exit_function; } } - else { + else + { #if (CONFIG_MMS_THREADLESS_STACK != 1) Semaphore_post(rc->rcbValuesLock); #endif @@ -2285,7 +2500,8 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* retVal = DATA_ACCESS_ERROR_SUCCESS; goto exit_function; } - else if (strcmp(elementName, "IntgPd") == 0) { + else if (strcmp(elementName, "IntgPd") == 0) + { if (!(self->iedServer->rcbSettingsWritable & IEC61850_REPORTSETTINGS_INTG_PD)) { @@ -2299,7 +2515,8 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* MmsValue* intgPd = ReportControl_getRCBValue(rc, elementName); - if (!MmsValue_equals(intgPd, value)) { + if (!MmsValue_equals(intgPd, value)) + { MmsValue_update(intgPd, value); #if (CONFIG_MMS_THREADLESS_STACK != 1) @@ -2308,16 +2525,21 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* refreshIntegrityPeriod(rc); - if (rc->buffered) { + if (rc->buffered) + { - if (rc->triggerOps & TRG_OPT_INTEGRITY) { + if (rc->triggerOps & TRG_OPT_INTEGRITY) + { - if (rc->intgPd > 0) { + if (rc->intgPd > 0) + { - if (rc->server->syncIntegrityReportTimes) { + if (rc->server->syncIntegrityReportTimes) + { rc->nextIntgReportTime = getNextRoundedStartTime(Hal_getTimeInMs(), rc->intgPd); } - else { + else + { rc->nextIntgReportTime = 0; } } @@ -2325,12 +2547,15 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* purgeBuf(rc); - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_PURGEBUF, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_PURGEBUF, NULL, DATA_ACCESS_ERROR_SUCCESS); } } } - else { + else + { #if (CONFIG_MMS_THREADLESS_STACK != 1) Semaphore_post(rc->rcbValuesLock); #endif @@ -2338,7 +2563,8 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* goto exit_function; } - else if (strcmp(elementName, "TrgOps") == 0) { + else if (strcmp(elementName, "TrgOps") == 0) + { if (!(self->iedServer->rcbSettingsWritable & IEC61850_REPORTSETTINGS_TRG_OPS)) { @@ -2352,24 +2578,29 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* MmsValue* trgOps = ReportControl_getRCBValue(rc, elementName); - if (!MmsValue_equals(trgOps, value)) { + if (!MmsValue_equals(trgOps, value)) + { MmsValue_update(trgOps, value); #if (CONFIG_MMS_THREADLESS_STACK != 1) Semaphore_post(rc->rcbValuesLock); #endif - if (rc->buffered) { + if (rc->buffered) + { purgeBuf(rc); - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_PURGEBUF, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_PURGEBUF, NULL, DATA_ACCESS_ERROR_SUCCESS); } } refreshTriggerOptions(rc); } - else { + else + { #if (CONFIG_MMS_THREADLESS_STACK != 1) Semaphore_post(rc->rcbValuesLock); #endif @@ -2377,18 +2608,22 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* goto exit_function; } - else if (strcmp(elementName, "EntryID") == 0) { + else if (strcmp(elementName, "EntryID") == 0) + { - if (MmsValue_getOctetStringSize(value) != 8) { + if (MmsValue_getOctetStringSize(value) != 8) + { retVal = DATA_ACCESS_ERROR_OBJECT_VALUE_INVALID; goto exit_function; } - if (checkForZeroEntryID(value) == false) { + if (checkForZeroEntryID(value) == false) + { - if (!checkReportBufferForEntryID(rc, value)) { + if (!checkReportBufferForEntryID(rc, value)) + { rc->reportBuffer->isOverflow = true; retVal = DATA_ACCESS_ERROR_OBJECT_VALUE_INVALID; @@ -2398,7 +2633,8 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* rc->reportBuffer->isOverflow = false; } - else { + else + { rc->reportBuffer->nextToTransmit = rc->reportBuffer->oldestReport; rc->reportBuffer->isOverflow = true; rc->isResync = false; @@ -2417,7 +2653,8 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* goto exit_function; } - else if (strcmp(elementName, "BufTm") == 0) { + else if (strcmp(elementName, "BufTm") == 0) + { if (!(self->iedServer->rcbSettingsWritable & IEC61850_REPORTSETTINGS_BUF_TIME)) { @@ -2431,24 +2668,29 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* MmsValue* bufTm = ReportControl_getRCBValue(rc, elementName); - if (!MmsValue_equals(bufTm, value)) { + if (!MmsValue_equals(bufTm, value)) + { MmsValue_update(bufTm, value); #if (CONFIG_MMS_THREADLESS_STACK != 1) Semaphore_post(rc->rcbValuesLock); #endif - if (rc->buffered) { + if (rc->buffered) + { purgeBuf(rc); - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_PURGEBUF, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_PURGEBUF, NULL, DATA_ACCESS_ERROR_SUCCESS); } } refreshBufferTime(rc); } - else { + else + { #if (CONFIG_MMS_THREADLESS_STACK != 1) Semaphore_post(rc->rcbValuesLock); #endif @@ -2456,7 +2698,8 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* goto exit_function; } - else if (strcmp(elementName, "RptID") == 0) { + else if (strcmp(elementName, "RptID") == 0) + { if (!(self->iedServer->rcbSettingsWritable & IEC61850_REPORTSETTINGS_RPT_ID)) { @@ -2470,22 +2713,27 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* MmsValue* rptId = ReportControl_getRCBValue(rc, elementName); - if (!MmsValue_equals(rptId, value)) { + if (!MmsValue_equals(rptId, value)) + { MmsValue_update(rptId, value); #if (CONFIG_MMS_THREADLESS_STACK != 1) Semaphore_post(rc->rcbValuesLock); #endif - if (rc->buffered) { + if (rc->buffered) + { purgeBuf(rc); - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_PURGEBUF, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_PURGEBUF, NULL, DATA_ACCESS_ERROR_SUCCESS); } } } - else { + else + { #if (CONFIG_MMS_THREADLESS_STACK != 1) Semaphore_post(rc->rcbValuesLock); #endif @@ -2493,34 +2741,44 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* goto exit_function; } - else if (strcmp(elementName, "ResvTms") == 0) { - if (rc->buffered) { + else if (strcmp(elementName, "ResvTms") == 0) + { + if (rc->buffered) + { resvTmsAccess = true; - if (rc->resvTms != -1) { + if (rc->resvTms != -1) + { int resvTms = MmsValue_toInt32(value); - if (resvTms >= 0) { + if (resvTms >= 0) + { rc->resvTms = resvTms; - if (rc->resvTms == 0) { + if (rc->resvTms == 0) + { rc->reservationTimeout = 0; rc->reserved = false; updateOwner(rc, NULL); - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_UNRESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_UNRESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); } } - else { + else + { rc->reservationTimeout = Hal_getTimeInMs() + (rc->resvTms * 1000); reserveRcb(rc, connection); - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); } } @@ -2529,21 +2787,27 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* if (resvTmsVal != NULL) MmsValue_update(resvTmsVal, value); } - else { + else + { retVal = DATA_ACCESS_ERROR_OBJECT_VALUE_INVALID; } } - else { - if (self->iedServer->edition < IEC_61850_EDITION_2_1) { + else + { + if (self->iedServer->edition < IEC_61850_EDITION_2_1) + { retVal = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED; } - else { + else + { rc->reservationTimeout = Hal_getTimeInMs() + (RESV_TMS_IMPLICIT_VALUE * 1000); reserveRcb(rc, connection); - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); } } } @@ -2551,27 +2815,32 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* goto exit_function; } } - else if (strcmp(elementName, "ConfRev") == 0) { + else if (strcmp(elementName, "ConfRev") == 0) + { retVal = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED; goto exit_function; } - else if (strcmp(elementName, "SqNum") == 0) { + else if (strcmp(elementName, "SqNum") == 0) + { retVal = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED; goto exit_function; } - else if (strcmp(elementName, "Owner") == 0) { + else if (strcmp(elementName, "Owner") == 0) + { retVal = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED; goto exit_function; } - else if (strcmp(elementName, "TimeofEntry") == 0) { + else if (strcmp(elementName, "TimeofEntry") == 0) + { retVal = DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED; goto exit_function; } - else if (strcmp(elementName, "OptFlds") == 0) { + else if (strcmp(elementName, "OptFlds") == 0) + { if (!(self->iedServer->rcbSettingsWritable & IEC61850_REPORTSETTINGS_OPT_FIELDS)) { @@ -2586,8 +2855,10 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* MmsValue* rcbValue = ReportControl_getRCBValue(rc, elementName); - if (rcbValue) { - if (dontUpdate == false) { + if (rcbValue) + { + if (dontUpdate == false) + { MmsValue_update(rcbValue, value); } @@ -2595,7 +2866,8 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* Semaphore_post(rc->rcbValuesLock); #endif } - else { + else + { #if (CONFIG_MMS_THREADLESS_STACK != 1) Semaphore_post(rc->rcbValuesLock); #endif @@ -2604,48 +2876,62 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, const char* goto exit_function; } - } - else { + else + { retVal = DATA_ACCESS_ERROR_TEMPORARILY_UNAVAILABLE; } exit_function: - /* every successful write access reserves the RCB (or for edition 2.1 it means that there is already a reservation) */ - if ((retVal == DATA_ACCESS_ERROR_SUCCESS) && (resvTmsAccess == false)) { - if (rc->buffered) { + /* every successful write access reserves the RCB (or for edition 2.1 it means that there is already a reservation) + */ + if ((retVal == DATA_ACCESS_ERROR_SUCCESS) && (resvTmsAccess == false)) + { + if (rc->buffered) + { rc->reservationTimeout = Hal_getTimeInMs() + (RESV_TMS_IMPLICIT_VALUE * 1000); - if (rc->resvTms == 0) { + if (rc->resvTms == 0) + { - if (rc->reserved == false) { + if (rc->reserved == false) + { rc->resvTms = RESV_TMS_IMPLICIT_VALUE; reserveRcb(rc, connection); - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); } } - } - else if (rc->resvTms == -1) { - if (rc->reserved == false) { + else if (rc->resvTms == -1) + { + if (rc->reserved == false) + { reserveRcb(rc, connection); - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, + RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); } } } } - else { - if (rc->reserved == false) { + else + { + if (rc->reserved == false) + { reserveRcb(rc, connection); - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_RESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_RESERVED, + NULL, DATA_ACCESS_ERROR_SUCCESS); } } } @@ -2669,8 +2955,10 @@ exit_function_only_tracking: updateGenericTrackingObjectValues(self, rc, IEC61850_SERVICE_TYPE_SET_URCB_VALUES, retVal); #endif /* (CONFIG_IEC61850_SERVICE_TRACKING == 1) */ - if (self->rcbEventHandler) { - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_SET_PARAMETER, elementName, retVal); + if (self->rcbEventHandler) + { + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_SET_PARAMETER, + elementName, retVal); } return retVal; @@ -2683,9 +2971,11 @@ Reporting_disableReportControlInstance(MmsMapping* self, ReportControl* rc) { if (self->rcbEventHandler) { - ClientConnection clientConnection = private_IedServer_getClientConnectionByHandle(self->iedServer, rc->clientConnection); + ClientConnection clientConnection = + private_IedServer_getClientConnectionByHandle(self->iedServer, rc->clientConnection); - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_DISABLE, NULL, DATA_ACCESS_ERROR_SUCCESS); + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_DISABLE, NULL, + DATA_ACCESS_ERROR_SUCCESS); } } @@ -2709,9 +2999,11 @@ Reporting_disableReportControlInstance(MmsMapping* self, ReportControl* rc) if (self->rcbEventHandler) { - ClientConnection clientConnection = private_IedServer_getClientConnectionByHandle(self->iedServer, rc->clientConnection); + ClientConnection clientConnection = + private_IedServer_getClientConnectionByHandle(self->iedServer, rc->clientConnection); - self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_UNRESERVED, NULL, DATA_ACCESS_ERROR_SUCCESS); + self->rcbEventHandler(self->rcbEventHandlerParameter, rc->rcb, clientConnection, RCB_EVENT_UNRESERVED, NULL, + DATA_ACCESS_ERROR_SUCCESS); } } @@ -2741,7 +3033,8 @@ Reporting_disableReportControlInstance(MmsMapping* self, ReportControl* rc) { if (rc->resvTms == 0) updateOwner(rc, NULL); - else if (rc->resvTms > 0) { + else if (rc->resvTms > 0) + { rc->reservationTimeout = Hal_getTimeInMs() + (rc->resvTms * 1000); } } @@ -2776,7 +3069,8 @@ Reporting_deactivateReportsForConnection(MmsMapping* self, MmsServerConnection c { ReportControl* rc = (ReportControl*)LinkedList_getData(rcElem); - if (rc->clientConnection == connection) { + if (rc->clientConnection == connection) + { Reporting_disableReportControlInstance(self, rc); } @@ -2830,13 +3124,13 @@ static void printReportId(ReportBufferEntry* report) { int i = 0; - for (i = 0; i < 8; i++) { + for (i = 0; i < 8; i++) + { printf("%02x ", report->entryId[i]); } } #endif - static void removeAllGIReportsFromReportBuffer(ReportBuffer* reportBuffer) { @@ -2878,7 +3172,8 @@ removeAllGIReportsFromReportBuffer(ReportBuffer* reportBuffer) reportBuffer->lastEnqueuedReport = reportBuffer->oldestReport; } } - else { + else + { lastReport = currentReport; } @@ -2894,8 +3189,8 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ { if (DEBUG_IED_SERVER) printf("IED_SERVER: enqueueReport: RCB name: %s (SQN:%u) enabled:%i buffered:%i buffering:%i intg:%i GI:%i\n", - reportControl->name, (unsigned) reportControl->sqNum, reportControl->enabled, - reportControl->isBuffering, reportControl->buffered, isIntegrity, isGI); + reportControl->name, (unsigned)reportControl->sqNum, reportControl->enabled, reportControl->isBuffering, + reportControl->buffered, isIntegrity, isGI); ReportBuffer* buffer = reportControl->reportBuffer; @@ -2913,7 +3208,8 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ /* calculate size of complete buffer entry */ int bufferEntrySize = MemoryAllocator_getAlignedSize(sizeof(ReportBufferEntry)); - int inclusionFieldSize = MemoryAllocator_getAlignedSize(MmsValue_getBitStringByteSize(reportControl->inclusionField)); + int inclusionFieldSize = + MemoryAllocator_getAlignedSize(MmsValue_getBitStringByteSize(reportControl->inclusionField)); MmsValue inclusionFieldStatic; @@ -2954,7 +3250,8 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ dataSetEntry = dataSetEntry->sibling; } - bufferEntrySize += MemoryAllocator_getAlignedSize(sizeof(int) + dataBlockSize); /* add aligned_size(LEN + DATA) */ + bufferEntrySize += + MemoryAllocator_getAlignedSize(sizeof(int) + dataBlockSize); /* add aligned_size(LEN + DATA) */ } else { @@ -2979,7 +3276,8 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ } } - bufferEntrySize += MemoryAllocator_getAlignedSize(sizeof(int) + dataBlockSize + reasonForInclusionSize); /* add aligned_size (LEN + DATA + REASON) */ + bufferEntrySize += MemoryAllocator_getAlignedSize( + sizeof(int) + dataBlockSize + reasonForInclusionSize); /* add aligned_size (LEN + DATA + REASON) */ } if (DEBUG_IED_SERVER) @@ -2996,7 +3294,8 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ if (isBuffered) { /* remove old buffered GI reports */ - if (isGI) removeAllGIReportsFromReportBuffer(buffer); + if (isGI) + removeAllGIReportsFromReportBuffer(buffer); } uint8_t* entryBufPos = NULL; @@ -3009,8 +3308,8 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ { /* buffer is empty - we start at the beginning of the memory block */ entryBufPos = buffer->memoryBlock; - buffer->oldestReport = (ReportBufferEntry*) entryBufPos; - buffer->nextToTransmit = (ReportBufferEntry*) entryBufPos; + buffer->oldestReport = (ReportBufferEntry*)entryBufPos; + buffer->nextToTransmit = (ReportBufferEntry*)entryBufPos; } else { @@ -3024,14 +3323,16 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ printf("IED_SERVER: buffer->nextToTransmit: %p\n", buffer->nextToTransmit); } - if (DEBUG_IED_SERVER) printf ("IED_SERVER: Last buffer offset: %i\n", (int) ((uint8_t*) buffer->lastEnqueuedReport - buffer->memoryBlock)); + if (DEBUG_IED_SERVER) + printf("IED_SERVER: Last buffer offset: %i\n", + (int)((uint8_t*)buffer->lastEnqueuedReport - buffer->memoryBlock)); if (buffer->lastEnqueuedReport == buffer->oldestReport) { /* --> buffer->reportsCount == 1 */ assert(buffer->reportsCount == 1); - entryBufPos = (uint8_t*) ((uint8_t*) buffer->lastEnqueuedReport + buffer->lastEnqueuedReport->entryLength); + entryBufPos = (uint8_t*)((uint8_t*)buffer->lastEnqueuedReport + buffer->lastEnqueuedReport->entryLength); if ((entryBufPos + bufferEntrySize) > (buffer->memoryBlock + buffer->memoryBlockSize)) { @@ -3045,7 +3346,7 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ #endif buffer->reportsCount = 0; - buffer->oldestReport = (ReportBufferEntry*) entryBufPos; + buffer->oldestReport = (ReportBufferEntry*)entryBufPos; buffer->oldestReport->next = NULL; buffer->nextToTransmit = NULL; } @@ -3055,13 +3356,12 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ buffer->nextToTransmit = buffer->lastEnqueuedReport; buffer->oldestReport = buffer->lastEnqueuedReport; - buffer->oldestReport->next = (ReportBufferEntry*) entryBufPos; + buffer->oldestReport->next = (ReportBufferEntry*)entryBufPos; } - } else if (buffer->lastEnqueuedReport > buffer->oldestReport) { - entryBufPos = (uint8_t*) ((uint8_t*) buffer->lastEnqueuedReport + buffer->lastEnqueuedReport->entryLength); + entryBufPos = (uint8_t*)((uint8_t*)buffer->lastEnqueuedReport + buffer->lastEnqueuedReport->entryLength); if ((entryBufPos + bufferEntrySize) > (buffer->memoryBlock + buffer->memoryBlockSize)) { @@ -3069,7 +3369,7 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ entryBufPos = buffer->memoryBlock; /* remove old reports until enough space for new entry is available */ - while ((entryBufPos + bufferEntrySize) > (uint8_t*) buffer->oldestReport) + while ((entryBufPos + bufferEntrySize) > (uint8_t*)buffer->oldestReport) { assert(buffer->oldestReport != NULL); @@ -3083,7 +3383,9 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ #if (DEBUG_IED_SERVER == 1) printf("IED_SERVER: REMOVE report with ID "); printReportId(buffer->oldestReport); - printf(" (index: %i, size: %i)\n", (int)((uint8_t*)(buffer->oldestReport) - (uint8_t*)(buffer->memoryBlock)), buffer->oldestReport->entryLength); + printf(" (index: %i, size: %i)\n", + (int)((uint8_t*)(buffer->oldestReport) - (uint8_t*)(buffer->memoryBlock)), + buffer->oldestReport->entryLength); #endif buffer->oldestReport = buffer->oldestReport->next; @@ -3091,30 +3393,31 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ if (buffer->oldestReport == NULL) { - buffer->oldestReport = (ReportBufferEntry*) entryBufPos; + buffer->oldestReport = (ReportBufferEntry*)entryBufPos; buffer->oldestReport->next = NULL; break; } } } - buffer->lastEnqueuedReport->next = (ReportBufferEntry*) entryBufPos; + buffer->lastEnqueuedReport->next = (ReportBufferEntry*)entryBufPos; } else if (buffer->lastEnqueuedReport < buffer->oldestReport) { - entryBufPos = (uint8_t*) ((uint8_t*) buffer->lastEnqueuedReport + buffer->lastEnqueuedReport->entryLength); + entryBufPos = (uint8_t*)((uint8_t*)buffer->lastEnqueuedReport + buffer->lastEnqueuedReport->entryLength); - if ((entryBufPos + bufferEntrySize) > (buffer->memoryBlock + buffer->memoryBlockSize)) + if ((entryBufPos + bufferEntrySize) > (buffer->memoryBlock + buffer->memoryBlockSize)) { /* buffer overflow */ entryBufPos = buffer->memoryBlock; /* remove older reports in upper buffer part */ - while ((uint8_t*) buffer->oldestReport > buffer->memoryBlock) + while ((uint8_t*)buffer->oldestReport > buffer->memoryBlock) { assert(buffer->oldestReport != NULL); - if (buffer->nextToTransmit == buffer->oldestReport) { + if (buffer->nextToTransmit == buffer->oldestReport) + { buffer->nextToTransmit = buffer->oldestReport->next; buffer->isOverflow = true; overflow = true; @@ -3131,7 +3434,7 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ } /* remove older reports in lower buffer part that will be overwritten by new report */ - while ((entryBufPos + bufferEntrySize) > (uint8_t*) buffer->oldestReport) + while ((entryBufPos + bufferEntrySize) > (uint8_t*)buffer->oldestReport) { if (buffer->oldestReport == NULL) break; @@ -3157,7 +3460,8 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ } else { - while (((entryBufPos + bufferEntrySize) > (uint8_t*) buffer->oldestReport) && ((uint8_t*) buffer->oldestReport != buffer->memoryBlock)) + while (((entryBufPos + bufferEntrySize) > (uint8_t*)buffer->oldestReport) && + ((uint8_t*)buffer->oldestReport != buffer->memoryBlock)) { if (buffer->oldestReport == NULL) break; @@ -3182,17 +3486,16 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ } } - buffer->lastEnqueuedReport->next = (ReportBufferEntry*) entryBufPos; + buffer->lastEnqueuedReport->next = (ReportBufferEntry*)entryBufPos; } - } entryStartPos = entryBufPos; - buffer->lastEnqueuedReport = (ReportBufferEntry*) entryBufPos; + buffer->lastEnqueuedReport = (ReportBufferEntry*)entryBufPos; buffer->lastEnqueuedReport->next = NULL; buffer->reportsCount++; - ReportBufferEntry* entry = (ReportBufferEntry*) entryBufPos; + ReportBufferEntry* entry = (ReportBufferEntry*)entryBufPos; entry->timeOfEntry = timeOfEntry; @@ -3204,17 +3507,17 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ if (entryId <= reportControl->lastEntryId) entryId = reportControl->lastEntryId + 1; - #if (ORDER_LITTLE_ENDIAN == 1) - memcpyReverseByteOrder(entry->entryId, (uint8_t*) &entryId, 8); - #else - memcpy (entry->entryId, (uint8_t*) &entryId, 8); - #endif +#if (ORDER_LITTLE_ENDIAN == 1) + memcpyReverseByteOrder(entry->entryId, (uint8_t*)&entryId, 8); +#else + memcpy(entry->entryId, (uint8_t*)&entryId, 8); +#endif - #if (DEBUG_IED_SERVER == 1) +#if (DEBUG_IED_SERVER == 1) printf("IED_SERVER: ENCODE REPORT WITH ID: "); printReportId(entry); printf(" at pos %p\n", entryStartPos); - #endif +#endif if (reportControl->enabled == false) { @@ -3223,7 +3526,7 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ #endif MmsValue* entryIdValue = MmsValue_getElement(reportControl->rcbValues, 11); - MmsValue_setOctetString(entryIdValue, (uint8_t*) entry->entryId, 8); + MmsValue_setOctetString(entryIdValue, (uint8_t*)entry->entryId, 8); #if (CONFIG_MMS_THREADLESS_STACK != 1) Semaphore_post(reportControl->rcbValuesLock); @@ -3257,7 +3560,8 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ for (i = 0; i < inclusionBitStringSize; i++) { - if (dataSetEntry->value) { + if (dataSetEntry->value) + { entryBufPos += MmsValue_encodeMmsData(dataSetEntry->value, entryBufPos, 0, true); } else @@ -3305,8 +3609,8 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ if (reportControl->inclusionFlags[i] != REPORT_CONTROL_NONE) { - *entryBufPos = (uint8_t) reportControl->inclusionFlags[i]; - entryBufPos ++; + *entryBufPos = (uint8_t)reportControl->inclusionFlags[i]; + entryBufPos++; } } } @@ -3315,7 +3619,7 @@ enqueueReport(ReportControl* reportControl, bool isIntegrity, bool isGI, uint64_ if (DEBUG_IED_SERVER) printf("IED_SERVER: enqueueReport: encoded %i bytes for report (estimated %i) at buffer offset %i\n", - (int) (entryBufPos - entryStartPos), bufferEntrySize, (int) (entryStartPos - buffer->memoryBlock)); + (int)(entryBufPos - entryStartPos), bufferEntrySize, (int)(entryStartPos - buffer->memoryBlock)); #if (DEBUG_IED_SERVER == 1) printEnqueuedReports(reportControl); @@ -3339,11 +3643,14 @@ exit_function: if (mmsMapping->rcbEventHandler) { - if (overflow) { - mmsMapping->rcbEventHandler(mmsMapping->rcbEventHandlerParameter, reportControl->rcb, NULL, RCB_EVENT_OVERFLOW, NULL, DATA_ACCESS_ERROR_SUCCESS); + if (overflow) + { + mmsMapping->rcbEventHandler(mmsMapping->rcbEventHandlerParameter, reportControl->rcb, NULL, + RCB_EVENT_OVERFLOW, NULL, DATA_ACCESS_ERROR_SUCCESS); } - mmsMapping->rcbEventHandler(mmsMapping->rcbEventHandlerParameter, reportControl->rcb, NULL, RCB_EVENT_REPORT_CREATED, NULL, DATA_ACCESS_ERROR_SUCCESS); + mmsMapping->rcbEventHandler(mmsMapping->rcbEventHandlerParameter, reportControl->rcb, NULL, + RCB_EVENT_REPORT_CREATED, NULL, DATA_ACCESS_ERROR_SUCCESS); } } @@ -3370,7 +3677,7 @@ sendNextReportEntrySegment(ReportControl* self) int maxMmsPduSize = MmsServerConnection_getMaxMmsPduSize(self->clientConnection); int estimatedSegmentSize = 19; /* maximum size of header information (header can have 13-19 byte) */ - estimatedSegmentSize += 8; /* reserve space for more-segments-follow (3 byte) and sub-seq-num (3-5 byte) */ + estimatedSegmentSize += 8; /* reserve space for more-segments-follow (3 byte) and sub-seq-num (3-5 byte) */ bool segmented = self->segmented; bool moreFollows = false; @@ -3402,7 +3709,7 @@ sendNextReportEntrySegment(ReportControl* self) if (isBuffered) { MmsValue* entryIdValue = MmsValue_getElement(self->rcbValues, 11); - MmsValue_setOctetString(entryIdValue, (uint8_t*) report->entryId, 8); + MmsValue_setOctetString(entryIdValue, (uint8_t*)report->entryId, 8); } char rptIdBuf[130]; @@ -3421,7 +3728,8 @@ sendNextReportEntrySegment(ReportControl* self) /* use default rptId when RptID is empty in RCB */ updateWithDefaultRptId(self, &rptId); } - else { + else + { MmsValue_setVisibleString(&rptId, rptIdStr); } @@ -3439,7 +3747,7 @@ sendNextReportEntrySegment(ReportControl* self) MmsValue _inclusionField; - uint8_t* currentReportBufferPos = (uint8_t*) report + sizeof(ReportBufferEntry); + uint8_t* currentReportBufferPos = (uint8_t*)report + sizeof(ReportBufferEntry); MmsValue* inclusionField = NULL; @@ -3468,7 +3776,8 @@ sendNextReportEntrySegment(ReportControl* self) MmsValue* sqNum = ReportControl_getRCBValue(self, "SqNum"); - if (MmsValue_getBitStringBit(optFlds, 1)) { /* sequence number */ + if (MmsValue_getBitStringBit(optFlds, 1)) + { /* sequence number */ hasSeqNum = true; accessResultSize += MmsValue_encodeMmsData(sqNum, NULL, 0, false); } @@ -3479,13 +3788,13 @@ sendNextReportEntrySegment(ReportControl* self) if (MmsValue_getBitStringBit(optFlds, 2)) /* report time stamp */ { hasReportTimestamp = true; - _timeOfEntry.type = MMS_BINARY_TIME; - _timeOfEntry.value.binaryTime.size = 6; + _timeOfEntry.type = MMS_BINARY_TIME; + _timeOfEntry.value.binaryTime.size = 6; timeOfEntry = &_timeOfEntry; - MmsValue_setBinaryTime(timeOfEntry, report->timeOfEntry); + MmsValue_setBinaryTime(timeOfEntry, report->timeOfEntry); - accessResultSize += MmsValue_encodeMmsData(timeOfEntry, NULL, 0, false); + accessResultSize += MmsValue_encodeMmsData(timeOfEntry, NULL, 0, false); } MmsValue* datSet = ReportControl_getRCBValue(self, "DatSet"); @@ -3551,14 +3860,14 @@ sendNextReportEntrySegment(ReportControl* self) bool withDataReference = MmsValue_getBitStringBit(optFlds, 5); bool withReasonCode = MmsValue_getBitStringBit(optFlds, 3); - LogicalDevice* ld = (LogicalDevice*) self->parentLN->parent; + LogicalDevice* ld = (LogicalDevice*)self->parentLN->parent; - IedModel* iedModel = (IedModel*) ld->parent; + IedModel* iedModel = (IedModel*)ld->parent; int maxIndex = 0; char* iedName = iedModel->name; - int iedNameLength = (int) strlen(iedName); + int iedNameLength = (int)strlen(iedName); int i; @@ -3587,19 +3896,22 @@ sendNextReportEntrySegment(ReportControl* self) int j; - for (j = 0; j < iedNameLength; j++) { + for (j = 0; j < iedNameLength; j++) + { dataReference[currentPos++] = iedName[j]; } - int ldNameLength = (int) strlen(dataSetEntry->logicalDeviceName); - for (j = 0; j < ldNameLength; j++) { + int ldNameLength = (int)strlen(dataSetEntry->logicalDeviceName); + for (j = 0; j < ldNameLength; j++) + { dataReference[currentPos] = dataSetEntry->logicalDeviceName[j]; currentPos++; } dataReference[currentPos++] = '/'; - for (j = 0; j < (int) strlen(dataSetEntry->variableName); j++) { + for (j = 0; j < (int)strlen(dataSetEntry->variableName); j++) + { dataReference[currentPos++] = dataSetEntry->variableName[j]; } @@ -3627,13 +3939,14 @@ sendNextReportEntrySegment(ReportControl* self) return false; } - int dataElementSize = 1 + lenSize + length; + int dataElementSize = 1 + lenSize + length; elementSize += dataElementSize; currentReportBufferPos += dataElementSize; } - if (withReasonCode) { + if (withReasonCode) + { elementSize += 4; /* reason code size is always 4 byte */ } @@ -3671,7 +3984,7 @@ sendNextReportEntrySegment(ReportControl* self) return false; } - int dataElementSize = 1 + lenSize + length; + int dataElementSize = 1 + lenSize + length; currentReportBufferPos += dataElementSize; } @@ -3686,20 +3999,23 @@ sendNextReportEntrySegment(ReportControl* self) if (segmented) { - int segmentedSize = MmsValue_encodeMmsData(&_moreFollows, NULL, 0, false) + MmsValue_encodeMmsData(subSeqNum, NULL, 0, false); + int segmentedSize = + MmsValue_encodeMmsData(&_moreFollows, NULL, 0, false) + MmsValue_encodeMmsData(subSeqNum, NULL, 0, false); accessResultSize += segmentedSize; } uint32_t variableAccessSpecSize = 7; /* T L "RPT" */ uint32_t listOfAccessResultSize = accessResultSize + BerEncoder_determineLengthSize(accessResultSize) + 1; uint32_t informationReportContentSize = variableAccessSpecSize + listOfAccessResultSize; - uint32_t informationReportSize = 1 + informationReportContentSize + BerEncoder_determineLengthSize(informationReportContentSize); + uint32_t informationReportSize = + 1 + informationReportContentSize + BerEncoder_determineLengthSize(informationReportContentSize); uint32_t completeMessageSize = 1 + informationReportSize + BerEncoder_determineLengthSize(informationReportSize); - if (((int) completeMessageSize > maxMmsPduSize) || (numberOfAddedElements == 0)) + if (((int)completeMessageSize > maxMmsPduSize) || (numberOfAddedElements == 0)) { if (DEBUG_IED_SERVER) - printf("IED_SERVER: MMS PDU size too small to encode report data (max PDU size = %i) -> skip message!\n", maxMmsPduSize); + printf("IED_SERVER: MMS PDU size too small to encode report data (max PDU size = %i) -> skip message!\n", + maxMmsPduSize); self->startIndexForNextSegment = 0; segmented = false; @@ -3752,7 +4068,8 @@ sendNextReportEntrySegment(ReportControl* self) if (hasConfRev) bufPos = MmsValue_encodeMmsData(confRev, buffer, bufPos, true); - if (segmented) { + if (segmented) + { bufPos = MmsValue_encodeMmsData(subSeqNum, buffer, bufPos, true); bufPos = MmsValue_encodeMmsData(&_moreFollows, buffer, bufPos, true); } @@ -3769,7 +4086,7 @@ sendNextReportEntrySegment(ReportControl* self) bool addReferenceForEntry = false; if (report->flags > 0) - addReferenceForEntry = true; + addReferenceForEntry = true; else if (MmsValue_getBitStringBit(self->inclusionField, i)) addReferenceForEntry = true; @@ -3780,12 +4097,13 @@ sendNextReportEntrySegment(ReportControl* self) int j; - for (j = 0; j < iedNameLength; j++) { + for (j = 0; j < iedNameLength; j++) + { dataReference[currentPos++] = iedName[j]; } - int ldNameLength = (int) strlen(dataSetEntry->logicalDeviceName); - for (j = 0; j < ldNameLength; j++) + int ldNameLength = (int)strlen(dataSetEntry->logicalDeviceName); + for (j = 0; j < ldNameLength; j++) { dataReference[currentPos] = dataSetEntry->logicalDeviceName[j]; currentPos++; @@ -3793,7 +4111,8 @@ sendNextReportEntrySegment(ReportControl* self) dataReference[currentPos++] = '/'; - for (j = 0; j < (int) strlen(dataSetEntry->variableName); j++) { + for (j = 0; j < (int)strlen(dataSetEntry->variableName); j++) + { dataReference[currentPos++] = dataSetEntry->variableName[j]; } @@ -3815,13 +4134,15 @@ sendNextReportEntrySegment(ReportControl* self) currentReportBufferPos = valuesInReportBuffer; /* encode data set value elements */ - for (i = 0; i < maxIndex; i++) { + for (i = 0; i < maxIndex; i++) + { bool isInBuffer = false; if (report->flags > 0) isInBuffer = true; - else { + else + { if (MmsValue_getBitStringBit(inclusionField, i)) isInBuffer = true; } @@ -3832,16 +4153,18 @@ sendNextReportEntrySegment(ReportControl* self) int lenSize = BerDecoder_decodeLength(currentReportBufferPos + 1, &length, 0, report->entryLength); - if (lenSize < 0) { + if (lenSize < 0) + { if (DEBUG_IED_SERVER) printf("IED_SERVER: internal error in report buffer\n"); return SENT_REPORT_ENTRY_FAILED; } - int dataElementSize = 1 + lenSize + length; + int dataElementSize = 1 + lenSize + length; - if (i >= startElementIndex) { + if (i >= startElementIndex) + { /* copy value from report entry to message buffer */ memcpy(buffer + bufPos, currentReportBufferPos, dataElementSize); bufPos += dataElementSize; @@ -3852,7 +4175,8 @@ sendNextReportEntrySegment(ReportControl* self) } /* add reason code to report if requested */ - if (withReasonCode) { + if (withReasonCode) + { /* move to start position in report buffer */ currentReportBufferPos = valuesInReportBuffer + dataLen; @@ -3864,11 +4188,13 @@ sendNextReportEntrySegment(ReportControl* self) _reason.value.bitString.size = 6; _reason.value.bitString.buf = bsBuf; - for (i = 0; i < maxIndex; i++) { + for (i = 0; i < maxIndex; i++) + { bool isIncluded = false; - if (report->flags > 0) { + if (report->flags > 0) + { bsBuf[0] = 0; /* clear all bits */ if (report->flags & 0x02) /* GI */ @@ -3879,7 +4205,8 @@ sendNextReportEntrySegment(ReportControl* self) isIncluded = true; } - else if (MmsValue_getBitStringBit(self->inclusionField, i)) { + else if (MmsValue_getBitStringBit(self->inclusionField, i)) + { bsBuf[0] = 0; /* clear all bits */ uint8_t reasonForInclusion = *currentReportBufferPos; @@ -3896,10 +4223,11 @@ sendNextReportEntrySegment(ReportControl* self) isIncluded = true; } - if (isIncluded) { + if (isIncluded) + { if (i >= startElementIndex) - bufPos = MmsValue_encodeMmsData(&_reason, buffer, bufPos, true); + bufPos = MmsValue_encodeMmsData(&_reason, buffer, bufPos, true); currentReportBufferPos++; } @@ -3914,17 +4242,20 @@ sendNextReportEntrySegment(ReportControl* self) IsoConnection_unlock(self->clientConnection->isoConnection); - if (sentSuccess == false) { + if (sentSuccess == false) + { moreFollows = false; goto exit_function; } - if (moreFollows == false) { + if (moreFollows == false) + { /* reset sub sequence number */ segmented = false; self->startIndexForNextSegment = 0; } - else { + else + { /* increase sub sequence number */ uint32_t subSeqNumVal = MmsValue_toUint32(subSeqNum); subSeqNumVal++; @@ -3935,21 +4266,23 @@ sendNextReportEntrySegment(ReportControl* self) exit_remove_report: - if (segmented == false) { + if (segmented == false) + { assert(self->reportBuffer->nextToTransmit != self->reportBuffer->nextToTransmit->next); self->reportBuffer->nextToTransmit = self->reportBuffer->nextToTransmit->next; - #if (DEBUG_IED_SERVER == 1) +#if (DEBUG_IED_SERVER == 1) printf("IED_SERVER: reporting.c nextToTransmit: %p\n", self->reportBuffer->nextToTransmit); printEnqueuedReports(self); - #endif +#endif /* Increase sequence number */ self->sqNum++; - if (isBuffered == false) { + if (isBuffered == false) + { /* Unbuffered reporting --> sqNum is 8 bit only!!! */ if (self->sqNum == 256) self->sqNum = 0; @@ -3987,17 +4320,20 @@ sendNextReportEntry(ReportControl* self) int messageCount = 0; - while (self->reportBuffer->nextToTransmit) { + while (self->reportBuffer->nextToTransmit) + { messageCount++; bool sendNextEntrySegment = true; int sendResult = SENT_REPORT_ENTRY_FAILED; - while (sendNextEntrySegment) { + while (sendNextEntrySegment) + { sendResult = sendNextReportEntrySegment(self); - if (sendResult != SENT_REPORT_ENTRY_FAILED) { + if (sendResult != SENT_REPORT_ENTRY_FAILED) + { messageCount++; } @@ -4005,7 +4341,8 @@ sendNextReportEntry(ReportControl* self) sendNextEntrySegment = false; } - if (sendResult == SENT_REPORT_ENTRY_FAILED) { + if (sendResult == SENT_REPORT_ENTRY_FAILED) + { break; } @@ -4023,10 +4360,12 @@ Reporting_activateBufferedReports(MmsMapping* self) { LinkedList element = self->reportControls; - while ((element = LinkedList_getNext(element)) != NULL ) { - ReportControl* rc = (ReportControl*) element->data; + while ((element = LinkedList_getNext(element)) != NULL) + { + ReportControl* rc = (ReportControl*)element->data; - if (rc->buffered) { + if (rc->buffered) + { #if (CONFIG_MMS_THREADLESS_STACK != 1) Semaphore_wait(rc->rcbValuesLock); #endif @@ -4053,7 +4392,8 @@ processEventsForReport(ReportControl* rc, uint64_t currentTimeInMs) if (rc->gi) { /* send current events in event buffer before GI report */ - if (rc->triggered) { + if (rc->triggered) + { rc->triggered = false; enqueueReport(rc, false, false, currentTimeInMs); } @@ -4073,25 +4413,31 @@ processEventsForReport(ReportControl* rc, uint64_t currentTimeInMs) if (currentTimeInMs >= rc->nextIntgReportTime) { /* send current events in event buffer before integrity report */ - if (rc->triggered) { + if (rc->triggered) + { enqueueReport(rc, false, false, currentTimeInMs); rc->triggered = false; } - if (rc->server->syncIntegrityReportTimes) { + if (rc->server->syncIntegrityReportTimes) + { rc->nextIntgReportTime = getNextRoundedStartTime(currentTimeInMs, rc->intgPd); } - else { + else + { rc->nextIntgReportTime = rc->nextIntgReportTime + rc->intgPd; } /* check for system time change effects */ - if ((rc->nextIntgReportTime < currentTimeInMs) || (rc->nextIntgReportTime > currentTimeInMs + rc->intgPd)) + if ((rc->nextIntgReportTime < currentTimeInMs) || + (rc->nextIntgReportTime > currentTimeInMs + rc->intgPd)) { - if (rc->server->syncIntegrityReportTimes) { + if (rc->server->syncIntegrityReportTimes) + { rc->nextIntgReportTime = getNextRoundedStartTime(currentTimeInMs, rc->intgPd); } - else { + else + { rc->nextIntgReportTime = currentTimeInMs + rc->intgPd; } } @@ -4103,12 +4449,15 @@ processEventsForReport(ReportControl* rc, uint64_t currentTimeInMs) else { /* check for system time change effects */ - if ((rc->nextIntgReportTime < currentTimeInMs) || (rc->nextIntgReportTime > currentTimeInMs + rc->intgPd)) + if ((rc->nextIntgReportTime < currentTimeInMs) || + (rc->nextIntgReportTime > currentTimeInMs + rc->intgPd)) { - if (rc->server->syncIntegrityReportTimes) { + if (rc->server->syncIntegrityReportTimes) + { rc->nextIntgReportTime = getNextRoundedStartTime(currentTimeInMs, rc->intgPd); } - else { + else + { rc->nextIntgReportTime = currentTimeInMs + rc->intgPd; } } @@ -4139,9 +4488,9 @@ Reporting_processReportEvents(MmsMapping* self, uint64_t currentTimeInMs) { LinkedList element = self->reportControls; - while ((element = LinkedList_getNext(element)) != NULL ) + while ((element = LinkedList_getNext(element)) != NULL) { - ReportControl* rc = (ReportControl*) element->data; + ReportControl* rc = (ReportControl*)element->data; ReportControl_lockNotify(rc); @@ -4166,13 +4515,14 @@ Reporting_sendReports(MmsMapping* self, MmsServerConnection connection) while (element) { - ReportControl* rc = (ReportControl*) LinkedList_getData(element); + ReportControl* rc = (ReportControl*)LinkedList_getData(element); if (rc->clientConnection == connection) { ReportControl_lockNotify(rc); - if (rc->enabled) { + if (rc->enabled) + { sendNextReportEntry(rc); } @@ -4216,20 +4566,20 @@ Reporting_processReportEventsAfterUnlock(MmsMapping* self) uint64_t currentTime = Hal_getTimeInMs(); - while ((element = LinkedList_getNext(element)) != NULL ) + while ((element = LinkedList_getNext(element)) != NULL) { - ReportControl* rc = (ReportControl*) element->data; + ReportControl* rc = (ReportControl*)element->data; ReportControl_lockNotify(rc); if ((rc->enabled) || (rc->isBuffering)) { - if (rc->triggered) { + if (rc->triggered) + { copyValuesToReportBuffer(rc); processEventsForReport(rc, currentTime); } - } ReportControl_unlockNotify(rc); @@ -4258,7 +4608,8 @@ ReportControl_valueUpdated(ReportControl* self, int dataSetEntryIndex, int flag, if (modelLocked) { /* set flag to update values when report is to be sent or data model unlocked */ - self->inclusionFlags[dataSetEntryIndex] = self->inclusionFlags[dataSetEntryIndex] | flag | REPORT_CONTROL_NOT_UPDATED; + self->inclusionFlags[dataSetEntryIndex] = + self->inclusionFlags[dataSetEntryIndex] | flag | REPORT_CONTROL_NOT_UPDATED; } else { @@ -4285,12 +4636,14 @@ ReportControl_valueUpdated(ReportControl* self, int dataSetEntryIndex, int flag, bool ReportControlBlock_getRptEna(ReportControlBlock* self) { - if (self->trgOps & 64) { + if (self->trgOps & 64) + { ReportControl* rc = (ReportControl*)(self->sibling); return rc->enabled; } - else { + else + { return false; } } @@ -4316,7 +4669,8 @@ ReportControlBlock_getRptID(ReportControlBlock* self) return rptIdStr; } - else { + else + { return strdup(self->rptId); } } @@ -4324,7 +4678,8 @@ ReportControlBlock_getRptID(ReportControlBlock* self) char* ReportControlBlock_getDataSet(ReportControlBlock* self) { - if (self->trgOps & 64) { + if (self->trgOps & 64) + { ReportControl* rc = (ReportControl*)(self->sibling); #if (CONFIG_MMS_THREADLESS_STACK != 1) @@ -4341,7 +4696,8 @@ ReportControlBlock_getDataSet(ReportControlBlock* self) return dataSetStr; } - else { + else + { return strdup(self->dataSetName); } } @@ -4349,7 +4705,8 @@ ReportControlBlock_getDataSet(ReportControlBlock* self) uint32_t ReportControlBlock_getConfRev(ReportControlBlock* self) { - if (self->trgOps & 64) { + if (self->trgOps & 64) + { ReportControl* rc = (ReportControl*)(self->sibling); #if (CONFIG_MMS_THREADLESS_STACK != 1) @@ -4366,7 +4723,8 @@ ReportControlBlock_getConfRev(ReportControlBlock* self) return confRev; } - else { + else + { return self->confRef; } } @@ -4374,7 +4732,8 @@ ReportControlBlock_getConfRev(ReportControlBlock* self) uint32_t ReportControlBlock_getOptFlds(ReportControlBlock* self) { - if (self->trgOps & 64) { + if (self->trgOps & 64) + { ReportControl* rc = (ReportControl*)(self->sibling); #if (CONFIG_MMS_THREADLESS_STACK != 1) @@ -4391,7 +4750,8 @@ ReportControlBlock_getOptFlds(ReportControlBlock* self) return optFlds; } - else { + else + { return self->options; } } @@ -4399,7 +4759,8 @@ ReportControlBlock_getOptFlds(ReportControlBlock* self) uint32_t ReportControlBlock_getBufTm(ReportControlBlock* self) { - if (self->trgOps & 64) { + if (self->trgOps & 64) + { ReportControl* rc = (ReportControl*)(self->sibling); #if (CONFIG_MMS_THREADLESS_STACK != 1) @@ -4416,7 +4777,8 @@ ReportControlBlock_getBufTm(ReportControlBlock* self) return bufTm; } - else { + else + { return self->bufferTime; } } @@ -4424,7 +4786,8 @@ ReportControlBlock_getBufTm(ReportControlBlock* self) uint16_t ReportControlBlock_getSqNum(ReportControlBlock* self) { - if (self->trgOps & 64) { + if (self->trgOps & 64) + { ReportControl* rc = (ReportControl*)(self->sibling); #if (CONFIG_MMS_THREADLESS_STACK != 1) @@ -4441,7 +4804,8 @@ ReportControlBlock_getSqNum(ReportControlBlock* self) return sqNum; } - else { + else + { return 0; } } @@ -4449,12 +4813,14 @@ ReportControlBlock_getSqNum(ReportControlBlock* self) uint32_t ReportControlBlock_getTrgOps(ReportControlBlock* self) { - if (self->trgOps & 64) { + if (self->trgOps & 64) + { ReportControl* rc = (ReportControl*)(self->sibling); return rc->triggerOps; } - else { + else + { return (int)(self->trgOps); } } @@ -4462,12 +4828,14 @@ ReportControlBlock_getTrgOps(ReportControlBlock* self) uint32_t ReportControlBlock_getIntgPd(ReportControlBlock* self) { - if (self->trgOps & 64) { + if (self->trgOps & 64) + { ReportControl* rc = (ReportControl*)(self->sibling); return rc->intgPd; } - else { + else + { return self->intPeriod; } } @@ -4475,7 +4843,8 @@ ReportControlBlock_getIntgPd(ReportControlBlock* self) bool ReportControlBlock_getGI(ReportControlBlock* self) { - if (self->trgOps & 64) { + if (self->trgOps & 64) + { ReportControl* rc = (ReportControl*)(self->sibling); #if (CONFIG_MMS_THREADLESS_STACK != 1) @@ -4492,7 +4861,8 @@ ReportControlBlock_getGI(ReportControlBlock* self) return gi; } - else { + else + { return false; } } @@ -4502,7 +4872,8 @@ ReportControlBlock_getPurgeBuf(ReportControlBlock* self) { bool purgeBuf = false; - if (self->trgOps & 64) { + if (self->trgOps & 64) + { ReportControl* rc = (ReportControl*)(self->sibling); #if (CONFIG_MMS_THREADLESS_STACK != 1) @@ -4511,7 +4882,8 @@ ReportControlBlock_getPurgeBuf(ReportControlBlock* self) MmsValue* purgeBufValue = ReportControl_getRCBValue(rc, "PurgeBuf"); - if (purgeBufValue) { + if (purgeBufValue) + { purgeBuf = MmsValue_getBoolean(purgeBufValue); } @@ -4528,7 +4900,8 @@ ReportControlBlock_getEntryId(ReportControlBlock* self) { MmsValue* entryId = NULL; - if (self->trgOps & 64) { + if (self->trgOps & 64) + { ReportControl* rc = (ReportControl*)(self->sibling); #if (CONFIG_MMS_THREADLESS_STACK != 1) @@ -4552,7 +4925,8 @@ ReportControlBlock_getTimeofEntry(ReportControlBlock* self) { uint64_t timeofEntry = 0; - if (self->trgOps & 64) { + if (self->trgOps & 64) + { ReportControl* rc = (ReportControl*)(self->sibling); #if (CONFIG_MMS_THREADLESS_STACK != 1) @@ -4561,7 +4935,8 @@ ReportControlBlock_getTimeofEntry(ReportControlBlock* self) MmsValue* timeofEntryValue = ReportControl_getRCBValue(rc, "TimeofEntry"); - if (timeofEntryValue) { + if (timeofEntryValue) + { timeofEntry = MmsValue_getBinaryTimeAsUtcMs(timeofEntryValue); } @@ -4578,7 +4953,8 @@ ReportControlBlock_getResvTms(ReportControlBlock* self) { int16_t resvTms = 0; - if (self->trgOps & 64) { + if (self->trgOps & 64) + { ReportControl* rc = (ReportControl*)(self->sibling); #if (CONFIG_MMS_THREADLESS_STACK != 1) @@ -4587,7 +4963,8 @@ ReportControlBlock_getResvTms(ReportControlBlock* self) MmsValue* resvTmsValue = ReportControl_getRCBValue(rc, "ResvTms"); - if (resvTmsValue) { + if (resvTmsValue) + { resvTms = (int16_t)MmsValue_toInt32(resvTmsValue); } @@ -4604,7 +4981,8 @@ ReportControlBlock_getResv(ReportControlBlock* self) { bool resv = false; - if (self->trgOps & 64) { + if (self->trgOps & 64) + { ReportControl* rc = (ReportControl*)(self->sibling); #if (CONFIG_MMS_THREADLESS_STACK != 1) @@ -4613,7 +4991,8 @@ ReportControlBlock_getResv(ReportControlBlock* self) MmsValue* resvValue = ReportControl_getRCBValue(rc, "Resv"); - if (resvValue) { + if (resvValue) + { resv = MmsValue_getBoolean(resvValue); } @@ -4628,10 +5007,12 @@ ReportControlBlock_getResv(ReportControlBlock* self) MmsValue* ReportControlBlock_getOwner(ReportControlBlock* self) { - if (self->trgOps & 64) { + if (self->trgOps & 64) + { ReportControl* rc = (ReportControl*)(self->sibling); - if (rc->hasOwner) { + if (rc->hasOwner) + { #if (CONFIG_MMS_THREADLESS_STACK != 1) Semaphore_wait(rc->rcbValuesLock); @@ -4650,7 +5031,8 @@ ReportControlBlock_getOwner(ReportControlBlock* self) else return NULL; } - else { + else + { return NULL; } } diff --git a/src/iec61850/server/model/model.c b/src/iec61850/server/model/model.c index 577f3b4a..ae42d065 100644 --- a/src/iec61850/server/model/model.c +++ b/src/iec61850/server/model/model.c @@ -58,7 +58,6 @@ IedModel_setAttributeValuesToNull(IedModel* iedModel) while (ld != NULL) { - LogicalNode* ln = (LogicalNode*)ld->firstChild; while (ln != NULL)