diff --git a/src/mms/inc_private/cotp.h b/src/mms/inc_private/cotp.h index cba02c19..b7877cc8 100644 --- a/src/mms/inc_private/cotp.h +++ b/src/mms/inc_private/cotp.h @@ -84,7 +84,8 @@ CotpConnection_setTpduSize(CotpConnection* self, int tpduSize /* in byte */); LIB61850_INTERNAL void CotpConnection_init(CotpConnection* self, Socket socket, - ByteBuffer* payloadBuffer, ByteBuffer* readBuffer, ByteBuffer* writeBuffer); + ByteBuffer* payloadBuffer, ByteBuffer* readBuffer, ByteBuffer* writeBuffer, + uint8_t* socketExtensionBuffer, int socketExtensionBufferSize); LIB61850_INTERNAL CotpIndication CotpConnection_parseIncomingMessage(CotpConnection* self); diff --git a/src/mms/iso_client/iso_client_connection.c b/src/mms/iso_client/iso_client_connection.c index 6e71263a..435ab9bc 100644 --- a/src/mms/iso_client/iso_client_connection.c +++ b/src/mms/iso_client/iso_client_connection.c @@ -200,8 +200,12 @@ sendConnectionRequestMessage(IsoClientConnection self) self->cotpConnection->handleSet = NULL; } + int socketExtensionBufferSize = CONFIG_MMS_MAXIMUM_PDU_SIZE + 1000; + uint8_t* socketExtensionBuffer = GLOBAL_MALLOC(socketExtensionBufferSize); + /* COTP (ISO transport) handshake */ - CotpConnection_init(self->cotpConnection, self->socket, self->receiveBuffer, self->cotpReadBuffer, self->cotpWriteBuffer); + CotpConnection_init(self->cotpConnection, self->socket, self->receiveBuffer, self->cotpReadBuffer, self->cotpWriteBuffer, + socketExtensionBuffer, socketExtensionBufferSize); #if (CONFIG_MMS_SUPPORT_TLS == 1) if (self->parameters->tlsConfiguration) { @@ -774,9 +778,13 @@ IsoClientConnection_destroy(IsoClientConnection self) GLOBAL_FREEMEM(self->receiveBuf); if (self->receiveBuffer != NULL) GLOBAL_FREEMEM(self->receiveBuffer); + if (self->cotpConnection != NULL) { if (self->cotpConnection->handleSet != NULL) Handleset_destroy(self->cotpConnection->handleSet); + + GLOBAL_FREEMEM(self->cotpConnection->socketExtensionBuffer); + GLOBAL_FREEMEM(self->cotpConnection); } diff --git a/src/mms/iso_cotp/cotp.c b/src/mms/iso_cotp/cotp.c index 80df4ce1..70f3dc62 100644 --- a/src/mms/iso_cotp/cotp.c +++ b/src/mms/iso_cotp/cotp.c @@ -503,7 +503,8 @@ cpo_error: void CotpConnection_init(CotpConnection* self, Socket socket, - ByteBuffer* payloadBuffer, ByteBuffer* readBuffer, ByteBuffer* writeBuffer) + ByteBuffer* payloadBuffer, ByteBuffer* readBuffer, ByteBuffer* writeBuffer, + uint8_t* socketExtensionBuffer, int socketExtensionBufferSize) { self->state = 0; self->socket = socket; @@ -536,8 +537,8 @@ CotpConnection_init(CotpConnection* self, Socket socket, self->readBuffer = readBuffer; self->packetSize = 0; - self->socketExtensionBuffer = GLOBAL_MALLOC(CONFIG_MMS_MAXIMUM_PDU_SIZE + 120); - self->socketExtensionBufferSize = CONFIG_MMS_MAXIMUM_PDU_SIZE + 120; + self->socketExtensionBuffer = socketExtensionBuffer; + self->socketExtensionBufferSize = socketExtensionBufferSize; self->socketExtensionBufferFill = 0; } diff --git a/src/mms/iso_server/iso_connection.c b/src/mms/iso_server/iso_connection.c index caf4331e..653379e4 100644 --- a/src/mms/iso_server/iso_connection.c +++ b/src/mms/iso_server/iso_connection.c @@ -122,6 +122,8 @@ finalizeIsoConnection(IsoConnection self) if (self->cotpConnection) { if (self->cotpConnection->handleSet) Handleset_destroy(self->cotpConnection->handleSet); + + GLOBAL_FREEMEM(self->cotpConnection->socketExtensionBuffer); } GLOBAL_FREEMEM(self->cotpConnection); @@ -527,7 +529,10 @@ IsoConnection_create(Socket socket, IsoServer isoServer, bool isSingleThread) ByteBuffer_wrap(&(self->cotpWriteBuffer), self->cotpWriteBuf, 0, CONFIG_COTP_MAX_TPDU_SIZE + TPKT_RFC1006_HEADER_SIZE); self->cotpConnection = (CotpConnection*) GLOBAL_CALLOC(1, sizeof(CotpConnection)); - CotpConnection_init(self->cotpConnection, self->socket, &(self->rcvBuffer), &(self->cotpReadBuffer), &(self->cotpWriteBuffer)); + int socketExtensionBufferSize = CONFIG_MMS_MAXIMUM_PDU_SIZE + 1000; + uint8_t* socketExtensionBuffer = GLOBAL_MALLOC(socketExtensionBufferSize); + CotpConnection_init(self->cotpConnection, self->socket, &(self->rcvBuffer), &(self->cotpReadBuffer), &(self->cotpWriteBuffer), + socketExtensionBuffer, socketExtensionBufferSize); #if (CONFIG_MMS_SUPPORT_TLS == 1) if (self->tlsSocket) @@ -602,6 +607,8 @@ IsoConnection_destroy(IsoConnection self) if (self->cotpConnection) { if (self->cotpConnection->handleSet) Handleset_destroy(self->cotpConnection->handleSet); + + GLOBAL_FREEMEM(self->cotpConnection->socketExtensionBuffer); } GLOBAL_FREEMEM(self);