Deep dive
wolfIP
wolfIP is wolfSSL's TCP/IP stack with no dynamic memory. I built secure networking services on it for the STM32H563, ported it to the STM32N6, added STM32CubeMX support, and fixed a TCP handshake bug that hung CI.
Secure networking on a microcontroller with no heap
Most embedded TCP/IP stacks assume an allocator or an RTOS. wolfIP assumes neither: every socket and buffer is sized at compile time and the whole stack runs from one poll loop. That makes memory use predictable, but every protocol on top has to fit in fixed buffers and never block. The core stack (sockets, TCP, IP, the device interface) is its maintainers' design. My part is the services and drivers on top of it, the STM32 ports, the tooling, and fixes in the TCP and application layers.
Opt-in services on one loop
On the NUCLEO-H563ZI, wolfSSL, wolfSSH and wolfMQTT each talk to wolfIP through a small I/O glue file that maps the library's send and receive callbacks onto wolfIP sockets #14. Because there is no RTOS, nothing may block: the MQTT client is a non-blocking state machine that the main loop steps alongside the TLS, HTTPS and SSH servers. Each service is a build flag (ENABLE_TLS, ENABLE_HTTPS, ENABLE_SSH, ENABLE_MQTT), so an image carries only what the product needs.
For Ethernet there are two drivers on purpose. The CubeMX pack's HAL driver detects F4, F7, H5 and H7 RMII or MII setups and trades some size for portability #19. The standalone H563 example keeps a bare-metal driver that bypasses the HAL, because on that board it was more reliable. The STM32N6 port extends the shared driver for the GMAC v5.20 dual-channel DMA #85.
Main changes
- TLS 1.3, HTTPS, SSH and MQTT over TLS on the STM32H563, also checked with TrustZone enabled.#14
- STM32CubeMX and CubeIDE support: a CMSIS pack, a code-generation template, and a HAL Ethernet driver.#19 #110
- STM32N6 port: Cortex-M55 at 600 MHz, GMAC v5.20 DMA, hardware TRNG, and the N6 security setup.#85
- Coverity in CI and the fixes it found, plus HTTP and TFTP correctness fixes.#64 #68 #83 #156 #134
The SYN-ACK that was never retransmitted
The wolfSSL integration test started hanging on the Linux and FreeBSD CI runners. The host's connect() timed out and the job sat there. It only happened when the first SYN-ACK did not get through, which pointed at retransmission rather than the TLS layer.
The cause was an orphaned retransmission timer in wolfIP_sock_accept(). When a SYN arrived, the listening socket moved to SYN_RCVD and armed its RTO timer. accept() then created the new socket and set it straight to ESTABLISHED, and the listening socket went back to LISTEN with the timer still attached to it. If that SYN-ACK was lost, no socket was responsible for resending it, and the handshake never finished.
The fix keeps the accepted socket in SYN_RCVD until the final ACK arrives, starts the RTO timer on the new socket, and stops the orphaned one on the listener. It also holds back the writable event until the handshake completes, so an application cannot start sending on a half-open connection. On the test side I switched the integration test to a non-blocking connect with a select loop, added three unit tests for the timer and state transitions, and corrected three existing assertions that had expected ESTABLISHED right after accept().
| Before the fix | After the fix | |
|---|---|---|
| New socket after accept() | ESTABLISHED immediately | SYN_RCVD until the final ACK |
| Retransmission timer | left armed on the listening socket | started on the new socket, listener's stopped |
| Lost SYN-ACK | never resent, client connect() times out | resent by the new socket's RTO |
| Writable event | signaled before the handshake finished | signaled after the final ACK |
Fixed in #43.
How it was checked
| PR | Evidence |
|---|---|
| #43 | 3 new unit tests; unit suite 517/517; Linux, FreeBSD and macOS CI pass without hanging |
| #14 | Every service run on a NUCLEO-H563ZI with DHCP; the base stack also with TZEN=1 |
| #85 | ping -c 5 5/5 replies under 0.2 ms RTT, TCP echo on port 7, H5 and H7 still build |
| #64 | Coverity Scan in CI, with its findings fixed in follow-up PRs |
What is not done yet
The H5 demo embeds a self-signed test certificate and a test SSH password, which is fine for a demo and wrong for a product; the next step is provisioning real credentials from secure storage. The N6 port has ping and TCP echo so far, so moving the H5 services across is the natural follow-on.
All my merged pull requests 14 in wolfSSL/wolfip
- #156Coverity fixes to publish POSIX host calls atomically and validate DHCP requests
- #150Fix STM32H563 wolfSSH source list
- #134Correctness and robustness fixes across HTTP, TFTP, and ports
- #110IDE/STM32Cube: fix broken pack download link (#108)
- #85STM32N6 (NUCLEO-N657X0-Q) wolfIP Port
- #83Fix wolfIP coverity
- #68Fix Coverity Findings
- #67Fix coverity issue
- #64Add coverity for wolfIP
- #46Fix wolfIP security review issues
- #28Upgrade wolfIP CI Testing
- #19Add wolfIP STM32 CubeMX Support
- #43Fix SYN-ACK retransmission bug in accept() causing CI timeouts
- #14Add TLS, HTTPS, SSH, and MQTT support for STM32H563 port