Skip to content

feat(mirror): Sync books over the phone's mobile data (hotspot + proxy shim) - #26

Draft
ynsgnr wants to merge 14 commits into
develop-retinkfrom
feat/mirror-wifi-sync
Draft

ynsgnr wants to merge 14 commits into
develop-retinkfrom
feat/mirror-wifi-sync

Conversation

@ynsgnr

@ynsgnr ynsgnr commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Draft: not run on hardware. App side: ynsgnr/retink#11 (stacked on #8/#10). Contains #21's commits (the pairing code and link guard): this PR targets develop-retink so that CI publishes it as the OTA channel pr-26; its own change is the two commits after #21.

What it does

Mirror > Sync books over phone runs the stock OPDS sync through the phone's mobile data. The phone (Retink app, Wi-Fi sync switched on) opens a LocalOnlyHotspot and a proxy that leads out through cellular and offers both over the encrypted BLE link. The device joins the hotspot, turns on a proxy shim, runs opdssync::syncNow() (it finds Wi-Fi already up and skips its own join) and then always undoes everything: shim off, Wi-Fi off, phone told done. The phone also stops on its own after 10 minutes or when the BLE link drops.

The shim, and why it is not in the SDK

All HTTP goes through the FreeInk SDK's SecureHttpClient, which opens its own sockets. Instead of changing the SDK, the two lwIP calls every connection ends in (lwip_getaddrinfo, lwip_connect) are wrapped by the linker (-Wl,--wrap=... in platformio_mirror.ini, the same technique as the OTA loop hook). While on: a host name gets a fake address and connecting to it sends CONNECT name:port to the phone and waits for 2xx; TLS runs through the tunnel as before. While off (always, except during this sync) both hooks pass straight through. UDP, IPv6 lookups, the proxy itself and the hotspot subnet are never touched. No SDK change, no upstream file change.

The updater is protected from it

MirrorUpdateActivity switches the shim off when it opens and uses the plain sockets, so a build with a broken shim can still fetch its own fix over normal Wi-Fi and does not need a USB cable. A build that does not boot is still handled by the fallback (#22).

Checks run

cmake/ctest mirror: 596 checks, 0 failures. New: ProxyShim (fake addresses, CONNECT reply parsing), ProxyHook (the real ProxyHook.cpp against a fake proxy, lwIP mapped to POSIX), PhoneSync (order, refusals, failures, cleanup), session sync messages. macro ctest, check-manifest.sh, OTA test.sh ok; clang-format ok. MirrorPhoneSync.cpp and the hook's lwIP linkage are compiled for the device only by CI.

Verify on hardware (in this order)

  1. Normal Wi-Fi sync and the firmware updater still work (the pass-through).
  2. Phone app from retink#11 with Wi-Fi sync on: Mirror > Sync books over phone. The status line goes asking, joining, syncing; PROXY log lines show each tunnel.
  3. A wrong state is safe: phone app Wi-Fi sync off shows "Wi-Fi sync is off in the phone app"; kill the app mid-sync: the hotspot disappears.
  4. Check that the hotspot band is 2.4 GHz for the X4 Pro (it was on a Pixel 10 Pro).

🤖 Generated with Claude Code

ynsgnr and others added 3 commits November 21, 2026 20:13
… shown on the device

- LinkGuard: a central that is not encrypted and authenticated within 5 s (60 s while pairing) is disconnected, so one stranger cannot hold the only slot.
- Pairing code: advertises features.pairing_code, shows the code the phone sends (pair_code) until pair_ok. Generated files synced from the retink spec (protocol version unchanged).

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

While a phone sync runs, every TCP connection leaves through the phone's proxy: a name lookup returns a fake address (198.18.x.y) and connecting to it sends CONNECT name:port to the proxy; TLS then runs through the tunnel unchanged. Disabled, both hooks pass straight through. Done with linker --wrap of lwip_connect and lwip_getaddrinfo (the same technique as the OTA loop hook), so neither the FreeInk SDK nor any upstream file changes.
- core/ProxyShim: fake host table and the CONNECT request/reply (pure, host-tested).
- device/ProxyHook: the two wrappers and enable/disable; host-tested against a fake proxy with lwIP mapped to POSIX (tests/stubs).
- generated/: protocol_gen.h synced from the retink spec (wifi_sync feature, SyncRequest/SyncOffer).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…on, OPDS sync, always undo)

