Skip to content

TLS client sockets for the Elite II and C64 Ultimate - #1095

Open
JC-000 wants to merge 142 commits into
GideonZ:masterfrom
JC-000:c64u-tls-offload
Open

JC-000 wants to merge 142 commits into
GideonZ:masterfrom
JC-000:c64u-tls-offload

Conversation

@JC-000

@JC-000 JC-000 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

This PR is stacked on #953 and the PRs below it, and it shares the TLS engine with #997, so the two overlap until one merges. The commits specific to this PR are listed under "Change".

Problem

#997 gives C64 programs TLS client sockets (OPEN_TLS, START_TLS, TLS_INFO, TLS_TRUST_CA, TLS_RELEASE) on the Ultimate 64 and Ultimate 64 Elite, with the crypto on the ESP32. On the Ultimate 64 Elite II and the C64 Ultimate, whose control module is u64ctrl, those commands answer 90,TLS NOT AVAILABLE. A C64 program that uses them works on one product family and not on the other.

Change

The same engine (software/wifi/tls/) goes into u64ctrl, so both modules run one TLS implementation.

  • Module. u64ctrl serves CMD_TLS_* (0x30-0x35) from the shared engine: six dispatcher cases, the TLS task started at start-up, tls_rpc_note_block() after every command, and sntp_has_time() for the certificate date check. The reply channel is unchanged. The module version is bumped so the updater installs it; the number is a placeholder for the maintainer to assign at merge.

  • sdkconfig. The Mbed TLS options the engine refuses to build without, as raw_u64 has them: TLS 1.3 with its key exchange modes, HAVE_TIME_DATE, client only, no renegotiation, ChaCha20-Poly1305, software MPI for large keys. The certificate bundle is unchanged.

  • Which products. The gate in network_target.h was (U64 == 1) && defined(NIOS). It now also names the Elite II and C64 Ultimate target (U64 == 2). The RISC-V Ultimate 64 target stays off. make -C target/pc/linux/wifitls test runs the host checks in three passes: Nios II U64, Elite II / C64 Ultimate, and the RISC-V U64, where it asserts the gate is 0. A gate of U64 >= 1 fails that last pass. The Elite II target's Makefiles build wifi_tls.cc, and doc/uci_tls.md lists the products.

  • Recovery and certificate dates. The engine needs Mbed TLS to check certificate dates, which also made the module's https recovery check them. The module has no battery clock, so before SNTP has run every certificate looks not yet valid, and an https recovery server that worked before was refused. The recovery now keeps the bundle's verify callback and clears the four date flags (certificate and CRL, expired and not yet valid) only while the clock is unknown: SNTP has not set it and time() is before 2024-01-01. With a valid clock, dates are enforced. The policy runs before the bundle callback, because ESP-IDF's callback returns at once unless the flags are exactly "not trusted", so clearing the date flags after it left a 1970 clock failing the lookup. A time kept in the RTC across a soft restart counts as valid. Other flags and the manifest signature check are unchanged. recovery.c refuses to build without CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_CROSS_SIGNED_VERIFY, which the built-in servers' chains need. The policy is host-tested against a stand-in for IDF's callback.

  • Voltage read with the radio on. On these products the module reads the supply voltages every 10 s. That read took the entropy gate exclusively even with the radio on, where it does not touch the source. It runs at the lowest task priority, so Wi-Fi tasks preempt it, and a hold longer than the TLS draw's 60 ms wait failed a handshake with NO ENTROPY while the radio source never went off. With the radio on the read now holds the gate shared: draws proceed, a radio start or stop still waits for the read, and a second read gets BUSY. With the radio off (the ADC source on) it still takes the gate exclusively, because it switches the source off. radio_entropy.c is shared with Add NET_CMD_GET_RANDOM: hardware random bytes for C64 programs #953 and is changed here, because only these products have this read.

  • S18 (the module's dispatcher is not blocked). net_tls_test S18 requires that the longest time the module's dispatcher blocked since boot is under 50 ms. The dispatcher sleeps 1 s on MACHINE_OFF and 3 s on MACHINE_REBOOT on purpose, and S18 read 1001 and 3002 ms from those after a power-off or reboot. Those sleeps are no longer counted.

  • WiFi Disabled. On these products the module serves TLS over Ethernet with the radio off, so net_tls_test no longer requires WiFi Enabled on them.

  • Hardening. Three changes from Mbed TLS 4.1.2, for a 4.1.1 build:

    1. The engine refuses a TLS 1.2 ServerHello that leaves the session version above 1.2. That closes the HelloRetryRequest-first case of CVE-2026-115490, equivalent to upstream's fix ff52b208fe for this engine. The host tests hrr_legacy_version_13 and legacy_version_13 fail without the check and pass with it.
    2. secp256k1 and the three Brainpool curves are off in all three module sdkconfig files (CVE-2026-90471). x25519, P-256, P-384 and P-521 stay. The roots in the store use RSA, P-384, P-256 and P-521, so nothing shipped needs the others. Each image is about 13.5 KB smaller (u64ctrl.bin 1,098,272 bytes, 1,111,776 without the hardening).
    3. The recovery HTTPS client of u64ctrl is pinned to TLS 1.2, as esp-tls allows per connection. Both built-in recovery servers speak TLS 1.2.

    No other 4.1.2 CVE reaches this client-only build with variable buffer length off. The one remaining 4.1.2 fix without a CVE, a TLS 1.2 CertificateRequest over-read, is reachable only after the server's certificate and signature are verified. It arrives with ESP-IDF's own Mbed TLS update.

    Accepted limits: a private PKI whose certificates use a Brainpool curve no longer connects, and a recovery server set from the menu that speaks only TLS 1.3 now fails. The hardening is host-tested; it has not run on hardware, and the hardware results below are for the build before it.

  • Docs. doc/uci_tls.md: the product list, the entropy sources on these products (the ADC source with the radio off, the 60 ms wait, status 13 for a source lost mid-handshake), status 90 meaning "the module's application has no TLS" and not a radio state, what a voltage read can do to a draw, and what a wrong clock does to the recovery.

Commits above #997: the module (b303a6b), the gate and Makefiles (acaedf2), the recovery dates (be360de, a09ae10, 9152c4c), the host-test include path (7e64566) and the RISC-V pass (c68b0e1), the voltage read (76c4bad), the S18 and WiFi Disabled change (cb4fc7d), the docs (ebc3c46, 0f52d67, a02bf5d), the module build details (d3e1dd3, ce4f701), and the merges of #997's entropy-gate branch (f8f5fd4, 3509c38, 3cd97ae) and of #997's updated head (1d182c9). For ESP-IDF 6.1.1: the sdkconfig (6ca99a0), the recovery date test's model of the bundle callback (7192935), the Mozilla and Mbed TLS source texts (54abb49), a guard against a null memcpy for an empty step input (9fe692b), and the hardening (a7b992b, 8d6a3e6, 0ebe75d, 7942dd5).

Two TLS engines. #936 adds a second TLS implementation on the same module. I asked in the coordination comment, #936 (comment), whether one engine can serve both; that is not decided here.

Testing

ESP-IDF 6.1.1

Device. One C64 Ultimate: firmware 3.15a, FPGA 126, core 1.50, reporting product Ultimate 64-II. One work-in-progress build (git hash 1a0778724) of the whole stack with this PR and #997 merged in, plus #835 and test-only fixes. It was installed with the updater, the ROMs were written back, and the configuration was reset. The 6.0.3 figures in brackets are from the first round below. The hardening above is not in this build.

The RED column below stays valid: it is master, where the feature is absent. The move from 6.0.3 to 6.1.1 is a toolchain change with no RED of its own.

Test GREEN (6.1.1)
net_tls_test, both routes, Ethernet Final run, all scenarios: GREEN on the REST and the native route, 25 REST and 24 native scenario runs OK, 3,264 s. S18's block_max read 3004 ms. That is the maximum since boot, and it includes the module's 3 s reboot sleep from two soft power cycles earlier in the session (the INFO read before the first scenario already showed it; the 60-minute loop before those cycles read 8 ms), as with the 3002 ms noted below. An earlier run had stopped at S35 and S33 on the native route because the C64U menu was opened at the bench mid-transfer, which froze the C64; the test now reports a frozen or unreadable C64 as a lost link.
run-tests --e2e --profile standard all 73 suite runs passed (72 of 73 on 6.0.3, one failure from the test host)
uci-net-target, deep profile exit 0 over Ethernet and over WiFi
60-minute TLS loop all 29 iterations passed, S18 at 8 ms (6.0.3: 28 iterations)
bulk-aes-gcm (S40), TLS bulk transfer GREEN
61 WiFi Disable/Enable toggles, during handshakes all handshakes verified, net_tls_test exit 0 (6.0.3: 64 toggles)
soak set with WiFi Disabled 10 of 10 suite runs passed (9 of 10 on 6.0.3, where network-connection failed on the test host's ping -w)

ESP-IDF 6.1.1 changed esp_aes_gcm.c, which the engine links; S40 is the hardware check for it.

Open item: net_tls_test against the C64U's WiFi address. The REST route over the WiFi address fails at its first scenario, S0. Its startup sweep sends CLOSE for handles 0 to 15, and over WiFi each CLOSE takes 1.4 to 1.8 s, against 0.62 s over Ethernet. CLOSE 5 got no answer within the sweep's bound and was aborted after 23.6 s, and the run stops there. The time tracks the WiFi link: a REST get_info over WiFi has a median of 64 ms and a 90th percentile of 153 ms, against a median of 12 ms over Ethernet. WiFi power save is off on the device. I have no 6.0.3 run of this suite over WiFi, so I cannot say whether 6.1.1 changed it.

First round (ESP-IDF 6.0.3)

Device. One C64 Ultimate: firmware 3.15a, FPGA 126, core 1.50, reporting product Ultimate 64-II. A work-in-progress build of this branch at a02bf5d, merged with the #997 follow-up test branch, with a bench module version, and with #835 (full-size UDP) as every bench image has it. It runs with the c64-test-harness holding the device lock. After the flash I reset the configuration and set only what each run needs. The S18 and WiFi Disabled change (cb4fc7d) came after this build; see the last row.

Test RED (master) GREEN (this branch)
net_tls_test, both routes (REST and native), full RED as expected over 52 scenario runs, 400s: every TLS scenario answers 21,UNKNOWN COMMAND every scenario passes on both routes, 998 s, except S18 (block_max 1001 ms, the dispatcher sleep above, fixed in cb4fc7d). S32 on REST and S19e, S19e2b on native are skipped by design (a REST call per byte; REST-only abort)
run-tests --e2e --profile standard 72 of 73 suite runs pass, the same single observability failure 72 of 73 suite runs pass. The one failure is the observability self-test case that extracts a still with ffmpeg: this host's ffmpeg rejects the -vsync option
deep UCI suites (uci-net-target, uci-net-route, uci-net-route-precondition, uci-net-tls-selftest) uci-net-target fails: GET_RANDOM and OPEN_UDP_LOCAL answer 21 (UNKNOWN COMMAND), and the empty-UDP READ costs 777 ms more than one that returns at once all 4 pass (net_target_test 340 checks)
64 WiFi Disable/Enable toggles, one every 4 s, while handshakes run (S2, S23, S30, S34) all handshakes verify; S18 fails as above (3002 ms, a reboot sleep)
TLS over Ethernet with WiFi Disabled (S0, S1, S2, S23, S5, S30; real hosts google.com, wikipedia.org, example.com over TLS 1.3, handshakes 1.4 to 2.3 s) 6 of 6 scenario runs GREEN in 221 s, which spans about 20 of the module's 10 s voltage reads
software power cycle from the menu, then the capability record the module comes up with module, entropy and time ready, after each of two cycles
soak 8 of 10 suite runs pass. network-connection fails because this host's ping has no -w. browser-refresh-leak fails: about 1,685 bytes per matrix run (5,056 over 3); later attempts failed earlier, in the filesystem-refresh suite. On master it passed at the first attempt; on this branch it failed the first attempt twice (1,685 and 251 bytes per run) and passed on a retry. This suite measures the file manager, which this branch does not touch; I read it as a borderline slope, not a TLS effect, but I did not establish that.

Final image. A second work-in-progress build that also carries cb4fc7d (the S18 and WiFi Disabled change): net_tls_test --test all on both routes passes every scenario, S18 included (52 scenario runs, 983 s). S18 reads 7 ms right after the flash, 8 ms after a power cycle (3002 ms on the earlier build) and 8 ms after a reboot. On this build: the standard profile passes 72 of 73 suite runs (the same observability host failure; printer-stall needed one retry on its SoftIEC clock timing check); the soak set (run-tests --soak --profile standard) passes 9 of 10, the one failure again network-connection from this host's ping -w, with browser-refresh-leak passing at the first attempt; and a 60-minute TLS loop of S1, S2, S23, S30, S22 and S18, alternating the REST and native routes (28 iterations, 196 scenario runs, real hosts included), had no failures, no handshake timeouts, and S18 at 8 ms throughout.

Host. make -C target/pc/linux/wifitls test (three passes, above), the recovery-dates test, the radio-entropy test (a draw during a read with the radio on, which fails without the change; a radio stop waiting for a read; two reads not overlapping), and net_tls_selftest.

Not tested

  • The hardening has not run on hardware.
  • net_tls_test over the C64U's WiFi address (open item above).
  • The Ultimate 64 Elite II itself, and all Ultimate-II cartridges. The gate change does not touch the cartridge builds, and I did not build or run them for this PR.
  • Heap under two sessions on the device. The only figures are a QEMU estimate: about 33 KB per established session and a peak of about 70 KB for two.
  • A module restart in the middle of a session.
  • The recovery end to end. Only the date policy is tested, on the host.
  • The Keep a WiFi Disable across power cycles on the Elite II / C64 Ultimate #1042 mains-pull leg (settings persistence after pulling the power). Only the software power cycle above ran.

Written with Claude Opus 5.5 in Claude Code.

JC-000 and others added 30 commits October 30, 2026 14:29
…DF 6.0.3

u64ctrl moves to ESP-IDF 6.0.3 (mbedTLS 4) and bumps the module version
so the updater installs it. This changes the toolchain of the C64
Ultimate's power controller, not only of its WiFi: the module runs
power, button and keepalive handling. It is one commit because none of
its parts builds alone: the CMake check stops CI's ESP-IDF 5.3.1 build,
and the recovery code does not compile under mbedTLS 4.

- my_uart.c: uart_periph.h moved from soc/ to hal/, and
  uart_isr_handle_t (a typedef of intr_handle_t) is gone. The same two
  changes GideonZ#996 makes for raw_u64.
- CMakeLists.txt: configure stops on an ESP-IDF older than 6.
- sdkconfig: regenerated by idf.py build from the ESP-IDF 5.3.1 file.
  Values present in both versions are carried; of the 1498 options in
  the 5.3.1 file only the esptool before/after spelling, DHCP option
  length (68 to 69), X509 trusted cert callback and
  ESP_NETIF_RECEIVE_REPORT_ERRORS changed value (SOC_ constants aside).
  Options that are new take ESP-IDF 6's defaults, among them picolibc
  instead of newlib and the FreeRTOS and ring-buffer functions running
  from flash rather than IRAM. Brownout level 7 and the 100 Hz tick are
  carried.
- rpc_dispatch.h: the module version is the next minor above master's,
  see the history line. The maintainer assigns the number at merge.
- CI builds u64ctrl in espressif/idf:v6.0.3, pinned by digest in
  $IDF6_IMAGE; raw_u64 and raw_c3 stay in my_docker_image. The ESP32
  cache key names both images. README.txt and software/u64ctrl/README.md
  say how to build it.

The recovery code from the Wi-Fi recovery change is ported to mbedTLS 4
and PSA Crypto, because it did not compile: mbedTLS 4 has no public
mbedtls/sha256.h and no mbedtls_pk_get_type(). The mbedTLS 4 port is of
code written for mbedTLS 3.

- recovery_verify.c: the key type comes from mbedtls_pk_get_key_type()
  (an ECC public key); the manifest hash is psa_hash_compute();
  psa_crypto_init() is always called, so the init does not depend on
  MBEDTLS_USE_PSA_CRYPTO, which is still defined as a legacy symbol that
  is slated for removal. A failure to start is reported as
  RECOVERY_ERR_CRYPTO ("crypto library failed"), not as a bad signature.
  The signature itself is still checked by mbedtls_pk_verify() with a DER
  ECDSA signature, as before.
- recovery_verify.h, recovery_verify.c: the streaming hash of a
  downloaded file moves out of recovery.c into recovery_hash_*(), on
  psa_hash_*(), so the host test can run it. It also holds the compare
  with the manifest's hash, reported as RECOVERY_ERR_HASH_MISMATCH.
- recovery.c: stream_file() uses it. The checks, their order and the log
  line for a differing hash are as before; a failure of the crypto
  library is logged by name.
- Two result codes are added after the existing ones; nothing that was
  returned before changes.
- The host test links TF-PSA-Crypto from ESP-IDF 6, so it moves out of
  make host_tests, which CI runs in ESP-IDF 5.3.1, into host_tests_idf6
  and its own CI step in $IDF6_IMAGE.

Tests, written first and red against the unported code (recovery_verify.c
cannot include mbedtls/sha256.h under ESP-IDF 6), check by the error each
case names:

- a valid manifest is accepted;
- the wrong key, a tampered manifest, and a manifest correctly signed by
  an RSA key (rsa512.manifest) are refused as a bad signature;
- a changed or truncated image or bitstream is refused as a hash
  mismatch, and so is a file whose manifest hash differs in its first,
  middle or last byte, which a compare that stopped early would accept;
- a crypto library that will not start, or a hash that fails in its
  update or finish, is reported as such, never as a bad signature or a
  match. The test forces these through --wrap=psa_crypto_init,
  psa_hash_update and psa_hash_finish, so the product code carries no
  test hook.
The signed vectors are unchanged; the two RSA files are new.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
On mbedTLS 4, PSA's key slots are protected by a mutex only with
MBEDTLS_THREADING_C. It is ESP-IDF 6's default; the regenerated
sdkconfig had carried 5.3.1's "not set". The WiFi supplicant
(ESP_WIFI_MBEDTLS_CRYPTO, on in this project) imports and destroys PSA
keys now, and it runs next to anything else that uses PSA. The pthread
implementation comes with it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…T buffer

When no UART buffer is free, the receive hook returned ERR_BUF and
wlanif_input() freed the packet. On ESP-IDF 5.3.1 the WiFi driver was
then told ESP_OK; on ESP-IDF 6 esp_netif_receive() passes the error
on, so the driver would see ESP_FAIL on this path. Stock ESP-IDF 6
already returns ESP_FAIL whenever lwIP's input mailbox is full, so the
driver handles it; free the packet here and return ERR_OK only to
leave this path exactly as before. The packet is dropped either way.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
UART1 is routed to the FPGA pins in two places: at boot, in
setup_modem(), and whenever the machine is switched on, in
regulator_enable(). Before either, the pins hold their reset state or,
after check_fpga() or a power off, a pull-down (check_fpga() sets it on
RXD only; the power-off path sets it on all four). ESP-IDF 5.3.1's
uart_set_pin() put a pull-up on RXD and CTS before connecting them,
replacing it. ESP-IDF 6's uart_set_pin() never touches pulls, so RXD
would stay pulled down and CTS at its reset state while the FPGA
configures, reading as a break and as clear to send where 5.3.1 read
idle and not clear.

One helper, my_uart_connect_pins(), sets the pull-ups and then routes
the pins, in that order as 5.3.1 did, and both places call it. While
the machine is off RX and CTS stay routed, pulled down; a boot that
stays off has the pull-ups on for about 100 ms until
regulator_enable(0), the same as on 5.3.1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ESP-IDF 6's brownout interrupt waits for every enabled UART's
transmitter to drain before it resets the chip; 5.3.1 reset at once.
UART1 honours CTS, and CTS idles high through its pull-up when the FPGA
loses power with the machine, so bytes left in the transmit FIFO would
never leave and the wait would last until the 300 ms interrupt
watchdog, ending in a panic reset instead of a brownout reset.

Register a brownout callback, which runs in IRAM ahead of that wait,
that turns CTS flow control off so the FIFO drains. A failed
registration is logged and does not stop the boot.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The host test only used keys of its own. Load every key in
recovery_trusted_keys as an EC public key, require a spare next to the main
key, require that no two shipped keys are the same, and check that a manifest
is verified by a key placed behind all of them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ESP-IDF 6 moved the FreeRTOS queue/task and ring buffer functions to
flash by default (CONFIG_FREERTOS_IN_IRAM and CONFIG_RINGBUF_IN_IRAM are
off); ESP-IDF 5.3.1 had them in IRAM. Every frame passes
xQueueGenericSend, xQueueReceive and xRingbufferReceive in both
directions, so each call can wait on a flash cache miss. Set both options
to put them back in IRAM (12,140 B more shared IRAM/DRAM, 157,151 B of 341,760 stay free; flash code drops by 13,024 B).

The effect was measured on the U64E's classic ESP32 module only (raw_u64:
writemem p50/p90/p99 back in the IDF 5.3.1 range, the REST probe and FTP
get not fully). On this module it is not measured yet; the C64U bench run is pending.
The change is the same two sdkconfig lines.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…flash

The WiFi task runs on core 0. esp_intr_alloc() binds an interrupt to the core it is called on, so my_uart_init() now runs from a short task pinned to core 1, which keeps the UART ISR off the core the WiFi driver is using. The ISR, the UART buffer code, hacked_recv(), dispatch() and cmd_send_eth_packet() move to IRAM with a linker fragment (noflash). The ISR flags stay 0, so the interrupt is masked while the flash cache is off (NVS writes) and nothing in the handler has to be safe to run then; the overflow branch calls the flash function uart_hal_rxfifo_rst(), but RXFIFO_OVF is not in the enable mask, so it does not run. The dispatch task is pinned to core 1 at priority 19 so it runs where the ISR feeds it. Also check the init semaphore and the task create.

The whole of my_uart.c is noflash, so my_uart_connect_pins() and the brownout callback now sit in IRAM too (the callback already was IRAM_ATTR), and the callback is registered from the core 1 task. Neither depends on the core: the brownout interrupt is a separate system interrupt, and the pin routing is called as before from task context. This is harmless.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The RX full threshold drops from 120 to 64 and the TX empty threshold from 10 to 64 (the hardware flow control threshold of 122 is unchanged). At 5 Mbaud the interrupt latency budget before RTS asserts goes from 2 bytes (4 us) to 58 bytes (116 us), and the TX FIFO has 128 us instead of 20 us to be refilled. The margin after RTS asserts stays 6 bytes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…IFI_EXTRA_IRAM_OPT)

