|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
/*
|
|
|
|
|
* reporting.c
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2013-2020 Michael Zillgith
|
|
|
|
|
* Copyright 2013-2021 Michael Zillgith
|
|
|
|
|
*
|
|
|
|
|
* This file is part of libIEC61850.
|
|
|
|
|
*
|
|
|
|
@ -2651,20 +2651,25 @@ exit_function:
|
|
|
|
|
return;
|
|
|
|
|
} /* enqueuReport() */
|
|
|
|
|
|
|
|
|
|
#define SENT_REPORT_ENTRY_FAILED 0
|
|
|
|
|
#define SENT_REPORT_ENTRY_FINISHED 1
|
|
|
|
|
#define SENT_REPORT_ENTRY_MORE_FOLLOWS 2
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
sendNextReportEntrySegment(ReportControl* self)
|
|
|
|
|
{
|
|
|
|
|
if (self->clientConnection == NULL)
|
|
|
|
|
return false;
|
|
|
|
|
return SENT_REPORT_ENTRY_FAILED;
|
|
|
|
|
|
|
|
|
|
if (self->reportBuffer->nextToTransmit == NULL)
|
|
|
|
|
return SENT_REPORT_ENTRY_FINISHED;
|
|
|
|
|
|
|
|
|
|
bool sentSuccess = true;
|
|
|
|
|
|
|
|
|
|
bool isBuffered = self->buffered;
|
|
|
|
|
|
|
|
|
|
int maxMmsPduSize = MmsServerConnection_getMaxMmsPduSize(self->clientConnection);
|
|
|
|
|
|
|
|
|
|
if (self->reportBuffer->nextToTransmit == NULL) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) */
|
|
|
|
|
|
|
|
|
@ -3102,7 +3107,7 @@ sendNextReportEntrySegment(ReportControl* self)
|
|
|
|
|
if (DEBUG_IED_SERVER)
|
|
|
|
|
printf("IED_SERVER: internal error in report buffer\n");
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
return SENT_REPORT_ENTRY_FAILED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int dataElementSize = 1 + lenSize + length;
|
|
|
|
@ -3174,12 +3179,17 @@ sendNextReportEntrySegment(ReportControl* self)
|
|
|
|
|
|
|
|
|
|
reportBuffer->size = bufPos;
|
|
|
|
|
|
|
|
|
|
MmsServerConnection_sendMessage(self->clientConnection, reportBuffer);
|
|
|
|
|
sentSuccess = MmsServerConnection_sendMessage(self->clientConnection, reportBuffer);
|
|
|
|
|
|
|
|
|
|
MmsServer_releaseTransmitBuffer(self->server->mmsServer);
|
|
|
|
|
|
|
|
|
|
IsoConnection_unlock(self->clientConnection->isoConnection);
|
|
|
|
|
|
|
|
|
|
if (sentSuccess == false) {
|
|
|
|
|
moreFollows = false;
|
|
|
|
|
goto exit_function;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (moreFollows == false) {
|
|
|
|
|
/* reset sub sequence number */
|
|
|
|
|
segmented = false;
|
|
|
|
@ -3222,7 +3232,14 @@ sendNextReportEntrySegment(ReportControl* self)
|
|
|
|
|
|
|
|
|
|
exit_function:
|
|
|
|
|
self->segmented = segmented;
|
|
|
|
|
return moreFollows;
|
|
|
|
|
|
|
|
|
|
if (sentSuccess == false)
|
|
|
|
|
return SENT_REPORT_ENTRY_FAILED;
|
|
|
|
|
|
|
|
|
|
if (moreFollows)
|
|
|
|
|
return SENT_REPORT_ENTRY_MORE_FOLLOWS;
|
|
|
|
|
else
|
|
|
|
|
return SENT_REPORT_ENTRY_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
@ -3234,8 +3251,25 @@ sendNextReportEntry(ReportControl* self)
|
|
|
|
|
|
|
|
|
|
while (self->reportBuffer->nextToTransmit) {
|
|
|
|
|
messageCount++;
|
|
|
|
|
while (sendNextReportEntrySegment(self)) {
|
|
|
|
|
messageCount++;
|
|
|
|
|
|
|
|
|
|
bool sendNextEntrySegment = true;
|
|
|
|
|
|
|
|
|
|
int sendResult = SENT_REPORT_ENTRY_FAILED;
|
|
|
|
|
|
|
|
|
|
while (sendNextEntrySegment) {
|
|
|
|
|
sendResult = sendNextReportEntrySegment(self);
|
|
|
|
|
|
|
|
|
|
if (sendResult != SENT_REPORT_ENTRY_FAILED) {
|
|
|
|
|
messageCount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sendResult != SENT_REPORT_ENTRY_MORE_FOLLOWS)
|
|
|
|
|
sendNextEntrySegment = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sendResult == SENT_REPORT_ENTRY_FAILED) {
|
|
|
|
|
//printf("Failed to send report\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (messageCount > 100)
|
|
|
|
|