From 0593f348eac28eaf04fde15105df5dfa78242119 Mon Sep 17 00:00:00 2001 From: Denis Lazarev Date: Sat, 5 Oct 2024 19:36:47 +0300 Subject: [PATCH 1/2] MmsFileService: Don't use file size on read The size value shall be interpreted as an estimated file size and shall not be used to determine absolute size. --- src/mms/iso_mms/server/mms_file_service.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/mms/iso_mms/server/mms_file_service.c b/src/mms/iso_mms/server/mms_file_service.c index ca5d80f79..1f65fc175 100644 --- a/src/mms/iso_mms/server/mms_file_service.c +++ b/src/mms/iso_mms/server/mms_file_service.c @@ -826,22 +826,14 @@ void mmsMsg_createFileReadResponse(int maxPduSize, uint32_t invokeId, ByteBuffer* response, MmsFileReadStateMachine* frsm) { - /* determine remaining bytes in file */ - uint32_t bytesLeft = frsm->fileSize - frsm->readPosition; - - uint32_t fileChunkSize = 0; - uint32_t maxFileChunkSize = maxPduSize - 20; uint32_t fileReadResponseSize = 1; /* for tag */ bool moreFollows = true; - if (bytesLeft > maxFileChunkSize) { - fileChunkSize = maxFileChunkSize; - } - else { - fileChunkSize = bytesLeft; + uint32_t fileChunkSize = FileSystem_readFile(frsm->fileHandle, response->buffer + 20, maxFileChunkSize); + if (fileChunkSize != maxFileChunkSize) { moreFollows = false; fileReadResponseSize += 3; /* for moreFollows */ } @@ -869,7 +861,7 @@ mmsMsg_createFileReadResponse(int maxPduSize, uint32_t invokeId, bufPos = BerEncoder_encodeTL(0x49, fileReadResponseSize, buffer, bufPos); bufPos = BerEncoder_encodeTL(0x80, fileChunkSize, buffer, bufPos); - FileSystem_readFile(frsm->fileHandle, buffer + bufPos, fileChunkSize); + memmove(buffer + bufPos, buffer + 20, fileChunkSize); bufPos += fileChunkSize; if (!moreFollows) From bb7c77b900397ce415e74f3480cc4b6175ca5d13 Mon Sep 17 00:00:00 2001 From: Denis Lazarev Date: Sat, 5 Oct 2024 20:01:57 +0300 Subject: [PATCH 2/2] HAL: linux: Set socket protocol only for receive sockets When creating raw sockets the protocol must be set to 0. In case for receive sockets this means we will receive no packets until we "bind" the socket with a non-zero protocol. In case for only transmit sockets this avoids an expensive call packet receiving function in kernel thats overflow internal receive socket buffer. --- hal/ethernet/linux/ethernet_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hal/ethernet/linux/ethernet_linux.c b/hal/ethernet/linux/ethernet_linux.c index bb9896001..81c4aac0d 100644 --- a/hal/ethernet/linux/ethernet_linux.c +++ b/hal/ethernet/linux/ethernet_linux.c @@ -174,7 +174,7 @@ Ethernet_createSocket(const char* interfaceId, uint8_t* destAddress) if (self) { - self->rawSocket = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); + self->rawSocket = socket(AF_PACKET, SOCK_RAW, 0); if (self->rawSocket == -1) {