The option is off by default for the ESP32-S3 and places more of the WiFi driver send and receive code in IRAM.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Place esp_netif_transmit/receive/free_rx_buffer, wlanif_input, esp_pbuf_allocate/free, wifi_transmit/free, esp_wifi_internal_free_rx_buffer, pbuf_free, pbuf_alloced_custom, pbuf_init_alloced_pbuf, mem_malloc, mem_free, sys_arch_protect/unprotect and sys_mutex_lock/unlock in IRAM (noflash), so the per-packet path between the WiFi driver and the UART bridge no longer calls flash-resident code. What is left in flash is off that path: the one-time sys_mutex_new, the esp_event_post calls guarded by the runtime tx_rx_events_enabled flag, and the command handlers that dispatch() calls for non-packet commands.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
raw_u64 moves to ESP-IDF 6.0.3 (mbedTLS 4) and reports V1.7, so the
updater installs it. raw_c3 stays on ESP-IDF 5.3.1 in my_docker_image,
unchanged.

- my_uart.c: uart_periph.h moved from soc/ to hal/, and
  uart_isr_handle_t (a typedef of intr_handle_t) is gone.
- CMakeLists.txt: CMake 3.16, since the CMake 4 that ESP-IDF 6 ships
  warns that 3.5 is deprecated; configure stops on an ESP-IDF older
  than 6.
- sdkconfig: regenerated by idf.py reconfigure from the 5.3.1 file.
  Values present in both versions are carried unless ESP-IDF 6 forces
  them. Options that are new in ESP-IDF 6 take its defaults, and some
  of those change behaviour: picolibc replaces newlib, FreeRTOS and
  ring-buffer functions other than the ISR ones run from flash instead
  of IRAM, WPA3-compatible mode is compiled in (SAE H2E stays compiled
  in, as in 5.3.1), and esp_netif_receive() now always returns errors
  to the WiFi driver. The toolchain goes from GCC 13.2 to 15.2. A
  second reconfigure and a build leave sdkconfig unchanged.
- rpc_dispatch.h: V1.7, the next minor after master's 1.6. The open
  GET_RANDOM change (GideonZ#953) also wants a minor; whichever of the two
  lands second adapts its number and history line.
- CI builds raw_u64 next to u64ctrl in the espressif/idf:v6.0.3
  image, pinned by digest, and raw_c3 in my_docker_image as before.
- README.txt, raw_u64/README.md and u64ctrl/README.md say which
  ESP-IDF each module needs and how to build it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
On mbedTLS 4, PSA's key slots are protected by a mutex only with
MBEDTLS_THREADING_C. It is ESP-IDF 6's default; the regenerated
sdkconfig had carried 5.3.1's "not set". It makes PSA safe with more
than one PSA user: the WiFi supplicant (ESP_WIFI_MBEDTLS_CRYPTO, on
in this project) imports and destroys PSA keys now, and a TLS engine
would be another. The pthread implementation comes with it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
When no UART buffer is free, the receive hook returned ERR_BUF and
wlanif_input() freed the packet. On ESP-IDF 5.3.1 the WiFi driver was
then told ESP_OK; on ESP-IDF 6 esp_netif_receive() passes the error
on, so the driver would see ESP_FAIL on this path. Stock ESP-IDF 6
already returns ESP_FAIL whenever lwIP's input mailbox is full, so the
driver handles it; free the packet here and return ERR_OK only to
leave this path exactly as before. The packet is dropped either way.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ESP-IDF 6 moved the FreeRTOS queue/task and ring buffer functions to
flash by default (CONFIG_FREERTOS_IN_IRAM and CONFIG_RINGBUF_IN_IRAM are
off); ESP-IDF 5.3.1 had them in IRAM. Every frame passes
xQueueGenericSend, xQueueReceive and xRingbufferReceive in both
directions, so each call can wait on a flash cache miss. Set both options
to put them back in IRAM (about 10.6 KB more IRAM; 31,197 B of 131,072
stay free).

Measured on a U64E over WiFi, one leg per image (the same suite and
commands in each): with these two options the writemem latency (p50, p90,
p99 = 35.8, 82.5, 155.8 ms) is back in the range of the IDF 5.3.1 image
(34.0-35.7, 75.6-85.0, 135.7-158.5 ms); without them it was 40.8, 102.2,
202.7 ms. The REST probe only moves part of the way back (p50 91.3 ms
against 75.6-76.7 on 5.3.1 and 96.7 without), and the FTP get is not
restored.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ntested)

Same IDF 6 fixes as raw_u64: uart_periph.h moved to hal/, uart_isr_handle_t
is gone, CMake 3.16 and an IDF >= 6 check, the receive hook frees the pbuf
and returns ERR_OK when no UART buffer is free, and MBEDTLS_THREADING_C on.
sdkconfig is regenerated by idf.py reconfigure. The version is bumped to
1.7 only to label the image: the U2+L updater does not compare it. Built
only: no U2+L hardware, never flashed or run.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The WiFi task runs on core 0. esp_intr_alloc() binds an interrupt to the core it is called on, so my_uart_init() now runs from a short task pinned to core 1, which keeps the UART ISR off the core (and cache) the WiFi driver is using. The ISR, the UART buffer code, hacked_recv() and dispatch() move to IRAM with a linker fragment (noflash). The ISR is allocated with flags 0 and is not an IRAM-safe interrupt: it must not run while the flash cache is off, and the buffer code it calls is in IRAM anyway. The dispatch task is pinned to core 1 at priority 19 so it runs where the ISR feeds it. Also checks the init semaphore and the task create.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
With raw_c3 on ESP-IDF 6, none of the ESP32 modules needs ESP-IDF 5.3.1
any more, so CI builds all of them with one `make esp32` in the pinned
espressif/idf:v6.0.3 image instead of one module in my_docker_image and
two beside it. The ESP32 cache key no longer names my_docker_image's
image id, since that image does not build them now.

README.txt and the three module READMEs lose the notes that said the
modules need different ESP-IDF versions and that `make` could not
complete with one IDF_PATH. They now say all three need ESP-IDF 6 and
that docker/Dockerfile still installs 5.3.1. raw_c3 gets a Building
section like the other two.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Trigger the RX FIFO interrupt at 64 bytes instead of 120 and the TX empty interrupt at 64 instead of 10, so the receive ISR has more FIFO left to absorb a delayed service. The RTS flow threshold (122) is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ESP-IDF 6 moved the FreeRTOS queue/task and ring buffer functions to
flash by default (CONFIG_FREERTOS_IN_IRAM and CONFIG_RINGBUF_IN_IRAM are
off); ESP-IDF 5.3.1 had them in IRAM. Every frame passes
xQueueGenericSend, xQueueReceive and xRingbufferReceive in both
directions, so each call can wait on a flash cache miss. Set both options
to put them back in IRAM (10,606 B more DRAM, 165,180 B of 321,296 stay free; flash code drops by 10,748 B).

The effect was measured on the U64E's classic ESP32 module only (raw_u64:
writemem p50/p90/p99 back in the IDF 5.3.1 range, the REST probe and FTP
get not fully). On this module it is not measured yet; raw_c3 is only built, not run on hardware.
The change is the same two sdkconfig lines.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Put more of the WiFi driver hot path into IRAM, so frames are not delayed by flash cache misses.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Move the UART ISR, the UART buffer code, hacked_recv(), dispatch() and cmd_send_eth_packet() to IRAM with a linker fragment (noflash). Placement only: the chip has one core, so no task is pinned and no priority changes. The ISR flags stay 0, so the interrupt is masked while the flash cache is off (NVS writes) and nothing in the handler has to be safe to run then; the overflow branch calls the flash function uart_hal_rxfifo_rst(), but RXFIFO_OVF is not in the enable mask, so it does not run.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add noflash entries to the linker fragment for the per-frame path between the WiFi driver and the UART: esp_netif_transmit/receive/free_rx_buffer, wlanif_input, esp_pbuf_allocate/free, pbuf_free, pbuf_alloced_custom, wifi_netif wifi_transmit/wifi_free, mem_malloc/mem_free and esp_wifi_internal_free_rx_buffer.

pbuf_free() and mem_malloc() also take the lwIP lock through sys_arch_protect() and sys_arch_unprotect(), which would still run from flash on every frame, and with -O2 the lock is split into a sys_mutex_lock.part.0 helper that a per-function mapping does not reach. Map the whole sys_arch object to IRAM (about 1.1 KB). cmd_send_eth_packet() and pbuf_init_alloced_pbuf() are inlined at -O2, so they need no entry.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…I_EXTRA_IRAM_OPT)

The option is off by default for the ESP32-C3 and places more of the WiFi driver send and receive code in IRAM.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Set CONFIG_COMPILER_OPTIMIZATION_PERF (sdkconfig as idf.py 6.0.3 writes it, which also drops CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER) and remove the unused _err in cmd_send_eth_packet.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Place esp_netif_transmit/receive/free_rx_buffer, wlanif_input, esp_pbuf_allocate/free, wifi_transmit/free, esp_wifi_internal_free_rx_buffer, pbuf_free, pbuf_alloced_custom, pbuf_init_alloced_pbuf, mem_malloc, mem_free, sys_arch_protect/unprotect and sys_mutex_lock/unlock in IRAM (noflash), so the per-packet path between the WiFi driver and the UART bridge no longer calls flash-resident code. What is left in flash is off that path: the one-time sys_mutex_new, the esp_event_post calls guarded by the runtime tx_rx_events_enabled flag, and the command handlers that dispatch() calls for non-packet commands.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…abled work

