Summary: Mbedtls can't complete handshaking when the default settings of LWIP
Group: lwIP - A Lightweight TCP/IP stack
Submitter: cjchenigel
Category: None
Priority: 5 - Normal
Severity: 3 - Normal
Status: None
Privacy: Public
Fixed the handshake issue when the default settings of LWIP TCP_MSS=536 and TCP_WND=4*TCP_MSS are used.
In the function altcp_mbedtls_bio_send():
The original code 'u16_t write_len = (u16_t)LWIP_MIN(size_left, 0xFFFF);' could easily lead to an ERR_MEM error following altcp_write.
A more effective approach is to compare it with the value returned by altcp_sndbuf. This adjustment ensures that the write length exactly fits the currently available space.
On the next round, the write_len would be 0, and the function returns the number of bytes that have been written.
Additionally, there is a minor correction needed for the dataptr: it should be incremented by write_len for the next round.
In the function altcp_mbedtls_handle_rx_appldata:
An attempt to complete the handshake should be made again, especially when TCP_MSS is not large, indicating that the handshake might not have been completed yet.
Fix proposed here: https://github.com/cjchenigel/lwip/compare/master...version/2.2.0