Metadata-Version: 2.5
Name: symbiolink
Version: 0.6.2.post1
Summary: adb + scrcpy for Symbian S60 3rd Edition phones: symdb CLI and symcast screen mirror over Wi-Fi or USB
Project-URL: Homepage, https://github.com/manojanasuri16/SymbioLink
Project-URL: Repository, https://github.com/manojanasuri16/SymbioLink
Project-URL: Issues, https://github.com/manojanasuri16/SymbioLink/issues
Author-email: Manoj Anasuri <manojanasuri16@gmail.com>
License: MIT
License-File: LICENSE
Keywords: adb,n79,n82,nokia,pys60,retro,s60,scrcpy,screen-mirror,symbian
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Environment :: X11 Applications :: Qt
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: End Users/Desktop
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Communications
Classifier: Topic :: System :: Hardware
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Requires-Dist: pyqt5>=5.15
Provides-Extra: usb
Requires-Dist: libusb-package>=1.0; (sys_platform == 'win32' or sys_platform == 'darwin') and extra == 'usb'
Requires-Dist: pyusb>=1.2; extra == 'usb'
Description-Content-Type: text/markdown

# SymbioLink

[![PyPI](https://img.shields.io/pypi/v/symbiolink)](https://pypi.org/project/symbiolink/)
[![Python](https://img.shields.io/pypi/pyversions/symbiolink)](https://pypi.org/project/symbiolink/)
[![Tests](https://github.com/manojanasuri16/SymbioLink/actions/workflows/tests.yml/badge.svg)](https://github.com/manojanasuri16/SymbioLink/actions/workflows/tests.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

**adb and scrcpy, for Symbian.** Android has `adb` (Android Debug Bridge) and
`scrcpy`. SymbioLink brings the same workflow to Symbian S60 3rd Edition phones:

| Android | Symbian (this package) | What it is |
|---|---|---|
| `adb` - Android Debug Bridge | **`symdb` - Symbian Debug Bridge** | command line: connect, files, screenshots, keys, text, device info |
| `scrcpy` | **`symcast`** | live screen mirror with full keypad control |

Both come from one Python package, and talk to the small **SymbioLink** app on
the phone over **Wi-Fi or a USB cable**. The name: *Symbian* comes from
*symbiosis*, the PC and the phone working together.

```sh
pip install symbiolink
symdb connect --usb          # or: symdb connect 192.168.1.20
symdb shell info
symcast --usb                # mirror and control the phone
```

> **Full functionality needs a developer-unlocked phone.** The phone app asks for
> `SwEvent` (key control) and `CommDD` (USB cable), which a stock phone will
> not grant, so a stock phone refuses the install. Turn on **Open4All**
> (RomPatcher+) or use a developer certificate first:
> [unlock guide](https://manojanasuri16.github.io/RetroArchive/guides/unlock-n79/),
> [symbian-unlock-guide](https://github.com/manojanasuri16/symbian-unlock-guide).

Built for S60 3rd Edition (Symbian OS 9.1-9.3, FP1 and FP2). *Tested on: Nokia
N79 (FP2) and Nokia N82 (FP1), over Wi-Fi and USB.*

---

## Install

The package is on PyPI as [`symbiolink`](https://pypi.org/project/symbiolink/).
It needs Python 3.9+ on Linux and brings PyQt5 for `symcast`; `symdb` itself
uses only the standard library. The phone installer (`SymbioLink.sis`) and the
Linux USB rule ship inside the package.

| How | Command | Use it when |
|---|---|---|
| pip | `pip install symbiolink` | you have a virtual environment or `--user` install |
| pipx (recommended for the commands) | `pipx install symbiolink` | you want `symdb` / `symcast` on your PATH in their own environment |
| uv tool | `uv tool install symbiolink` | same, with uv |
| uv project | `uv add symbiolink` | you use SymbioLink from your own Python code (see *Python API*) |
| Latest from GitHub | `pipx install git+https://github.com/manojanasuri16/SymbioLink.git` | you want `master` before the next release |

Upgrade with `pipx upgrade symbiolink` (or `pip install -U symbiolink`,
`uv tool upgrade symbiolink`). Check with `symdb --version`.

<details>
<summary>Run from a clone (development)</summary>

```sh
git clone https://github.com/manojanasuri16/SymbioLink.git
cd SymbioLink
uv sync
uv run symdb --version
uv run symcast --fake        # a simulated phone, no hardware needed
```
</details>

## First run

1. **Unlock the phone for development** (Open4All on), see the box above.
2. **Put the SymbioLink app on the phone.** It is **one file** that already
   contains the Python for S60 1.4.5 runtime, so there is nothing else to
   install. The package carries it:
   ```sh
   symdb sis-path        # prints where SymbioLink.sis is
   ```
   Copy it to the memory card (mass storage mode or a card reader) or send it
   over Bluetooth, and open it in **Files** on the phone. The installer adds
   Python for S60 too, or skips it when the phone already has it. If Python for
   S60 is already installed, pick the **same drive** for SymbioLink. Later
   updates can go over the link itself:
   `symdb install-app`, then open **Files > Phone memory > SymbioLink.sis**.
3. **USB cable only, once per PC (Linux):**
   ```sh
   symdb setup-udev --install   # shows the rule, asks, then installs it
   ```
4. **Open SymbioLink on the phone** and leave it running (press End to go to
   the home screen; it keeps running). Then:
   ```sh
   symcast --usb              # phone in PC Suite mode, over the cable
   symcast 192.168.1.20       # or over Wi-Fi (the IP is on the app screen)
   symcast --discover         # or let it find the phone on the LAN
   ```

## adb commands and their symdb equivalents

Connect once (`symdb connect ...`) and the phone is remembered; `-s DEVICE`
picks one per command (`-s 192.168.1.20`, `-s usb`, `-s usb:/dev/ttyACM1`,
`-s usblib`, `-s bt:00:1D:FD:8A:AD:44`, or the phone id `symdb devices` shows).

**0.6: pair first.** A 0.6 phone app only obeys PCs it is paired with (USB
through the relay is trusted). Run `symdb pair` once and type the 6-digit
code the phone shows; see *Pairing and security*.

The 0.5.0 rows (install, uninstall, pm list, start, ps, kill, logcat, reboot,
wait-for-device, bootstart) **need a developer-unlocked (Open4All) phone**: since 0.5.0 the
SIS asks for the system capabilities TrustedUI and PowerMgmt (plus SwEvent), so
it no longer installs on a stock phone. They are implemented and tested
against the fake phone; hardware test pending (docs/CHECKLIST.md).

| adb (Android) | symdb (Symbian) | Notes |
|---|---|---|
| `adb devices` | `symdb devices [--bt]` | every phone on USB, Wi-Fi (UDP 47021 announcements) and with `--bt` Bluetooth, with its id and pairing state; `--discover` = only the Wi-Fi list |
| `adb -s SERIAL ...` | `symdb -s SPEC ...` | `host[:port]`, `usb[:/dev/ttyACMn]`, `usblib[:BUS-ADDR]`, `bt:MAC[/CH]`, or a phone id (16 hex) |
| `adb connect 192.168.1.20` | `symdb connect 192.168.1.20` | Wi-Fi, TCP 47020 |
| *(adb over USB)* | `symdb connect --usb` | PC Suite mode; auto-detects `/dev/ttyACM*` |
| *(adb over USB, no driver)* | `symdb connect --usblib` | the cable through libusb (`pip install 'symbiolink[usb]'`), for Windows/macOS; untested there |
| *(Bluetooth)* | `symdb connect bt:00:1D:FD:8A:AD:44` | RFCOMM, after Options > Bluetooth > On in the app |
| *(adb key authorization)* | `symdb pair`, `symdb unpair [--all]`, `symdb paired` | 6-digit code shown on the phone; keys in `~/.config/symbiolink/keys.json` |
| `adb forward tcp:8000 tcp:80` | `symdb forward tcp:8000 HOST:80` | PC port -> phone -> HOST:80 (`127.0.0.1` = the phone itself); runs until Ctrl+C |
| `adb reverse tcp:8000 tcp:8000` | `symdb reverse tcp:8000 tcp:127.0.0.1:8000` | phone `127.0.0.1:8000` -> PC; runs until Ctrl+C |
| *(phone uses the PC's internet)* | `symdb reverse --proxy [8080]` | HTTP/HTTPS proxy for phone apps at `127.0.0.1:8080`; see *Internet through the PC* |
| `adb disconnect` | `symdb disconnect` | forget the remembered phone |
| `adb push photo.jpg /sdcard/` | `symdb push photo.jpg 'E:\Images\'` | Symbian paths: `C:` phone memory, `E:` memory card |
| `adb pull /sdcard/file.txt .` | `symdb pull 'E:\file.txt' .` | |
| `adb shell ls /sdcard` | `symdb shell ls 'E:\'` | |
| `adb shell mkdir ...` | `symdb shell mkdir 'E:\Others\new'` | |
| `adb shell rm ...` | `symdb shell rm 'E:\Others\old.txt'` | files or empty folders |
| `adb shell getprop` / `dumpsys` | `symdb shell info` | model, firmware, screen, memory, native module |
| `adb shell dumpsys battery` | `symdb shell battery` | |
| `adb shell input keyevent KEYCODE_MENU` | `symdb input key menu` | keys: `up down left right select lsk rsk call end menu clear 0-9 star hash` |
| `adb shell input text "hello"` | `symdb input text hello` | |
| `adb exec-out screencap -p > s.png` | `symdb screencap s.jpg` | JPEG, full 240x320 |
| `adb install app.apk` | `symdb install app.sis [--drive C\|E]` | silent (`RSWInstSilentLauncher`): pushes to `C:\Data\symdb_install.sis`, installs, deletes the copy. Installing SymbioLink itself hands over to `symbiolink_updater.exe` and waits for the new version (see *Self-update*). **Needs a developer-unlocked phone** (TrustedUI) |
| `adb uninstall pkg` | `symdb uninstall 0x2000ABCD` | silent, by package UID. **Needs a developer-unlocked phone** |
| `adb shell pm list packages` | `symdb shell pm list [FILTER]` | UID, caption, exe path (`RApaLsSession`) |
| `adb shell am start -n ...` | `symdb shell start <uid\|name>` (or `shell am start`) | `RApaLsSession::StartApp` |
| `adb shell ps` | `symdb shell ps` | SID, priority, state, full process name (`*` = SymbioLink) |
| `adb shell kill` / `am force-stop` | `symdb shell kill <uid\|name\|exe\|caption> [--force]` | `RProcess::Kill` (name matches the process, the exe file name such as `Calcsoft.exe` or the app caption); refuses SymbioLink itself and core system processes unless `--force`. **Needs a developer-unlocked phone** (PowerMgmt) |
| `adb logcat` | `symdb logcat [PATH] [-f] [--from-start]`, `symdb logcat --list` | without PATH: every `*_log.txt` on `E:\` and `C:\Data` (including the crash log `E:\symbiolink_crash_log.txt`), lines prefixed with the file name; with PATH tails one file (0.5 s poll) |
| `adb shell` (python) | `symdb shell py`, `symdb shell py -c CODE` | Python 2.2 REPL running on the phone in a persistent namespace (`:reset` clears it) |
| *(notifications)* | `symdb notify [--no-desktop] [--json]` | new SMS and missed calls, printed and shown via `notify-send`; Python: `symbiolink.events.listen()` |
| `adb shell content query sms` | `symdb sms list [--folder inbox\|sent] [--limit N]`, `symdb sms send NUMBER TEXT --yes` | PyS60 `inbox` / `messaging`; send refuses without `--yes` |
| *(contacts)* | `symdb contacts list`, `symdb contacts export out.vcf`, `symdb contacts import in.vcf` | vCard via the PyS60 `contacts` module |
| *(camera)* | `symdb camera snap out.jpg [--size 640x480] [--front]` | `camera.take_photo` (size must be one the camera offers) |
| `scrcpy --audio` (partial) | `symdb audio record out.wav --seconds N` | records on the phone (`audio.Sound.record`), then pulls the file; no live audio stream |
| `adb backup` / `restore` | `symdb backup DIR`, `symdb restore DIR` | C:\Data files + SMS (JSON) + contacts (.vcf); restore pushes files and imports contacts, SMS cannot be restored |
| `adb shell cmd clipboard` | `symdb clip get`, `symdb clip set TEXT`, `echo hi \| symdb clip set -` | the phone clipboard (plain text, what Copy/Paste in S60 editors use) |
| *(adbd status)* | `symdb daemon status\|app\|off\|on`, `symdb daemon boot-app on\|off` | the background server `symbiolinkd` (works with the app closed, core commands only); `app` starts the full app |
| `adb reboot` | `symdb reboot` | reports "not available": the public SDKs have no restart API (see docs/PROTOCOL.md) |
| `adb wait-for-device` | `symdb wait-for-device [--timeout 120]` | retries USB, the last device, remembered Wi-Fi addresses and discovery |
| *(none)* | `symdb bootstart on\|off` | SymbioLink start at boot (also on the phone menu) |
| *(push the installer only)* | `symdb install-app` | pushes the bundled SymbioLink.sis for a manual install |
| `adb version` | `symdb --version` | |
| - | `symdb caps` | what this phone can and cannot do |
| - | `symdb sis-path`, `symdb setup-udev` | setup helpers |

## scrcpy and symcast

| scrcpy | symcast | Notes |
|---|---|---|
| `scrcpy` | `symcast` | finds the phone itself: USB cable first, then the last Wi-Fi phone, then discovery; about 8-10 fps (the phone's JPEG encoding is the limit) |
| `scrcpy -s <serial>` | `symcast --usb` / `symcast 192.168.1.20` | pick the link explicitly |
| `scrcpy --record file.mp4` | `symcast ... --record file.avi` | MJPEG AVI via ffmpeg |
| mouse and keyboard | keyboard + clickable keypad | the phones have no touchscreen |
| `scrcpy --max-size` | `symcast --scale 2` | window scale |

Keys in the symcast window: arrows = d-pad, Enter/Space = select, F1 / F2 =
left / right softkey (Esc = right softkey), F3 = call, F4 = end, F5 = menu,
Backspace/Delete = clear, 0-9 * # direct, Ctrl+T = type text, Ctrl+S =
screenshot to ~/Pictures, Ctrl+R = reconnect, H or ? = help overlay.

## Python API

`uv add symbiolink` (or `pip install symbiolink`) and script the phone:

```python
from symbiolink import connect

phone = connect("usb", 47020)            # or connect("192.168.1.20", 47020)
print(phone.info()["model"], phone.battery())

phone.write_file("E:\\Others\\notes.txt", data=b"hello from the PC")
print(phone.read_file("E:\\Others\\notes.txt"))
for entry in phone.ls("E:\\Others\\")["entries"]:
    print(entry["name"], entry["size"])

meta, jpeg = phone.screencap()
open("screen.jpg", "wb").write(jpeg)

phone.request("input.key", key="menu")   # press a key
phone.request("input.text", text="hi")   # type text
phone.close()
```

The wire protocol (SL/1) is documented in
[protocol/slproto.md](protocol/slproto.md) and [docs/PROTOCOL.md](docs/PROTOCOL.md).

> **Status: 0.5.1.** Wi-Fi and USB verified on real phones (connect, device
> info, file transfer, live mirror, every key). 0.5.0 adds silent install /
> uninstall, app list / start, process list / kill, logcat, start at boot and
> wait-for-device (verified on the N82 except self-update; 0.5.1 adds
> `symbiolink_updater.exe` for self-update, which failed on the N82; fixed in
> 0.5.2, hardware test pending). Remaining limits (about
> 10 fps, no reboot API, one client at a time, no authentication) are listed below and in [docs/CHECKLIST.md](docs/CHECKLIST.md).

## What works today

State as of 0.6.2. "Verified" means run on a real phone (N82, FP1, unless noted);
"implemented" means written and covered by the offline tests only.

| Area | State | Notes |
|---|---|---|
| SL/1 protocol, device server, `symdb`, Wi-Fi and USB | **verified** | one client at a time; 107 PC tests + phone-side tests |
| Screen mirror, `rgb565z` delta format (default) | **verified** | phone 22-34 ms per frame vs ~110 ms for JPEG; sends nothing while the screen is still; JPEG kept as fallback |
| Key and text input, files, apps, processes, SIS install, self-update | **verified** | needs Open4All (see Requirements) |
| Clipboard (`symdb clip`), `symdb shell py`, SMS and contacts list, camera snapshot | **verified** (0.6.0) | |
| Pairing (`symdb pair`) | **partly verified** | USB pairing verified; code pairing over Wi-Fi not yet |
| Background server `symbiolinkd.exe` | **partly verified** | most ops verified; hand-over after the app exits not yet |
| USB relay with stale-data protection (0.6.2) | **implemented** | fixes garbled sessions seen in 0.6.0/0.6.1 |
| Own Wi-Fi network picker (0.6.2) | **implemented** | the system picker crashed the app in 0.6.0/0.6.1 |
| Port forwarding, reverse, HTTP proxy through the PC | **implemented** | |
| Notifications (`symdb notify`), SMS send, backup/restore, audio record, crash log | **implemented** | SMS restore is not possible on PyS60 |
| `symcast --record out.mp4`, drag and drop | **implemented** | |
| Bluetooth (`-s bt:MAC`), several phones (`-s`), libusb (`-s usblib`) | **implemented** | Windows/macOS untested |
| Touch injection | **blocked** | needs a touchscreen device |
| Reboot | **unsupported** | no public API on S60 3rd Edition |

Open issues are tracked in [docs/CHECKLIST.md](docs/CHECKLIST.md) ("0.6.x open issues").

## Requirements in detail

**Phone**

- An S60 3rd Edition phone (FP1 or FP2; see *Tested on* above) for the reference path
  (FP1 and 5th Edition need their own platform adapter - see
  [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md#platforms)). Verified on firmware
  10.045 (RM-348).
- **Python for S60 1.4.5**: bundled. `SymbioLink.sis` embeds Nokia's
  `PythonForS60_1_4_5_3rdEd.sis` unchanged; the installer skips it when that
  version is already on the phone. The script shell is not needed.
- Wi-Fi, for the Wi-Fi transport. The phone picks the access point when the
  server binds its socket. The USB transport does not need Wi-Fi.
- For USB: the phone's connection mode set to **PC Suite**.
- Install SymbioLink on **the same drive as Python for S60** (phone memory,
  C:, is recommended; start at boot also needs C:). Installing on a different
  drive is experimental: a helper (`symbiolink_rscfix.exe`) runs during the
  install to make it work, but this is not yet confirmed on a phone.
- **A developer-unlocked phone: Open4All (or a developer certificate) active when you
  install.** The package asks for `SwEvent` (key input) and `CommDD` (USB
  relay), system capabilities a stock phone refuses, so on a stock phone
  the whole install is refused. See the box at the top for the unlock guide.

| Works on | Developer-unlocked S60v3 phone (Open4All) | Stock phone |
|---|---|---|
| Install SymbioLink | yes | no (installer refuses) |
| Wi-Fi: mirror, screenshots, files, info | yes | - |
| Key and text input | yes | - |
| USB cable | yes | - |

**PC**

- Linux with Python 3.9+. `pipx install symbiolink` brings PyQt5 (for
  `symcast`) along; `symdb` itself uses only the standard library.
- For USB: the udev rule installed (`symdb setup-udev --install`, see First run).
  Without it the phone's second serial port does not appear and `--usb` finds
  nothing.
- Only to rebuild the phone package yourself: the Symbian toolchain
  [symbian-s60v3-toolchain](https://github.com/manojanasuri16/symbian-s60v3-toolchain)
  (GnuPoc + CodeSourcery GCCE 3.4.3 + S60 3.2 SDK) and Python 2.7 for ensymble.
  The PC package already ships a built `SymbioLink.sis`.

## Details

### Ports and devices

`-s host[:port]` selects a device explicitly, `-s usb` or `--usb` the cable
(`-s usblib`, `-s bt:MAC`, `-s <phone id>`: see below);
`SYMDB_DEVICE` does the same from the environment. Ports: **47020/TCP** (server,
also the local end of the USB relay), **47021/UDP** (announcements).

The TCP port can be changed in the app (**Options → Port**, used after a
restart). The phone announces it, so `symdb devices` still finds the phone;
without discovery use `symdb connect <phone-ip>:<port>`. The USB cable follows
the setting by itself. Most people should keep 47020.

### Pairing and security

From 0.6 the phone app only takes commands from paired PCs:

```sh
symdb pair              # the phone shows a code (screen + pop-up), type it here
symdb shell info        # from now on this PC authenticates by itself
symdb paired            # phones this PC is paired with
symdb unpair            # forget this PC on the phone and the phone here
```

Over the USB cable no code is needed: the relay proves the session came over
the cable (a per-install token), so USB works unpaired and `symdb pair` over
USB pairs without a code. Wi-Fi and Bluetooth always need pairing. On the
phone, **Options → Paired PCs → Forget all** drops every PC. Pairing uses
SPAKE2 with the code (a Wi-Fi sniffer learns nothing; three wrong codes stop
the pairing for 30 s), later connections a mutual HMAC-MD5 challenge. The
session itself is not encrypted: details and limits in docs/PROTOCOL.md.
A 0.5 `symdb`/`symcast` gets "pairing required ... too old" from a 0.6 phone
over Wi-Fi; update it (`pip install -U symbiolink`).

### Port forwarding and internet through the PC

```sh
symdb forward tcp:8022 127.0.0.1:22        # PC :8022 -> a server running on the phone
symdb reverse tcp:8000 tcp:127.0.0.1:8000  # phone 127.0.0.1:8000 -> PC :8000
symdb reverse --proxy                      # phone apps get the PC's internet
symdb reverse --proxy -L tcp:8022=127.0.0.1:22   # several tunnels, one session
```

The tunnels ride inside the normal connection (Wi-Fi, USB or Bluetooth) and
last until Ctrl+C. The phone has one client connection, so put every tunnel
of a session in one command (`-L`, `-R`); running another `symdb` command
takes the connection over and ends them. At most 4 tunnelled connections at a
time on the phone (socket server limit).

**Internet through the PC.** `symdb reverse --proxy` runs an HTTP proxy on the
PC (plain `http://` requests and `CONNECT` for HTTPS and other TCP) and opens
it on the phone at `127.0.0.1:8080`. Phone apps use it when their access point
has that proxy:

1. **Settings → Connectivity → Destinations** (FP1: **Connection → Access
   points**), open the access point the app uses, **Options → Advanced
   settings** (or **Proxy server address**): address `127.0.0.1`, port
   `8080`.
2. Start `symdb reverse --proxy` (keep it running), then open the app.

Limits: the app still needs that access point to come up (the phone starts a
connection before it uses a proxy; a Wi-Fi network without internet access
works, a packet data access point needs a SIM and a non-Offline profile).
HTTPS still runs between the phone app and the server: the proxy only
relays the encrypted bytes, so the app's own TLS (old ciphers, expired
roots) is unchanged; plain HTTP through the proxy works regardless. Apps that
ignore the access point proxy (most Java ME and socket apps) are not proxied.
PyS60 apps can connect to `127.0.0.1:8080` themselves.

### Background server (symbiolinkd)

`symbiolinkd.exe` comes with the app and keeps SymbioLink reachable when the
app is closed, like adbd: it starts at boot (and whenever the app starts),
listens on the same port while the app is not running and gets out of the
way as soon as the app runs. It has the core commands (files, screen and
symcast, keys and text, install/uninstall, apps, processes, logs, clipboard)
and the same pairing keys; SMS, contacts, camera, audio, `shell py`, port
forwarding, Bluetooth and pairing itself need the app: `symdb daemon app`
starts it (reconnect after ~12 s). `symdb daemon off` stops it for good
(file `C:\Data\symbiolinkd_off.txt`), `symdb daemon boot-app on` makes it
start the full app at boot as well. Its log is `E:\symbiolinkd_log.txt`.
Details: docs/ARCHITECTURE.md.

### Bluetooth

On the phone **Options → Bluetooth → On** starts an RFCOMM service named
SymbioLink (off by default). Pair the phone with the PC in the system
Bluetooth settings, then `symdb -s bt:<phone MAC> shell info` (Linux/BlueZ).
`symdb devices --bt` probes the Bluetooth devices BlueZ already knows; there
is no inquiry scan. Bluetooth needs SymbioLink pairing like Wi-Fi.

### Several phones

`symdb devices` lists every phone with its id; pick one with `-s`, like adb:
`-s 3f2a9c0d11e4b7a8` finds that phone on whatever transport it is on now
(the last address it was seen at, USB, Wi-Fi, then Bluetooth when
`SYMDB_BT_SCAN=1`). `SYMDB_DEVICE` does the same from the environment.

### USB on Windows and macOS (libusb, untested)

Linux uses the serial driver and the udev rule. Elsewhere, and on Linux
without the rule, `pip install 'symbiolink[usb]'` adds a libusb transport that
talks to the phone's USB interfaces directly: `symdb -s usblib shell info`,
`symcast` the same way. **Not tested on Windows or macOS.**

- **Windows:** the phone's SymbioLink port needs the WinUSB driver. With the
  phone in PC Suite mode run [Zadig](https://zadig.akeo.ie/), **Options →
  List All Devices**, and replace the driver of the phone's CDC interface with
  protocol 255 *and* the data interface right after it (N82: interfaces 12
  and 13; N79: 3 and 4) with **WinUSB**. Leave the other interfaces alone,
  so Nokia PC Suite/Ovi keep working. libusb itself comes with the
  `libusb-package` wheel the extra installs.
- **macOS:** no driver change should be needed (the vendor-protocol port has
  no macOS driver); libusb comes from the same wheel.
- **Linux without the rule:** the rule's third line gives access to the USB
  device; libusb detaches `cdc_acm` while it runs and reattaches it.

### Wi-Fi network

SymbioLink asks once which Wi-Fi network to use and remembers it, so later
starts (including after updates and at boot) connect without asking. To switch:
**Options → Wi-Fi network** in the app, or from the PC `symdb wifi` (list),
`symdb wifi "<name>"` or `symdb wifi <id>` (switch), `symdb wifi --clear`
(ask again next start). A new choice is saved and used from the next start of
the app (switching it while the app runs could close it). In the Offline profile the phone still asks whether to
allow Wi-Fi; that question comes from the phone itself, not from SymbioLink.

### The USB rule

`symdb setup-udev --install` copies the bundled `70-symbiolink.rules` to
`/etc/udev/rules.d/` and reloads udev. The rule does two things. The phone's
second CDC-ACM port (the one `symbiolink_usb.exe` uses) declares a vendor protocol, so
Linux `cdc_acm` skips it; the rule adds the Nokia id so it appears as an extra
`/dev/ttyACMn`, normally `ttyACM1`. The logged-in user also gets access
(`uaccess`), so no `sudo` or `uucp` group is needed. The phone's own modem port
(`ttyACM0`) is held by the phone and reports `KErrAccessDenied`; it is not used.

### Try it without a phone (from a clone)

The fake phone implements the server side over a local directory, so the CLI and
the protocol can be exercised anywhere:

```sh
uv run python tests/fake_phone.py --root /tmp/phone --announce &
uv run symdb -s 127.0.0.1:47020 shell info
uv run symdb -s 127.0.0.1:47020 screencap /tmp/fake.jpg
uv run symcast --fake
```

## How it fits together

```
 PC (Python 3)                          Phone (PyS60 1.4.5 + native helpers)
 ┌──────────────┐   TCP 47020 / SL/1   ┌────────────────────────────────┐
 │ symdb       │ ───────────────────► │ linkserver.py  (app + sockets)   │
 │ symcast    │ ◄─────────────────── │ handlers.py  (commands)        │
 │ (PyQt5)      │   UDP 47021 announce │ s60v3.py     (platform)        │
 └──────────────┘                      │ n79.py       (hardware profile)│
        ▲                              │ _symbiolink.pyd (WS/HAL, native) │
        │ USB CDC-ACM (SL/1 bytes)     └──────────────▲─────────────────┘
        └────────────── cable ─────────── symbiolink_usb.exe ───┘ relays ACM::1 <-> 127.0.0.1:47020
```

- **Capability-driven.** Every command the phone cannot do comes back as a
  refusal with a reason, never as a silent failure. `symdb caps` prints the
  whole table.
- **Transport-independent protocol.** The same SL/1 byte stream runs over Wi-Fi
  TCP and over the USB cable (through the phone-side `symbiolink_usb.exe` relay). Nothing
  above the transport layer knows which one is in use.
- **Native where Python cannot reach.** PyS60 can screenshot and move files but
  cannot inject keys, list apps or report capabilities. Those go into native
  modules, behind the same protocol.

Detail: [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md),
[docs/FEASIBILITY.md](docs/FEASIBILITY.md),
[protocol/slproto.md](protocol/slproto.md),
[docs/PROTOCOL.md](docs/PROTOCOL.md) (command meanings).

## Verified on hardware (0.3.5)

Nokia N79, firmware 10.045 (RM-348), 2026-11-29, server 0.3.5. Full evidence per
item is in [docs/CHECKLIST.md](docs/CHECKLIST.md).

- Connect, hello, caps, info and battery over Wi-Fi (TCP 47020) and over USB.
- Stream: q50 at 8.8 fps over USB and 7.4 fps over Wi-Fi (q30: 9.0 and 8.9),
  frames of about 14-18 KB. The limit is the phone's JPEG encode, about 80 ms per
  frame.
- Transfer: push about 132 KB/s over USB and 124 KB/s over Wi-Fi; pull about
  257 KB/s and 222 KB/s. Request round trip median 54 ms over USB, 56 ms over
  Wi-Fi.
- Keys seen on the screen: d-pad, select, both softkeys, call, end, menu, 0-9,
  star, hash, clear, `input.text`. The keypad autolock blocks injected keys until
  the phone is unlocked (LSK then `*`).
- Switching between USB and Wi-Fi works: a new client replaces a stale one.

## Roadmap

| Phase | Content | State |
|---|---|---|
| 1 | Protocol, `symdb`, device server, native helper, packaging | done; verified on hardware (Wi-Fi and USB) |
| 2 | Live screen mirroring, `symcast` viewer, frame rate/latency measurement | done; measured on hardware (about 8-9 fps) |
| 3 | Remote control: key injection (`SwEvent`), key maps, touch profiles | keys done; touch blocked |
| 4 | App list/launch/stop, processes, logs, SIS install | implemented in 0.5.0 and verified on the N82 (developer-unlocked); self-update via the updater in 0.5.1 pending test; reboot not available |
| 5 | Polished `symdb` + `symcast`, reconnection | partly: Ctrl+R reconnect; the rest planned |
| 6 | Other Symbian devices and OS generations | planned |
| 0.6 | Delta mirror, pairing, forwarding, Bluetooth, background server, phone data features | implemented; hardware testing in progress |

## Limitations (read before filing a bug)

- **PyS60 1.4.5 only.** One Python runtime per S60 3rd Edition generation; S60
  5th Edition and Symbian^3 ship PyS60 2.x with a different socket API.
- **Frame rate is capped at about 10 fps** by the phone's JPEG encode.
- **One client at a time**, and the phone cannot tell who connected (PyS60 has
  no `getpeername`), hence the UDP announcement direction.
- **Keypad autolock** blocks injected keys until the phone is unlocked.
- **0.5.0 needs a developer-unlocked phone**: silent install (TrustedUI) and process kill
  (PowerMgmt) are system capabilities; a stock phone refuses the SIS.
- **No reboot**: the public S60 3rd SDKs have no restart API (`symdb reboot`
  says so). `symdb shell kill SysAp --force` may force a restart (untested:
  a dying system-critical process reboots the phone), but that is a crash, not an API.
- **Start at boot** works when SymbioLink is installed to `C:`.
- **Key injection needs `SwEvent`**, a system capability: a stock phone refuses
  a self-signed package that declares it. Use an Open4All phone or a developer
  certificate.
- **Authenticated, not encrypted (0.6).** Only paired PCs (and the USB cable)
  can send commands, but the session is not encrypted or integrity-protected
  after the handshake: someone who can take over TCP connections on the LAN
  can still read or inject traffic. Pair over USB on untrusted Wi-Fi.
- **Bluetooth and the libusb transport are new in 0.6** and only partly
  tested (see docs/CHECKLIST.md); Windows/macOS USB is untested.

## Related projects

- [symbian-s60v3-toolchain](https://github.com/manojanasuri16/symbian-s60v3-toolchain) - the toolchain used to build this.
- [RetroSend](https://github.com/manojanasuri16/RetroSend),
  [RetroTele](https://github.com/manojanasuri16/RetroTele) - sibling S60 apps whose
  socket, packaging and native-helper patterns this project reuses.
- RetroCamKey - the key-injection pattern (`SimulateRawEvent`) this project follows.
- [localsend-py22](https://github.com/manojanasuri16/localsend-py22) - the
  PyS60 network notes that shaped the server.

## Development

Building the phone package, tests and releasing: see
[docs/DEVELOPMENT.md](https://github.com/manojanasuri16/SymbioLink/blob/master/docs/DEVELOPMENT.md).

## Licence

MIT, see [LICENSE](LICENSE). The Python for S60 1.4.5 runtime bundled in
`SymbioLink.sis` is Nokia's, released as open source under the Apache License
2.0 (see [phone/vendor/README.md](phone/vendor/README.md)); it is included
unchanged. The S60 SDK and the Symbian toolchain keep their own licences and
are not redistributed here.
