diff --git a/examples/iec61850_client_example2/client_example2.c b/examples/iec61850_client_example2/client_example2.c index 92afae44..939deab1 100644 --- a/examples/iec61850_client_example2/client_example2.c +++ b/examples/iec61850_client_example2/client_example2.c @@ -116,9 +116,13 @@ main(int argc, char** argv) LinkedList_destroy(dataObjects); + printf("IedConnection_getLogicalNodeDirectory(%s)\n", lnRef); LinkedList dataSets = IedConnection_getLogicalNodeDirectory(con, &error, lnRef, ACSI_CLASS_DATA_SET); + if (error != IED_ERROR_OK) + printf("get logical node data sets --> error: %i\n", error); + LinkedList dataSet = LinkedList_getNext(dataSets); while (dataSet != NULL) { @@ -193,7 +197,7 @@ main(int argc, char** argv) LinkedList_destroy(deviceList); - IedConnection_close(con); + IedConnection_abort(con, &error); } else { printf("Connection failed!\n"); diff --git a/src/iec61850/client/ied_connection.c b/src/iec61850/client/ied_connection.c index 12195040..1e3d4447 100644 --- a/src/iec61850/client/ied_connection.c +++ b/src/iec61850/client/ied_connection.c @@ -617,8 +617,8 @@ void IedConnection_close(IedConnection self) { if (IedConnection_getState(self) == IED_STATE_CONNECTED) { - MmsConnection_close(self->connection); IedConnection_setState(self, IED_STATE_CLOSED); + MmsConnection_close(self->connection); } } diff --git a/src/iec61850/inc/iec61850_client.h b/src/iec61850/inc/iec61850_client.h index 91a0eeed..731ff064 100644 --- a/src/iec61850/inc/iec61850_client.h +++ b/src/iec61850/inc/iec61850_client.h @@ -1162,9 +1162,21 @@ ClientReportControlBlock_setDataSetReference(ClientReportControlBlock self, cons uint32_t ClientReportControlBlock_getConfRev(ClientReportControlBlock self); +/** + * \brief Gets the OptFlds parameter of the RCB (decides what information to include in a report) + * + * \param self the RCB instance + * \return bit field representing the optional fields of a report (uses flags from \ref REPORT_OPTIONS) + */ int ClientReportControlBlock_getOptFlds(ClientReportControlBlock self); +/** + * \brief Set the OptFlds parameter of the RCB (decides what information to include in a report) + * + * \param self the RCB instance + * \param optFlds bit field representing the optional fields of a report (use flags from \ref REPORT_OPTIONS) + */ void ClientReportControlBlock_setOptFlds(ClientReportControlBlock self, int optFlds); diff --git a/src/mms/iso_client/iso_client_connection.c b/src/mms/iso_client/iso_client_connection.c index bddbebcc..a8bcafbb 100644 --- a/src/mms/iso_client/iso_client_connection.c +++ b/src/mms/iso_client/iso_client_connection.c @@ -141,6 +141,9 @@ connectionHandlingThread(IsoClientConnection self) Thread_sleep(1); if (self->stopHandlingThread) { + + if (DEBUG_ISO_CLIENT) + printf("ISO_CLIENT_CONNECTION: stop thread requested\n"); packetState = TPKT_ERROR; break; } @@ -292,6 +295,9 @@ IsoClientConnection_associate(IsoClientConnection self, IsoConnectionParameters Socket_setConnectTimeout(self->socket, connectTimeoutInMs); + self->stopHandlingThread = false; + self->destroyHandlingThread = false; + #if (CONFIG_ACTIVATE_TCP_KEEPALIVE == 1) Socket_activateTcpKeepAlive(self->socket, CONFIG_TCP_KEEPALIVE_IDLE, @@ -599,6 +605,9 @@ IsoClientConnection_abort(IsoClientConnection self) IsoSession_createAbortSpdu(self->session, sessionBuffer, presentationBuffer); + if (DEBUG_ISO_CLIENT) + printf("ISO_CLIENT: send abort message\n"); + CotpConnection_sendDataMessage(self->cotpConnection, sessionBuffer); Semaphore_post(self->transmitBufferMutex); @@ -643,6 +652,9 @@ IsoClientConnection_release(IsoClientConnection self) IsoSession_createFinishSpdu(NULL, sessionBuffer, presentationBuffer); + if (DEBUG_ISO_CLIENT) + printf("ISO_CLIENT: send release message\n"); + CotpConnection_sendDataMessage(self->cotpConnection, sessionBuffer); Semaphore_post(self->transmitBufferMutex); diff --git a/src/mms/iso_mms/client/mms_client_connection.c b/src/mms/iso_mms/client/mms_client_connection.c index d88aba2f..48375575 100644 --- a/src/mms/iso_mms/client/mms_client_connection.c +++ b/src/mms/iso_mms/client/mms_client_connection.c @@ -1314,19 +1314,31 @@ MmsConnection_connect(MmsConnection self, MmsError* mmsError, const char* server waitForConnectResponse(self); if (DEBUG_MMS_CLIENT) - printf("MmsConnection_connect: received response conState: %i\n", getConnectionState(self)); + printf("MmsConnection_connect: received response conState: %i assocState: %i\n", getConnectionState(self), getAssociationState(self)); if (getConnectionState(self) == MMS_CON_ASSOCIATED) { - mmsClient_parseInitiateResponse(self); + if (mmsClient_parseInitiateResponse(self) == false) { + if (DEBUG_MMS_CLIENT) + printf("MmsConnection_connect: failed to parse initiate response\n"); + + setAssociationState(self, MMS_STATE_CLOSED); + + setConnectionState(self, MMS_CON_ASSOCIATION_FAILED); + } + else { + setAssociationState(self, MMS_STATE_CONNECTED); + } releaseResponse(self); - setAssociationState(self, MMS_STATE_CONNECTED); + } - else + else { setAssociationState(self, MMS_STATE_CLOSED); - setConnectionState(self, MMS_CON_IDLE); + setConnectionState(self, MMS_CON_ASSOCIATION_FAILED); + } + if (DEBUG_MMS_CLIENT) printf("MmsConnection_connect: states: con %i ass %i\n", getConnectionState(self), getAssociationState(self)); diff --git a/src/mms/iso_mms/client/mms_client_initiate.c b/src/mms/iso_mms/client/mms_client_initiate.c index 10810ec5..e00b2239 100644 --- a/src/mms/iso_mms/client/mms_client_initiate.c +++ b/src/mms/iso_mms/client/mms_client_initiate.c @@ -162,7 +162,7 @@ parseInitResponseDetail(MmsConnection self, uint8_t* buffer, int bufPos, int max bool mmsClient_parseInitiateResponse(MmsConnection self) { - bool result = false; + bool result = true; self->parameters.maxPduSize = CONFIG_MMS_MAXIMUM_PDU_SIZE; self->parameters.dataStructureNestingLevel = DEFAULT_DATA_STRUCTURE_NESTING_LEVEL; @@ -236,6 +236,5 @@ mmsClient_parseInitiateResponse(MmsConnection self) bufPos += length; } - return result; }