Repository navigation
Embedded reliability, zero-heap memory architecture, split RTOS concurrency, CoAP RTT estimation with watchdog protection, and non-blocking handshake state machine.
🚀 Protocol & Library Additions
-
C Core & Arduino — Asynchronous Non-Blocking Handshake State Machine (
usmp_step,beginAsync): Introduced explicit non-blocking finite state machine (USMP_STATE_IDLE,USMP_STATE_CONNECTING_SOCKET,USMP_STATE_AWAITING_CHALLENGE,USMP_STATE_CALCULATING_ECDH,USMP_STATE_AWAITING_SESSION_OK,USMP_STATE_ESTABLISHED). Addedusmp_connect_async(),usmp_reconnect_async(), andusmp_step()in C core. Refactored ArduinoUSMPClientwithbeginAsync()overloads,state()/isConnecting()queries, and non-blockingmaintain()driving connection bring-up and reconnects without synchronous 2–5 second CPU stalls or watchdog timer resets. -
C Core — Split RTOS Mutex Architecture (
tx_mutex&rx_mutex): Embedded dedicated transmission and reception synchronization handles inusmp_t(core/include/usmp.h). Decouples egress encryption from ingress defragmentation, eliminating full-duplex socket deadlocks whenusmp_recv()blocks while completely serializing concurrentusmp_send()calls to prevent AES-GCM nonce reuse. In-band rekeying (usmp_rekey) and session teardown (usmp_close) enforce strict hierarchical lock order (tx_mutexfollowed byrx_mutex) to guarantee deadlock freedom. -
Core HAL — Mutex Primitives (
usmp_port_mutex_*) & Typed Status Code: Addedusmp_mutex_t,usmp_port_mutex_create(),usmp_port_mutex_lock(),usmp_port_mutex_unlock(), andusmp_port_mutex_destroy()declarations tocore/include/usmp_port.h. Implemented priority-inheriting FreeRTOS mutexes (xSemaphoreCreateMutex()) on ESP32, FreeRTOS/no-op stubs on Arduino, and Win32CRITICAL_SECTION/ POSIXpthread_mutex_ton test platforms. AddedUSMP_ERR_MUTEX_FAILED = -10tousmp_err_t. -
C Core — Zero-Heap Handshake Scratchpad Memory: Added
scratchandscratch_lenfields tousmp_tand#define USMP_HANDSHAKE_SCRATCH_LEN 1024incore/include/usmp.h. When provided,usmp_handshake()slices caller-managed memory into 512-byte TX and RX frame buffers with zero dynamic heap allocations, securely zeroizes scratchpad contents upon completion viambedtls_platform_zeroize(), and preserves scratchpad pointers acrossusmp_connect()andusmp_reconnect(). Includes#ifdef USMP_ZERO_HEAPguard for strict static-only build verification. -
Arduino Port — Static Memory Transport Contexts (
init_static): Addedinit_static(usmp_transport_t* t, USMPArduinoTcpCtx* ctx)andinit_static(usmp_transport_t* t, USMPArduinoUdpCtx* ctx)toUSMPTCPTransportandUSMPUDPTransport. Enables caller/BSS allocation of transport contexts, delegating standardinit()toinit_static()and installingdestroy_static()hooks that safely stop sockets without callingdeleteon static pointers. -
Arduino Port — Zero-Heap Client Architecture &
USMPClientStatic: RefactoredUSMPClientto decouple RX buffer storage into pointer + capacity (_rx_buf,_rx_buf_capacity,_owns_rx_buf). Added constructor overload accepting external buffer memory,setHandshakeScratch()for cryptographic scratchpad injection, andbegin(transport, static_ctx = nullptr)overloads. AddedUSMPClientStatic<RxBufferSize, ScratchBufferSize>template wrapper embedding both buffers directly in object memory for pure.bsszero-heap embedded deployments. -
Arduino Examples — Zero-Heap Reference Sketch: Added
ports/usmp-arduino/examples/zero_heap/zero_heap.inodemonstrating 100% static allocation withUSMPClientStaticand static transport contexts. -
Core HAL — Watchdog Timer Service Hook (
usmp_port_wdt_feed): Addedusmp_port_wdt_feed(void)HAL declaration tocore/include/usmp_port.hwith implementations for Arduino (yield()/ESP.wdtFeed()), ESP32 ESP-IDF (esp_task_wdt_reset()), and POSIX test runners. -
Arduino & ESP32 Ports — CoAP RTT Estimation & Watchdog Guard for UDP ARQ: Implemented RFC 7252 / Jacobson-Karn smoothed RTT (
srtt), variance (rttvar), and dynamic timeout (rto) inUSMPArduinoUdpCtx. Retransmission timeout scales with binary exponential backoff ($100\text{ ms} \dots 5000\text{ ms}$ ) on packet loss while avoiding retransmission ambiguity by measuring samples only on first-attempt ACKs. Integratedusmp_port_wdt_feed()inside transmission and reception wait loops to guard against hardware watchdog timer resets during link outages. -
C Core — Fast Table-Driven CRC-16 Lookup Engine: Replaced bitwise 8-iteration software shifting loop in
usmp_crc16_step()with a precomputed 256-word Flash lookup table (.rodata, 512 bytes ROM, 0 bytes RAM). Delivers ~8x faster single-cycle per-byte CRC-16 calculation across all incoming and outgoing frames on microcontrollers (ESP32/ARM Cortex-M/AVR) with 100% bit-exact wire-compatibility (#51). -
Arduino Port — Bounded Handshake Timeouts & Watchdog Protection: Introduced
USMP_HANDSHAKE_RECV_TIMEOUT_MS(default 5000 ms). Replaced unbounded handshake receive loops inUSMPTransport.cpp(both TCP and UDP) with bounded timeouts to prevent MCU hangs when the server is unresponsive. Addedusmp_port_wdt_feed()in all TCP byte reception and progress loops to guard against hardware watchdog timer and FreeRTOS Task Watchdog Timer (TWDT) reset loops during link negotiation. -
C Core — Early Corrupted Packet Rejection: Hardened
usmp_parse_packet()to compute and verify the frame CRC directly over the incoming wire buffer before executingmemcpy(pkt->payload, ...). Discards corrupted, incomplete, or spoofed frames in zero copy cycles, preventing internal buffer pollution and eliminating CPU waste during frame floods. -
C Core & Arduino — Human-Readable Error Translation (
usmp_strerror,lastError,lastErrorString): Addedconst char* usmp_strerror(usmp_err_t err)in C core returning descriptive static string literals for all library error codes. AddedlastError()andlastErrorString()to ArduinoUSMPClient, automatically capturing and exposing status codes from handshake, transmission, and background maintenance. -
C Core & Python SDK — Graceful Teardown Status Code (
USMP_ERR_PEER_CLOSED): AddedUSMP_ERR_PEER_CLOSED = -11tousmp_err_tandUSMPErrorCode.PEER_CLOSED = -11in Python SDK. Graceful peer disconnects viaPKT_BYEframes now return-11instead of ambiguous generic argument errors (-1), enabling clients to cleanly distinguish peer shutdown from malformed traffic. -
Arduino Port — Binary PSK Constructors: Added
USMPClient(const uint8_t* psk, size_t psk_len)andUSMPClientStatic(const uint8_t* psk, size_t psk_len)overloads accepting explicit binary key buffers. Preventsstrlen()from prematurely truncating random high-entropy pre-shared keys containing0x00bytes. -
Arduino Port — Standard Print Interface Inheritance (
usmp.print,usmp.println): InheritedUSMPClientfrom Arduino's standardPrintclass, implementingwrite(uint8_t),write(const uint8_t*, size_t),flush(), andavailableForWrite(). Enables idiomatic stream printing (usmp.print("Sensor: "),usmp.println(val)) with intelligent zero-heap line buffering that aggregates prints into single encrypted frames upon encountering\nor explicitflush()calls. -
Python SDK — Built-in CLI Dev / Echo Server (
python -m usmp.server,usmp-server): Added command-line development and test server with ANSI colored logging, interactive startup banner,--echomode for loopback verification,--generate-psk256-bit key generation, and hex-encoded PSK parsing (hex:<bytes>). Addedis_connectedandinfoproperties toUSMPSession. -
Python SDK — String Transmission, Direct Text Receiving & Payload Inspector (
session.send(str),session.recv_str(),session.print()): EnhancedUSMPSession.send()to natively acceptbytes | str(automatically encodingstras UTF-8). Addedsession.recv_str()for direct string reception. Addedsession.print(data, tag=...)providing rich console payload inspection with timestamps, device ID badges, payload length, and automatic text vs. hex dump formatting integrated with USMP's ANSI logger. -
ESP-IDF Port & Core HAL — Zero-Heap Static Transport Initializers (
usmp_transport_tcp_init_static,usmp_transport_udp_init_static): Exposedusmp_tcp_ctx_tandusmp_udp_ctx_tcontext types incore/include/usmp_transport.halong with static initializers accepting caller-managed static/.bssmemory buffers. Implemented static transport destroy hooks (destroy_static) that safely shut down sockets without callingfree(). Eliminates mandatory dynamic memory (malloc) for transports in safety-critical and zero-heap embedded environments (#DX-06). -
Build & Tooling — MbedTLS 3.x Assertion & UV Build Upper Bound: Added minimum version assert in
CMakeLists.txtenforcing MbedTLS >= 3.0.0 for host builds. Expandeduv_buildupper bound insdk/python/pyproject.tomlto<0.14.0for clean build compatibility with modern uv toolchains.
🛠️ Tooling, CI/CD & Developer Experience (Maintainers)
-
Tests — Zero-Heap Static Transport Initialization Suite: Added
test_static_transport_initialization()incore/tests/test_main.casserting NULL argument validation guards, struct layout sizing, static context binding, socket creation, and safe static teardown without heap freeing. -
Tests — Error Translation & Graceful Teardown Suite: Added
test_usmp_strerror()tocore/tests/test_main.cvalidating string mapping for all defined error codes and invalid fallback values. Updatedtest_bye_on_close()to verifyUSMP_ERR_PEER_CLOSEDreturn status. -
Tests — Asynchronous Handshake State Machine Suite: Added
test_async_handshake_fsm()incore/tests/test_main.casserting non-blocking tick progression, state transitions (IDLE->AWAITING_CHALLENGE->CALCULATING_ECDH->AWAITING_SESSION_OK->ESTABLISHED), non-blocking empty reads, reconnect FSM reset, and static assert layout verification forstateandhs_ctx. -
Tests — Split Mutex Concurrency & Multi-Threaded Serialization Suite: Added
test_split_mutex_concurrency()incore/tests/test_main.casserting lock/unlock balance, non-blocking full-duplex send execution whilerx_mutexis held, safe NULL de-referencing on teardown, and multi-threaded race condition resistance across 4 concurrent threads executing 100 total transmissions with 0 duplicate nonces. Added_Static_assertvalidations fortx_mutexandrx_mutexstruct offsets. -
Tests — C Core Handshake & Scratchpad Verification: Added
test_zero_heap_handshake()incore/tests/test_main.cvalidating complete mock handshake execution, session key derivation parity, and post-handshake memory zeroization. Added_Static_assertvalidations forcipher_suite,scratch, andscratch_lenstruct offsets between C Core and Arduino headers. -
Tests — CoAP RTT & Watchdog Feed Unit Test Suite: Added
test_coap_rtt_estimation()tocore/tests/test_main.cvalidating Jacobson/Karn RTT convergence, retransmission ambiguity exclusion, min/max timeout clamping ($100\text{ ms} \dots 5000\text{ ms}$ ), binary exponential backoff progression, andusmp_port_wdt_feed()invocation counters.
What's Changed
- feat(core,arduino): zero-heap handshake scratchpad & static memory architecture by @winterx64 in #46
- docs(changelog): separate library changes from maintainer tooling by @winterx64 in #47
- feat(transport): CoAP RTT estimation and WDT guard for UDP ARQ by @winterx64 in #48
- feat(core): Split RTOS Mutex Architecture in C Core (#5) by @winterx64 in #49
- feat(core,arduino): Non-Blocking Handshake State Machine & Version Bump to 1.3.0 by @winterx64 in #50
- perf(core): fast table-driven CRC-16 lookup engine by @winterx64 in #51
- fix(arduino): bounded handshake timeouts and watchdog feed in transport loops by @winterx64 in #52
- perf(core): early corrupted packet rejection before payload copy by @winterx64 in #53
- feat(dx): human-readable error translation, binary PSK constructors, and peer teardown status by @winterx64 in #54
- feat(dx): CLI dev server, Arduino Print interface, ESP32 static transports, and documentation overhaul by @winterx64 in #55
- chore: dependency upgrades, MbedTLS 3.x CMake guard, emoji removal, and PR template overhaul by @winterx64 in #56
- fix(ci): suppress powershell progress in arduino zip packager by @winterx64 in #57
- release: USMP v1.3.0 - Embedded Reliability & Zero-Heap Architecture by @winterx64 in #58
Full Changelog: v1.2.2...v1.3.0