Repository navigation
feat: connect over the LAN with the secure channel - #138
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
Adds LAN direct (contracts docs/lan.md) as a transport between Bluetooth and MQTT. When Bluetooth isn't ready and the phone is on a local network, the app looks for the device (the address entered in settings, mDNS, the UDP probe, then the last known address) and connects over TCP with the secure channel, pinned to the device identity enrolled over Bluetooth. - LanCarTransport: a socket with the stream framing and a SecureChannel; keepalives when idle; refuses system commands. - lan_discovery: the UDP probe and a legacy-unicast mDNS query, so no multicast lock or new package is needed. - lanLinkProvider owns the link: searches with a growing delay, drops the link when Bluetooth is ready, searches again when it drops. - The pill, settings, connection log and dashboard tier know the Wi-Fi link; system commands stay Bluetooth-only (carriesSystemCommands). - Settings: a Wi-Fi address row for networks that block discovery. - The device's SystemState.lan_address is kept as the last known address. - lan_constants.g.dart is generated from transport.toml's [lan]. Closes #130 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
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#135 and firmware#136. Requested changes
ResultsTests 8 (flash cost) and 9 (PC plan) are in the firmware PR comments. Setup (2026-12-06)
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
Per the hardware-test review: the LAN carries basic state and commands only, like MQTT, and the pill says Remote for any remote transport (only the connection log names it). A manual Wi-Fi address is used alone. The link closes after receive_timeout_ms of silence, the app searches again right away on resume, and the first search waits briefly while Bluetooth is connecting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkZEiUcxbhmHS339r4nWo6
|
All in d3a9dbd (plus format fixes); tests, analyze and format are green.
Contracts are pinned to contracts#52's b101725 in its own commit. Docs updated (architecture, ui, ui-screens). Generated by Claude Code |
Hardware retest: WiCAN (ESP32-C3) + virtual-carRetest after 555a5d6, 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)
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. R3. A manual address is used alone: pass
R4. Receive timeout, after a board reset: pass
17.2 s from reset to reconnect, against 42.9 s before the change. That fits the 15 s receive timeout followed by an immediate search. R5. Search right away on resume: passScreen off at 04:42:53.8. Android cut the app's network (board: R6. Cold start with Bluetooth on: passApp started at 04:37:07. BLE connected at 04:37:08.8 and subscribed at 09.8, with no LAN connection. Before the change the app did a LAN handshake at every start. R2 (device side of the remote tier), R7–R8 and R9 are in the firmware PR comments. 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 contracts#44: LAN direct in the app. Closes #130. Contract: OpenCarControls/contracts#52; firmware side: OpenCarControls/firmware#135.
When Bluetooth isn't ready and the phone is on a local network, the app looks for the device and connects over TCP, running the secure channel from phase 1 on the socket. Transport selection is now BLE → LAN → MQTT.
lib/transport/lan_transport.dart):LanCarTransportconnects, handshakes with the pinned device identity, carries basic and advanced commands, sends keepalives when idle, and refuses system commands (they stay Bluetooth-only).lib/transport/lan_discovery.dart): the address entered in settings, then the contract order: mDNS (a legacy-unicast query, so no multicast lock and no new package), the UDP probe naming the key ID, the last known address. An address is only a hint; the handshake proves the device.lib/providers/lan_link_provider.dart): searches while Bluetooth isn't ready, the identity is pinned and the client key enrolled; retries with a growing delay; lets go of the link when Bluetooth is ready; searches again when it drops. It owns the link's disposal.TransportType.carriesSystemCommands). Settings gets a Wi-Fi address row for networks that block discovery.SystemState.lan_address(from Bluetooth or the LAN) is kept as the last known address.lan_constants.g.dartis generated fromtransport.toml[lan].How it was tested
test/lan_transport_test.dart(address parsing, the probe and the contract's reply vector, the mDNS parser, discovery order,LanCarTransportover a loopback socket against the fake secure device) andtest/lan_link_test.dart(search order, pinned key, BLE taking over, retry after a drop, no search without an enrolled key or a LAN).settings_test.dartcovers the Wi-Fi tier and the address row.dart format,flutter analyzeandflutter testwere not run; CI is the first run. Formatting was matched by hand.[network.lan] enabled = true) and the phone on the same Wi-Fi.Checklist
feat:,fix:,docs:,chore:); CI validates itdart format,flutter analyze --fatal-infosandflutter testpass (left to CI, see above)docs/or README) updated if behaviour changedconfig.tomlor credentials committed; generated files not hand-editedSafety
Vehicle commands can now go over the LAN, only through the secure channel with the device key pinned over Bluetooth, and only for a phone whose client key the device enrolled. The device still decides availability and authorization (firmware#135 holds every command back for a phone that isn't validated). System commands are refused before sending on the LAN. Pairing and bonding are untouched. The contracts submodule is pinned to contracts#52's branch; it moves to contracts main once that merges.
Generated by Claude Code