Repository navigation
feat(lan): serve the secure channel over TCP on the LAN, with UDP discovery - #135
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
…covery core-interface gets lan.rs: connection slots, frames in and out per connection (command responses, a system state with the client's command availability and the LAN address, the full vehicle state), the UDP discovery reply and the mDNS TXT records. Sessions now know whether their link is LAN or relay, and handshake inits are rate-limited before any X25519 work. SystemState.lan_address goes out over BLE too. The PC board serves it with [network.lan] (non-blocking sockets polled from one task, mDNS through mdns-sd), and tools/lan_client.py plays the app's part for an end-to-end test. Closes #120 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
Enrolling a client key needs a validated phone, so the LAN tests validate both phones, enroll them, then end the validations by approving another car, like the secure channel tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
Hardware test: WiCAN (ESP32-C3) + virtual-carTested together with contracts#52, firmware#136 (built on top of this PR; the WiCAN ran #136) and mobile-app#138, plus this PR's own PC test plan. Requested changes
ResultsSetup (2026-12-06)
9. [PR #135] The PR's PC test plan: passTwo clients enrolled through the BLE mock, A from 127.0.0.1 and B from 172.17.0.2 (the mock tells phones apart by IP).
On the WiCAN (with firmware#136, which carries this PR's core): 1. [Analysis] Boot, and Bluetooth with the new app: passThe boot log shows 2. [PR] Bluetooth off → Wi-Fi, commands, connection log, settings: pass, but see the tier change below
Lock and unlock work over Wi-Fi. The connection log shows Wi-Fi connected, and Settings hides the Bluetooth-only sections and shows the Wi-Fi address row. The availability over LAN follows the dev lock (dimmed while locked), and the dev lock can only be unlocked over Bluetooth, as expected for a system command. 3. [PR] Discovery, from the container: pass
4. [Analysis] Strangers on the LAN can't push the phone off: pass (twice)With the phone's session in slot 0, three raw TCP connections were opened one second apart and never handshaked. Each took slot 1 from the previous one, and the last was closed 10.0 s after connecting. The phone's session never dropped. The free heap was 66380 B with the phone alone and 65892 B with the phone and one stranger. 5. [PR] Board reset while on Wi-Fi: pass, but slow on the direct path
Through the VPN, the subnet router reset the dead connection quickly. On the direct path nothing tells the app the board is gone, so it waits for its idle keepalive (see mobile-app#138). 6. [Analysis] Bluetooth back on → LAN released: pass (twice)Direct: BLE connected at 01:36:45.9, the app subscribed at 01:36:47.46, and the LAN connection was 7. [PR] Manual Wi-Fi address: pass as built, but the requested behaviour changes (see mobile-app#138)With 10. [Analysis] Screen lock and unlock on Wi-Fi: passScreen off at 01:33:53, and Android cut the app's network about 4 s after it stopped (board: Not tested: an address change from DHCP or a WiFi reconnection, the heap with MQTT over TLS, two real phones on the LAN at once (the second session was a PC client), iOS, LTE builds (LAN is left out by design), E-GMP in the car, and the 0x310 frame on |
…racts#52) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
- A secure channel session gets the basic vehicle state only, and its client's advanced commands are reported unavailable and refused with REJECTED_UNAVAILABLE: reaching the device over a network is no proof of being at the car. - The system state repeats every LAN_SYSTEM_STATE_REPEAT_MS (from the contract), which the app's receive timeout relies on. - lan_mdns_instance_name: the BLE name and the key ID's first four characters, so the PC board announces the same name as the ESP. - lan_is_open, for the boards' logs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
|
Both done in a7bb7fe:
CI is green. Generated by Claude Code |
Hardware retest: WiCAN (ESP32-C3) + virtual-carRetest after a7bb7fe, together with contracts#52 All the requested changes check out. Nothing is left to change from the hardware side. Setup (2026-12-06, same bench as the first test)
R2. Wi-Fi is the remote tier, on the device (PC): passOver the LAN session, decoded:
Regression: with two sessions open, a third connection is still refused ( R1. Wi-Fi is the remote tier, in the app: passBluetooth off at 04:38:29.19 → LAN connected at 29.39, handshake 190 ms. The pill says Remote, and the dashboard is the remote one (car picture, Doors, Driving, Odometer; no Gear, Speed or Custom 1). Doors lock and unlock work. The connection log says it's Wi-Fi, and Settings still hides the Bluetooth-only sections. Bluetooth back on: BLE connected at 04:56:05.30, and the LAN connection was closed by the app at 06.82. R7. mDNS instance name: passESP: R8. Log reason for a replaced connection: passThree raw TCP connections from the container while the phone held slot 0: both replacements logged as Not retested (code unchanged): the probe byte format and its rate limit, the 10 s handshake timeout. Still not tested: an address change from DHCP or a WiFi reconnection, the heap with MQTT over TLS, two real phones, iOS, LTE builds, E-GMP in the car, |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
Requested by Michaël · project thread
What and why
Phase 2 of OpenCarControls/contracts#44 (LAN direct), firmware core and PC board. Closes #120. Implements OpenCarControls/contracts#52 (contracts#47); the submodule is pinned to that PR's branch in its own commit, to re-pin to
mainonce it merges.core-interface
lan.rs. The board stays dumb:lan_acceptgives it a connection slot,lan_receive_frametakes a frame (without its length prefix) and returns the reply,lan_next_frame/lan_try_next_framegive the next sealed frame, andlan_should_close/lan_closehandle closing.lan_address, sent when the session starts, when either changes, and every 5 s;LAN_MAX_CLIENTS(2). When both are taken, a connection without a session loses its slot. When both have sessions, the new connection is refused. A connection is closed if it has no handshake within 10 s, or once its sessions have ended.lan_discovery_reply(the probe and reply from the contract, rate-limited) andlan_mdns_txt(id,v).ChannelLinknow has aLinkKind(LanorRelay). LAN responses go to their connection's queue, and relay ones keepSECURE_TX_CHANNEL. Handshake inits are capped atMAX_HANDSHAKE_INITS_PER_SECOND(8) before any X25519 work. New helpersnewest_sessionandhas_open_session, plusclient_command_availability_at.SystemState.lan_addressalso goes out over BLE with the CAN access state, and again whenever it changes.PC board:
lan_task(port, name, mdns)polls a non-blockingTcpListener, its connections and the UDP discovery socket from one Embassy task, so a slow client can't freeze the executor (#89). It reports its IPv4 address (checked every 30 s). mDNS goes throughmdns-sd(0.22, its own thread). I did mDNS on PC, behind[network.lan] mdns.xtask:
[network.lan](enabled,portdefaulting to the contract's,mdns), documented inconfig.toml.example(off by default). The PCmain.rsgets{LAN_SPAWN}. ESP builds print a warning and ignore it until #121.End-to-end client:
tools/lan_client.py(Pythonnoiseprotocol, run withpython -I).setuppairs, approves, validates (cluster code from the log) and enrolls through the BLE mock.discoversends the UDP probe.run --lockhandshakes and prints the handshake time, the state and the command's response.Docs: new
docs/lan.md, plusdocs/architecture.mdand the README.How it was tested
protoc, so nothing that buildscore-interfaceran. CI on this PR is the first compile, and I'll fix what it finds.cargo fmt --all -- --checkandcargo clippy --package xtask -- -D warnings.main.rswith LAN on (thelan_taskspawn is right).mdns-sd0.22 calls, in a scratch crate.tools/lan_client.py's Noise and protobuf helpers, checked against a Python responder (message sizes 96 and 48, as in the contract).core-interface/tests/lan.rs:[network.lan] enabled = true):tools/lan_client.py setup, thendiscover, thenrun --lock. Check thatcandump vcan0shows the 0x310 command frame.runagain does a fresh handshake.LAN: refused).avahi-browse -r _opencar._tcpshowsidandvonly.Checklist
cargo fmt --all -- --check,cargo xtask clippyandcargo xtask testpass: fmt passes; clippy and tests are left to CI (noprotochere)docs/or README) updated if behaviour changedconfig.toml, credentials, build artifacts or.binfiles committed (.lan-client.jsonis gitignored)Safety
LAN commands go through the same
handle_secure_messagepath as phase 1: they get the same checks as the phone over BLE, and system commands are dropped. Thesource_device_idcomes from the session's client, never from the app. Nothing new reaches CAN TX.Generated by Claude Code