From 48b02ec1b0f64632d5989988918a24788df87117 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Tue, 14 Apr 2015 16:53:09 +0200 Subject: [PATCH] - extended server_example3.c to show Timestamp handling - fixed server crash bug when whole LN is requested in a read request (bug #309) --- examples/server_example3/server_example3.c | 20 +++++++++++++++---- src/iec61850/server/mms_mapping/mms_mapping.c | 7 +++++-- src/mms/iso_cotp/cotp.c | 8 +++++++- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/examples/server_example3/server_example3.c b/examples/server_example3/server_example3.c index 2dfa2fc..b5f6e0b 100644 --- a/examples/server_example3/server_example3.c +++ b/examples/server_example3/server_example3.c @@ -129,14 +129,26 @@ main(int argc, char** argv) IedServer_lockDataModel(iedServer); + Timestamp iecTimestamp; + + Timestamp_clearFlags(&iecTimestamp); + Timestamp_setTimeInMilliseconds(&iecTimestamp, timestamp); + + /* toggle clock-not-synchronized flag in timestamp */ + if (((int) t % 2) == 0) + Timestamp_setClockNotSynchronized(&iecTimestamp, true); + IedServer_updateFloatAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_AnIn1_mag_f, an1); - IedServer_updateUTCTimeAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_AnIn1_t, timestamp); + IedServer_updateTimestampAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_AnIn1_t, &iecTimestamp); + IedServer_updateFloatAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_AnIn2_mag_f, an2); - IedServer_updateUTCTimeAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_AnIn2_t, timestamp); + IedServer_updateTimestampAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_AnIn2_t, &iecTimestamp); + IedServer_updateFloatAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_AnIn3_mag_f, an3); - IedServer_updateUTCTimeAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_AnIn3_t, timestamp); + IedServer_updateTimestampAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_AnIn3_t, &iecTimestamp); + IedServer_updateFloatAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_AnIn4_mag_f, an4); - IedServer_updateUTCTimeAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_AnIn4_t, timestamp); + IedServer_updateTimestampAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_AnIn4_t, &iecTimestamp); IedServer_unlockDataModel(iedServer); diff --git a/src/iec61850/server/mms_mapping/mms_mapping.c b/src/iec61850/server/mms_mapping/mms_mapping.c index feeca50..ac4bee6 100644 --- a/src/iec61850/server/mms_mapping/mms_mapping.c +++ b/src/iec61850/server/mms_mapping/mms_mapping.c @@ -2156,10 +2156,13 @@ mmsReadAccessHandler (void* parameter, MmsDomain* domain, char* variableId, MmsS if (DEBUG_IED_SERVER) printf("IED_SERVER: mmsReadAccessHandler: Requested %s\n", variableId); -#if (CONFIG_IEC61850_SETTING_GROUPS == 1) - char* separator = strchr(variableId, '$'); + if (separator == NULL) + return DATA_ACCESS_ERROR_SUCCESS; + +#if (CONFIG_IEC61850_SETTING_GROUPS == 1) + if (isFunctionalConstraintSE(separator)) { SettingGroup* sg = getSettingGroupByMmsDomain(self, domain); diff --git a/src/mms/iso_cotp/cotp.c b/src/mms/iso_cotp/cotp.c index 10c24c4..4d53f77 100644 --- a/src/mms/iso_cotp/cotp.c +++ b/src/mms/iso_cotp/cotp.c @@ -577,7 +577,13 @@ parseCotpMessage(CotpConnection* self) uint8_t tpduType; len = buffer[0]; - assert(len <= tpduLength); + + if (len > tpduLength) { + if (DEBUG_COTP) + printf("COTP: parseCotpMessage: len=%d tpduLength=%d\n", len, tpduLength); + + return COTP_ERROR; + } tpduType = buffer[1];