diff --git a/src/mms/inc/iso_connection_parameters.h b/src/mms/inc/iso_connection_parameters.h index dcdbaaa9..9e95c238 100644 --- a/src/mms/inc/iso_connection_parameters.h +++ b/src/mms/inc/iso_connection_parameters.h @@ -1,7 +1,7 @@ /* * iso_connection_parameters.h * - * Copyright 2013, 2014 Michael Zillgith + * Copyright 2013-2018 Michael Zillgith * * This file is part of libIEC61850. * @@ -37,7 +37,7 @@ extern "C" { /** - * \brief authentication mechanism úsed by AcseAuthenticator + * \brief authentication mechanism used by AcseAuthenticator */ typedef enum { @@ -154,7 +154,7 @@ typedef struct sIsoConnectionParameters* IsoConnectionParameters; * NOTE: This function used internally by the MMS client library. When using the MMS or IEC 61850 API * there should be no reason for the user to call this function. * - * \return new IsoConnectionParameters + * \return new IsoConnectionParameters instance */ LIB61850_API IsoConnectionParameters IsoConnectionParameters_create(void); diff --git a/src/mms/inc/mms_client_connection.h b/src/mms/inc/mms_client_connection.h index dd1ee1ca..4a27e521 100644 --- a/src/mms/inc/mms_client_connection.h +++ b/src/mms/inc/mms_client_connection.h @@ -3,22 +3,22 @@ * * Copyright 2013-2018 Michael Zillgith * - * This file is part of libIEC61850. + * This file is part of libIEC61850. * - * libIEC61850 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * libIEC61850 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * libIEC61850 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * libIEC61850 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with libIEC61850. If not, see . + * You should have received a copy of the GNU General Public License + * along with libIEC61850. If not, see . * - * See COPYING file for the complete license text. + * See COPYING file for the complete license text. */ #ifndef MMS_CLIENT_CONNECTION_H_ diff --git a/src/mms/inc/mms_value.h b/src/mms/inc/mms_value.h index 66f12917..cf6a4e2e 100644 --- a/src/mms/inc/mms_value.h +++ b/src/mms/inc/mms_value.h @@ -3,22 +3,22 @@ * * Copyright 2013-2018 Michael Zillgith * - * This file is part of libIEC61850. + * This file is part of libIEC61850. * - * libIEC61850 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * libIEC61850 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * libIEC61850 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * libIEC61850 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with libIEC61850. If not, see . + * You should have received a copy of the GNU General Public License + * along with libIEC61850. If not, see . * - * See COPYING file for the complete license text. + * See COPYING file for the complete license text. */ #ifndef MMS_VALUE_H_ diff --git a/src/mms/inc_private/acse.h b/src/mms/inc_private/acse.h index 82ee151e..76316e86 100644 --- a/src/mms/inc_private/acse.h +++ b/src/mms/inc_private/acse.h @@ -1,7 +1,7 @@ /* * acse.h * - * Copyright 2013 Michael Zillgith + * Copyright 2013-2018 Michael Zillgith * * This file is part of libIEC61850. * diff --git a/src/mms/inc_private/cotp.h b/src/mms/inc_private/cotp.h index f15e2e45..62ed9a30 100644 --- a/src/mms/inc_private/cotp.h +++ b/src/mms/inc_private/cotp.h @@ -1,7 +1,7 @@ /* * cotp.h * - * Copyright 2013, 2014 Michael Zillgith + * Copyright 2013-2018 Michael Zillgith * * This file is part of libIEC61850. * diff --git a/src/mms/inc_private/iso_presentation.h b/src/mms/inc_private/iso_presentation.h index 8f46f5b8..df45185f 100644 --- a/src/mms/inc_private/iso_presentation.h +++ b/src/mms/inc_private/iso_presentation.h @@ -3,22 +3,22 @@ * * Copyright 2013 Michael Zillgith * - * This file is part of libIEC61850. + * This file is part of libIEC61850. * - * libIEC61850 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * libIEC61850 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * libIEC61850 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * libIEC61850 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with libIEC61850. If not, see . + * You should have received a copy of the GNU General Public License + * along with libIEC61850. If not, see . * - * See COPYING file for the complete license text. + * See COPYING file for the complete license text. */ #ifndef ISO_PRESENTATION_H_ diff --git a/src/mms/inc_private/iso_session.h b/src/mms/inc_private/iso_session.h index 93a0e01c..5d205136 100644 --- a/src/mms/inc_private/iso_session.h +++ b/src/mms/inc_private/iso_session.h @@ -1,24 +1,24 @@ /* * ise_session.h * - * Copyright 2013 Michael Zillgith + * Copyright 2013-2018 Michael Zillgith * - * This file is part of libIEC61850. + * This file is part of libIEC61850. * - * libIEC61850 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * libIEC61850 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * libIEC61850 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * libIEC61850 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with libIEC61850. If not, see . + * You should have received a copy of the GNU General Public License + * along with libIEC61850. If not, see . * - * See COPYING file for the complete license text. + * See COPYING file for the complete license text. */ #ifndef ISE_SESSION_H_ diff --git a/src/mms/inc_private/mms_client_internal.h b/src/mms/inc_private/mms_client_internal.h index 008ed5d0..077b4e63 100644 --- a/src/mms/inc_private/mms_client_internal.h +++ b/src/mms/inc_private/mms_client_internal.h @@ -3,22 +3,22 @@ * * Copyright 2013-2018 Michael Zillgith * - * This file is part of libIEC61850. + * This file is part of libIEC61850. * - * libIEC61850 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * libIEC61850 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * libIEC61850 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * libIEC61850 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with libIEC61850. If not, see . + * You should have received a copy of the GNU General Public License + * along with libIEC61850. If not, see . * - * See COPYING file for the complete license text. + * See COPYING file for the complete license text. */ #ifndef MMS_MSG_INTERNAL_H_ @@ -42,16 +42,6 @@ #define DEBUG_MMS_CLIENT 0 #endif -#if 0 -typedef enum { - MMS_CON_IDLE, - MMS_CON_WAITING, - MMS_CON_ASSOCIATION_FAILED, - MMS_CON_ASSOCIATED, - MMS_CON_RESPONSE_PENDING -} ConnectionState; -#endif - #define CONCLUDE_STATE_CONNECTION_ACTIVE 0 #define CONCLUDE_STATE_REQUESTED 1 #define CONCLUDE_STATE_REJECTED 2 @@ -98,42 +88,42 @@ struct sMmsConnection { Semaphore lastInvokeIdLock; uint32_t lastInvokeId; - Semaphore outstandingCallsLock; - MmsOutstandingCall outstandingCalls; + Semaphore outstandingCallsLock; + MmsOutstandingCall outstandingCalls; - uint32_t requestTimeout; - uint32_t connectTimeout; + uint32_t requestTimeout; + uint32_t connectTimeout; - IsoClientConnection isoClient; + IsoClientConnection isoClient; #if (CONFIG_MMS_THREADLESS_STACK == 0) - Thread connectionHandlingThread; - bool createThread; - bool connectionThreadRunning; + Thread connectionHandlingThread; + bool createThread; + bool connectionThreadRunning; #endif - volatile MmsConnectionState connectionState; - Semaphore associationStateLock; + volatile MmsConnectionState connectionState; + Semaphore associationStateLock; - MmsConnectionParameters parameters; - IsoConnectionParameters isoParameters; + MmsConnectionParameters parameters; + IsoConnectionParameters isoParameters; - MmsConnectionStateChangedHandler stateChangedHandler; - void* stateChangedHandlerParameter; + MmsConnectionStateChangedHandler stateChangedHandler; + void* stateChangedHandlerParameter; - MmsInformationReportHandler reportHandler; - void* reportHandlerParameter; + MmsInformationReportHandler reportHandler; + void* reportHandlerParameter; - MmsConnectionLostHandler connectionLostHandler; - void* connectionLostHandlerParameter; + MmsConnectionLostHandler connectionLostHandler; + void* connectionLostHandlerParameter; - MmsConnection_ConcludeAbortHandler concludeHandler; - void* concludeHandlerParameter; - uint64_t concludeTimeout; + MmsConnection_ConcludeAbortHandler concludeHandler; + void* concludeHandlerParameter; + uint64_t concludeTimeout; #if (CONFIG_MMS_RAW_MESSAGE_LOGGING == 1) - void* rawMmsMessageHandler; - void* rawMmsMessageHandlerParameter; + void* rawMmsMessageHandler; + void* rawMmsMessageHandlerParameter; #endif #if (MMS_OBTAIN_FILE_SERVICE == 1) @@ -236,8 +226,7 @@ mmsClient_createGetNamedVariableListAttributesRequestAssociationSpecific(uint32_ ByteBuffer* writeBuffer, const char* listNameId); LIB61850_INTERNAL LinkedList -mmsClient_parseGetNamedVariableListAttributesResponse(ByteBuffer* message, uint32_t* invokeId, - bool* /*OUT*/ deletable); +mmsClient_parseGetNamedVariableListAttributesResponse(ByteBuffer* message, bool* /*OUT*/ deletable); LIB61850_INTERNAL int mmsClient_createGetVariableAccessAttributesRequest( diff --git a/src/mms/inc_private/mms_common_internal.h b/src/mms/inc_private/mms_common_internal.h index a9dfcc2e..59e0b76e 100644 --- a/src/mms/inc_private/mms_common_internal.h +++ b/src/mms/inc_private/mms_common_internal.h @@ -1,7 +1,7 @@ /* * mms_common_internal.h * - * Copyright 2013, 2014, 2015 Michael Zillgith + * Copyright 2013-2018 Michael Zillgith * * This file is part of libIEC61850. * @@ -77,6 +77,7 @@ LIB61850_INTERNAL FileHandle mmsMsg_openFile(const char* basepath, char* fileName, bool readWrite); #endif /* (MMS_FILE_SERVICE == 1) */ + typedef struct sMmsServiceError { int errorClass; diff --git a/src/mms/inc_private/mms_server_connection.h b/src/mms/inc_private/mms_server_connection.h index 02564e95..f78fc3fa 100644 --- a/src/mms/inc_private/mms_server_connection.h +++ b/src/mms/inc_private/mms_server_connection.h @@ -3,22 +3,22 @@ * * Copyright 2013-2018 Michael Zillgith * - * This file is part of libIEC61850. + * This file is part of libIEC61850. * - * libIEC61850 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * libIEC61850 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * libIEC61850 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * libIEC61850 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with libIEC61850. If not, see . + * You should have received a copy of the GNU General Public License + * along with libIEC61850. If not, see . * - * See COPYING file for the complete license text. + * See COPYING file for the complete license text. */ /** diff --git a/src/mms/inc_private/mms_server_internal.h b/src/mms/inc_private/mms_server_internal.h index 9ee08749..45ed7882 100644 --- a/src/mms/inc_private/mms_server_internal.h +++ b/src/mms/inc_private/mms_server_internal.h @@ -1,24 +1,24 @@ /* * mms_server_internal.h * - * Copyright 2013, 2014 Michael Zillgith + * Copyright 2013-2018 Michael Zillgith * - * This file is part of libIEC61850. + * This file is part of libIEC61850. * - * libIEC61850 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * libIEC61850 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * libIEC61850 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * libIEC61850 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with libIEC61850. If not, see . + * You should have received a copy of the GNU General Public License + * along with libIEC61850. If not, see . * - * See COPYING file for the complete license text. + * See COPYING file for the complete license text. */ #ifndef MMS_SERVER_INTERNAL_H_ diff --git a/src/mms/inc_private/mms_value_cache.h b/src/mms/inc_private/mms_value_cache.h index a309606c..8c89be4e 100644 --- a/src/mms/inc_private/mms_value_cache.h +++ b/src/mms/inc_private/mms_value_cache.h @@ -1,24 +1,24 @@ /* * mms_value_cache.h * - * Copyright 2013 Michael Zillgith + * Copyright 2013-2018 Michael Zillgith * - * This file is part of libIEC61850. + * This file is part of libIEC61850. * - * libIEC61850 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * libIEC61850 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * libIEC61850 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * libIEC61850 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with libIEC61850. If not, see . + * You should have received a copy of the GNU General Public License + * along with libIEC61850. If not, see . * - * See COPYING file for the complete license text. + * See COPYING file for the complete license text. */ #ifndef MMS_VARIABLE_CACHE_H_ diff --git a/src/mms/iso_mms/client/mms_client_connection.c b/src/mms/iso_mms/client/mms_client_connection.c index 942ca4cc..3bb10924 100644 --- a/src/mms/iso_mms/client/mms_client_connection.c +++ b/src/mms/iso_mms/client/mms_client_connection.c @@ -82,7 +82,7 @@ handleUnconfirmedMmsPdu(MmsConnection self, ByteBuffer* message) if (mmsPdu->choice.unconfirmedPDU.unconfirmedService.present == UnconfirmedService_PR_informationReport) - { + { char* domainId = NULL; InformationReport_t* report = @@ -90,12 +90,13 @@ handleUnconfirmedMmsPdu(MmsConnection self, ByteBuffer* message) if (report->variableAccessSpecification.present == VariableAccessSpecification_PR_variableListName) - { + { if (report->variableAccessSpecification.choice.variableListName.present == ObjectName_PR_vmdspecific) - { + { int nameSize = report->variableAccessSpecification.choice.variableListName.choice.vmdspecific.size; + uint8_t* buffer = report->variableAccessSpecification.choice.variableListName.choice.vmdspecific.buf; @@ -116,7 +117,7 @@ handleUnconfirmedMmsPdu(MmsConnection self, ByteBuffer* message) } else if (report->variableAccessSpecification.present == VariableAccessSpecification_PR_listOfVariable) - { + { int listSize = report->listOfAccessResult.list.count; int variableSpecSize = report->variableAccessSpecification.choice.listOfVariable.list.count; @@ -133,10 +134,10 @@ handleUnconfirmedMmsPdu(MmsConnection self, ByteBuffer* message) for (i = 0; i < variableSpecSize; i++) { if (report->variableAccessSpecification.choice.listOfVariable.list.array[i]->variableSpecification.present == VariableSpecification_PR_name) - { + { if (report->variableAccessSpecification.choice.listOfVariable.list.array[i] ->variableSpecification.choice.name.present == ObjectName_PR_vmdspecific) - { + { int nameSize = report->variableAccessSpecification.choice.listOfVariable.list.array[i] ->variableSpecification.choice.name.choice.vmdspecific.size; @@ -158,7 +159,7 @@ handleUnconfirmedMmsPdu(MmsConnection self, ByteBuffer* message) self->reportHandler(self->reportHandlerParameter, domainId, variableListName, value, false); - /* report handler should have deleted the MmsValue! */ + /* report handler is responsible to delete the MmsValue object */ if (variableSpecSize != 1) MmsValue_setElement(values, i, NULL); else @@ -169,24 +170,24 @@ handleUnconfirmedMmsPdu(MmsConnection self, ByteBuffer* message) ->variableSpecification.choice.name.present == ObjectName_PR_domainspecific) { int domainNameSize = - report->variableAccessSpecification.choice.listOfVariable.list.array[i] - ->variableSpecification.choice.name.choice.domainspecific.domainId.size; + report->variableAccessSpecification.choice.listOfVariable.list.array[i] + ->variableSpecification.choice.name.choice.domainspecific.domainId.size; int itemNameSize = - report->variableAccessSpecification.choice.listOfVariable.list.array[i] - ->variableSpecification.choice.name.choice.domainspecific.itemId.size; + report->variableAccessSpecification.choice.listOfVariable.list.array[i] + ->variableSpecification.choice.name.choice.domainspecific.itemId.size; - if (domainNameSize < 65 && itemNameSize < 65) { + if ((domainNameSize < 65) && (itemNameSize < 65)) { char domainNameStr[65]; char itemNameStr[65]; uint8_t* domainNameBuffer = - report->variableAccessSpecification.choice.listOfVariable.list.array[i] - ->variableSpecification.choice.name.choice.domainspecific.domainId.buf; + report->variableAccessSpecification.choice.listOfVariable.list.array[i] + ->variableSpecification.choice.name.choice.domainspecific.domainId.buf; uint8_t* itemNamebuffer = report->variableAccessSpecification.choice.listOfVariable.list.array[i] - ->variableSpecification.choice.name.choice.domainspecific.itemId.buf; + ->variableSpecification.choice.name.choice.domainspecific.itemId.buf; memcpy(domainNameStr, domainNameBuffer, domainNameSize); domainNameStr[domainNameSize] = 0; @@ -201,7 +202,7 @@ handleUnconfirmedMmsPdu(MmsConnection self, ByteBuffer* message) self->reportHandler(self->reportHandlerParameter, domainNameStr, itemNameStr, value, false); - /* report handler should have deleted the MmsValue! */ + /* report handler is responsible to delete the MmsValue object */ if (variableSpecSize != 1) MmsValue_setElement(values, i, NULL); else @@ -323,6 +324,10 @@ sendMessage(MmsConnection self, ByteBuffer* message) } #endif /* (CONFIG_MMS_RAW_MESSAGE_LOGGING == 1) */ +#if (CONFIG_MMS_COLLECT_STATISTICS == 1) + self->statAplMessagesSent++; +#endif + IsoClientConnection_sendMessage(self->isoClient, message); } @@ -549,6 +554,7 @@ mmsMsg_parseConfirmedErrorPDU(uint8_t* buffer, int bufPos, int maxBufPos, uint32 tag = buffer[bufPos++]; bufPos = BerDecoder_decodeLength(buffer, &length, bufPos, maxBufPos); + if (bufPos < 0) goto exit_error; @@ -575,7 +581,7 @@ mmsMsg_parseConfirmedErrorPDU(uint8_t* buffer, int bufPos, int maxBufPos, uint32 return bufPos; - exit_error: +exit_error: if (DEBUG_MMS_CLIENT) printf("MMS_CLIENT: error parsing confirmed error PDU\n"); @@ -608,6 +614,7 @@ mmsMsg_parseRejectPDU(uint8_t* buffer, int bufPos, int maxBufPos, uint32_t* invo tag = buffer[bufPos++]; bufPos = BerDecoder_decodeLength(buffer, &length, bufPos, maxBufPos); + if (bufPos < 0) goto exit_error; @@ -717,7 +724,7 @@ handleAsyncResponse(MmsConnection self, ByteBuffer* response, uint32_t bufPos, M if (response) { bool deletable = false; - LinkedList accessSpec = mmsClient_parseGetNamedVariableListAttributesResponse(response, NULL, &deletable); + LinkedList accessSpec = mmsClient_parseGetNamedVariableListAttributesResponse(response, &deletable); if (accessSpec == false) err = MMS_ERROR_PARSING_RESPONSE; @@ -1061,6 +1068,7 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload) } } else if (tag == 0xa2) { /* confirmed error PDU */ + if (DEBUG_MMS_CLIENT) printf("MMS_CLIENT: Confirmed error PDU!\n"); @@ -1098,6 +1106,7 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload) } } else if (tag == 0xa4) { /* reject PDU */ + if (DEBUG_MMS_CLIENT) printf("MMS_CLIENT: reject PDU!\n"); @@ -1714,11 +1723,15 @@ MmsConnection_abort(MmsConnection self, MmsError* mmsError) success = true; break; } + else { + Thread_sleep(10); + } } } if (success == false) { + IsoClientConnection_close(self->isoClient); *mmsError = MMS_ERROR_SERVICE_TIMEOUT; } @@ -1744,7 +1757,6 @@ concludeHandler(void* parameter, MmsError mmsError, bool success) Semaphore_post(parameters->sem); } - void MmsConnection_conclude(MmsConnection self, MmsError* mmsError) { @@ -2282,7 +2294,6 @@ exit_function: return invokeId; } - MmsValue* MmsConnection_readNamedVariableListValues(MmsConnection self, MmsError* mmsError, const char* domainId, const char* listName, @@ -2346,14 +2357,12 @@ exit_function: return invokeId; } - MmsValue* MmsConnection_readNamedVariableListValuesAssociationSpecific( MmsConnection self, MmsError* mmsError, const char* listName, bool specWithResult) { - MmsValue* value = NULL; MmsError err = MMS_ERROR_NONE; @@ -2638,7 +2647,6 @@ exit_function: return invokeId; } - void MmsConnection_defineNamedVariableListAssociationSpecific(MmsConnection self, MmsError* mmsError, const char* listName, LinkedList variableSpecs) @@ -2694,7 +2702,6 @@ exit_function: return invokeId; } - bool MmsConnection_deleteNamedVariableList(MmsConnection self, MmsError* mmsError, const char* domainId, const char* listName) @@ -4279,14 +4286,13 @@ void MmsVariableAccessSpecification_destroy(MmsVariableAccessSpecification* self) { if (self->domainId != NULL) - GLOBAL_FREEMEM((void* ) self->domainId); + GLOBAL_FREEMEM((void*) self->domainId); if (self->itemId != NULL) - GLOBAL_FREEMEM((void* ) self->itemId); + GLOBAL_FREEMEM((void*) self->itemId); if (self->componentName != NULL) - GLOBAL_FREEMEM((void* ) self->componentName); + GLOBAL_FREEMEM((void*) self->componentName); GLOBAL_FREEMEM(self); } - diff --git a/src/mms/iso_mms/client/mms_client_files.c b/src/mms/iso_mms/client/mms_client_files.c index 55029570..776f058a 100644 --- a/src/mms/iso_mms/client/mms_client_files.c +++ b/src/mms/iso_mms/client/mms_client_files.c @@ -527,6 +527,7 @@ parseListOfDirectoryEntries(uint8_t* buffer, int bufPos, int maxBufPos, uint32_t int length; bufPos = BerDecoder_decodeLength(buffer, &length, bufPos, maxBufPos); + if (bufPos < 0) return false; int endPos = bufPos + length; diff --git a/src/mms/iso_mms/client/mms_client_get_namelist.c b/src/mms/iso_mms/client/mms_client_get_namelist.c index 1653be2e..23de82b0 100644 --- a/src/mms/iso_mms/client/mms_client_get_namelist.c +++ b/src/mms/iso_mms/client/mms_client_get_namelist.c @@ -1,24 +1,24 @@ /* * mms_client_get_namelist.c * - * Copyright 2013 Michael Zillgith + * Copyright 2013-2018 Michael Zillgith * - * This file is part of libIEC61850. + * This file is part of libIEC61850. * - * libIEC61850 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * libIEC61850 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * libIEC61850 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * libIEC61850 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with libIEC61850. If not, see . + * You should have received a copy of the GNU General Public License + * along with libIEC61850. If not, see . * - * See COPYING file for the complete license text. + * See COPYING file for the complete license text. */ #include "libiec61850_platform_includes.h" @@ -121,6 +121,7 @@ mmsClient_parseGetNameListResponse(LinkedList* nameList, ByteBuffer* message) uint8_t tag = buffer[bufPos++]; if (tag == 0xa2) { + // TODO parse confirmed error PDU goto exit_error; } if (tag != 0xa1) goto exit_error; diff --git a/src/mms/iso_mms/client/mms_client_get_var_access.c b/src/mms/iso_mms/client/mms_client_get_var_access.c index d66f5f22..68d6449d 100644 --- a/src/mms/iso_mms/client/mms_client_get_var_access.c +++ b/src/mms/iso_mms/client/mms_client_get_var_access.c @@ -1,24 +1,24 @@ /* * mms_client_get_var_access.c * - * Copyright 2013 Michael Zillgith + * Copyright 2013-2018 Michael Zillgith * - * This file is part of libIEC61850. + * This file is part of libIEC61850. * - * libIEC61850 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * libIEC61850 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * libIEC61850 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * libIEC61850 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with libIEC61850. If not, see . + * You should have received a copy of the GNU General Public License + * along with libIEC61850. If not, see . * - * See COPYING file for the complete license text. + * sSee COPYING file for the complete license text. */ #include "libiec61850_platform_includes.h" diff --git a/src/mms/iso_mms/client/mms_client_named_variable_list.c b/src/mms/iso_mms/client/mms_client_named_variable_list.c index 18134602..e34305fd 100644 --- a/src/mms/iso_mms/client/mms_client_named_variable_list.c +++ b/src/mms/iso_mms/client/mms_client_named_variable_list.c @@ -250,7 +250,7 @@ parseNamedVariableAttributes(GetNamedVariableListAttributesResponse_t* response, } LinkedList /* */ -mmsClient_parseGetNamedVariableListAttributesResponse(ByteBuffer* message, uint32_t* invokeId, bool* /*OUT*/deletable) +mmsClient_parseGetNamedVariableListAttributesResponse(ByteBuffer* message, bool* /*OUT*/deletable) { MmsPdu_t* mmsPdu = 0; @@ -262,12 +262,6 @@ mmsClient_parseGetNamedVariableListAttributesResponse(ByteBuffer* message, uint3 if (rval.code == RC_OK) { if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) { -#if 0 - //TODO remove - if (invokeId != NULL) - *invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu); -#endif - if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present == ConfirmedServiceResponse_PR_getNamedVariableListAttributes) { @@ -289,7 +283,7 @@ mmsClient_createDefineNamedVariableListRequest( ByteBuffer* writeBuffer, const char* domainId, const char* listNameId, - LinkedList /**/listOfVariables, + LinkedList /**/ listOfVariables, bool associationSpecific) { MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId); @@ -370,8 +364,7 @@ mmsClient_createDefineNamedVariableListRequest( alternateAccess->list.array[0]->present = AlternateAccess__Member_PR_unnamed; alternateAccess->list.array[0]->choice.unnamed = (AlternateAccessSelection_t*) GLOBAL_CALLOC(1, sizeof(AlternateAccessSelection_t)); - alternateAccess->list.array[0]->choice.unnamed->present = - AlternateAccessSelection_PR_selectAlternateAccess; + alternateAccess->list.array[0]->choice.unnamed->present = AlternateAccessSelection_PR_selectAlternateAccess; alternateAccess->list.array[0]->choice.unnamed->choice.selectAlternateAccess.accessSelection.present = AlternateAccessSelection__selectAlternateAccess__accessSelection_PR_index; diff --git a/src/mms/iso_mms/client/mms_client_read.c b/src/mms/iso_mms/client/mms_client_read.c index 8eb2caf3..4bc82e9e 100644 --- a/src/mms/iso_mms/client/mms_client_read.c +++ b/src/mms/iso_mms/client/mms_client_read.c @@ -1,7 +1,7 @@ /* * mms_client_read.c * - * Copyright 2013 Michael Zillgith + * Copyright 2013-2018 Michael Zillgith * * This file is part of libIEC61850. * diff --git a/src/mms/iso_mms/common/mms_value.c b/src/mms/iso_mms/common/mms_value.c index 1d8485e2..9273f13a 100644 --- a/src/mms/iso_mms/common/mms_value.c +++ b/src/mms/iso_mms/common/mms_value.c @@ -3,22 +3,22 @@ * * Copyright 2013-2018 Michael Zillgith * - * This file is part of libIEC61850. + * This file is part of libIEC61850. * - * libIEC61850 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * libIEC61850 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * libIEC61850 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * libIEC61850 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with libIEC61850. If not, see . + * You should have received a copy of the GNU General Public License + * along with libIEC61850. If not, see . * - * See COPYING file for the complete license text. + * See COPYING file for the complete license text. */ #include "libiec61850_platform_includes.h" @@ -130,7 +130,7 @@ MmsValue_equals(const MmsValue* self, const MmsValue* otherValue) return true; break; case MMS_INTEGER: - case MMS_UNSIGNED: + case MMS_UNSIGNED: return Asn1PrimitivaValue_compare(self->value.integer, otherValue->value.integer); break; case MMS_UTC_TIME: @@ -162,7 +162,7 @@ MmsValue_equals(const MmsValue* self, const MmsValue* otherValue) break; case MMS_VISIBLE_STRING: - case MMS_STRING: + case MMS_STRING: if (self->value.visibleString.buf != NULL) { if (otherValue->value.visibleString.buf != NULL) { if (strcmp(self->value.visibleString.buf, otherValue->value.visibleString.buf) == 0) @@ -315,7 +315,6 @@ MmsValue* MmsValue_newBitString(int bitSize) { MmsValue* self = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); - ; if (self == NULL) return NULL; @@ -524,7 +523,6 @@ MmsValue* MmsValue_newFloat(float variable) { MmsValue* self = (MmsValue*) GLOBAL_MALLOC(sizeof(MmsValue)); - ; if (self == NULL) return NULL; @@ -587,7 +585,6 @@ MmsValue* MmsValue_newIntegerFromInt8(int8_t integer) { MmsValue* self = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); - ; self->type = MMS_INTEGER; self->value.integer = BerInteger_createFromInt32((int32_t) integer); @@ -599,7 +596,6 @@ MmsValue* MmsValue_newIntegerFromInt16(int16_t integer) { MmsValue* self = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); - ; self->type = MMS_INTEGER; self->value.integer = BerInteger_createFromInt32((int32_t) integer); @@ -833,7 +829,6 @@ MmsValue* MmsValue_newUnsignedFromUint32(uint32_t integer) { MmsValue* self = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); - ; if (self == NULL) return NULL; @@ -848,7 +843,6 @@ MmsValue* MmsValue_newIntegerFromInt64(int64_t integer) { MmsValue* self = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); - ; if (self == NULL) return NULL; @@ -914,8 +908,6 @@ MmsValue_toFloat(const MmsValue* self) return val; } } - else - printf("MmsValue_toFloat: conversion error. Wrong type!\n"); return 0.f; } @@ -967,7 +959,7 @@ MmsValue_getSizeInMemory(const MmsValue* self) switch (self->type) { case MMS_ARRAY: - case MMS_STRUCTURE: + case MMS_STRUCTURE: { memorySize += (MemoryAllocator_getAlignedSize(sizeof(MmsValue*)) * self->value.structure.size); @@ -982,7 +974,7 @@ MmsValue_getSizeInMemory(const MmsValue* self) break; case MMS_INTEGER: - case MMS_UNSIGNED: + case MMS_UNSIGNED: memorySize += MemoryAllocator_getAlignedSize(sizeof(Asn1PrimitiveValue)); memorySize += MemoryAllocator_getAlignedSize(self->value.integer->maxSize); break; @@ -1018,7 +1010,7 @@ MmsValue_cloneToBuffer(const MmsValue* self, uint8_t* destinationAddress) switch (self->type) { case MMS_ARRAY: - case MMS_STRUCTURE: + case MMS_STRUCTURE: { newValue->value.structure.components = (MmsValue**) destinationAddress; destinationAddress += (sizeof(MmsValue*) * self->value.structure.size); @@ -1038,7 +1030,7 @@ MmsValue_cloneToBuffer(const MmsValue* self, uint8_t* destinationAddress) break; case MMS_INTEGER: - case MMS_UNSIGNED: + case MMS_UNSIGNED: { newValue->value.integer = (Asn1PrimitiveValue*) destinationAddress; Asn1PrimitiveValue* newAsn1Value = (Asn1PrimitiveValue*) destinationAddress; @@ -1067,7 +1059,7 @@ MmsValue_cloneToBuffer(const MmsValue* self, uint8_t* destinationAddress) break; case MMS_STRING: - case MMS_VISIBLE_STRING: + case MMS_VISIBLE_STRING: newValue->value.visibleString.buf = (char*) destinationAddress; newValue->value.visibleString.size = self->value.visibleString.size; strcpy((char*) destinationAddress, self->value.visibleString.buf); @@ -1081,7 +1073,6 @@ MmsValue_cloneToBuffer(const MmsValue* self, uint8_t* destinationAddress) return destinationAddress; } -// create a deep clone MmsValue* MmsValue_clone(const MmsValue* self) { @@ -1098,7 +1089,7 @@ MmsValue_clone(const MmsValue* self) { case MMS_ARRAY: - case MMS_STRUCTURE: + case MMS_STRUCTURE: { int componentCount = self->value.structure.size; newValue->value.structure.size = componentCount; @@ -1112,7 +1103,7 @@ MmsValue_clone(const MmsValue* self) break; case MMS_INTEGER: - case MMS_UNSIGNED: + case MMS_UNSIGNED: newValue->value.integer = Asn1PrimitiveValue_clone(self->value.integer); break; @@ -1153,7 +1144,7 @@ MmsValue_clone(const MmsValue* self) break; case MMS_VISIBLE_STRING: - case MMS_STRING: + case MMS_STRING: size = self->value.visibleString.size; newValue->value.visibleString.buf = (char*) GLOBAL_MALLOC(size + 1); newValue->value.visibleString.size = size; @@ -1168,7 +1159,7 @@ MmsValue_clone(const MmsValue* self) break; } - exit_function: +exit_function: return newValue; } @@ -1191,7 +1182,7 @@ MmsValue_delete(MmsValue* self) switch (self->type) { case MMS_INTEGER: - case MMS_UNSIGNED: + case MMS_UNSIGNED: Asn1PrimitiveValue_destroy(self->value.integer); break; case MMS_FLOAT: @@ -1204,12 +1195,12 @@ MmsValue_delete(MmsValue* self) GLOBAL_FREEMEM(self->value.octetString.buf); break; case MMS_VISIBLE_STRING: - case MMS_STRING: + case MMS_STRING: if (self->value.visibleString.buf != NULL) GLOBAL_FREEMEM(self->value.visibleString.buf); break; case MMS_ARRAY: - case MMS_STRUCTURE: + case MMS_STRUCTURE: { int componentCount = self->value.structure.size; int i; @@ -1237,7 +1228,7 @@ MmsValue_deleteConditional(MmsValue* self) switch (self->type) { case MMS_INTEGER: - case MMS_UNSIGNED: + case MMS_UNSIGNED: Asn1PrimitiveValue_destroy(self->value.integer); break; case MMS_FLOAT: @@ -1250,12 +1241,12 @@ MmsValue_deleteConditional(MmsValue* self) GLOBAL_FREEMEM(self->value.octetString.buf); break; case MMS_VISIBLE_STRING: - case MMS_STRING: + case MMS_STRING: if (self->value.visibleString.buf != NULL) GLOBAL_FREEMEM(self->value.visibleString.buf); break; case MMS_ARRAY: - case MMS_STRUCTURE: + case MMS_STRUCTURE: { int componentCount = self->value.structure.size; int i; @@ -1497,7 +1488,7 @@ MmsValue_newDefaultValue(const MmsVariableSpecification* typeSpec) if (self != NULL) self->deleteValue = 0; - exit_function: +exit_function: return self; } @@ -1526,7 +1517,7 @@ setVisibleStringValue(MmsValue* self, const char* string) self->value.visibleString.buf[0] = 0; } - exit_function: +exit_function: return; } @@ -1559,7 +1550,7 @@ MmsValue_newString(const char* string, MmsType type) setVisibleStringValue(self, string); } - exit_function: +exit_function: return self; } @@ -1590,7 +1581,7 @@ MmsValue_newStringWithSize(int size, MmsType type) self->value.visibleString.buf[0] = 0; - exit_function: +exit_function: return self; } @@ -1715,9 +1706,8 @@ void MmsValue_setMmsString(MmsValue* self, const char* string) { if (self->type == MMS_STRING) { - assert(self->value.visibleString.buf != NULL); - - setVisibleStringValue(self, string); + if (self->value.visibleString.buf != NULL); + setVisibleStringValue(self, string); } } @@ -1740,7 +1730,7 @@ MmsValue_newStringFromByteArray(const uint8_t* byteArray, int size, MmsType type self = NULL; } - exit_function: +exit_function: return self; } @@ -1760,9 +1750,8 @@ void MmsValue_setVisibleString(MmsValue* self, const char* string) { if (self->type == MMS_VISIBLE_STRING) { - assert(self->value.visibleString.buf != NULL); - - setVisibleStringValue(self, string); + if (self->value.visibleString.buf != NULL); + setVisibleStringValue(self, string); } } @@ -1809,7 +1798,7 @@ MmsValue_newUtcTime(uint32_t timeval) valueArray[3] = timeArray[3]; #endif - exit_function: +exit_function: return self; } @@ -1856,7 +1845,7 @@ MmsValue_createArray(MmsVariableSpecification* elementType, int size) } } - exit_function: +exit_function: return self; } @@ -1883,7 +1872,7 @@ MmsValue_createEmptyArray(int size) self->value.structure.components[i] = NULL; } - exit_function: +exit_function: return self; } @@ -2013,7 +2002,7 @@ MmsValue_printToBuffer(const MmsValue* self, char* buffer, int bufferSize) switch (MmsValue_getType(self)) { case MMS_STRUCTURE: - case MMS_ARRAY: + case MMS_ARRAY: { if (bufferSize == 0) break; diff --git a/src/mms/iso_presentation/iso_presentation.c b/src/mms/iso_presentation/iso_presentation.c index 01f4bd5b..10fd97a4 100644 --- a/src/mms/iso_presentation/iso_presentation.c +++ b/src/mms/iso_presentation/iso_presentation.c @@ -1,7 +1,7 @@ /* * iso_presentation.c * - * Copyright 2013 Michael Zillgith + * Copyright 2013-2018 Michael Zillgith * * This file is part of libIEC61850. *