On the Ultimate 64 and Ultimate II+L, Disable only stopped the Ultimate's WiFi
task: the module stayed associated and transmitting, and "WiFi Enabled" =
Disabled did nothing until the next boot, which then did not start the module.

Disable and Enable now send CMD_WIFI_DISABLE / CMD_WIFI_ENABLE, as on the Elite II
and C64 Ultimate, and the module serves them with the control module's connector
code: radio_stop() / radio_start() (software/wifi/common, esp_wifi_stop/start in
one place), EVENT_DISABLED, a Disabled state. The WiFi module and task keep
running whatever the setting, so remote wake-up and the default (Enabled) are
unchanged; Disabled means radio off.

- The module starts with its radio off. The task turns it on (setting Enabled) or
  keeps it off (Disabled) as soon as it finds the module. Disabled is shown when
  the module confirms; link events are dropped until then, and after 10 s without
  confirmation the task follows the module's link state again.
- An older Ultimate application never sends Enable: its connection query, with no
  Disable since CMD_IDENTIFY, starts the radio as before. An older module answers
  Disable with "not supported"; the task then holds the module off as before.
- A restart of the module's own (crash, watchdog, brownout) restores the radio as it
  was, from a checked record in RTC memory, and sends EVENT_RESTARTED.
- On the U64 and U2+L "WiFi Enabled" is the one switch: the menu's Enable and Disable (context
  menu and config menu) set it and save it when it changes, and its change hook turns the
  radio on or off; a boot reads it. (The Elite II / C64 Ultimate actions are unchanged.)
- A Disable or Autoconnect taken while the connector walks its AP lists is kept.

Host tests: software/io/wifi/tests (task), software/wifi/tests (module), each with
a -red target that runs the same checks against the code as it was.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…he control module

On the Elite II / C64 Ultimate module, a Disable or Autoconnect taken between two
connect attempts of the scanned or stored AP walks was overwritten by the line
after the loop, so the radio stayed off while the connector thought it was not
disabled, and the next Enable was refused. The walk now moves on only when nothing
set another state. Enable clears an earlier explicit Disconnect, like Connect and
Autoconnect, so Disconnect, Disable, Enable reconnects.

Opening the AP list sends a rescan; with WiFi disabled the module took it as a reason
to start its radio. A Scan while Disabled is now refused by the module and dropped by
the WiFi task, and the AP list is emptied when WiFi is disabled, so no stale entry stays
pickable. The menu actions that scan or connect ("Select AP from list", "Enter AP
manually", "Connect to last AP", a pick from the list) now ask "WiFi is disabled. Enable
it?" while Disabled: Yes enables WiFi and the action goes on (the scan once the radio
is on), No does nothing. On the U64 and U2+L, Yes is the menu's Enable (it sets and saves "WiFi Enabled"); on the
Elite II / C64 Ultimate it is the Enable action. A Connect that the module accepted but that
fails now continues in Disconnected (retry with backoff) in every state, instead of
idling in Connected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Opening the AP list sends a rescan. The WiFi task took its interface down and set
"not connected" when the scan was done, although the module stays associated through
a scan and sends no new connect event: the interface stayed down until the link
dropped and came back. A scan now leaves the interface up and the task returns to the
state it was in. No packet goes out while the scan runs (wifi_tx_packet sends only
when Connected); events the module sent meanwhile are taken afterwards.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The modules connected by SSID with ESP-IDF's default fast scan, which joins the first
AP it hears with that SSID, going up from channel 1: a far AP while a near one was in
the room, and no connection where the network only lets a client join the closest AP.
attempt_connect() now asks for an all-channel scan sorted by signal, so the station
joins the strongest AP of the SSID (the others stay as fallbacks). All connect paths
go through it. The connect takes about one scan of the band longer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
JC-000 and others added 17 commits November 16, 2026 14:57
ESP-IDF 6.1.1 added CONFIG_ESP_WIFI_ENABLE_WPA3_OWE_SOFTAP, which defaults to y. 6.0.3 had no such option, and the module only runs as a station, so it is set to n to keep the 6.0.3 behavior and not link soft-AP code.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The 1.20 line of the version history said the module was built with ESP-IDF 6.0.3. It is now built with 6.1.1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ESP-IDF 6.1.1 added CONFIG_ESP_WIFI_ENABLE_WPA3_OWE_SOFTAP, which defaults to y. 6.0.3 had no such option, and the module only runs as a station, so it is set to n to keep the 6.0.3 behavior and not link soft-AP code.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The 1.13 line of the version history said the module was built with ESP-IDF 6.0.3. It is now built with 6.1.1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ESP-IDF 6.1.1 added CONFIG_ESP_WIFI_ENABLE_WPA3_OWE_SOFTAP, which defaults to y. 6.0.3 had no such option, and the module only runs as a station, so it is set to n to keep the 6.0.3 behavior and not link soft-AP code.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…branch

