Skip to content
Snippets Groups Projects
Commit 0e782abc authored by Nicolò Caruso's avatar Nicolò Caruso
Browse files

[Wiz5500] Fix on the recvfrom not handling more than one packet

The Wizznet driver in recvfrom was failing in case of received more than one packet. In that case the recvlength was greater than the length, making fail the recvfrom. Also it did not consume the data therefore not recovering from the failure.
parent 09d06ed5
Branches
Tags
No related merge requests found
Pipeline #11416 failed
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <interfaces/endianness.h> #include <interfaces/endianness.h>
#include <kernel/scheduler/scheduler.h> #include <kernel/scheduler/scheduler.h>
#include <utils/KernelTime.h> #include <utils/KernelTime.h>
#include <algorithm>
#include "WIZ5500Defs.h" #include "WIZ5500Defs.h"
...@@ -378,18 +379,19 @@ ssize_t Wiz5500::recvfrom(int sock_n, uint8_t* data, size_t len, WizIp& dst_ip, ...@@ -378,18 +379,19 @@ ssize_t Wiz5500::recvfrom(int sock_n, uint8_t* data, size_t len, WizIp& dst_ip,
// Remove what we have already read. // Remove what we have already read.
recv_len -= sizeof(WizIp) + sizeof(uint16_t) + sizeof(uint16_t); recv_len -= sizeof(WizIp) + sizeof(uint16_t) + sizeof(uint16_t);
// Check if we actually have space // Read the minimum between the received length and the maximum length
if (recv_len < len) uint16_t read_len = std::min(static_cast<size_t>(recv_len), len);
spiRead(Wiz::getSocketRxBlock(sock_n), addr, data, recv_len);
addr += recv_len; spiRead(Wiz::getSocketRxBlock(sock_n), addr, data, read_len);
addr += read_len;
spiWrite16(Wiz::getSocketRegBlock(sock_n), Wiz::Socket::REG_RX_RD, addr); spiWrite16(Wiz::getSocketRegBlock(sock_n), Wiz::Socket::REG_RX_RD, addr);
// Finally tell the device that we correctly received and read the data // Finally tell the device that we correctly received and read the data
spiWrite8(Wiz::getSocketRegBlock(sock_n), Wiz::Socket::REG_CR, spiWrite8(Wiz::getSocketRegBlock(sock_n), Wiz::Socket::REG_CR,
Wiz::Socket::CMD_RECV); Wiz::Socket::CMD_RECV);
return recv_len < len ? recv_len : -1; return read_len;
} }
void Wiz5500::close(int sock_n, int timeout) void Wiz5500::close(int sock_n, int timeout)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment