Metadata-Version: 2.5
Name: symbiolink
Version: 0.4.4
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
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
```

> **Needs a hacked phone for full functionality.** The phone app asks for
> `SwEvent` (key control) and `CommDD` (USB cable), which a stock phone will
> not grant, so an unhacked 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. **Hack the phone** (Open4All on), see the box above.
2. **Install Python for S60 1.4.5** on the phone (interpreter + script shell
   for S60 3rd Edition), like every PyS60 app.
3. **Put the SymbioLink app on the phone.** 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. Install it on the
   **same drive as Python for S60**. Later updates can go over the link itself:
   `symdb install-app`, then open **Files > Phone memory > SymbioLink.sis**.
4. **USB cable only, once per PC (Linux):**
   ```sh
   symdb setup-udev --install   # shows the rule, asks, then installs it
   ```
5. **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`).

| adb (Android) | symdb (Symbian) | Notes |
|---|---|---|
| `adb devices` | `symdb devices --discover` | phones announcing on the LAN (UDP 47021) |
| `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 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` | pushes the bundled SymbioLink.sis; you confirm on the phone (no silent install on Symbian) |
| `adb version` | `symdb --version` | |
| - | `symdb caps` | what this phone can and cannot do |
| - | `symdb sis-path`, `symdb setup-udev` | setup helpers |
| `adb logcat`, `adb reboot`, `adb shell ps`, `adb shell am start` | *not yet* | see the roadmap; app/process lists need native helpers |

## scrcpy and symcast

| scrcpy | symcast | Notes |
|---|---|---|
| `scrcpy` | `symcast --usb` / `symcast 192.168.1.20` | about 8-10 fps (the phone's JPEG encoding is the limit) |
| `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.4.4.** Wi-Fi and USB verified on real phones (connect, device
> info, file transfer, live mirror, every key). Remaining limits (about 10 fps,
> no process or app list, no silent install, one client at a time, no
> authentication) are listed below and in [docs/CHECKLIST.md](docs/CHECKLIST.md).

## What works today

| Area | State | Notes |
|---|---|---|
| SL/1 protocol (PC + phone + tests) | **working** | 37 offline tests pass (14 PC-side, 23 phone-side) |
| Device server (PyS60 1.4.5) | **working** | Wi-Fi and USB; one client at a time |
| `_symbiolink.pyd` (native screen capture, HAL facts, capability list, key injection), UID `0xE7A3D5F7` | **working** | keys and stream verified on the phone |
| `symbiolink_usb.exe` USB relay (phone side), UID `0xE7A3D5F8` | **working** | CDC-ACM port to the server, PC Suite mode |
| USB transport (PC side, `--usb`) | **working** | needs the udev rule; ~0.65 s to auto-detect |
| Wi-Fi TCP transport | **working** | 47020/TCP; the pattern RetroSend uses on this phone |
| Connect, hello, caps, info, battery | **working** | over Wi-Fi and USB |
| File push, pull, ls, mkdir, rm | **working** | 100 KB round trip byte-identical; a SIS pushed over the bridge installed |
| Live screen stream (`screen.stream`) and `symcast` mirror | **working** | ~8.8 fps over USB, ~7.4 fps over Wi-Fi at quality 50 (cap about 10 fps) |
| Key and text input (`input.key`, `input.text`) | **working** | keyboard and clickable keypad in `symcast`; needs Open4All (see Requirements) |
| `symcast` screenshot (Ctrl+S), help overlay, reconnect (Ctrl+R) | **working** | |
| UDP discovery | **implemented** | phone broadcasts, PC reads the source address |
| `symcast --record` (MJPEG AVI via ffmpeg) | **implemented, not yet run on a phone** | |
| Touch injection | **blocked** | needs a touchscreen device (S60 5th Edition / Symbian^3) |
| App list, process list, SIS install from the bridge | **blocked** | needs native helpers (`RApaLsSession`, `TFindProcess`); the install UI is the only route |

## 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** installed (`PythonForS60_1_4_5_3rdEd.sis` plus
  `PythonScriptShell_1_4_5_3rdEd.SIS`).
- 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**.
- The SymbioLink `.sis` installed **on the same drive as Python for S60**
  (usually the memory card). A cross-drive install needs the `rscfix` helper,
  which is not built yet.
- **A hacked 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 an unhacked phone
  the whole install is refused. See the box at the top for the unlock guide.

| Works on | Hacked 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;
`SYMDB_DEVICE` does the same from the environment. Ports: **47020/TCP** (server,
also the local end of the USB relay), **47021/UDP** (announcements).

### 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
```

## Building the phone package

The `SymbioLink.sis` bundled in the Python package is a build artifact of the
phone side. Rebuild it from a clone with:

```sh
sh scripts/build_native.sh    # -> phone/native/out/_symbiolink.pyd, symbiolink_usb.exe
sh scripts/build_sis.sh       # -> src/symbiolink/data/SymbioLink.sis
```

`build_native.sh` expects the toolchain next to this repository; point it
elsewhere with `SYMBIAN_SDK=/path/to/symbian-s60v3-toolchain`.
`build_sis.sh` looks for Python 2 and ensymble in the neighbouring RetroSend
checkout; override with `PY2=... ENSYMBLE=...`. The package carries
`_symbiolink.pyd` and `symbiolink_usb.exe`. Commit the rebuilt
`src/symbiolink/data/SymbioLink.sis` (it is excepted from the `*.sis` ignore
rule); `dist/` is only for `uv build` output.

## Tests

```sh
uv run pytest                        # framing, client, CLI, viewer (PC side)
python2 tests/test_phone_server.py   # device modules on Python 2.7
sh scripts/check_py22.sh             # rejects syntax newer than Python 2.2
sh scripts/build_native.sh           # native module compiles (arm-none-symbianelf-gcc)
sh scripts/build_sis.sh              # package builds
```

`tests/test_proto.py` and `tests/test_symcast.py` also run on their own with
`python3` (the viewer test needs PyQt5 and uses `QT_QPA_PLATFORM=offscreen`).
CI runs the pytest suite; the Python 2.7 phone test runs locally only, as
GitHub's setup-python no longer provides 2.7.

The phone-side checks above run offline. The hardware results in this README were
observed by hand on the phone, not by these tests.

## 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 | blocked on native helpers |
| 5 | Polished `symdb` + `symcast`, reconnection | partly: Ctrl+R reconnect; the rest planned |
| 6 | Other Symbian devices and OS generations | planned |

## 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.
- **No process or app list** yet; silent `symdb install` does not exist (`symdb install-app` only pushes the SIS). A SIS pushed
  over the bridge still has to be installed from the phone's own UI, which is
  not silent.
- **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.
- **No TLS, no authentication.** The server accepts any connection on the local
  network or the cable. Use it on networks you trust, or keep Wi-Fi off when not
  needed.

## 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.

## Publishing

Releases go to PyPI and GitHub Releases from `.github/workflows/release.yml`
when a `v*` tag is pushed.

One-time setup on PyPI (trusted publisher, no API token): at
<https://pypi.org/manage/account/publishing/> add a pending publisher with
PyPI project `symbiolink`, owner `manojanasuri16`, repository `SymbioLink`,
workflow `release.yml`, environment `pypi`. Create the `pypi` environment in the
GitHub repository settings (Environments) as well.

Then, for each release:

1. Bump `__version__` in `src/symbiolink/__init__.py` (the package version is
   read from it).
2. Rebuild the phone package if the phone side changed
   (`sh scripts/build_sis.sh`) and commit it.
3. `git tag vX.Y.Z && git push origin vX.Y.Z`.

The workflow builds the sdist and wheel with `uv build`, creates the GitHub
Release with them plus `SymbioLink.sis`, and publishes to PyPI.

## Licence

MIT, see [LICENSE](LICENSE). Python for S60, the S60 SDK and the Symbian
toolchain keep their own licences; none of them are redistributed here.