- core/PhoneSync: the whole sequence against a PhoneSyncIo interface; host-tested order, refusals, failures, cleanup.
- Session: sendSyncRequest / takeSyncOffer (control template, sync schema); capabilities advertise wifi_sync.
- device/MirrorPhoneSync.cpp: the radio, the shim and opdssync::syncNow(); MirrorActivity gets a 'Sync books over phone' button and runs it from loop() after releasing its mutex (the render task needs it).
- MirrorUpdateActivity switches the shim off on entry: the updater always uses plain sockets.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ynsgnr
ynsgnr changed the base branch from feat/mirror-link-security to develop-retink November 22, 2026 13:57
@ynsgnr ynsgnr changed the title feat(mirror): phone proxy shim for Wi-Fi sync feat(mirror): Sync books over the phone's mobile data (hotspot + proxy shim) Nov 22, 2026
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Firmware builds

Automatically generated for the latest commit of this PR (82392a4).

Download the file for your device, extract the .bin from the ZIP, then flash it with CrossPoint Reader Flash Tools. Make sure you use the correct firmware file for your device.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ynsgnr
ynsgnr deployed to ota-signing November 22, 2026 18:50 — with GitHub Actions Active
claude and others added 8 commits November 22, 2026 19:37
The SDK's HTTP client refused header lines over 4096 bytes, and GitHub's 302 for a release download carries a 4.2 KB Content-Security-Policy header: every release download (Firmware channels, font downloads) failed with status -1. FreeInk SDK 6a208c0c skips oversized header lines. This is the one-line bump upstream made for the same reason (crosspoint-reader#4420, ddd3b1d).

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

The mirror build and the OTA publisher only watched mirror/**, platformio.ini and the Home files, so a submodule bump built nothing mirror-related and published no channel.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… heap around the phone sync

OpdsSyncCore counts a failure without logging when canContinue() is false (deadline, or free heap under the TLS floor): a phone sync that reaches the feed but downloads nothing showed only 'failed=1'. canContinue now logs the reason with free heap and largest block, and the phone sync logs both before and after syncNow().

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Covers the fix in 1dda517: the CONNECT exchange's 10 s step timeout must not stay on the socket (it limited the TLS session that followed). Verified to fail on the previous ProxyHook.cpp (rcv=10 snd=10) and pass now.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ynsgnr
ynsgnr deployed to ota-signing November 24, 2026 22:23 — with GitHub Actions Active
Serial log of a failing sync: 'OSY Stopping: low memory (free 44540, max block 15860)'. With Wi-Fi and Bluetooth both up only 54 KB / 31 KB is free before TLS and the largest block falls under the 20 KB the download needs (a normal Wi-Fi sync without Bluetooth has 105 KB / 63 KB). The sequence now stops Bluetooth after the offer, joins the hotspot, syncs, undoes Wi-Fi and the shim, restarts Bluetooth, waits for the phone to reconnect and sends done. Host-tested order; the phone keeps its hotspot through the gap (retink WifiSyncController).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ynsgnr
ynsgnr deployed to ota-signing November 24, 2026 22:56 — with GitHub Actions Active
…be joined

Replaces the 'Sync books over phone' button. opdssync::syncNow() (timer wake) and Sync Now ask a registered NetworkFallback when no saved Wi-Fi can be joined; the mirror build registers the phone (device/PhoneRoute.cpp). Sleep-time joins keep using joinWifi() and never start it. Any failure (no phone, no answer, refusal, hotspot not joined) leaves Bluetooth, Wi-Fi and the shim off and skips the round; the next timer wake or Sync Now tries again.
- core/PhoneRoute: the sequence against a PhoneRouteIo interface (host-tested, every failure), plus the frames of a link without a Session and capabilities without templates.
- device/PhoneRoute.cpp: the screen-less link (MirrorBle), the hotspot join, the shim; registration at start-up.
- OpdsAutoSync.h/.cpp (upstream, +20 lines), OpdsSyncPopup.cpp (+4): the hook, and Sync Now gets online before it opens the Wi-Fi selection.
- Removed: the button, MirrorActivity's sync code, the Session sync messages.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ynsgnr
ynsgnr deployed to ota-signing November 24, 2026 23:24 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
ota-signing — 82392a43 Deployed Nov 24, 2026 by ynsgnr via publish #22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants