Skip to content

Commit

Permalink
- IED server: fixed - write access to whole array doesn't work (LIB61…
Browse files Browse the repository at this point in the history
…850-436)(#499)
  • Loading branch information
mzillgith committed Mar 21, 2024
1 parent ea32783 commit 49c64eb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 34 deletions.
30 changes: 17 additions & 13 deletions src/mms/iso_mms/common/mms_type_spec.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* mms_type_spec.c
*
* Copyright 2013 Michael Zillgith
* Copyright 2013-2024 Michael Zillgith
*
* This file is part of libIEC61850.
*
Expand Down Expand Up @@ -108,36 +108,40 @@ MmsVariableSpecification_getType(MmsVariableSpecification* self)
bool
MmsVariableSpecification_isValueOfType(MmsVariableSpecification* self, const MmsValue* value)
{
if ((self->type) == (value->type)) {

if ((self->type == MMS_STRUCTURE) || (self->type == MMS_ARRAY)) {

if ((self->type) == (value->type))
{
if ((self->type == MMS_STRUCTURE) || (self->type == MMS_ARRAY))
{
int componentCount = self->typeSpec.structure.elementCount;

if (componentCount != (int) MmsValue_getArraySize(value))
return false;

if (self->type == MMS_STRUCTURE) {

if (self->type == MMS_STRUCTURE)
{
int i;
for (i = 0; i < componentCount; i++) {

for (i = 0; i < componentCount; i++)
{
if (MmsVariableSpecification_isValueOfType(self->typeSpec.structure.elements[i], MmsValue_getElement(value, i)) == false)
return false;
}

return true;
}
else {
else
{
int i;
for (i = 0; i < componentCount; i++) {

for (i = 0; i < componentCount; i++)
{
if (MmsVariableSpecification_isValueOfType(self->typeSpec.array.elementTypeSpec, MmsValue_getElement(value, i)) == false)
return false;
}

return true;
}
}
else if (self->type == MMS_BIT_STRING) {
else if (self->type == MMS_BIT_STRING)
{
if (self->typeSpec.bitString == value->value.bitString.size)
return true;

Expand Down
53 changes: 32 additions & 21 deletions src/mms/iso_mms/server/mms_write_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,12 +598,13 @@ mmsServer_handleWriteRequest(

MmsServer_lockModel(connection->server);

if (writeRequest->variableAccessSpecification.present == VariableAccessSpecification_PR_variableListName) {
if (writeRequest->variableAccessSpecification.present == VariableAccessSpecification_PR_variableListName)
{
handleWriteNamedVariableListRequest(connection, writeRequest, invokeId, response);
goto exit_function;
}
else if (writeRequest->variableAccessSpecification.present == VariableAccessSpecification_PR_listOfVariable) {

else if (writeRequest->variableAccessSpecification.present == VariableAccessSpecification_PR_listOfVariable)
{
int numberOfWriteItems = writeRequest->variableAccessSpecification.choice.listOfVariable.list.count;

if (numberOfWriteItems < 1) {
Expand All @@ -627,7 +628,8 @@ mmsServer_handleWriteRequest(

int i;

for (i = 0; i < numberOfWriteItems; i++) {
for (i = 0; i < numberOfWriteItems; i++)
{
ListOfVariableSeq_t* varSpec =
writeRequest->variableAccessSpecification.choice.listOfVariable.list.array[i];

Expand All @@ -644,7 +646,8 @@ mmsServer_handleWriteRequest(

char nameIdStr[65];

if (varSpec->variableSpecification.choice.name.present == ObjectName_PR_domainspecific) {
if (varSpec->variableSpecification.choice.name.present == ObjectName_PR_domainspecific)
{
Identifier_t domainId = varSpec->variableSpecification.choice.name.choice.domainspecific.domainId;

char domainIdStr[65];
Expand Down Expand Up @@ -687,8 +690,8 @@ mmsServer_handleWriteRequest(

AlternateAccess_t* alternateAccess = varSpec->alternateAccess;

if (alternateAccess != NULL) {

if (alternateAccess != NULL)
{
if ((variable->type == MMS_STRUCTURE) && (mmsServer_isComponentAccess(alternateAccess) == false)) {
accessResults[i] = DATA_ACCESS_ERROR_OBJECT_ATTRIBUTE_INCONSISTENT;
continue;
Expand All @@ -714,12 +717,13 @@ mmsServer_handleWriteRequest(
continue;
}

if (alternateAccess != NULL) {

if (alternateAccess != NULL)
{
if (domain == NULL)
domain = (MmsDomain*) device;

if (mmsServer_isIndexAccess(alternateAccess)) {
if (mmsServer_isIndexAccess(alternateAccess))
{
MmsValue* cachedArray = MmsServer_getValueFromCache(connection->server, domain, nameIdStr);

if (cachedArray == NULL) {
Expand All @@ -730,16 +734,17 @@ mmsServer_handleWriteRequest(
int index = mmsServer_getLowIndex(alternateAccess);
int numberOfElements = mmsServer_getNumberOfElements(alternateAccess);

if (numberOfElements == 0) { /* select single array element with index */

if (numberOfElements == 0) /* select single array element with index */
{
MmsValue* elementValue = MmsValue_getElement(cachedArray, index);

if (elementValue == NULL) {
accessResults[i] = DATA_ACCESS_ERROR_OBJECT_ATTRIBUTE_INCONSISTENT;
goto end_of_main_loop;
}

if (mmsServer_isAccessToArrayComponent(alternateAccess)) {
if (mmsServer_isAccessToArrayComponent(alternateAccess))
{
MmsVariableSpecification* namedVariable = MmsDomain_getNamedVariable(domain, nameIdStr);

if (namedVariable) {
Expand All @@ -757,16 +762,18 @@ mmsServer_handleWriteRequest(
goto end_of_main_loop;
}
}
else { /* select sub-array with start-index and number-of-elements */

if (MmsValue_getType(value) != MMS_ARRAY) {
else /* select sub-array with start-index and number-of-elements */
{
if (MmsValue_getType(value) != MMS_ARRAY)
{
accessResults[i] = DATA_ACCESS_ERROR_TYPE_INCONSISTENT;
goto end_of_main_loop;
}

int elementNo;

for (elementNo = 0; elementNo < numberOfElements; elementNo++) {
for (elementNo = 0; elementNo < numberOfElements; elementNo++)
{
MmsValue* newElement = MmsValue_getElement(value, elementNo);
MmsValue* elementValue = MmsValue_getElement(cachedArray, index++);

Expand All @@ -785,22 +792,26 @@ mmsServer_handleWriteRequest(
accessResults[i] = DATA_ACCESS_ERROR_SUCCESS;
goto end_of_main_loop;
}
else if (mmsServer_isComponentAccess(alternateAccess)) {
else if (mmsServer_isComponentAccess(alternateAccess))
{
variable = getComponent(connection, domain, alternateAccess, variable, nameIdStr);

if (variable == NULL) {
if (variable == NULL)
{
accessResults[i] = DATA_ACCESS_ERROR_OBJECT_NONE_EXISTENT;
goto end_of_main_loop;
}
}
else {
else
{
accessResults[i] = DATA_ACCESS_ERROR_SUCCESS;
goto end_of_main_loop;
}
}

/* Check for correct type */
if (MmsVariableSpecification_isValueOfType(variable, value) == false) {
if (MmsVariableSpecification_isValueOfType(variable, value) == false)
{
accessResults[i] = DATA_ACCESS_ERROR_TYPE_INCONSISTENT;
goto end_of_main_loop;
}
Expand Down

0 comments on commit 49c64eb

Please sign in to comment.