Skip to content

Add NET_CMD_GET_RANDOM: hardware random bytes for C64 programs - #953

Open
JC-000 wants to merge 81 commits into
GideonZ:masterfrom
JC-000:uci-net-get-random
Open

JC-000 wants to merge 81 commits into
GideonZ:masterfrom
JC-000:uci-net-get-random

Conversation

@JC-000

@JC-000 JC-000 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Refs #952. Documentation: GideonZ/1541u-documentation#35. Area contact: barryw (UCI).

Builds on the WiFi PR (#1041, now merged), because GET_RANDOM uses its radio switch (radio_is_on, radio_epoch, radio_start), and on #996 and #1028 (ESP-IDF 6.1.1 for raw_u64 and u64ctrl). The branch is stacked after #1029 as well, and its U2+L commit touches raw_c3. Until they merge, the "Commits" tab also shows theirs; this PR's own commits are the last ones (tests included). Base: master 3db34d2. Module version numbers are placeholders for the maintainer to assign at merge.

Problem

A C64 program on the Ultimate has no hardware source of unpredictable bytes fit for keys or nonces. The SID's voice 3 noise ($D41B) is a 23-bit LFSR on both the UltiSID and a real 8580: a model fitted to one 256-sample block predicted over 99% of what followed. Christian's independent check above, learning from 64 samples, predicted the next 192 exactly. The CIA timers and raster counter share its clock, so mixing them adds only the human-timed moment of sampling. The main firmware has no source either (LWIP_RAND() is rand()). The WiFi modules of the Ultimate 64, Ultimate 64 Elite, Ultimate 64 Elite II and C64 Ultimate are ESP32s with a hardware RNG.

Change

NET_CMD_GET_RANDOM ($20) in the network target, command [target, $20, len_lo, len_hi], len 1 to 512, returned in one reply block:

Status Meaning
00,OK exactly len bytes
81 / 82 malformed command / len 0 or above 512
86,INTERNAL ERROR malformed answer from the module
87,NO ENTROPY SOURCE (new) the module has no entropy source: WiFi application not running, a module without the call (older than the version this PR assigns), a product whose module firmware lacks the call (U2+L) or that has no module (U2, U2+), or a module whose SAR ADC source did not read back
88,ENTROPY SOURCE BUSY (new) no answer within 200 ms, another request in progress, a radio change or a voltage read holds the source; retry

Any status but 00,OK carries no data, and there is no software fallback. The radio being off is no longer a refusal: the call is served with the radio off on the U64, U64 Elite, Elite II and C64 Ultimate.

  • ESP32 (raw_u64 and u64ctrl): new call CMD_GET_RANDOM returns bytes from esp_fill_random(). With the radio on, Espressif documents the RNG as true random. With the radio off, the module enables the bootloader_random SAR ADC source, reads the hardware back, and reports ENTROPY_ADC only if the readback is right; otherwise the answer is 87. Shared code in software/wifi/common/radio_entropy.c keeps radio starts and stops, voltage reads and draws apart with a reader/writer gate, so a draw never straddles a radio change; the call's definitions are in software/wifi/common/rpc_shared.h. The control module (u64ctrl) now starts and stops its radio through the shared code of the WiFi PR (one commit here).
  • U2+L (raw_c3): has no GET_RANDOM; a small commit links the radio entropy hooks into the module so the shared code builds.
  • Ultimate application (wifi_dedicated.cc, Nios on the U64, RISC-V on the Elite II / C64 Ultimate): GET_RANDOM uses its own request channel with a deadline, because the existing RPC reply path waits forever. A reply counts only if command, sequence number and length all match. Built for U64 == 1 and U64 == 2. The C64 Ultimate and Elite II support from the previous revision is kept.
  • All products with a WiFi module (dma_uart.cc): ClearRxBuffer() runs with the scheduler suspended and counts pool resets, so a reply queued before a reset is dropped instead of freed twice.
  • Other products (U2, U2+, U2+L) only get the $20 handler, answering 87, so a program can tell "no source here" from "firmware too old".

Overlaps: #997 (TLS) is stacked on this PR and shares wifi_dedicated.*; in #997 its UNSENT result is mapped to 88. #936 conflicts in u64ctrl's module version and in a few adjacent additions; whichever lands second rebases. #835 adds a switch case and test scenarios next to this one ($16 and $20 do not clash).

Testing

Host tests (macOS, and in the CI image ghcr.io/gideonz/riscv; make host_tests and make host_tests_idf6 RC=0 on this head): the suites for this PR are wifirandom (the module's answer checks), wifidedicated (a scripted FreeRTOS/UART world for the deadline, late and foreign replies, pool resets), radioentropy (the gate and the readback), getrandompaths (the UCI paths the E2E suite cannot reach: 86, a real 88, 87 on a U64, busy mapping, the voltage read) and wifireply; the radio epoch cases are in software/wifi/tests/radio_test.cpp. make host_tests is not in CI for these targets.

Hardware, ESP-IDF 6.0.3. One work-in-progress build (git hash fdb59b059) carried this PR together with the whole stack (#1028, #996, #1029, the WiFi PR, #997) and test-only commits that are in no PR here (the lwIP pbuf pool change for SEND ERROR: 12, and #835). Every PR head is an ancestor of that commit, so this PR's patches are the bench's. The RED runs were on the image before the flash (ESP-IDF 5.3.1 modules, no TLS, no GET_RANDOM); after the flash the config was reset and only needed settings set. Radio-off windows were watched by a sniffer on the bench channel (station frames per second, positive control before each window); the E2E draws on the U64E were made so that they did not turn the radio on. Frames from a MAC other than the station's (the soft AP) are not counted.

Ultimate 64 Elite (U64E), firmware 3.15a, core 1.50, Ethernet for the commands:

Test RED (pre-flash image) GREEN (fdb59b059)
get-random-lengths, -bytes-vary, -refusals, -leaves-sockets-alone, -radio-off all FAIL with 21,UNKNOWN COMMAND; the control read-length-limit passes (14 checks) radio on: 12/12 sessions exit 0, 0 x 87/88, 0 FAIL
Menu Disable, then 20 draws of 32 bytes n/a (no call) 20/20 00,OK, 32 bytes each, no repeats, no 87/88; 0 station frames from 2.5 s after the Disable (last frame) to 139 s, including the draws; row and item Disabled before and after
get-random-radio-off (WiFi Enabled set to Disabled, draws, set back), 11 runs FAIL (21,UNKNOWN COMMAND) 11/11 OK (5 checks), 0 x 87/88; counted window per run (8.3 s): frames only in 1 sniffer second, 0.1 to 0.9 s after the set (the radio stopping), none after
Stored WiFi Disabled, plug pulled, power button n/a boots radio-off; 10/10 00,OK 32 bytes, no repeats, 0 frames in the 123 s after the REST API answered
uci-net-target, deep profile exit 0 over Ethernet and over WiFi; Ethernet run: 26 GET_RANDOM lines, 0 x 87,, 0 x SEND ERROR: 12

C64 Ultimate (C64U), firmware 3.15a, core 1.50:

Test RED (pre-flash image) GREEN (fdb59b059)
get-random-lengths, -bytes-vary, -refusals, -leaves-sockets-alone all FAIL with 21,UNKNOWN COMMAND; read-length-limit OK; -radio-off SKIP (the C64U has no such setting) radio on, 15/15 sessions exit 0, 0 x 87/88
Menu Disable (240 s window), draws during it n/a all 00,OK, 0 x 87/88; 0 active sniffer seconds of 236 in the window (positive control 23 of 26 s before); last station frame 2.3 s after the Disable; row Disabled before and after the draws
10 menu Disable / Enable cycles, a draw session after each Disable and each Enable n/a 10/10, all OK, 0 x 87/88, 0 active seconds in all 10 Disabled windows (about 11 s each, so short; the 240 s window is above)
uci-net-target, deep profile exit 0 over Ethernet and over WiFi; 82 GET_RANDOM lines each, 0 x 87,, 0 x SEND ERROR: 12

What hardware shows: with the radio off, from the menu on both machines and from "WiFi Enabled" on the U64E, GET_RANDOM is served, the sniffer sees no station frames while it is, and the bytes do not repeat. Where the bytes come from rests on the code and the host tests, not on hardware: the Ultimate drops the source field and the bench has no way to read which source the module used, so the SAR ADC path (bootloader_random) is checked by the host tests and by reading the code, not by a hardware readout.

Again on ESP-IDF 6.1.1. The modules of this PR build with 6.1.1 (bootloader_random and the hardware RNG code are the same as in 6.0.3), and one work-in-progress build (git hash 1a0778724) carried them to both devices. U64E, WiFi stored as Disabled, plug pulled, power button: boots radio-off and 10/10 GET_RANDOM draws answer 00,OK (10/10 on 6.0.3). uci-net-target, deep profile, which draws GET_RANDOM, exits 0 over Ethernet and over WiFi on the U64E and on the C64U. The sniffer windows and the menu Disable/Enable cycles in the tables above are from the 6.0.3 image.

Not covered

  • No Ultimate-II cartridge was tested. U2, U2+ and U2+L builds were compiled only. The Elite II builds the same target/u64ii application and u64ctrl module as the C64U and was not run. The U64 (non-Elite) was not run.
  • The source used with the radio off (SAR ADC, bootloader_random) has no hardware readout (above).
  • A real 88 while TLS holds the module channel was not provoked on hardware: it needs one program interleaving both on one UCI client. The UNSENT to 88 mapping rests on the host tests.
  • GET_VOLTAGES after a radio-off draw on the C64U shares the SAR ADC; the voltage read takes the same gate, and its effect on the readings was not examined on hardware (no voltage readout).
  • radio_stop() skipping the RF stop would not show in frame counts; an ACK-probe test is future work.
  • On a U64 or U64 Elite, the suite's get-random-radio-off turns "WiFi Enabled" off and back on; on the C64U it is skipped.
  • CI runs neither host test target for these suites.

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. 3.16 Targeted for release 3.16. uci C64-side Ultimate Command Interface, command targets, and Ultimate DOS commands; REST is network. network Networking and remote services: REST, Socket DMA, FTP, Telnet, and online access. labels Oct 4, 2026
@chrisgleissner

chrisgleissner commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

Hi @JC-000,

Thanks a lot for this PR. The description is excellent, particularly the explanation of how it fits alongside the other work, the merge compatibility checks, and the detailed test results.

I like your incremental approach: establish the foundations first, then build on them. The code also appears consistent with the existing style.

Having read #952, I understand that your planned series provides TLS sockets through the network target, whereas #936 adds HTTPS to the existing HTTP target. Do you see these as complementary features that we should aim to support together? It would be useful to agree how the related TLS work should fit together before the later PRs arrive.

It may also be worth giving the discussion in #952 some time to gather further feedback before progressing much further with implementation. Early implementations can be valuable prototypes and help make the discussion concrete, provided there is room to reshape them substantially as we agree on the direction.

One practical concern is balancing reviewability with testing. Smaller PRs are easier to review, but a growing stack of unmerged dependencies makes it harder for testers to obtain a build containing the complete feature. Combining everything into one large PR creates the opposite problem.

Your plan to submit the PRs one at a time sounds sensible. I would suggest pacing them around review, testing, and agreement on the direction. Alongside the implementation, we need time for discussions with testers and other firmware developers so we can settle on an approach and work towards merging it.

Thanks again for starting this work and putting so much effort into making it reviewable. It is good to have more options.

@enver-haase

enver-haase commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

For what it's worth, Sid Meier's 'Pirates!' is testing the SID and reports if the random generator is broken or not.

I also cannot hold back with my opinion here: I am totally bewildered by the idea of erecting a massive wall of API for an FPGA C64 to use, so that new programs are just 8-bit control stubs navigating some 64-bit operating system's methods and resources - and will no longer run on classic C64s.

If the random number generator is broken in the SID, fix the SID.

That said, I do see the effort and the good intentions - so I hope I don't sound too harsh. I do believe though that C64 programs do not belong in the firmware or even gateware. But it is not my call, of course.

@chrisgleissner

chrisgleissner commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Hi @enver-haase, thanks for sharing your thoughts. Was your Pirates! point mainly about checking whether the FPGA SID behaves like the original? I may have read more into it than you intended.

This is just additional fact finding on randomness and TLS. I'll leave the architecture, API scope and C/VHDL decisions to @GideonZ.

TLS requires a cryptographically secure generator, properly seeded so that observing public random values doesn't reveal secret key material (RFC 8446, C.1 and C.3). It doesn't prescribe a particular hardware source or universal seed size.

There is a reproducible SID check in the published captures: take the second 256-byte block of A_ulti_tb1_1M.bin or F_real_1M.bin, learn a linear recurrence from bit 7 of the first 64 bytes, then apply it to the byte values to predict the remaining 192. I independently checked this: 192/192 predicted exactly for both captures, without using those later bytes to fit or align the prediction. That's one board and sampling setup, but it backs up the concern about relying on SID output alone.

For other sources, SP 800-90B provides raw-sample assessment, restart tests and health checks. Those still need evidence about the underlying noise mechanism; there's no single output test that proves cryptographic security.

One existing hardware possibility is the ESP32: Espressif documents physical entropy with RF enabled or its internal SAR ADC entropy source explicitly enabled. Whether that fits the project is a separate decision.

Hope this helps clarify the SID/TLS question. Thanks!

@enver-haase

Copy link
Copy Markdown
Contributor

@chrisgleissner Much narrower than that. All I had in mind was that Pirates!, as far as I remember, complains when there is no SID, because its random numbers come from the SID's noise. I didn't know whether that makes the SID a good random source, let alone one good enough for TLS. Your 192/192 prediction answers that: it isn't. Thanks for checking.

@JC-000

JC-000 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

I've shortened the description to fit the new CONTRIBUTING.md (#965): problem, change, testing (now naming the host), and what isn't covered. Nothing in the code changed. The full original write-up is still linked from the Testing section, including the security reasoning with file:line references, the timings and the per-mutant results.

@enver-haase and @barryw, I've mentioned you as the network and UCI contacts the guide lists.

@enver-haase

enver-haase commented Oct 14, 2026 via email

Copy link
Copy Markdown
Contributor

@JC-000

JC-000 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

@enver-haase Yes, it was considered. It's the same case as the CIA timers in the description, and it isn't enough for keys.

  • TI is the jiffy clock: ticks of 1/60 s since power-on, counted from a CIA timer interrupt and wrapping after 24 hours. Its only unknown is when the program read it. If an attacker knows that to within a minute, that's 3,600 possible values, about 12 bits. Even a whole day is only about 22 bits. A TLS key needs 128 or more.
  • RND(-TI) doesn't add anything. RND is a deterministic generator with a few bytes of state, so everything it returns follows from the seed. Seeding it with TI still leaves those 12 to 22 bits.

It's fine for games. Keys for cryptography need a source an attacker can't reconstruct, which is why #953 reads the ESP32's hardware RNG. If we want TLS or HTTPS in the Ultimate network interface, we must have a real RNG. At that point exposing it to the C64 via UCI is basically free and would close the RNG gap for anyone that wants to do strong cryptography like in my C64-https and C64-wireguard projects.

JC-000 added a commit to JC-000/c64-https that referenced this pull request Oct 15, 2026
…te over its include closure

adv-296 round 2 on #300:
- The source for $20-$25 IS public: JC-000/1541ultimate esp32-tls-offload
  (tip 72f33796, network_target.h defines $20-$25, the 90-94 lines are in
  network_target.cc), linked from GideonZ/1541ultimate#952. FIRMWARE_SOURCE
  says so, that the demo has not run on a build of it, and the upstream
  status says not upstream (GideonZ/1541ultimate#953 is GET_RANDOM only).
- 'No demo image has been run on any firmware but the build named above'
  was false: the script's own history validated earlier images on
  esp-tls/m3 f2e46946. The line is now per-image (none recorded for a
  non-measured PRG) plus EARLIER_RUNS.
- The adapter gate diffed src/net/uci-m3 only, so a change to
  src/net/uci/uci_regs.inc (uci_fence) moved the PRG and the README still
  said 'unchanged'. It now diffs every file in build/net/uci-m3/*.d plus
  cfg/c64-https-uci-m3.cfg, and names the files that changed.
- #296, not #296.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@JC-000 JC-000 changed the title Add NET_CMD_GET_RANDOM: Provide C64 programs hardware random bytes from the U64's WiFi module Add NET_CMD_GET_RANDOM: Provide C64 programs hardware random bytes from the WiFi module Oct 18, 2026
@JC-000

JC-000 commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

Extended to the Ultimate 64 Elite II and the C64 Ultimate: four commits on top of a9f30d23, a fast-forward, head now 03cfc648. The description is updated.

  • What changed: u64ctrl, the module of those two products, now answers CMD_GET_RANDOM with the same wire format (module version 1.14 → 1.15; Add authenticated HTTPS to the existing target 6 HTTP interface #936 sets 1.18 and enables its TLS from 1.16, so if it lands first this PR takes 1.19). The definitions moved to software/wifi/common/rpc_shared.h, shared by both modules and the Ultimate application. The Ultimate application serves it on the U64 (Nios) and on the Elite II / C64 Ultimate (RISC-V). The e2e suite now expects bytes from those products while the radio is on. Nothing else changed.
  • WiFi disabled: 87 on every product. A U64 / U64 Elite then stops its WiFi application; u64ctrl stops the radio, and the ESP32-S3 RNG is true random only while the RF subsystem or the SAR ADC runs (ESP32-S3 TRM, "Random Number Generator"). A draw during which the radio was stopped is refused too. A separate follow-up addresses the radio-off case. Clients have to handle 87 regardless.
  • Evidence, C64 Ultimate, 2026-10-17, uci-net-target, Spike for #807: NET_CMD_WRITE_SOCKET_CHUNK ($16), a payload larger than one command as one datagram #835 merged into each bench image (it is not part of this PR):
    • a9f30d23 firmware built for this product: every GET_RANDOM scenario that expects bytes gets 87,NO ENTROPY SOURCE. Suite FAIL.
    • 03b5034e: quick suite OK, 47 checks; full suite OK, 237 checks, 843 s; REST and native route.
    • Radio, switched from the menu and read with the menu closed: on, 00,OK 32 bytes; WiFi Disabled, 87 with no data, 5/5; enabled again, 00,OK 5/5. A mutant with entropy_source() forced to "radio on" still answers 00,OK with WiFi Disabled, so the check discriminates.
    • The U64 Elite results are for a9f30d23, not re-run. At 03cfc648 the U64's raw_u64 image differs only in the build time, the ELF hash and the checksum and digest over it, and the U64 application's code and read-only data are identical to a9f30d23's apart from the build time and build-machine strings (objdump in the evidence).
  • Merge conflicts: Machine code monitor debugger #705 is clean. Add authenticated HTTPS to the existing target 6 HTTP interface #936 now conflicts in four files (u64ctrl's rpc_dispatch.h module version, the esp_depends.py directory list, u64ctrl's CMakeLists.txt, the u64ii Makefile), all adjacent additions. Merged, the Elite II image has both Add authenticated HTTPS to the existing target 6 HTTP interface #936's receive hook and this PR's reply channel. The hook only takes Add authenticated HTTPS to the existing target 6 HTTP interface #936's 0x30/0x31 frames, so they don't meet (read, not run). Whichever of us lands second rebases. Spike for #807: NET_CMD_WRITE_SOCKET_CHUNK ($16), a payload larger than one command as one datagram #835 conflicts as before.
  • Evidence head: the C64 Ultimate runs are at 03b5034e; 03cfc648 changes one test comment.
  • Not run: the Ultimate 64 Elite II (same target/u64ii application and module as the C64 Ultimate) and the U2 family.

The Elite II / C64 Ultimate commits (50d3d906, 509ac24b, 03b5034e, 03cfc648): written with Claude Code; reviewed adversarially by Claude Opus.

🤖 Generated with Claude Code

@JC-000

JC-000 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

I moved GET_RANDOM's internal module RPC from 0x1A to 0x20 (74bc02e). #1012 uses 0x1A/0x1B for the recovery URL, and 0x20 matches the UCI command number ($20). It's a three-line change in rpc_shared.h and two comments. The UCI command and its behaviour are unchanged, and the host tests pass.

JC-000 and others added 5 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>
JC-000 and others added 2 commits November 12, 2026 13:23
…ci-net-get-random (base update for GideonZ#953)

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

# Conflicts:
#	software/io/network/network_target.h
…rom master

Master moved command execution to a worker task: the commands run in
NetworkTarget::execute(), and network_target.h includes FreeRTOS and takes
CMD_MAX_COMMAND_LEN. The test cut the GET_RANDOM case out of parse_command(),
which no longer holds it, and did not build against the new header.

It now cuts the case out of execute(), supplies the FreeRTOS stand-ins that
the wifi_dedicated test already has, and defines CMD_MAX_COMMAND_LEN in its
command_intf.h stand-in. No product code changes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@JC-000

JC-000 commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Merged the updated #1029 into this branch (a51f7a9). #1029 now contains #1028, #996 and current master. There was one conflict, in network_target.h, and both sides stay: master's new worker-task declarations and this PR's reply-block check. With master's worker-based NetworkTarget, GET_RANDOM now runs in the worker's execute(). The getrandompaths host test no longer compiled against that, so a separate commit fixes it; that commit changes only the test. make host_tests and make host_tests_idf6 pass, the three ESP32 modules build in ESP-IDF 6.0.3, and the U64 and U64-II firmware build. The merged head has not been run on hardware yet.

Written with Claude Sonnet 5.5 in Claude Code.

JC-000 added a commit to JC-000/1541ultimate that referenced this pull request Nov 13, 2026
…aster) into pr/3-tls-r1 (base update for GideonZ#997)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
JC-000 and others added 23 commits November 16, 2026 14:25
The build instructions name the 6.1.1 image, and the sdkconfig is regenerated by 6.1.1 with every existing value unchanged, including the IRAM placement options.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The build instructions name the 6.1.1 image, and the sdkconfig is regenerated by 6.1.1 with every existing value unchanged, including the IRAM placement options.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
CI and the build instructions move from the 6.0.3 image to espressif/idf:v6.1.1, pinned by digest. The sdkconfig is regenerated by 6.1.1; every value the module sets is unchanged, including the IRAM placement options (FreeRTOS, ring buffer and Wi-Fi in IRAM). Its mbedTLS is the same Mbed TLS 4.1.1 commit as 6.0.3.

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

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The reason codes WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT, _AUTH_FAIL and
_HANDSHAKE_TIMEOUT keep the values 15, 202 and 204 in ESP-IDF 6.1.1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The 1.31 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.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
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>
@chrisgleissner

chrisgleissner commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Hi @JC-000 ,

Thanks for fixing the merge conflicts.

Also, this PR changed over 100 files. I suppose you have already done so, but would you mind again adversarially reviewing this PR with Opus 5.5 High or Sol 6.2 High, ensuring it is minimal whilst being architecturally consistent?

I am basically keen to get your PRs merged, and having a long list of unmerged PRs adds overheard not just for you (keeping them merge ready), but also for us as repo maintainers (trying to make sense of all these outstanding changes and their interdependencies).

Having said that, I am most grateful for your efforts and especially your attention to detail.

Thanks

@JC-000

JC-000 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@chrisgleissner, first why this PR is not small and not standalone: GET_RANDOM is tied to the WiFi module work, because without that work it does not always have an entropy source. The bytes come from the ESP32's hardware RNG, which is only a true random source while the radio is on. Since #1041, WiFi Disable turns the radio off, so the PR also gathers entropy with the radio off, from the SAR ADC. On the ESP32-S3 (Elite II and C64 Ultimate) that source only works on ESP-IDF 6, so the PR sits on the three ESP-IDF 6.1.1 PRs. That is where the 104 files come from; the PR's own share is 74 files, about 1,300 lines of product code and 3,600 lines of tests.

I had it reviewed again against "minimal whilst architecturally consistent". The answer is that it is not minimal. The findings:

The review found the behaviour itself sound: the command runs on the network worker and not on the UCI task, the two error statuses are right, and the answer buffer is cleared before it is filled.

What I will do: remove the second reply mechanism and the redundant check, cut the tie to #1029, and move the tests into the suites CI runs. Radio-off entropy stays, since a random source that stops when WiFi is disabled is not one a program can rely on. My estimate is that the PR's own share drops from 74 to about 55 files and to about 1,050 product and 2,400 test lines. #997 shares the reply mechanism and will be adapted to match. The changes go on as new commits; the module changes get a hardware run before I ask for a merge.

Written with Claude Fable 5.2 and Claude Opus 5.5 in Claude Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.16 Targeted for release 3.16. 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.

3 participants