# Conflicts:
#	software/u64ctrl/main/rpc_dispatch.h
#	software/wifi/raw_c3/main/rpc_dispatch.h
#	software/wifi/raw_u64/main/rpc_dispatch.h
This branch turns off the supplicant's TLS client. The option is ESP_WIFI_MBEDTLS_TLS_CLIENT in 6.0.3 and in 6.1.1 alike; WPA_MBEDTLS_TLS_CLIENT is its deprecated alias. 6.1.1 writes the deprecated-alias block twice, and the merged sdkconfig held the second copy at y, next to the real option set to off. The first build under 6.1.1 resolved the alias to off and rewrote the file. The file now holds what the build produces, so the setting is the same as before.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
esp_crt_verify_callback in esp_crt_bundle.c is the same code in ESP-IDF 6.1.1
as in 6.0.3, so the model the test follows still holds.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The raw_u64 README gave the date of the Mozilla root list that ESP-IDF ships as that of 6.0.3 (2025-12-02). The list in 6.1.1 is of 2026-02-11. The comment on the entropy draws of the TLS engine named the IDF 6.0.3 copy of mbedTLS 4.1.1; it names 6.1.1 now.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fill_step copied the ciphertext and plaintext input of a step with memcpy whatever their length. A step with nothing to send of one kind has a null pointer for it, and memcpy's pointer arguments must not be null even when it copies 0 bytes. Built with UndefinedBehaviorSanitizer, the wifitls host test stopped there ("null pointer passed as argument 2, which is declared to never be null"). Each copy is now made only when its length is not 0. The wifitls and nettls tests pass under the sanitizer.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
mbedTLS's TLS 1.2 ServerHello parser takes legacy_version as the session
version, so a hello claiming 0x0304 carried on in the TLS 1.3 machine without
a key exchange. After a HelloRetryRequest the engine's group check does not
catch it. Refuse it at the ServerHello with protocol_version.

Host test (host-tls rig): hrr_legacy_version_13 and legacy_version_13.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit b759883)
The engine offers x25519, P-256, P-384 and P-521 only; the build also
carried secp256k1 and the three Brainpool curves. The roots in the CA store
use P-256, P-384 and P-521 (and RSA), so nothing shipped needs the others.
Applied to all three module products.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit f2655e3)
The control module's recovery client took TLS 1.2 or 1.3 from the server.
Both built-in recovery servers speak TLS 1.2. Pin it, as esp-tls allows per
connection.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit ec31688)
@JC-000

JC-000 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Hardware check of the Mbed TLS hardening commits (a7b992b, 8d6a3e6, 0ebe75d recovery server pinned to TLS 1.2, 7942dd5 docs) on a C64 Ultimate, flashed with a bench build of this branch's head 7942dd5 together with our other open PRs:

  • TLS E2E suite, all routes: 54 of 54 scenario runs passed
  • uci-net-target, standard profile: passed
  • six passes of a loop over five TLS scenarios: 6 of 6 passed

Written with Claude Opus 5.5 in Claude Code.

@chrisgleissner chrisgleissner added enhancement New functionality or an improvement to existing behavior, including formats and developer tooling. network Networking and remote services: REST, Socket DMA, FTP, Telnet, and online access. uci C64-side Ultimate Command Interface, command targets, and Ultimate DOS commands; REST is network. labels Nov 20, 2026
JC-000 and others added 6 commits November 23, 2026 13:22
Conflicts resolved:
- software/u64ctrl/main/rpc_dispatch.h: master's GideonZ#1097 took V1.30 for the root list
  change; this branch keeps its own V1.31 (ESP-IDF 6.1.1) and carries master's
  1.30 history note below it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Brings in master 40188c7 through the merged pr/idf6-u64ctrl branch (the PR
below this one in the stack, merge/1028-master-1123). No conflicts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Brings in master 40188c7 through the merged pr/2-idf6-r4 branch (the PR
below this one in the stack, merge/996-master-1123). No conflicts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Brings in master 40188c7 through the merged pr/idf6-raw_c3 branch (merge/1029-master-1123).

Conflicts resolved:
- Makefile (host_tests): this branch added four GET_RANDOM host test lines (radioentropy,
  wifirandom, wifidedicated, getrandompaths) where master added the userinterface
  tests line; both kept, so host_tests runs all of them.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Brings in master 40188c7 through the merged uci-net-get-random branch (merge/953-master-1123).

Conflicts resolved:
- Makefile (host_tests): this branch added the wifitls test line where master added the
  userinterface tests line; both kept, so host_tests runs both.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
network_target.cc dispatches the TLS commands to NetworkTarget::open_tls and
four more, which live in network_target_tls.cc, so the network-target test
could not link (upstream CI fails "Test Ethernet Transmit Framing" on it).
The host build has U64 undefined, so NET_TLS is 0 and the file contributes
the "TLS not available" branch the product also uses without the WiFi
module; no fakes are needed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New functionality or an improvement to existing behavior, including formats and developer tooling. network Networking and remote services: REST, Socket DMA, FTP, Telnet, and online access. uci C64-side Ultimate Command Interface, command targets, and Ultimate DOS commands; REST is network.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants