Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
015a9c59bc | ||
|
|
305818466f | ||
|
|
3339d9ee59 | ||
|
|
8ba41f72b6 | ||
|
|
861a60b73d | ||
|
|
4c4d7fc467 | ||
|
|
18285c3212 | ||
|
|
e707a5f2d4 | ||
|
|
5bec851a1a | ||
|
|
9dfe675db7 | ||
|
|
079de4aec7 | ||
|
|
6b71aace4f | ||
|
|
7223147f26 | ||
|
|
01a8e2a233 | ||
|
|
0498916740 | ||
|
|
298407b5cf | ||
|
|
9808013fc0 | ||
|
|
9b6457d1ec |
@@ -114,6 +114,14 @@ _Avoid_: terminal, command line, REPL
|
|||||||
The WireGuard connection to one server, over whatever Wi-Fi the device is on. It carries either everything or the one subnet the device's address in it belongs to. Wanted or not is the user's switch; up or not depends on Wi-Fi, the clock and the server.
|
The WireGuard connection to one server, over whatever Wi-Fi the device is on. It carries either everything or the one subnet the device's address in it belongs to. Wanted or not is the user's switch; up or not depends on Wi-Fi, the clock and the server.
|
||||||
_Avoid_: VPN connection, link, session
|
_Avoid_: VPN connection, link, session
|
||||||
|
|
||||||
|
**Session**:
|
||||||
|
The one SSH connection to a shell on another machine, from login until either side ends it. It belongs to the SSH Service, not to the SSH App: it goes on while another App is in front.
|
||||||
|
_Avoid_: connection, tunnel, terminal (the terminal is what draws it)
|
||||||
|
|
||||||
|
**Device Key**:
|
||||||
|
The Ed25519 key pair the device makes for itself to log in over SSH. The private half never leaves the device and is never shown; the public half is meant to be copied to servers.
|
||||||
|
_Avoid_: identity, SSH key file, certificate
|
||||||
|
|
||||||
**Sharing**:
|
**Sharing**:
|
||||||
Serving the SD card as a web page to a browser on the same network, for as long as the Storage App's Share screen is open, to whoever typed the code that screen shows.
|
Serving the SD card as a web page to a browser on the same network, for as long as the Storage App's Share screen is open, to whoever typed the code that screen shows.
|
||||||
_Avoid_: file server, web server, FTP, upload mode
|
_Avoid_: file server, web server, FTP, upload mode
|
||||||
@@ -193,6 +201,7 @@ _Avoid_: telnet, remote shell, Debug Build (there is one firmware)
|
|||||||
- **Services** keep running underneath, regardless of which **App** is in the foreground.
|
- **Services** keep running underneath, regardless of which **App** is in the foreground.
|
||||||
- The **Mesh Service** speaks one or more **Mesh Protocols** and tracks the known **Nodes**.
|
- The **Mesh Service** speaks one or more **Mesh Protocols** and tracks the known **Nodes**.
|
||||||
- The **Wi-Fi Service** is either Connected or Monitoring, never both. Monitoring pauses the **IRC Service**, which reconnects and rejoins its **Buffers** afterwards.
|
- The **Wi-Fi Service** is either Connected or Monitoring, never both. Monitoring pauses the **IRC Service**, which reconnects and rejoins its **Buffers** afterwards.
|
||||||
|
- The SSH App draws the one **Session**; the **Session** and the **IRC Service**'s connection don't fit in memory together, so each waits for the other.
|
||||||
- **Services** raise **Notifications**; the **Status Bar** summarises **Service** state.
|
- **Services** raise **Notifications**; the **Status Bar** summarises **Service** state.
|
||||||
- The **Radio Service** owns the radio; the **Mesh Service** and the LoRa Scanner use it.
|
- The **Radio Service** owns the radio; the **Mesh Service** and the LoRa Scanner use it.
|
||||||
- A **Sweep** pauses the **Mesh Service**; a **Sniffer** does not.
|
- A **Sweep** pauses the **Mesh Service**; a **Sniffer** does not.
|
||||||
|
|||||||
@@ -6,15 +6,16 @@ A multi-app firmware for the **M5Stack Cardputer ADV** with the **Cap LoRa-1262*
|
|||||||
|
|
||||||
What it does today:
|
What it does today:
|
||||||
|
|
||||||
- **LoRa Scanner:** every packet it hears, with the Meshtastic header read; a spectrum Sweep; captures for Wireshark. It listens and never transmits: the mesh messenger is the next milestone.
|
- **LoRa Scanner:** every packet it hears, with the Meshtastic or MeshCore header read; a spectrum Sweep; captures for Wireshark. It listens and never transmits: the mesh messenger is the next milestone.
|
||||||
- **GNSS:** position, sky view, tracks as GPX.
|
- **GNSS:** position, sky view, tracks as GPX.
|
||||||
- **Gemini:** a browser, with bookmarks and pages saved for offline.
|
- **Gemini:** a browser, with bookmarks and pages saved for offline.
|
||||||
- **IRC:** over TLS, with logs on the card.
|
- **IRC:** over TLS, with logs on the card.
|
||||||
- **Wi-Fi Tools:** the networks around, sorted, filtered, logged.
|
- **Wi-Fi Tools:** the networks around, sorted, filtered, logged.
|
||||||
- **Notes:** plain text files of any size, saved by themselves.
|
- **Notes:** plain text files of any size, saved by themselves.
|
||||||
- **Storage:** the SD card: copy, move, rename, delete; viewers for text, hex, pictures (PNG, JPEG, BMP, GIF), tracks, captures and update files; **sharing with a phone's browser**.
|
- **Storage:** the SD card: copy, move, rename, delete; viewers for text, hex, pictures (PNG, JPEG, BMP, GIF), tracks, captures and update files; **sharing with a phone's browser**.
|
||||||
- **Shell:** the firmware's commands on the device itself, with completion, including `ping`, `nslookup`, `port`, `traceroute` and `ifconfig`.
|
- **Shell:** the firmware's commands on the device itself, with completion, including `ping`, `nslookup`, `port`, `traceroute`, `tls` and `ifconfig`.
|
||||||
- **System:** load, tasks, memory, network, battery, live.
|
- **System:** load, tasks, memory, network, battery, live.
|
||||||
|
- **SSH:** a terminal on another machine, with a password or the device's own key.
|
||||||
- **VPN:** a WireGuard tunnel.
|
- **VPN:** a WireGuard tunnel.
|
||||||
- **Everywhere:** Fn+h lists the keys of the screen you are on; Fn+p takes a screenshot.
|
- **Everywhere:** Fn+h lists the keys of the screen you are on; Fn+p takes a screenshot.
|
||||||
- **Updates:** signed, from the project's server, the card or a PC, with a rollback if the new firmware fails.
|
- **Updates:** signed, from the project's server, the card or a PC, with a rollback if the new firmware fails.
|
||||||
@@ -137,7 +138,7 @@ On a page, `b` bookmarks it, `s` saves it to the SD card to read offline (a non-
|
|||||||
|
|
||||||
## LoRa Scanner
|
## LoRa Scanner
|
||||||
|
|
||||||
The LoRa Scanner (docs/milestones/M3.md) listens with the Cap's radio and **never transmits**. The Sniffer lists what it hears, newest first: time, RSSI, SNR, and for Meshtastic packets the sender and receiver (their last 4 hex digits) and hops. Enter shows a packet's details: the Meshtastic header (which is never encrypted) and a hex dump. `p` picks one of the 7 Meshtastic presets allowed in EU868 (LongFast by default), `c` starts or stops a Capture: a pcap file with LoRaTap headers in `/captures/lora/`, for Wireshark. A Capture keeps recording with the App closed; otherwise the radio sleeps when the App isn't open. Tab switches to **Sweep**: the signal strength across 863–870 MHz in 100 kHz steps, as bars with peak hold and a waterfall, with the Sniffer's frequency marked; the Sniffer is paused meanwhile and picks up where it was. The GNSS receiver on the same Cap raises the radio's noise floor by 8 dB while it runs: Settings > "Pause GNSS for LoRa" (off by default) puts it in standby while the radio listens, except during a Track. The Status Bar shows `L` while the radio listens (bright for a moment on each packet), `SW` while sweeping, and `CAP` while capturing.
|
The LoRa Scanner (docs/milestones/M3.md) listens with the Cap's radio and **never transmits**. The Sniffer lists what it hears, newest first: time, RSSI, SNR, and for Meshtastic packets the sender and receiver (their last 4 hex digits) and hops; for MeshCore packets what they are (an advert with the node's name, a message with the first byte of each node's key, a message on the public channel read, with the name its sender gives; any other channel message with the channel's byte) and the hops in their path. Enter shows a packet's details: what is never encrypted (the Meshtastic header; MeshCore's header, path and, in an advert, the node's name, kind, key and position; and a public channel message's sender, time and text, decrypted with the channel's published key) and a hex dump. `p` picks **MeshCore** (the default; its EU/UK Narrow setting: 869.618 MHz, 62.5 kHz, SF8, CR 4/8) or one of the 7 Meshtastic presets allowed in EU868, `c` starts or stops a Capture: a pcap file with LoRaTap headers in `/captures/lora/`, for Wireshark. A Capture keeps recording with the App closed; otherwise the radio sleeps when the App isn't open. Tab switches to **Sweep**: the signal strength across 863–870 MHz in 100 kHz steps, as bars with peak hold and a waterfall, with the Sniffer's frequency marked; the Sniffer is paused meanwhile and picks up where it was. The GNSS receiver on the same Cap raises the radio's noise floor by 8 dB while it runs: Settings > "Pause GNSS for LoRa" (off by default) puts it in standby while the radio listens, except during a Track. The Status Bar shows `L` while the radio listens (bright for a moment on each packet), `SW` while sweeping, and `CAP` while capturing.
|
||||||
|
|
||||||
## Storage
|
## Storage
|
||||||
|
|
||||||
@@ -160,7 +161,7 @@ Enter on a file opens it by type; Tab switches to the same file as a hex dump or
|
|||||||
|
|
||||||
- **Text** (`.txt`, `.log`, `.gmi`, `.csv`, and anything that looks like text): only the screen's worth is read from the card, so a file of any size opens at once. Logs open at the end. Up and Down move a line, Left and Right a page, `t` and `b` go to the top and the end, `e` edits it, whatever its size (see Notes).
|
- **Text** (`.txt`, `.log`, `.gmi`, `.csv`, and anything that looks like text): only the screen's worth is read from the card, so a file of any size opens at once. Logs open at the end. Up and Down move a line, Left and Right a page, `t` and `b` go to the top and the end, `e` edits it, whatever its size (see Notes).
|
||||||
- **Pictures** (`.png`, `.jpg`, `.bmp`, `.gif`; issue #45): shrunk to fit the screen, or at their own size with Enter, the arrows then moving half a screen at a time; `i` gives the size in pixels. Dithered to the screen's 256 colours, decoded straight into the screen's buffer with no copy in memory, on the storage task so the keys keep working (12 megapixels of JPEG: 7 s). A GIF shows its first picture. A progressive JPEG or an interlaced PNG opens as hex, with the reason.
|
- **Pictures** (`.png`, `.jpg`, `.bmp`, `.gif`; issue #45): shrunk to fit the screen, or at their own size with Enter, the arrows then moving half a screen at a time; `i` gives the size in pixels. Dithered to the screen's 256 colours, decoded straight into the screen's buffer with no copy in memory, on the storage task so the keys keep working (12 megapixels of JPEG: 7 s). A GIF shows its first picture. A progressive JPEG or an interlaced PNG opens as hex, with the reason.
|
||||||
- **Captures** (`.pcap`): the packets as the LoRa Scanner lists them; Enter shows one with its Meshtastic header and bytes.
|
- **Captures** (`.pcap`): the packets as the LoRa Scanner lists them; Enter shows one with its Meshtastic or MeshCore header and bytes.
|
||||||
- **Tracks** (`.gpx`): the number of points, the start, the duration and the distance.
|
- **Tracks** (`.gpx`): the number of points, the start, the duration and the distance.
|
||||||
- **Update Files** (`.ota`): the version, and whether the file would install: it's checked as an install checks it (signature and contents) without writing anything. Enter then installs it.
|
- **Update Files** (`.ota`): the version, and whether the file would install: it's checked as an install checks it (signature and contents) without writing anything. Enter then installs it.
|
||||||
- **Anything else:** a hex dump.
|
- **Anything else:** a hex dump.
|
||||||
@@ -177,6 +178,12 @@ A new note has no file until something is typed; its file is then named after it
|
|||||||
|
|
||||||
**A note can be any size** (issue #47): the editor keeps a window of about 8 KB around the cursor in memory and the rest on the card, so a megabyte opens as fast as a line and uses the same 17 KB. Up to 64 KB a save rewrites the file. Above, the five-second save writes only what changed to a side file, `<note>.edit`, and the file itself is rewritten when the note is left, with a progress bar (about 450 KB a second). After a power cut, opening the note picks the edit up where it was saved. Saving needs room on the card for a second copy. The Storage App's text viewer has `e` to edit a file with the same editor, anywhere on the card, unless the file is read-only.
|
**A note can be any size** (issue #47): the editor keeps a window of about 8 KB around the cursor in memory and the rest on the card, so a megabyte opens as fast as a line and uses the same 17 KB. Up to 64 KB a save rewrites the file. Above, the five-second save writes only what changed to a side file, `<note>.edit`, and the file itself is rewritten when the note is left, with a progress bar (about 450 KB a second). After a power cut, opening the note picks the edit up where it was saved. Saving needs room on the card for a second copy. The Storage App's text viewer has `e` to edit a file with the same editor, anywhere on the card, unless the file is read-only.
|
||||||
|
|
||||||
|
## SSH
|
||||||
|
|
||||||
|
The SSH App (docs/milestones/N1.md, issue #2) is a terminal on another machine: one session to a shell, over libssh (`ewpa/LibSSH-ESP32`) on mbedTLS. `user@host[:port]`, typed in the App or as `ssh user@host` in the Shell; up to eight hosts are remembered. **A server is trusted the first time, on its fingerprint, and a changed key is a warning** whose selected answer is Cancel. **The password is typed each time and kept nowhere;** or the device makes itself an Ed25519 key (kept in the device, never shown, no passphrase) whose public half is shown, written to `/ssh/id_ed25519.pub` and printed by `ssh status`, for a server's `authorized_keys`.
|
||||||
|
|
||||||
|
The terminal (`lib/term`, host-tested) understands what a shell, `less`, `top`, `nano` and `vim` send: the cursor, erasing, sixteen colours, scroll regions, the alternate screen; no mouse. Five text sizes with Ctrl and + or -, from 60 x 20 to 26 x 8, told to the far end; 100 lines of scrollback with Alt and up or down. The backtick key sends Esc. **Leaving the App doesn't end the session:** `SSH` shows in the Status Bar and the App finds it again. It costs 292 KB of flash (109 KB of it one table, for signing with the device's key) and about 50 KB of memory while a session is open, so it isn't started under 75 KB free and IRC doesn't connect while one is open.
|
||||||
|
|
||||||
## VPN
|
## VPN
|
||||||
|
|
||||||
A WireGuard tunnel (docs/milestones/N1.md), over whatever Wi-Fi the device is on: one peer, IPv4. Copy a client's `.conf` to the card as `/vpn/wg0.conf` and import it in Settings > VPN (or `vpn import`); the configuration, private key included, is then kept in the device and never shown, and Settings offers to delete the file. A switch brings the tunnel up until the next restart; "Start with Wi-Fi" does it every time. It waits for the clock, which WireGuard needs. `VPN` shows in the Status Bar, bright once the server has answered.
|
A WireGuard tunnel (docs/milestones/N1.md), over whatever Wi-Fi the device is on: one peer, IPv4. Copy a client's `.conf` to the card as `/vpn/wg0.conf` and import it in Settings > VPN (or `vpn import`); the configuration, private key included, is then kept in the device and never shown, and Settings offers to delete the file. A switch brings the tunnel up until the next restart; "Start with Wi-Fi" does it every time. It waits for the clock, which WireGuard needs. `VPN` shows in the Status Bar, bright once the server has answered.
|
||||||
@@ -185,7 +192,7 @@ A WireGuard tunnel (docs/milestones/N1.md), over whatever Wi-Fi the device is on
|
|||||||
|
|
||||||
## Shell
|
## Shell
|
||||||
|
|
||||||
The Shell App (docs/milestones/S1.md) runs the commands below on the device's own screen and keyboard: no PC, no cable, no Wi-Fi. **It shows the replies to its own commands and nothing else**: the console knows who each line is printed for, so a listing read by another task a moment later is still the Shell's, and what USB or the Debug Console asked for is not. Ctrl+b shows everything instead. Tab completes a command word by word (`lora st` gives `lora status`) and, past it, a path on the SD card (`ls /no` gives `ls /notes/`), Fn with up and down recalls earlier lines, Alt with up and down scrolls back. **An App's name with a capital opens it** (`Notes`, `Irc`, `Wifi`, `Gnss`, `Gemini`, `Lora`, `Storage`, `System`, `Settings`), from the consoles too. `rm` is Unix's, with a question: a folder needs `-r`; a file, or a folder with something in it, is asked about unless `-f` (`rm -rf`); an empty folder goes without a word. `*` and `?` in a name stand for several files (`rm /notes/*.txt` asks once, with the count; 64 at most). `clear` empties the screen and `quit` leaves. It is trusted like the USB port: `debug on` and `debug token` work from it. It uses about 7 KB of memory while it is open, and none otherwise. **For the network:** `ping`, `nslookup`, `port`, `traceroute`, `ifconfig` and `arp` (issue #90).
|
The Shell App (docs/milestones/S1.md) runs the commands below on the device's own screen and keyboard: no PC, no cable, no Wi-Fi. **It shows the replies to its own commands and nothing else**: the console knows who each line is printed for, so a listing read by another task a moment later is still the Shell's, and what USB or the Debug Console asked for is not. Ctrl+b shows everything instead. Tab completes a command word by word (`lora st` gives `lora status`) and, past it, a path on the SD card (`ls /no` gives `ls /notes/`), Fn with up and down recalls earlier lines, Alt with up and down scrolls back. **An App's name with a capital opens it** (`Notes`, `Irc`, `Wifi`, `Gnss`, `Gemini`, `Lora`, `Storage`, `Ssh`, `System`, `Settings`), from the consoles too. `rm` is Unix's, with a question: a folder needs `-r`; a file, or a folder with something in it, is asked about unless `-f` (`rm -rf`); an empty folder goes without a word. `*` and `?` in a name stand for several files (`rm /notes/*.txt` asks once, with the count; 64 at most). `clear` empties the screen and `quit` leaves. It is trusted like the USB port: `debug on` and `debug token` work from it. It uses about 7 KB of memory while it is open, and none otherwise. **For the network:** `ping`, `nslookup`, `port`, `traceroute`, `tls`, `ntp`, `ifconfig`, `arp` and `netstat` (issue #90).
|
||||||
|
|
||||||
## Development aids
|
## Development aids
|
||||||
|
|
||||||
@@ -227,7 +234,7 @@ The Shell App (docs/milestones/S1.md) runs the commands below on the device's ow
|
|||||||
| `lora probe` | Finds the radio: chip, oscillator, antenna switch, DIO1 interrupt, noise floor |
|
| `lora probe` | Finds the radio: chip, oscillator, antenna switch, DIO1 interrupt, noise floor |
|
||||||
| `lora status` | Radio settings, who's listening, packet and error counters, noise floor, task stack |
|
| `lora status` | Radio settings, who's listening, packet and error counters, noise floor, task stack |
|
||||||
| `lora rx on` / `lora rx off` | Listens and prints each packet on the console |
|
| `lora rx on` / `lora rx off` | Listens and prints each packet on the console |
|
||||||
| `lora preset <name>` / `lora custom <MHz> <BW kHz> <SF> <CR> <sync hex> [preamble]` | Receive settings: a Meshtastic preset, or anything else (`lora custom 868.1 125 7 5 34 8` for LoRaWAN) |
|
| `lora preset <name>` / `lora custom <MHz> <BW kHz> <SF> <CR> <sync hex> [preamble]` | Receive settings: a Meshtastic preset or `MeshCore`, or anything else (`lora custom 868.1 125 7 5 34 8` for LoRaWAN) |
|
||||||
| `lora capture start` / `lora capture stop` | A LoRa Capture, as `c` in the App |
|
| `lora capture start` / `lora capture stop` | A LoRa Capture, as `c` in the App |
|
||||||
| `lora sweep on [from MHz] [to MHz] [step kHz]` / `lora sweep off` / `lora sweep dump` | Sweep a band (863 870 100 by default), with a summary every 2 s (floor, strongest, peaks), or print the latest pass |
|
| `lora sweep on [from MHz] [to MHz] [step kHz]` / `lora sweep off` / `lora sweep dump` | Sweep a band (863 870 100 by default), with a summary every 2 s (floor, strongest, peaks), or print the latest pass |
|
||||||
| `gnss quiet on` / `gnss quiet off` | The "Pause GNSS for LoRa" setting |
|
| `gnss quiet on` / `gnss quiet off` | The "Pause GNSS for LoRa" setting |
|
||||||
@@ -242,7 +249,11 @@ The Shell App (docs/milestones/S1.md) runs the commands below on the device's ow
|
|||||||
| `loop spin on` / `loop spin off` | Make the main loop spin without resting, to compare load and radio noise |
|
| `loop spin on` / `loop spin off` | Make the main loop spin without resting, to compare load and radio noise |
|
||||||
| `crash abort` / `crash wdt` | Crash on purpose, or hang the main loop until the watchdog fires |
|
| `crash abort` / `crash wdt` | Crash on purpose, or hang the main loop until the watchdog fires |
|
||||||
| `ping <host> [count] [size]` / `nslookup <name> [server]` / `port <host> <port>` / `traceroute <host>` / `cancel` | Network troubleshooting (issue #90): does a host answer and how fast; a name's addresses, from which DNS server and in how long; is a TCP port open, refused or silent; the routers on the way. Each runs on a task of its own and prints as it goes, one at a time; `cancel` stops it |
|
| `ping <host> [count] [size]` / `nslookup <name> [server]` / `port <host> <port>` / `traceroute <host>` / `cancel` | Network troubleshooting (issue #90): does a host answer and how fast; a name's addresses, from which DNS server and in how long; is a TCP port open, refused or silent; the routers on the way. Each runs on a task of its own and prints as it goes, one at a time; `cancel` stops it |
|
||||||
| `ifconfig` / `arp` | The interfaces (Wi-Fi and the VPN) with their addresses, MTU, which is the default route, and the DNS servers; the neighbours heard on the Wi-Fi |
|
| `tls <host> [port]` / `ntp [server]` | A TLS handshake that checks nothing, then the certificate said in words: who it is for, who signed it, until when, its SHA-256, and whether this device's roots and the name asked for accept it (about 52 KB of heap while it runs; refused under 70 KB free). A time server's clock against the device's, with the round trip |
|
||||||
|
| `ifconfig` / `arp` / `netstat` | The interfaces (Wi-Fi and the VPN) with their addresses, MTU, which is the default route, and the DNS servers; the neighbours heard on the Wi-Fi; what listens and what is connected |
|
||||||
|
| `ssh user@host[:port]` / `ssh status` / `ssh stop` | Opens the SSH App and connects (the password is asked there, never on a console); the session's state and this device's public key; end the session |
|
||||||
|
| `scp [-f] [-P port] <file> user@host:path` / `scp [-f] [-P port] user@host:path <file>` | One file between the card and a server, with the device's key, or a password asked (masked) in the Shell, to a server the SSH App already trusts; `-f` replaces a file on the card; `cancel` stops it |
|
||||||
|
| `uname` | The firmware, its version and the chip it is built for (IRC has `/uname`) |
|
||||||
| `vpn status` / `vpn up [seconds]` / `vpn down` / `vpn import [path]` / `vpn forget` / `vpn auto on\|off` | The WireGuard tunnel: its state, on (for that many seconds, then off by itself: for trying a configuration from afar), off, read a `.conf` from the card (`/vpn/wg0.conf`), erase it, start with Wi-Fi. No key is ever printed |
|
| `vpn status` / `vpn up [seconds]` / `vpn down` / `vpn import [path]` / `vpn forget` / `vpn auto on\|off` | The WireGuard tunnel: its state, on (for that many seconds, then off by itself: for trying a configuration from afar), off, read a `.conf` from the card (`/vpn/wg0.conf`), erase it, start with Wi-Fi. No key is ever printed |
|
||||||
| `debug status` / `debug off [seconds]` | The Debug Console: whether it's on, has a token and a client; switch it off. With a number of seconds, it comes back by itself after that long |
|
| `debug status` / `debug off [seconds]` | The Debug Console: whether it's on, has a token and a client; switch it off. With a number of seconds, it comes back by itself after that long |
|
||||||
| `debug on` / `debug token <value>` / `debug token new` | USB serial only: switch it on (making a token if there's none), give it a token of 16 to 64 characters, or make a new one. The token is never printed |
|
| `debug on` / `debug token <value>` / `debug token new` | USB serial only: switch it on (making a token if there's none), give it a token of 16 to 64 characters, or make a new one. The token is never printed |
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
| Q92 | A **Radio Service** owns the SX1262: driver, bus lock, IRQ task. The LoRa Scanner uses it in M3; the Mesh Service sits on top of it in M4. |
|
| Q92 | A **Radio Service** owns the SX1262: driver, bus lock, IRQ task. The LoRa Scanner uses it in M3; the Mesh Service sits on top of it in M4. |
|
||||||
| Q93 | Every radio transfer takes the shared bus lock (`SPI.beginTransaction`, as the card does). DIO1's interrupt only wakes the task; no SPI in the ISR. **Done when** a Gemini page streams to the card while the Sniffer receives, with no lost packets and no card errors (`lora status` counters). |
|
| Q93 | Every radio transfer takes the shared bus lock (`SPI.beginTransaction`, as the card does). DIO1's interrupt only wakes the task; no SPI in the ISR. **Done when** a Gemini page streams to the card while the Sniffer receives, with no lost packets and no card errors (`lora status` counters). |
|
||||||
| Q94 | **Receive only:** the Radio Service has no transmit function in M3. It doesn't exist, rather than being unused. |
|
| Q94 | **Receive only:** the Radio Service has no transmit function in M3. It doesn't exist, rather than being unused. |
|
||||||
| Q95 | Sniffer defaults: **EU868 LongFast**, 869.525 MHz, BW 250 kHz, SF 11, CR 4/5, sync word 0x2B, preamble 16 (Q19). The other Meshtastic presets are offered, plus custom settings. |
|
| Q95 | Sniffer defaults: **EU868 LongFast**, 869.525 MHz, BW 250 kHz, SF 11, CR 4/5, sync word 0x2B, preamble 16 (Q19). The other Meshtastic presets are offered, plus custom settings. *Later, the default became is the MeshCore preset (869.618 MHz, BW 62.5 kHz, SF 8, CR 4/8, sync word 0x12): it is what is heard here.* |
|
||||||
| Q96 | The Sniffer lists packets (time, RSSI, SNR, frequency error, length; hex dump on Enter) **and decodes the Meshtastic header**: the first 16 bytes are never encrypted (destination, sender, packet ID, hop limit and hop start, channel hash, next hop, relay node). Host-tested. Payload decryption is M4. |
|
| Q96 | The Sniffer lists packets (time, RSSI, SNR, frequency error, length; hex dump on Enter) **and decodes the Meshtastic header**: the first 16 bytes are never encrypted (destination, sender, packet ID, hop limit and hop start, channel hash, next hop, relay node). Host-tested. Payload decryption is M4. |
|
||||||
| Q97 | A Sniffer **Capture** is pcap with **LoRaTap** headers (link type 270), for Wireshark. Started by hand, Status Bar mark, its own Clean-up category, the 90% rule. |
|
| Q97 | A Sniffer **Capture** is pcap with **LoRaTap** headers (link type 270), for Wireshark. Started by hand, Status Bar mark, its own Clean-up category, the 90% rule. |
|
||||||
| Q98 | **Sweep** steps across the Region's band (863–870 MHz) in 100 kHz steps by default, reading instant RSSI: bars with peak hold, and a waterfall, Wi-Fi Tools style. Optionally CAD on the preset's frequency to tell LoRa traffic from noise. |
|
| Q98 | **Sweep** steps across the Region's band (863–870 MHz) in 100 kHz steps by default, reading instant RSSI: bars with peak hold, and a waterfall, Wi-Fi Tools style. Optionally CAD on the preset's frequency to tell LoRa traffic from noise. |
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# N1 — Network tools
|
# N1 — Network tools
|
||||||
|
|
||||||
**Status:** in progress. The WireGuard tunnel (issue #8) shipped as **v0.19.0**. The first network troubleshooting commands (issue #90) shipped as **v0.20.0**: `ping`, `nslookup`, `port`, `traceroute`, `ifconfig`, `arp`; `tls`, `ntp` and `netstat` are still to do. SSH (#2) is not started.
|
**Status:** in progress. The WireGuard tunnel (issue #8) shipped as **v0.19.0**. The network troubleshooting commands (issue #90) shipped in two parts: `ping`, `nslookup`, `port`, `traceroute`, `ifconfig` and `arp` as **v0.20.0**; `tls`, `ntp` and `netstat` as **v0.21.0**. The SSH client (issue #2) shipped as **v0.22.0**.
|
||||||
|
|
||||||
**Goal:** reach things from the device that aren't on the Wi-Fi it happens to be on, and keep its traffic private on a network that isn't yours.
|
**Goal:** reach things from the device that aren't on the Wi-Fi it happens to be on, and keep its traffic private on a network that isn't yours.
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ The test keys were made for the purpose and deleted. Two rounds: first with the
|
|||||||
| Memory | 106.1 KB free before, 104.3 KB with the tunnel up, 106.2 KB after |
|
| Memory | 106.1 KB free before, 104.3 KB with the tunnel up, 106.2 KB after |
|
||||||
| Settings > VPN | The four rows, the state and "heard 66 s ago", the server, the address; no key anywhere on it |
|
| Settings > VPN | The four rows, the state and "heard 66 s ago", the server, the address; no key anywhere on it |
|
||||||
|
|
||||||
**Against a real server** (the maintainer's own, 2026-10-08): a configuration uploaded from a phone through the Storage App's sharing (issue #88) and imported in Settings; the server named by host name, on a port of its own, the device's address a /32, everything through the tunnel, "Start with Wi-Fi" on. The tunnel is up, and from another machine the device answers on its tunnel address: pings, and the Debug Console.
|
**Against a real server** (the maintainer's own, 2026-10-08): a configuration put on the card by the maintainer and imported in Settings; the server named by host name, on a port of its own, the device's address a /32, everything through the tunnel, "Start with Wi-Fi" on. The tunnel is up, and from another machine the device answers on its tunnel address: pings, and the Debug Console.
|
||||||
|
|
||||||
**Not checked:** from a network far from the server (the device was on the server's own network, reaching it by its public name). That the MTU is what limits a packet (larger pings were answered too, in pieces). Roaming from one Wi-Fi to another with the tunnel wanted. IRC through the tunnel. A day of uptime.
|
**Not checked:** from a network far from the server (the device was on the server's own network, reaching it by its public name). That the MTU is what limits a packet (larger pings were answered too, in pieces). Roaming from one Wi-Fi to another with the tunnel wanted. IRC through the tunnel. A day of uptime.
|
||||||
|
|
||||||
@@ -121,3 +121,102 @@ With a tunnel, fixed addresses and a file server on the device, "is it the netwo
|
|||||||
**Not checked:** without the VPN (every check went through the tunnel, or to the local network); a network that drops ICMP; the commands in Safe Mode, where they are not offered.
|
**Not checked:** without the VPN (every check went through the tunnel, or to the local network); a network that drops ICMP; the commands in Safe Mode, where they are not offered.
|
||||||
|
|
||||||
**Found on the way:** a refused connection is reported by lwIP as "reset", not "refused"; the first version called it "no route". And the header for the tested half was first given the same name as the service's, which makes a file include itself: the same mistake as an hour before, in the same way.
|
**Found on the way:** a refused connection is reported by lwIP as "reset", not "refused"; the first version called it "no route". And the header for the tested half was first given the same name as the service's, which makes a file include itself: the same mistake as an hour before, in the same way.
|
||||||
|
|
||||||
|
### The rest of the list: `tls`, `ntp`, `netstat` (2026-10-08)
|
||||||
|
|
||||||
|
- **`tls <host> [port]`** makes a handshake that checks nothing, so that a bad certificate can be looked at, and then checks it itself: against this device's roots (`ca_roots.h`, the ones the Update Service trusts) and the name asked for. It says who the certificate is for, who signed it, from when to when with the days left, the verdict with its reasons, and the SHA-256 that a Gemini pin is. It runs on a 12 KB task and isn't tried with less than 70 KB free: a handshake peaks at about 52 KB.
|
||||||
|
- **`ntp [server]`** sends one SNTP request and compares the answer with the device's clock, allowing for half the round trip. With no server it asks the first one in Settings.
|
||||||
|
- **`netstat`** reads lwIP's own lists: what listens, labelled where the firmware knows what it is, what is connected, and the UDP ports in use.
|
||||||
|
- Host tests: the NTP packet and the year 2036, the offset in words, a certificate's name (an old string type that mbedTLS prints as hex included), days between dates. 7 tests in `test/test_net_probe` in all.
|
||||||
|
|
||||||
|
| Check on the device | Result |
|
||||||
|
|---|---|
|
||||||
|
| `tls git.twis.la` | 709 ms; for git.twis.la, 67 days left, "this device trusts it", the SHA-256 |
|
||||||
|
| `tls geminiprotocol.net 1965` | "NOT trusted here: not signed by a root this device has": a capsule signs its own |
|
||||||
|
| `tls expired.badssl.com` | "EXPIRED 4197 days ago" |
|
||||||
|
| `tls wrong.host.badssl.com` | "NOT trusted here: not for that name" |
|
||||||
|
| `tls` to a port that isn't TLS | "no handshake ... An invalid SSL record was received" |
|
||||||
|
| `ntp` | The server, its stratum, 50 ms away; "this clock is right, to 0.1 s" |
|
||||||
|
| `netstat` | The update port and the Debug Console listening, the console's own connection, the UDP ports |
|
||||||
|
| Memory during a `tls` | 44.5 KB free at the lowest, from 104 KB |
|
||||||
|
|
||||||
|
**Not checked:** `tls` with IRC connected (it should refuse for lack of memory); `ntp` against a clock that is wrong; `netstat` while sharing.
|
||||||
|
|
||||||
|
## The SSH client (issue #2)
|
||||||
|
|
||||||
|
A terminal on another machine: one session to a shell, from the SSH App.
|
||||||
|
|
||||||
|
### Measured before deciding (2026-10-08)
|
||||||
|
|
||||||
|
`ewpa/LibSSH-ESP32` 5.10.0 (libssh on mbedTLS) was built into a trial firmware and a session opened against OpenSSH in a container, with a password.
|
||||||
|
|
||||||
|
| | Measured in the trial | As built |
|
||||||
|
|---|---|---|
|
||||||
|
| Flash | 120 KB | **292 KB** |
|
||||||
|
| Static RAM | 1.2 KB | |
|
||||||
|
| The session's task stack | 13 KB used | 13.7 KB used of 20 KB |
|
||||||
|
| Free heap with a session open | | 49 KB of 99 KB: it costs about 50 KB, the stack included |
|
||||||
|
| Lowest free heap during a login | | 30 KB |
|
||||||
|
| Key exchange (curve25519, ed25519 host key) | 227 ms | |
|
||||||
|
|
||||||
|
- **The trial undercounted the flash.** It logged in with a password. Signing with a key of the device's own (Q255) links libssh's table of multiples of the Ed25519 base point: `ge25519.c.o` alone is 109 KB. The rest of the difference is the public-key code, the terminal and three fonts. The firmware is at 71% of its slot.
|
||||||
|
- **libssh carries its own curve25519** (`src/external/curve25519_ref.c`) with the names libsodium uses, and libsodium is already here for WireGuard: two definitions don't link. A build script (`scripts/libssh_filter.py`) leaves libssh's copy out, and it uses libsodium's. It has to be a `pre:` script: libraries are built before any `post:` one runs.
|
||||||
|
- A session and a TLS connection don't fit together: IRC holds 40 KB.
|
||||||
|
|
||||||
|
### Decisions (design round 2026-10-08)
|
||||||
|
|
||||||
|
| # | Decision |
|
||||||
|
|---|---|
|
||||||
|
| Q254 | **LibSSH-ESP32 5.10.0**, with its duplicate curve file left out of the build. |
|
||||||
|
| Q255 | **A password, typed each time and never stored**, or **a key the device makes for itself** (Ed25519, no passphrase, kept in the settings store). Its public half is shown, written to `/ssh/id_ed25519.pub` and printed by `ssh status`. Keys made elsewhere aren't imported. |
|
||||||
|
| Q256 | **A terminal good enough for a shell, `less`, `top`, `nano` and `vim`:** cursor movement, erasing, sixteen colours, scroll regions, the alternate screen, the cursor keys' two modes. `TERM=xterm`. No mouse. |
|
||||||
|
| Q257 | **Five text sizes, changed with Ctrl and + or -** (the user's change to the round: the proposal was a setting). 4x6, 5x8, 6x10, 6x13 and 9x15 pixels: from 60 x 20 to 26 x 8 characters. The far end is told the new size; the choice is kept. |
|
||||||
|
| Q258 | **100 lines of scrollback**, as text, with Alt and up or down, as in the Shell. Not on the alternate screen. |
|
||||||
|
| Q259 | **Keys:** Ctrl with a letter; Tab; the backtick key sends Esc, as it is printed; Alt with it types a backtick; Fn with the arrow keys; Shift with those for Page Up and Down; Ctrl+Alt+q disconnects. Fn with backtick is Home, as everywhere. |
|
||||||
|
| Q260 | **The session outlives the App's time in front.** `SSH` in the Status Bar while one is open. |
|
||||||
|
| Q261 | **Not started under 75 KB free**, with the reason in words. |
|
||||||
|
| Q262 | **Up to eight hosts remembered**, the last used first, once a login has succeeded. Forgetting one forgets its server's fingerprint too, unless another remembered host is the same server. |
|
||||||
|
| Q263 | **Trust on first use,** on the SHA-256 fingerprint; sixteen servers remembered. **A changed key is a warning**, with Cancel selected. |
|
||||||
|
| Q264 | **UTF-8 in, the fonts' Latin-1 out:** what they lack is `?`, box-drawing lines are `+ - \|`. |
|
||||||
|
| Q265 | **`ssh user@host` in the Shell opens the App** and connects there. The password is never asked on a console. |
|
||||||
|
| Q266 | **Not built:** port forwarding, SFTP and scp, jump hosts, agent forwarding, keys with a passphrase, more than one session. |
|
||||||
|
|
||||||
|
### As built
|
||||||
|
|
||||||
|
- **`lib/term`** (host-tested, 12 tests in `test/test_terminal`): `Terminal`, the screen a program's output makes, with its history and the replies a program asks for; `encodeKey`, what a key sends; `SshHosts` and `SshKnownHosts`, the two lists kept in the settings store as lines of text.
|
||||||
|
- **`SshService`** (`src/services/ssh_service`): one session on a task of its own (20 KB of stack). The task and the main loop share the terminal, the bytes to send and the state under one lock. Its questions (is this the right server? the password?) are states it waits in until the App answers; the settings store is only written from the main loop. The password and the private key are overwritten after use.
|
||||||
|
- **`SshApp`** (`src/apps/ssh_app`): the hosts, the entry, the session, the key page. It draws the grid a run of same-coloured cells at a time, at most every 60 ms.
|
||||||
|
- **Keys that aren't characters now say what was held with them** (`lib/input/src/key_mapper.cpp`): the arrows, Enter, Del, Tab and Back carry Shift, Ctrl and Alt. The terminal needs it for Page Up and Alt+backtick. It also makes two documented keys work from the real keyboard, which until now only worked from the Debug Console's `key` command: Ctrl with Fn and up or down in a note, and Shift+Tab in Gemini.
|
||||||
|
- **IRC doesn't try to connect with less than 60 KB free** (`IrcService::kNeedFree`): see below.
|
||||||
|
- Settings: `SshHosts`, `SshKnown`, `SshKey`, `SshPublic`, `SshFont`.
|
||||||
|
|
||||||
|
### Checks on the device (2026-10-08, against OpenSSH 9.7 in a container on the same network)
|
||||||
|
|
||||||
|
| Check | Result |
|
||||||
|
|---|---|
|
||||||
|
| `ssh tester@host:2222` from the Debug Console | The App opens; the fingerprint shown is the one `ssh-keygen -lf` prints on the server |
|
||||||
|
| Trust it, a password | A shell; `stty size` says 15 48, `$TERM` is xterm |
|
||||||
|
| `ls -la`, `top`, `vim` (insert, Esc, `:wq`) | Drawn right: `top`'s reverse-video header, `vim`'s alternate screen and what was there before coming back; the file is on the server |
|
||||||
|
| Ctrl with + and - | `stty size` says 12 40, then 20 60; `top` redraws for it |
|
||||||
|
| `seq 1 60`, Alt with up | The history, in grey, with how far back in the corner |
|
||||||
|
| Fn+backtick, then the App again | The Launcher with `SSH` in the Status Bar; the session as it was |
|
||||||
|
| `sleep 100`, Ctrl+C; Alt+backtick | Interrupted; `` echo `id -u` `` prints 1000 |
|
||||||
|
| Ctrl+Alt+q; `exit` | "Disconnected"; "The session ended" |
|
||||||
|
| This device's key, its public half in `authorized_keys` | "Accepted publickey" in the server's log; no password asked |
|
||||||
|
| The server's host keys replaced | "THE SERVER'S KEY CHANGED" with the new fingerprint, Cancel selected. Cancel: "Not trusted: not connected". Replace: it connects, and doesn't ask again |
|
||||||
|
| A wrong password | "Wrong password", and asked again; Back gives up |
|
||||||
|
| A port nothing listens on | "Nothing listens there: the connection was refused" |
|
||||||
|
| `ssh nobody`, `ssh a@`, a port of 99999 | Refused, each with its reason |
|
||||||
|
| Forgetting a host | Asked, then gone from the list |
|
||||||
|
| `irc start` with a session open | "not enough memory: close the SSH session, retrying in 5 s", and no attempt: the lowest free heap doesn't move |
|
||||||
|
| Memory | 99 KB free before, 49 KB with a session open, 30 KB at the lowest during a login, 99 KB again after |
|
||||||
|
| Stacks | `ssh` 6.8 KB free of 20 KB; `loopTask` 1.9 KB free, as before |
|
||||||
|
|
||||||
|
**Not checked:** the refusal under 75 KB free (it is one comparison, and wasn't provoked). A server on the internet, or through the VPN. Wi-Fi lost in the middle of a session. Servers other than OpenSSH. `nano`, `less`, `htop`, `tmux`. Keyboard-interactive logins (two-factor prompts). A session left open for hours.
|
||||||
|
|
||||||
|
### What went wrong while building it
|
||||||
|
|
||||||
|
- **IRC, started with a session open, took the free heap down to 236 bytes.** A test script's keys went to the Launcher instead of the terminal and opened the IRC App, which connects when opened. Its TLS handshake found no memory, failed, and tried again with its usual back-off, six times; nothing crashed and it never connected, but 236 bytes is no margin at all. IRC now looks at the free heap before each attempt and says "not enough memory: close the SSH session" instead of trying.
|
||||||
|
- **The build script did nothing as a `post:` script:** the libraries were already built when it ran.
|
||||||
|
- **A failed connection was first shown as an empty terminal** with its reason squeezed on the last line, and a host was remembered before anyone had logged in to it. Both changed: the reason has a page, and a host is remembered once a login succeeds.
|
||||||
|
- **The trust question didn't fit its dialog:** the fingerprint is 50 characters. It is now split over two lines, under one line of words.
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ inline constexpr KeyHelp kGeminiAnswer[] = {
|
|||||||
inline constexpr KeyHelp kLora[] = {
|
inline constexpr KeyHelp kLora[] = {
|
||||||
{"; .", "up, down"},
|
{"; .", "up, down"},
|
||||||
{"Enter", "the packet's details"},
|
{"Enter", "the packet's details"},
|
||||||
{"p", "pick a Meshtastic preset"},
|
{"p", "pick a preset"},
|
||||||
{"c", "start a Capture, or stop it"},
|
{"c", "start a Capture, or stop it"},
|
||||||
{"Tab", "the Sweep"},
|
{"Tab", "the Sweep"},
|
||||||
};
|
};
|
||||||
@@ -313,6 +313,34 @@ inline constexpr KeyHelp kVpn[] = {
|
|||||||
{"; .", "up, down"},
|
{"; .", "up, down"},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ssh: SSH, the hosts
|
||||||
|
inline constexpr KeyHelp kSsh[] = {
|
||||||
|
{"Enter", "connect, open"},
|
||||||
|
{"; .", "up, down"},
|
||||||
|
{"n", "a new connection"},
|
||||||
|
{"d", "forget this host"},
|
||||||
|
};
|
||||||
|
|
||||||
|
// ssh-terminal: SSH, the terminal
|
||||||
|
inline constexpr KeyHelp kSshTerminal[] = {
|
||||||
|
{"`", "Esc"},
|
||||||
|
{"Alt `", "a backtick"},
|
||||||
|
{"Fn ; . , /", "the arrows"},
|
||||||
|
{"Fn Shift ; .", "Page Up, Page Down"},
|
||||||
|
{"Ctrl a..z", "Ctrl+C and the rest"},
|
||||||
|
{"Alt ; .", "scroll back, forward"},
|
||||||
|
{"Ctrl + -", "larger, smaller text"},
|
||||||
|
{"Ctrl Alt q", "disconnect"},
|
||||||
|
{"Fn `", "leave it running"},
|
||||||
|
};
|
||||||
|
|
||||||
|
// ssh-key: SSH, this device's key
|
||||||
|
inline constexpr KeyHelp kSshKey[] = {
|
||||||
|
{"Enter", "make a key, or a new one"},
|
||||||
|
{"w", "write the public half to the card"},
|
||||||
|
{"`", "back"},
|
||||||
|
};
|
||||||
|
|
||||||
// notes: Notes, the list
|
// notes: Notes, the list
|
||||||
inline constexpr KeyHelp kNotes[] = {
|
inline constexpr KeyHelp kNotes[] = {
|
||||||
{"; .", "up, down"},
|
{"; .", "up, down"},
|
||||||
|
|||||||
@@ -43,6 +43,15 @@ KeyEvent charEvent(uint32_t cp, const RawKeys& keys) {
|
|||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A key that isn't a character, with what was held: a terminal tells Alt+Enter from Enter (issue #2).
|
||||||
|
KeyEvent keyEvent(Key key, const RawKeys& keys) {
|
||||||
|
KeyEvent e = KeyEvent::of(key);
|
||||||
|
e.shift = keys.shift;
|
||||||
|
e.ctrl = keys.ctrl;
|
||||||
|
e.alt = keys.alt;
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
std::vector<KeyEvent> KeyMapper::update(const RawKeys& keys) {
|
std::vector<KeyEvent> KeyMapper::update(const RawKeys& keys) {
|
||||||
@@ -51,9 +60,9 @@ std::vector<KeyEvent> KeyMapper::update(const RawKeys& keys) {
|
|||||||
if (keys.opt && !previous_.opt && keys.chars.empty()) {
|
if (keys.opt && !previous_.opt && keys.chars.empty()) {
|
||||||
compose_ = compose_ ? 0 : kArmed; // a second opt cancels
|
compose_ = compose_ ? 0 : kArmed; // a second opt cancels
|
||||||
}
|
}
|
||||||
if (keys.enter && !previous_.enter) out.push_back(KeyEvent::of(Key::Select));
|
if (keys.enter && !previous_.enter) out.push_back(keyEvent(Key::Select, keys));
|
||||||
if (keys.del && !previous_.del) out.push_back(KeyEvent::of(Key::Delete));
|
if (keys.del && !previous_.del) out.push_back(keyEvent(Key::Delete, keys));
|
||||||
if (keys.tab && !previous_.tab) out.push_back(KeyEvent::of(Key::Tab));
|
if (keys.tab && !previous_.tab) out.push_back(keyEvent(Key::Tab, keys));
|
||||||
|
|
||||||
for (char c : keys.chars) {
|
for (char c : keys.chars) {
|
||||||
bool wasHeld = std::find(previous_.chars.begin(), previous_.chars.end(), c) != previous_.chars.end();
|
bool wasHeld = std::find(previous_.chars.begin(), previous_.chars.end(), c) != previous_.chars.end();
|
||||||
@@ -89,10 +98,10 @@ void KeyMapper::onChar(char c, const RawKeys& keys, std::vector<KeyEvent>& out)
|
|||||||
|
|
||||||
if (keys.fn || !textEntry_) {
|
if (keys.fn || !textEntry_) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case ';': out.push_back(KeyEvent::of(Key::Up)); return;
|
case ';': out.push_back(keyEvent(Key::Up, keys)); return;
|
||||||
case '.': out.push_back(KeyEvent::of(Key::Down)); return;
|
case '.': out.push_back(keyEvent(Key::Down, keys)); return;
|
||||||
case ',': out.push_back(KeyEvent::of(Key::Left)); return;
|
case ',': out.push_back(keyEvent(Key::Left, keys)); return;
|
||||||
case '/': out.push_back(KeyEvent::of(Key::Right)); return;
|
case '/': out.push_back(keyEvent(Key::Right, keys)); return;
|
||||||
case '`':
|
case '`':
|
||||||
if (keys.fn) {
|
if (keys.fn) {
|
||||||
out.push_back(KeyEvent::of(Key::Home));
|
out.push_back(KeyEvent::of(Key::Home));
|
||||||
@@ -126,7 +135,7 @@ void KeyMapper::onChar(char c, const RawKeys& keys, std::vector<KeyEvent>& out)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (c == '`') {
|
if (c == '`') {
|
||||||
out.push_back(KeyEvent::of(Key::Back));
|
out.push_back(keyEvent(Key::Back, keys));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
out.push_back(charEvent(static_cast<unsigned char>(c), keys));
|
out.push_back(charEvent(static_cast<unsigned char>(c), keys));
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
|
||||||
#include "base64.h"
|
#include "base64.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
namespace roro {
|
namespace roro {
|
||||||
|
|
||||||
@@ -284,7 +285,7 @@ void IrcSession::onPrivmsg(const IrcMessage& m, int64_t utc, bool notice) {
|
|||||||
action = true;
|
action = true;
|
||||||
text = rest;
|
text = rest;
|
||||||
} else {
|
} else {
|
||||||
if (verb == "VERSION" && !notice) send(std::string("NOTICE ") + from + " :" + kCtcp + "VERSION roro9stack" + kCtcp);
|
if (verb == "VERSION" && !notice) send(std::string("NOTICE ") + from + " :" + kCtcp + "VERSION " + kProductName + " " + versionString() + kCtcp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -359,10 +360,12 @@ void IrcSession::command(int b, const std::string& text, int64_t utc) {
|
|||||||
} else if (verb == "quit") {
|
} else if (verb == "quit") {
|
||||||
quit_ = true;
|
quit_ = true;
|
||||||
send(IrcMessage::serialize("QUIT", {rest.empty() ? "roro9stack" : rest}));
|
send(IrcMessage::serialize("QUIT", {rest.empty() ? "roro9stack" : rest}));
|
||||||
|
} else if (verb == "uname") { // shown here, not said to anyone
|
||||||
|
info(b, unameString(), utc);
|
||||||
} else if (verb == "raw" || verb == "quote") {
|
} else if (verb == "raw" || verb == "quote") {
|
||||||
if (!rest.empty()) send(rest);
|
if (!rest.empty()) send(rest);
|
||||||
} else {
|
} else {
|
||||||
info(b, "Unknown command /" + verb + " (try /join or /j, /part /msg /me /nick /topic /names /quit /raw)", utc);
|
info(b, "Unknown command /" + verb + " (try /join or /j, /part /msg /me /nick /topic /names /uname /quit /raw)", utc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
#include "meshcore_channel.h"
|
||||||
|
#include "meshcore_packet.h"
|
||||||
#include "meshtastic_header.h"
|
#include "meshtastic_header.h"
|
||||||
#include "meshtastic_presets.h"
|
#include "meshtastic_presets.h"
|
||||||
|
|
||||||
@@ -10,13 +13,137 @@ namespace roro::lora {
|
|||||||
|
|
||||||
using namespace meshtastic;
|
using namespace meshtastic;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::string hex(const uint8_t* p, size_t n) {
|
||||||
|
std::string out;
|
||||||
|
char s[4];
|
||||||
|
for (size_t i = 0; i < n; ++i) {
|
||||||
|
std::snprintf(s, sizeof s, "%02x", p[i]);
|
||||||
|
out += s;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Onto lines of `cols` characters at most, broken at spaces where there are some.
|
||||||
|
void wrapInto(std::vector<std::string>& lines, std::string text, size_t cols) {
|
||||||
|
while (text.size() > cols) {
|
||||||
|
size_t cut = text.rfind(' ', cols);
|
||||||
|
if (cut == std::string::npos || cut == 0) cut = cols;
|
||||||
|
lines.push_back(text.substr(0, cut));
|
||||||
|
text.erase(0, text[cut] == ' ' ? cut + 1 : cut);
|
||||||
|
}
|
||||||
|
if (!text.empty()) lines.push_back(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
// `room` characters at most: a node's name or a message is cut to fit.
|
||||||
|
std::string meshcoreRow(const meshcore::Packet& m, size_t room) {
|
||||||
|
std::string out = meshcore::payloadShort(m.type);
|
||||||
|
std::string hops = m.hops ? " " + std::to_string(m.hops) + "h" : "";
|
||||||
|
meshcore::Advert a;
|
||||||
|
meshcore::Discover d;
|
||||||
|
meshcore::ChannelText t;
|
||||||
|
if (meshcore::parseDiscover(m, d)) {
|
||||||
|
out = d.response ? "here " + hex(d.id, 2) : "who's there?";
|
||||||
|
} else if (meshcore::readChannelText(m, t)) {
|
||||||
|
out = (t.sender.empty() ? "" : t.sender + ": ") + t.text;
|
||||||
|
out = out.substr(0, room > hops.size() ? room - hops.size() : 0);
|
||||||
|
while (!out.empty() && out.back() == ' ') out.pop_back();
|
||||||
|
return out + hops;
|
||||||
|
} else if (meshcore::parseAdvert(m, a)) {
|
||||||
|
size_t used = out.size() + 1 + hops.size();
|
||||||
|
out += " " + (a.name.empty() ? hex(a.key, 2) : a.name.substr(0, room > used ? room - used : 0));
|
||||||
|
} else if (m.addressed() && m.payloadLen >= 2)
|
||||||
|
out += " " + hex(m.payload + 1, 1) + ">" + hex(m.payload, 1);
|
||||||
|
else if (m.group() && m.payloadLen >= 1)
|
||||||
|
out += " #" + hex(m.payload, 1);
|
||||||
|
else if (m.type == meshcore::Payload::AnonRequest && m.payloadLen >= 1)
|
||||||
|
out += " >" + hex(m.payload, 1);
|
||||||
|
return out + hops;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> meshcoreLines(const uint8_t* data, size_t len) {
|
||||||
|
meshcore::Packet m;
|
||||||
|
if (!meshcore::parsePacket(data, len, m)) return {};
|
||||||
|
char s[64];
|
||||||
|
std::vector<std::string> lines;
|
||||||
|
lines.push_back("MeshCore " + std::string(meshcore::payloadName(m.type)) + ", " + meshcore::routeName(m.route));
|
||||||
|
if (m.hasTransport) {
|
||||||
|
std::snprintf(s, sizeof s, "Region code %04x", m.transport[0]);
|
||||||
|
lines.push_back(s);
|
||||||
|
}
|
||||||
|
// A flood gathers who repeated it; a direct packet carries who is still to repeat it.
|
||||||
|
if (m.hops) {
|
||||||
|
std::string path = std::string(m.flood() ? "Through" : "Route");
|
||||||
|
for (uint8_t i = 0; i < m.hops; ++i) {
|
||||||
|
std::string hop = " " + hex(m.path + i * m.hashSize, m.hashSize);
|
||||||
|
if (path.size() + hop.size() > 36) { // onto another line
|
||||||
|
lines.push_back(path);
|
||||||
|
path = " ";
|
||||||
|
}
|
||||||
|
path += hop;
|
||||||
|
}
|
||||||
|
lines.push_back(path);
|
||||||
|
} else {
|
||||||
|
lines.push_back(m.flood() ? "Heard first hand: no repeater yet" : "No route in it: to a neighbour");
|
||||||
|
}
|
||||||
|
meshcore::Advert a;
|
||||||
|
meshcore::Discover d;
|
||||||
|
if (meshcore::parseDiscover(m, d) && d.response) {
|
||||||
|
lines.push_back(std::string(meshcore::kindName(d.kind)) + " answering a search");
|
||||||
|
lines.push_back("Key " + hex(d.id, 8) + "...");
|
||||||
|
std::snprintf(s, sizeof s, "It heard the search at %.1f dB SNR", d.snr);
|
||||||
|
lines.push_back(s);
|
||||||
|
} else if (meshcore::parseDiscover(m, d)) {
|
||||||
|
std::string who;
|
||||||
|
for (int kind = 1; kind <= 4; ++kind)
|
||||||
|
if (d.kinds & (1 << kind)) who += std::string(who.empty() ? "" : ", ") + meshcore::kindName(static_cast<uint8_t>(kind));
|
||||||
|
lines.push_back("A search for nodes nearby");
|
||||||
|
lines.push_back("Wanted: " + (who.empty() ? std::string("any") : who));
|
||||||
|
} else if (meshcore::parseAdvert(m, a)) {
|
||||||
|
lines.push_back(std::string(meshcore::kindName(a.kind)) + (a.name.empty() ? "" : " " + a.name));
|
||||||
|
lines.push_back("Key " + hex(a.key, 8) + "...");
|
||||||
|
if (a.hasLocation) {
|
||||||
|
std::snprintf(s, sizeof s, "At %.5f, %.5f", a.latE6 / 1e6, a.lonE6 / 1e6);
|
||||||
|
lines.push_back(s);
|
||||||
|
}
|
||||||
|
} else if (m.addressed() && m.payloadLen >= 4) {
|
||||||
|
std::snprintf(s, sizeof s, "From ..%02x to ..%02x, %u B encrypted", m.payload[1], m.payload[0], static_cast<unsigned>(m.payloadLen - 4));
|
||||||
|
lines.push_back(s);
|
||||||
|
} else if (meshcore::ChannelText t; meshcore::readChannelText(m, t)) {
|
||||||
|
lines.push_back(std::string("On the ") + t.channel + " channel" + (t.sender.empty() ? "" : ", from " + t.sender));
|
||||||
|
std::time_t sent = t.timestamp;
|
||||||
|
std::tm tm{};
|
||||||
|
gmtime_r(&sent, &tm);
|
||||||
|
std::strftime(s, sizeof s, "Sent %Y-%m-%d %H:%M:%S UTC", &tm);
|
||||||
|
lines.push_back(s);
|
||||||
|
wrapInto(lines, t.text, 38);
|
||||||
|
} else if (m.group() && m.payloadLen >= 3) {
|
||||||
|
std::snprintf(s, sizeof s, "Channel 0x%02x%s, %u B encrypted", m.payload[0], m.payload[0] == meshcore::kPublicChannelHash ? " (public?)" : "",
|
||||||
|
static_cast<unsigned>(m.payloadLen - 3));
|
||||||
|
lines.push_back(s);
|
||||||
|
} else if (m.type == meshcore::Payload::AnonRequest && m.payloadLen >= 35) {
|
||||||
|
std::snprintf(s, sizeof s, "To ..%02x from key %s...", m.payload[0], hex(m.payload + 1, 4).c_str());
|
||||||
|
lines.push_back(s);
|
||||||
|
} else if (m.type == meshcore::Payload::Ack && m.payloadLen >= 4) {
|
||||||
|
lines.push_back("Acknowledges " + hex(m.payload, 4));
|
||||||
|
}
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
Protocol protocolOf(uint8_t syncWord) {
|
||||||
|
return syncWord == meshtastic::kSyncWord ? Protocol::Meshtastic : syncWord == meshcore::kSyncWord ? Protocol::MeshCore : Protocol::None;
|
||||||
|
}
|
||||||
|
|
||||||
std::string row(const PacketSummary& p, const std::string& time) {
|
std::string row(const PacketSummary& p, const std::string& time) {
|
||||||
char s[64];
|
char s[64];
|
||||||
int n = std::snprintf(s, sizeof s, "%s %ld %.1f ", time.c_str(), std::lround(p.rssi), p.snr);
|
int n = std::snprintf(s, sizeof s, "%s %ld %.1f ", time.c_str(), std::lround(p.rssi), p.snr);
|
||||||
std::string out(s, n);
|
std::string out(s, n);
|
||||||
PacketHeader h;
|
PacketHeader h;
|
||||||
if (!p.crcOk) return out + "bad CRC, " + std::to_string(p.len) + " B";
|
if (!p.crcOk) return out + "bad CRC, " + std::to_string(p.len) + " B";
|
||||||
if (!p.meshtastic || !parseHeader(p.data, p.len, h)) return out + std::to_string(p.len) + " B";
|
meshcore::Packet m;
|
||||||
|
if (p.protocol == Protocol::MeshCore && meshcore::parsePacket(p.data, p.len, m)) return out + meshcoreRow(m, out.size() < 38 ? 38 - out.size() : 0);
|
||||||
|
if (p.protocol != Protocol::Meshtastic || !parseHeader(p.data, p.len, h)) return out + std::to_string(p.len) + " B";
|
||||||
auto shortId = [](uint32_t node) {
|
auto shortId = [](uint32_t node) {
|
||||||
if (node == kBroadcast) return std::string("all");
|
if (node == kBroadcast) return std::string("all");
|
||||||
char id[8];
|
char id[8];
|
||||||
@@ -48,7 +175,9 @@ std::vector<std::string> hexDump(const uint8_t* data, size_t len) {
|
|||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> headerLines(const uint8_t* data, size_t len) {
|
std::vector<std::string> headerLines(const uint8_t* data, size_t len, Protocol protocol) {
|
||||||
|
if (protocol == Protocol::MeshCore) return meshcoreLines(data, len);
|
||||||
|
if (protocol != Protocol::Meshtastic) return {};
|
||||||
PacketHeader h;
|
PacketHeader h;
|
||||||
if (!parseHeader(data, len, h)) return {};
|
if (!parseHeader(data, len, h)) return {};
|
||||||
char s[64];
|
char s[64];
|
||||||
|
|||||||
@@ -7,23 +7,30 @@
|
|||||||
|
|
||||||
namespace roro::lora {
|
namespace roro::lora {
|
||||||
|
|
||||||
|
// Whose packets the radio's settings were for, by their sync word: whose clear header to read.
|
||||||
|
enum class Protocol : uint8_t { None, Meshtastic, MeshCore };
|
||||||
|
Protocol protocolOf(uint8_t syncWord);
|
||||||
|
|
||||||
// What the LoRa Scanner shows of one packet (M3, Q96).
|
// What the LoRa Scanner shows of one packet (M3, Q96).
|
||||||
struct PacketSummary {
|
struct PacketSummary {
|
||||||
const uint8_t* data;
|
const uint8_t* data;
|
||||||
size_t len;
|
size_t len;
|
||||||
float rssi, snr;
|
float rssi, snr;
|
||||||
bool crcOk;
|
bool crcOk;
|
||||||
bool meshtastic; // received on Meshtastic settings (sync word 0x2B): read its clear header
|
Protocol protocol; // what the settings it was received on were for
|
||||||
};
|
};
|
||||||
|
|
||||||
// One list row, at most about 36 characters: "21:45:07 -97 6.2 5678>all 1/3". Nodes by their default
|
// One list row, at most about 36 characters: "21:45:07 -97 6.2 5678>all 1/3". Meshtastic nodes by their
|
||||||
// short name (the last 4 hex digits); headerLines() has the full numbers.
|
// default short name (the last 4 hex digits); headerLines() has the full numbers. MeshCore: what
|
||||||
|
// it is, then who ("adv Brussels-R1", "txt a3>7f", "chan #11", "who's there?", "here 18a6") and the hops in its path ("2h");
|
||||||
|
// a message on the public channel is read: "Alice: hello fro 2h".
|
||||||
std::string row(const PacketSummary& p, const std::string& time);
|
std::string row(const PacketSummary& p, const std::string& time);
|
||||||
|
|
||||||
// Eight bytes a line, with the printable ones: "0000 ff ff ff ff 78 56 34 12 ....xV4.".
|
// Eight bytes a line, with the printable ones: "0000 ff ff ff ff 78 56 34 12 ....xV4.".
|
||||||
std::vector<std::string> hexDump(const uint8_t* data, size_t len);
|
std::vector<std::string> hexDump(const uint8_t* data, size_t len);
|
||||||
|
|
||||||
// The Meshtastic header, one field a line; empty when the packet is too short to have one.
|
// What is in clear, one field a line: the Meshtastic header, or MeshCore's header, path and (for an
|
||||||
std::vector<std::string> headerLines(const uint8_t* data, size_t len);
|
// advert) who the node says it is, and a message on its public channel. Empty when the packet can't be read as that.
|
||||||
|
std::vector<std::string> headerLines(const uint8_t* data, size_t len, Protocol protocol = Protocol::Meshtastic);
|
||||||
|
|
||||||
} // namespace roro::lora
|
} // namespace roro::lora
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#include "scan_presets.h"
|
||||||
|
|
||||||
|
#include <cctype>
|
||||||
|
|
||||||
|
#include "meshcore_packet.h"
|
||||||
|
#include "meshtastic_presets.h"
|
||||||
|
|
||||||
|
namespace roro::lora {
|
||||||
|
|
||||||
|
size_t scanPresetCount() { return meshtastic::kEu868PresetCount + 1; }
|
||||||
|
|
||||||
|
ScanPreset scanPreset(size_t i) {
|
||||||
|
if (i < meshtastic::kEu868PresetCount) {
|
||||||
|
const meshtastic::Preset& p = meshtastic::kEu868Presets[i];
|
||||||
|
return {p.name, meshtastic::eu868FrequencyHz(p), p.bwKHz, p.sf, p.cr, meshtastic::kSyncWord, meshtastic::kPreambleLength, Protocol::Meshtastic};
|
||||||
|
}
|
||||||
|
return {meshcore::kPresetName, meshcore::kEuNarrowHz, meshcore::kEuNarrowBwKHz, meshcore::kEuNarrowSf, meshcore::kEuNarrowCr,
|
||||||
|
meshcore::kSyncWord, meshcore::kPreambleLength, Protocol::MeshCore};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool findScanPreset(const char* name, ScanPreset& out) {
|
||||||
|
for (size_t i = 0; i < scanPresetCount(); ++i) {
|
||||||
|
ScanPreset p = scanPreset(i);
|
||||||
|
const char *a = p.name, *b = name;
|
||||||
|
while (*a && *b && std::tolower(static_cast<unsigned char>(*a)) == std::tolower(static_cast<unsigned char>(*b))) ++a, ++b;
|
||||||
|
if (!*a && !*b) {
|
||||||
|
out = p;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace roro::lora
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include "packet_view.h"
|
||||||
|
|
||||||
|
namespace roro::lora {
|
||||||
|
|
||||||
|
// What the LoRa Scanner can be told to listen to by name: the Meshtastic presets allowed in
|
||||||
|
// EU_868, LongFast first, then MeshCore's EU/UK (Narrow), the default. The order is kept: the
|
||||||
|
// chosen one is stored by its number.
|
||||||
|
struct ScanPreset {
|
||||||
|
const char* name;
|
||||||
|
uint32_t frequencyHz;
|
||||||
|
float bwKHz;
|
||||||
|
uint8_t sf, cr, syncWord;
|
||||||
|
uint16_t preamble;
|
||||||
|
Protocol protocol;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr size_t kDefaultScanPreset = 7; // MeshCore: the Settings' default says the same
|
||||||
|
size_t scanPresetCount();
|
||||||
|
ScanPreset scanPreset(size_t i); // i < scanPresetCount()
|
||||||
|
// By name, whatever its case. False when there is none.
|
||||||
|
bool findScanPreset(const char* name, ScanPreset& out);
|
||||||
|
|
||||||
|
} // namespace roro::lora
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
#include "aes128.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
namespace roro::meshcore {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// The S-box and its inverse, worked out once rather than typed in.
|
||||||
|
struct Tables {
|
||||||
|
uint8_t s[256], inv[256];
|
||||||
|
Tables() {
|
||||||
|
auto rotl = [](uint8_t x, int n) { return static_cast<uint8_t>(x << n | x >> (8 - n)); };
|
||||||
|
uint8_t p = 1, q = 1;
|
||||||
|
do {
|
||||||
|
p = static_cast<uint8_t>(p ^ (p << 1) ^ (p & 0x80 ? 0x1B : 0)); // p times 3
|
||||||
|
q ^= static_cast<uint8_t>(q << 1); // q divided by 3
|
||||||
|
q ^= static_cast<uint8_t>(q << 2);
|
||||||
|
q ^= static_cast<uint8_t>(q << 4);
|
||||||
|
if (q & 0x80) q ^= 0x09;
|
||||||
|
uint8_t x = static_cast<uint8_t>(q ^ rotl(q, 1) ^ rotl(q, 2) ^ rotl(q, 3) ^ rotl(q, 4) ^ 0x63);
|
||||||
|
s[p] = x;
|
||||||
|
inv[x] = p;
|
||||||
|
} while (p != 1);
|
||||||
|
s[0] = 0x63;
|
||||||
|
inv[0x63] = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const Tables& tables() {
|
||||||
|
static const Tables t;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t mul(uint8_t a, uint8_t b) { // in GF(2^8)
|
||||||
|
uint8_t r = 0;
|
||||||
|
for (; b; b >>= 1) {
|
||||||
|
if (b & 1) r ^= a;
|
||||||
|
a = static_cast<uint8_t>(a << 1 ^ (a & 0x80 ? 0x1B : 0));
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
Aes128::Aes128(const uint8_t key[16]) {
|
||||||
|
const Tables& t = tables();
|
||||||
|
std::memcpy(roundKeys_, key, 16);
|
||||||
|
uint8_t rcon = 1;
|
||||||
|
for (int i = 16; i < 176; i += 4) {
|
||||||
|
uint8_t w[4];
|
||||||
|
std::memcpy(w, roundKeys_ + i - 4, 4);
|
||||||
|
if (i % 16 == 0) {
|
||||||
|
uint8_t first = w[0];
|
||||||
|
w[0] = static_cast<uint8_t>(t.s[w[1]] ^ rcon);
|
||||||
|
w[1] = t.s[w[2]];
|
||||||
|
w[2] = t.s[w[3]];
|
||||||
|
w[3] = t.s[first];
|
||||||
|
rcon = static_cast<uint8_t>(rcon << 1 ^ (rcon & 0x80 ? 0x1B : 0));
|
||||||
|
}
|
||||||
|
for (int j = 0; j < 4; ++j) roundKeys_[i + j] = roundKeys_[i - 16 + j] ^ w[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Aes128::decryptBlock(const uint8_t in[16], uint8_t out[16]) const {
|
||||||
|
const Tables& t = tables();
|
||||||
|
uint8_t s[16];
|
||||||
|
for (int i = 0; i < 16; ++i) s[i] = in[i] ^ roundKeys_[160 + i];
|
||||||
|
for (int round = 9; round >= 0; --round) {
|
||||||
|
// Rows shifted back and bytes substituted back, in one go: column c, row r came from column c - r.
|
||||||
|
uint8_t u[16];
|
||||||
|
for (int c = 0; c < 4; ++c)
|
||||||
|
for (int r = 0; r < 4; ++r) u[4 * c + r] = t.inv[s[4 * ((c - r + 4) % 4) + r]];
|
||||||
|
for (int i = 0; i < 16; ++i) u[i] ^= roundKeys_[16 * round + i];
|
||||||
|
if (round == 0) {
|
||||||
|
std::memcpy(s, u, 16);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (int c = 0; c < 4; ++c) {
|
||||||
|
const uint8_t* a = u + 4 * c;
|
||||||
|
s[4 * c + 0] = mul(a[0], 14) ^ mul(a[1], 11) ^ mul(a[2], 13) ^ mul(a[3], 9);
|
||||||
|
s[4 * c + 1] = mul(a[0], 9) ^ mul(a[1], 14) ^ mul(a[2], 11) ^ mul(a[3], 13);
|
||||||
|
s[4 * c + 2] = mul(a[0], 13) ^ mul(a[1], 9) ^ mul(a[2], 14) ^ mul(a[3], 11);
|
||||||
|
s[4 * c + 3] = mul(a[0], 11) ^ mul(a[1], 13) ^ mul(a[2], 9) ^ mul(a[3], 14);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::memcpy(out, s, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace roro::meshcore
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace roro::meshcore {
|
||||||
|
|
||||||
|
// AES-128 (FIPS 197), one block at a time, decryption only: what reading a MeshCore message
|
||||||
|
// takes. Small and dependency-free, so the same code runs in the PC tests and on the device.
|
||||||
|
class Aes128 {
|
||||||
|
public:
|
||||||
|
explicit Aes128(const uint8_t key[16]);
|
||||||
|
void decryptBlock(const uint8_t in[16], uint8_t out[16]) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t roundKeys_[176];
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace roro::meshcore
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
#include "meshcore_channel.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "aes128.h"
|
||||||
|
#include "sha256.h"
|
||||||
|
|
||||||
|
namespace roro::meshcore {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// izOH6cXN6mrJ5e26oRXNcg== in base64, as the apps show it.
|
||||||
|
const Channel kChannels[] = {
|
||||||
|
{"Public", {0x8b, 0x33, 0x87, 0xe9, 0xc5, 0xcd, 0xea, 0x6a, 0xc9, 0xe5, 0xed, 0xba, 0xa1, 0x15, 0xcd, 0x72}},
|
||||||
|
};
|
||||||
|
|
||||||
|
void hmacSha256(const uint8_t key[16], const uint8_t* data, size_t len, uint8_t out[32]) {
|
||||||
|
uint8_t pad[64], inner[32];
|
||||||
|
std::memset(pad, 0x36, sizeof pad);
|
||||||
|
for (int i = 0; i < 16; ++i) pad[i] ^= key[i];
|
||||||
|
Sha256 in;
|
||||||
|
in.update(pad, sizeof pad);
|
||||||
|
in.update(data, len);
|
||||||
|
in.finish(inner);
|
||||||
|
std::memset(pad, 0x5C, sizeof pad);
|
||||||
|
for (int i = 0; i < 16; ++i) pad[i] ^= key[i];
|
||||||
|
Sha256 o;
|
||||||
|
o.update(pad, sizeof pad);
|
||||||
|
o.update(inner, sizeof inner);
|
||||||
|
o.finish(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bytes that aren't printable ASCII become '?': one for a whole UTF-8 character.
|
||||||
|
std::string printable(const uint8_t* p, size_t n) {
|
||||||
|
std::string out;
|
||||||
|
for (size_t i = 0; i < n; ++i) {
|
||||||
|
if (p[i] >= 0x20 && p[i] < 0x7F) out += static_cast<char>(p[i]);
|
||||||
|
else if ((p[i] & 0xC0) != 0x80) out += '?';
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
size_t channelCount() { return sizeof kChannels / sizeof kChannels[0]; }
|
||||||
|
const Channel& channel(size_t i) { return kChannels[i]; }
|
||||||
|
|
||||||
|
uint8_t channelHash(const Channel& c) {
|
||||||
|
uint8_t h[32];
|
||||||
|
Sha256::hash(c.key, sizeof c.key, h);
|
||||||
|
return h[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool readChannelText(const Packet& p, ChannelText& out) {
|
||||||
|
// The channel's hash, 2 bytes of check, then whole AES blocks.
|
||||||
|
if (p.type != Payload::GroupText || p.payloadLen < 3 + 16 || (p.payloadLen - 3) % 16) return false;
|
||||||
|
const uint8_t* cipher = p.payload + 3;
|
||||||
|
size_t len = p.payloadLen - 3;
|
||||||
|
for (size_t i = 0; i < channelCount(); ++i) {
|
||||||
|
const Channel& c = channel(i);
|
||||||
|
if (channelHash(c) != p.payload[0]) continue;
|
||||||
|
uint8_t mac[32];
|
||||||
|
hmacSha256(c.key, cipher, len, mac);
|
||||||
|
if (mac[0] != p.payload[1] || mac[1] != p.payload[2]) continue;
|
||||||
|
uint8_t plain[192];
|
||||||
|
Aes128 aes(c.key);
|
||||||
|
for (size_t at = 0; at < len; at += 16) aes.decryptBlock(cipher + at, plain + at);
|
||||||
|
// Timestamp, then a byte whose top 6 bits say what follows: 0 is plain text, "name: words".
|
||||||
|
if (plain[4] >> 2) return false;
|
||||||
|
ChannelText t;
|
||||||
|
t.channel = c.name;
|
||||||
|
t.timestamp = static_cast<uint32_t>(plain[0] | plain[1] << 8 | plain[2] << 16 | static_cast<uint32_t>(plain[3]) << 24);
|
||||||
|
size_t end = 5;
|
||||||
|
while (end < len && plain[end]) ++end; // padded with zeros
|
||||||
|
std::string all = printable(plain + 5, end - 5);
|
||||||
|
size_t colon = all.find(": ");
|
||||||
|
if (colon == std::string::npos) {
|
||||||
|
t.text = all;
|
||||||
|
} else {
|
||||||
|
t.sender = all.substr(0, colon);
|
||||||
|
t.text = all.substr(colon + 2);
|
||||||
|
}
|
||||||
|
out = t;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace roro::meshcore
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "meshcore_packet.h"
|
||||||
|
|
||||||
|
// MeshCore's channel messages: encrypted with a key everyone on the channel has. The public
|
||||||
|
// channel's key is published, so what is said there can be read by anyone listening.
|
||||||
|
namespace roro::meshcore {
|
||||||
|
|
||||||
|
struct Channel {
|
||||||
|
const char* name;
|
||||||
|
uint8_t key[16];
|
||||||
|
};
|
||||||
|
|
||||||
|
// The channels whose key is known here: the public one, for now.
|
||||||
|
size_t channelCount();
|
||||||
|
const Channel& channel(size_t i);
|
||||||
|
// What a message on the channel starts with: the first byte of the SHA-256 of its key.
|
||||||
|
uint8_t channelHash(const Channel& c);
|
||||||
|
|
||||||
|
struct ChannelText {
|
||||||
|
const char* channel = "";
|
||||||
|
uint32_t timestamp = 0; // the sender's clock, seconds since 1970
|
||||||
|
std::string sender; // what the sender calls itself: not signed, anyone can claim a name
|
||||||
|
std::string text; // printable ASCII kept, the rest as '?'
|
||||||
|
};
|
||||||
|
|
||||||
|
// True when the packet is a text on a known channel and its check (2 bytes of HMAC-SHA256) holds.
|
||||||
|
bool readChannelText(const Packet& p, ChannelText& out);
|
||||||
|
|
||||||
|
} // namespace roro::meshcore
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
#include "meshcore_packet.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
namespace roro::meshcore {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
int32_t le32(const uint8_t* p) { return static_cast<int32_t>(p[0] | p[1] << 8 | p[2] << 16 | static_cast<uint32_t>(p[3]) << 24); }
|
||||||
|
constexpr size_t kMaxPath = 64, kMaxPayload = 184;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
bool parsePacket(const uint8_t* data, size_t len, Packet& out) {
|
||||||
|
if (!data || len < 2) return false;
|
||||||
|
uint8_t header = data[0];
|
||||||
|
if (header >> 6) return false; // versions 1 to 3 are reserved
|
||||||
|
uint8_t type = (header >> 2) & 0x0F;
|
||||||
|
if (type >= 0xC && type <= 0xE) return false; // reserved
|
||||||
|
Packet p;
|
||||||
|
p.route = static_cast<Route>(header & 0x03);
|
||||||
|
p.type = static_cast<Payload>(type);
|
||||||
|
size_t at = 1;
|
||||||
|
p.hasTransport = p.route == Route::TransportFlood || p.route == Route::TransportDirect;
|
||||||
|
if (p.hasTransport) {
|
||||||
|
if (len < at + 5) return false;
|
||||||
|
p.transport[0] = static_cast<uint16_t>(data[at] | data[at + 1] << 8);
|
||||||
|
p.transport[1] = static_cast<uint16_t>(data[at + 2] | data[at + 3] << 8);
|
||||||
|
at += 4;
|
||||||
|
}
|
||||||
|
uint8_t pathLen = data[at++];
|
||||||
|
p.hops = pathLen & 0x3F;
|
||||||
|
p.hashSize = static_cast<uint8_t>((pathLen >> 6) + 1);
|
||||||
|
size_t pathBytes = static_cast<size_t>(p.hops) * p.hashSize;
|
||||||
|
if (p.hashSize > 3 || pathBytes > kMaxPath || at + pathBytes > len) return false;
|
||||||
|
p.path = data + at;
|
||||||
|
at += pathBytes;
|
||||||
|
p.payload = data + at;
|
||||||
|
p.payloadLen = len - at;
|
||||||
|
if (p.payloadLen > kMaxPayload) return false;
|
||||||
|
out = p;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool parseAdvert(const Packet& p, Advert& out) {
|
||||||
|
constexpr size_t kFixed = 32 + 4 + 64; // key, timestamp, signature
|
||||||
|
if (p.type != Payload::Advert || p.payloadLen < kFixed + 1) return false;
|
||||||
|
Advert a;
|
||||||
|
std::memcpy(a.key, p.payload, 32);
|
||||||
|
a.timestamp = static_cast<uint32_t>(le32(p.payload + 32));
|
||||||
|
const uint8_t* app = p.payload + kFixed;
|
||||||
|
size_t left = p.payloadLen - kFixed;
|
||||||
|
uint8_t flags = app[0];
|
||||||
|
size_t at = 1;
|
||||||
|
a.kind = flags & 0x0F;
|
||||||
|
if (flags & 0x10) {
|
||||||
|
if (left < at + 8) return false;
|
||||||
|
a.hasLocation = true;
|
||||||
|
a.latE6 = le32(app + at);
|
||||||
|
a.lonE6 = le32(app + at + 4);
|
||||||
|
at += 8;
|
||||||
|
}
|
||||||
|
if (flags & 0x20) at += 2; // two reserved fields
|
||||||
|
if (flags & 0x40) at += 2;
|
||||||
|
if (at > left) return false;
|
||||||
|
if (flags & 0x80)
|
||||||
|
for (; at < left && app[at]; ++at) a.name += app[at] >= 0x20 && app[at] < 0x7F ? static_cast<char>(app[at]) : '?';
|
||||||
|
out = a;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool parseDiscover(const Packet& p, Discover& out) {
|
||||||
|
if (p.type != Payload::Control || p.payloadLen < 6) return false;
|
||||||
|
uint8_t sub = p.payload[0] >> 4;
|
||||||
|
Discover d;
|
||||||
|
d.tag = static_cast<uint32_t>(le32(p.payload + 2));
|
||||||
|
if (sub == 0x8) {
|
||||||
|
d.kinds = p.payload[1];
|
||||||
|
} else if (sub == 0x9) {
|
||||||
|
d.response = true;
|
||||||
|
d.kind = p.payload[0] & 0x0F;
|
||||||
|
d.snr = static_cast<int8_t>(p.payload[1]) / 4.0f;
|
||||||
|
d.id = p.payload + 6;
|
||||||
|
d.idLen = p.payloadLen - 6;
|
||||||
|
if (d.idLen != 8 && d.idLen != 32) return false;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
out = d;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* routeName(Route r) {
|
||||||
|
switch (r) {
|
||||||
|
case Route::TransportFlood: return "flood in a region";
|
||||||
|
case Route::Flood: return "flood";
|
||||||
|
case Route::Direct: return "direct";
|
||||||
|
case Route::TransportDirect: return "direct in a region";
|
||||||
|
}
|
||||||
|
return "?";
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* payloadName(Payload t) {
|
||||||
|
switch (t) {
|
||||||
|
case Payload::Request: return "request";
|
||||||
|
case Payload::Response: return "response";
|
||||||
|
case Payload::Text: return "text message";
|
||||||
|
case Payload::Ack: return "ack";
|
||||||
|
case Payload::Advert: return "advert";
|
||||||
|
case Payload::GroupText: return "channel message";
|
||||||
|
case Payload::GroupData: return "channel data";
|
||||||
|
case Payload::AnonRequest: return "anonymous request";
|
||||||
|
case Payload::Path: return "returned path";
|
||||||
|
case Payload::Trace: return "trace";
|
||||||
|
case Payload::Multipart: return "multipart";
|
||||||
|
case Payload::Control: return "control";
|
||||||
|
case Payload::RawCustom: return "custom";
|
||||||
|
}
|
||||||
|
return "?";
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* payloadShort(Payload t) {
|
||||||
|
switch (t) {
|
||||||
|
case Payload::Request: return "req";
|
||||||
|
case Payload::Response: return "rsp";
|
||||||
|
case Payload::Text: return "txt";
|
||||||
|
case Payload::Ack: return "ack";
|
||||||
|
case Payload::Advert: return "adv";
|
||||||
|
case Payload::GroupText: return "chan";
|
||||||
|
case Payload::GroupData: return "cdat";
|
||||||
|
case Payload::AnonRequest: return "anon";
|
||||||
|
case Payload::Path: return "path";
|
||||||
|
case Payload::Trace: return "trace";
|
||||||
|
case Payload::Multipart: return "multi";
|
||||||
|
case Payload::Control: return "ctl";
|
||||||
|
case Payload::RawCustom: return "raw";
|
||||||
|
}
|
||||||
|
return "?";
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* kindName(uint8_t kind) {
|
||||||
|
switch (kind) {
|
||||||
|
case 1: return "Chat node";
|
||||||
|
case 2: return "Repeater";
|
||||||
|
case 3: return "Room server";
|
||||||
|
case 4: return "Sensor";
|
||||||
|
}
|
||||||
|
return "Node";
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace roro::meshcore
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// MeshCore's packets as they are on air (its docs/packet_format.md and docs/payloads.md): what is
|
||||||
|
// sent in clear, which is the header, the path, and a node's advertisement. meshcore_channel.h
|
||||||
|
// reads the public channel's messages.
|
||||||
|
namespace roro::meshcore {
|
||||||
|
|
||||||
|
// Radio settings: RadioLib's "private" sync word, and the preset its EU/UK networks use.
|
||||||
|
constexpr uint8_t kSyncWord = 0x12;
|
||||||
|
constexpr uint16_t kPreambleLength = 16;
|
||||||
|
constexpr const char* kPresetName = "MeshCore"; // "EU/UK (Narrow)" in its apps
|
||||||
|
constexpr uint32_t kEuNarrowHz = 869618000;
|
||||||
|
constexpr float kEuNarrowBwKHz = 62.5f;
|
||||||
|
constexpr uint8_t kEuNarrowSf = 8, kEuNarrowCr = 8;
|
||||||
|
|
||||||
|
// The first byte of the SHA-256 of the public channel's key (izOH6cXN6mrJ5e26oRXNcg==): what a
|
||||||
|
// group message on the channel every node has starts with.
|
||||||
|
constexpr uint8_t kPublicChannelHash = 0x11;
|
||||||
|
|
||||||
|
enum class Route : uint8_t { TransportFlood = 0, Flood = 1, Direct = 2, TransportDirect = 3 };
|
||||||
|
enum class Payload : uint8_t {
|
||||||
|
Request = 0x0, Response = 0x1, Text = 0x2, Ack = 0x3, Advert = 0x4, GroupText = 0x5, GroupData = 0x6,
|
||||||
|
AnonRequest = 0x7, Path = 0x8, Trace = 0x9, Multipart = 0xA, Control = 0xB, RawCustom = 0xF,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Packet {
|
||||||
|
Route route = Route::Flood;
|
||||||
|
Payload type = Payload::Request;
|
||||||
|
bool hasTransport = false;
|
||||||
|
uint16_t transport[2] = {0, 0}; // the first is the region's; the second is reserved
|
||||||
|
uint8_t hops = 0; // entries in the path
|
||||||
|
uint8_t hashSize = 1; // bytes each
|
||||||
|
const uint8_t* path = nullptr; // hops * hashSize bytes
|
||||||
|
const uint8_t* payload = nullptr;
|
||||||
|
size_t payloadLen = 0;
|
||||||
|
|
||||||
|
bool flood() const { return route == Route::Flood || route == Route::TransportFlood; }
|
||||||
|
// Sent to one node from one node, each named by the first byte of its key.
|
||||||
|
bool addressed() const { return type == Payload::Request || type == Payload::Response || type == Payload::Text || type == Payload::Path; }
|
||||||
|
bool group() const { return type == Payload::GroupText || type == Payload::GroupData; }
|
||||||
|
};
|
||||||
|
|
||||||
|
// False when the bytes can't be a MeshCore packet: a version other than the first, a reserved
|
||||||
|
// type, or a path longer than what follows.
|
||||||
|
bool parsePacket(const uint8_t* data, size_t len, Packet& out);
|
||||||
|
|
||||||
|
// A node saying who it is, signed: never encrypted.
|
||||||
|
struct Advert {
|
||||||
|
uint8_t key[32];
|
||||||
|
uint32_t timestamp = 0; // the node's clock, seconds since 1970
|
||||||
|
uint8_t kind = 0; // 1 chat, 2 repeater, 3 room server, 4 sensor
|
||||||
|
bool hasLocation = false;
|
||||||
|
int32_t latE6 = 0, lonE6 = 0;
|
||||||
|
std::string name; // printable ASCII kept, the rest as '?'
|
||||||
|
};
|
||||||
|
bool parseAdvert(const Packet& p, Advert& out);
|
||||||
|
|
||||||
|
// Control packets that look for nodes nearby, and the answers: sent in clear, to neighbours only.
|
||||||
|
struct Discover {
|
||||||
|
bool response = false;
|
||||||
|
uint8_t kinds = 0; // a request: one bit per kind of node wanted (bit 2: repeaters)
|
||||||
|
uint8_t kind = 0; // a response: what answers, as in an advert
|
||||||
|
float snr = 0; // a response: how well it heard the request, dB
|
||||||
|
uint32_t tag = 0; // random in the request, repeated in its responses
|
||||||
|
const uint8_t* id = nullptr; // a response: the node's key, or its first 8 bytes
|
||||||
|
size_t idLen = 0;
|
||||||
|
};
|
||||||
|
bool parseDiscover(const Packet& p, Discover& out);
|
||||||
|
|
||||||
|
const char* routeName(Route r); // "flood", "direct", ...
|
||||||
|
const char* payloadName(Payload t); // "advert", "text", ...
|
||||||
|
const char* payloadShort(Payload t); // for a list row: "adv", "txt", ...
|
||||||
|
const char* kindName(uint8_t kind); // "Chat node", "Repeater", ...
|
||||||
|
|
||||||
|
} // namespace roro::meshcore
|
||||||
@@ -224,4 +224,77 @@ bool parseDnsAnswer(const uint8_t* m, size_t len, uint16_t id, DnsAnswer& out) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void buildNtpRequest(uint8_t out[kNtpPacket]) {
|
||||||
|
std::memset(out, 0, kNtpPacket);
|
||||||
|
out[0] = 0x23; // no warning, version 4, a client
|
||||||
|
}
|
||||||
|
|
||||||
|
bool parseNtpAnswer(const uint8_t* p, size_t len, NtpAnswer& out) {
|
||||||
|
if (len < kNtpPacket || (p[0] & 0x07) != 4) return false; // not a server's
|
||||||
|
if (p[1] == 0 || p[1] > 15) return false; // "kiss of death", or not synchronised
|
||||||
|
uint32_t secs = (static_cast<uint32_t>(p[40]) << 24) | (p[41] << 16) | (p[42] << 8) | p[43];
|
||||||
|
uint32_t frac = (static_cast<uint32_t>(p[44]) << 24) | (p[45] << 16) | (p[46] << 8) | p[47];
|
||||||
|
if (!secs) return false;
|
||||||
|
// NTP counts from 1900 and wraps in 2036: a small number is the era after.
|
||||||
|
constexpr int64_t k1900To1970 = 2208988800LL;
|
||||||
|
int64_t since1900 = secs < 0x80000000u ? static_cast<int64_t>(secs) + 4294967296LL : static_cast<int64_t>(secs);
|
||||||
|
out.stratum = p[1];
|
||||||
|
out.seconds = since1900 - k1900To1970;
|
||||||
|
out.millis = static_cast<uint32_t>((static_cast<uint64_t>(frac) * 1000) >> 32);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string clockOffset(int64_t ownMs, int64_t serverMs) {
|
||||||
|
int64_t diff = ownMs - serverMs, size = diff < 0 ? -diff : diff;
|
||||||
|
if (size < 100) return "right, to 0.1 s";
|
||||||
|
std::string amount = size < 10000 ? std::to_string(size / 1000) + "." + std::to_string(size % 1000 / 100) + " s"
|
||||||
|
: size < 120000 ? std::to_string(size / 1000) + " s"
|
||||||
|
: size < 7200000 ? std::to_string(size / 60000) + " min"
|
||||||
|
: size < 172800000LL ? std::to_string(size / 3600000) + " h" : std::to_string(size / 86400000LL) + " days";
|
||||||
|
return amount + (diff > 0 ? " ahead" : " behind");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string certName(const std::string& dn) {
|
||||||
|
for (const char* key : {"CN=", "O="}) {
|
||||||
|
size_t at = 0;
|
||||||
|
while ((at = dn.find(key, at)) != std::string::npos) {
|
||||||
|
if (at == 0 || dn[at - 1] == ' ' || dn[at - 1] == ',') {
|
||||||
|
size_t from = at + std::strlen(key), end = dn.find(", ", from);
|
||||||
|
std::string name = dn.substr(from, end == std::string::npos ? std::string::npos : end - from);
|
||||||
|
// An old kind of string comes out as "#" and hex, type and length first: read it.
|
||||||
|
if (name.size() > 5 && name[0] == '#' && name.size() % 2 == 1) {
|
||||||
|
std::string plain;
|
||||||
|
for (size_t i = 5; i + 1 < name.size(); i += 2) {
|
||||||
|
auto digit = [](char c) { return c >= '0' && c <= '9' ? c - '0' : c >= 'A' && c <= 'F' ? c - 'A' + 10 : c >= 'a' && c <= 'f' ? c - 'a' + 10 : -1; };
|
||||||
|
int hi = digit(name[i]), lo = digit(name[i + 1]);
|
||||||
|
if (hi < 0 || lo < 0 || hi * 16 + lo < 0x20 || hi * 16 + lo > 0x7E) return name;
|
||||||
|
plain += static_cast<char>(hi * 16 + lo);
|
||||||
|
}
|
||||||
|
return plain;
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
at++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dn;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// Days since a fixed day long ago (the civil calendar, leap years and all).
|
||||||
|
long dayNumber(int y, int m, int d) {
|
||||||
|
y -= m <= 2;
|
||||||
|
long era = (y >= 0 ? y : y - 399) / 400;
|
||||||
|
long yoe = y - era * 400, doy = (153 * (m + (m > 2 ? -3 : 9)) + 2) / 5 + d - 1;
|
||||||
|
return era * 146097 + yoe * 365 + yoe / 4 - yoe / 100 + doy;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
int daysBetween(int y1, int m1, int d1, int y2, int m2, int d2) { return static_cast<int>(dayNumber(y2, m2, d2) - dayNumber(y1, m1, d1)); }
|
||||||
|
|
||||||
|
const char* portLabel(uint16_t port, bool tcp) {
|
||||||
|
if (tcp) return port == 3232 ? "updates" : port == 2323 ? "Debug Console" : port == 80 ? "sharing" : "";
|
||||||
|
return port == 68 ? "DHCP" : port == 123 ? "NTP" : "";
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace roro::net
|
} // namespace roro::net
|
||||||
|
|||||||
@@ -68,4 +68,31 @@ struct DnsAnswer {
|
|||||||
// False if it isn't the answer to query `id`, or is cut short.
|
// False if it isn't the answer to query `id`, or is cut short.
|
||||||
bool parseDnsAnswer(const uint8_t* message, size_t len, uint16_t id, DnsAnswer& out);
|
bool parseDnsAnswer(const uint8_t* message, size_t len, uint16_t id, DnsAnswer& out);
|
||||||
|
|
||||||
|
// --- NTP: the clock's offset
|
||||||
|
|
||||||
|
constexpr size_t kNtpPacket = 48;
|
||||||
|
void buildNtpRequest(uint8_t out[kNtpPacket]);
|
||||||
|
struct NtpAnswer {
|
||||||
|
int stratum = 0; // 1: a reference clock; 2 and up: that many steps from one
|
||||||
|
int64_t seconds = 0; // the server's clock when it answered, UTC since 1970
|
||||||
|
uint32_t millis = 0; // and the part of a second
|
||||||
|
};
|
||||||
|
// False if it isn't a server's answer, or says the server has no time to give.
|
||||||
|
bool parseNtpAnswer(const uint8_t* packet, size_t len, NtpAnswer& out);
|
||||||
|
// "0.3 s ahead", "12 s behind", "right, to 0.1 s": this clock against the server's, both in ms.
|
||||||
|
std::string clockOffset(int64_t ownMs, int64_t serverMs);
|
||||||
|
|
||||||
|
// --- TLS: who a certificate is for
|
||||||
|
|
||||||
|
// The common name out of a certificate's subject or issuer as mbedTLS prints it
|
||||||
|
// ("C=US, O=Let's Encrypt, CN=R11"): the CN, else the O, else all of it.
|
||||||
|
std::string certName(const std::string& dn);
|
||||||
|
// Whole days from one date to another (negative: the second is earlier).
|
||||||
|
int daysBetween(int y1, int m1, int d1, int y2, int m2, int d2);
|
||||||
|
|
||||||
|
// --- netstat
|
||||||
|
|
||||||
|
// What listens on a port of this firmware, or "".
|
||||||
|
const char* portLabel(uint16_t port, bool tcp);
|
||||||
|
|
||||||
} // namespace roro::net
|
} // namespace roro::net
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ const Definition kDefinitions[] = {
|
|||||||
{"wifi_on", Kind::Bool, 1, nullptr, 0, 1},
|
{"wifi_on", Kind::Bool, 1, nullptr, 0, 1},
|
||||||
{"gnss_on", Kind::Bool, 1, nullptr, 0, 1},
|
{"gnss_on", Kind::Bool, 1, nullptr, 0, 1},
|
||||||
{"coord_dms", Kind::Bool, 0, nullptr, 0, 1},
|
{"coord_dms", Kind::Bool, 0, nullptr, 0, 1},
|
||||||
{"lora_preset", Kind::Int, 0, nullptr, 0, 6}, // LongFast first
|
{"lora_preset", Kind::Int, 7, nullptr, 0, 7}, // MeshCore, after the 7 Meshtastic ones
|
||||||
{"dns1", Kind::String, 0, "9.9.9.9", 7, 15}, // Quad9
|
{"dns1", Kind::String, 0, "9.9.9.9", 7, 15}, // Quad9
|
||||||
{"dns2", Kind::String, 0, "1.1.1.1", 0, 15}, // Cloudflare
|
{"dns2", Kind::String, 0, "1.1.1.1", 0, 15}, // Cloudflare
|
||||||
{"dns_always", Kind::Bool, 0, nullptr, 0, 1},
|
{"dns_always", Kind::Bool, 0, nullptr, 0, 1},
|
||||||
@@ -48,6 +48,11 @@ const Definition kDefinitions[] = {
|
|||||||
{"help_told", Kind::Bool, 0, nullptr, 0, 1},
|
{"help_told", Kind::Bool, 0, nullptr, 0, 1},
|
||||||
{"vpn_config", Kind::String, 0, "", 0, 900}, // empty, or a .conf that parses
|
{"vpn_config", Kind::String, 0, "", 0, 900}, // empty, or a .conf that parses
|
||||||
{"vpn_auto", Kind::Bool, 0, nullptr, 0, 1},
|
{"vpn_auto", Kind::Bool, 0, nullptr, 0, 1},
|
||||||
|
{"ssh_hosts", Kind::String, 0, "", 0, 800},
|
||||||
|
{"ssh_known", Kind::String, 0, "", 0, 2400},
|
||||||
|
{"ssh_key", Kind::String, 0, "", 0, 800},
|
||||||
|
{"ssh_public", Kind::String, 0, "", 0, 200},
|
||||||
|
{"ssh_font", Kind::Int, 1, nullptr, 0, 4},
|
||||||
};
|
};
|
||||||
static_assert(sizeof(kDefinitions) / sizeof(kDefinitions[0]) == static_cast<size_t>(Setting::Count),
|
static_assert(sizeof(kDefinitions) / sizeof(kDefinitions[0]) == static_cast<size_t>(Setting::Count),
|
||||||
"every Setting needs a definition");
|
"every Setting needs a definition");
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ enum class Setting : uint8_t {
|
|||||||
WifiEnabled, // bool: the Wi-Fi Service stays Connected when a Saved Network is in range
|
WifiEnabled, // bool: the Wi-Fi Service stays Connected when a Saved Network is in range
|
||||||
GnssEnabled, // bool: the GNSS Service reads the receiver (M2, Q58)
|
GnssEnabled, // bool: the GNSS Service reads the receiver (M2, Q58)
|
||||||
CoordinatesDms, // bool: show degrees, minutes and seconds instead of decimal degrees (Q64)
|
CoordinatesDms, // bool: show degrees, minutes and seconds instead of decimal degrees (Q64)
|
||||||
LoraPreset, // int: the LoRa Scanner's Meshtastic preset, an index into the EU868 list (M3, Q95)
|
LoraPreset, // int: the LoRa Scanner's preset, an index into lora::scanPreset (M3, Q95): MeshCore by default
|
||||||
Dns1, // string: the first DNS server, an IPv4 address (S1, Q108, Q109)
|
Dns1, // string: the first DNS server, an IPv4 address (S1, Q108, Q109)
|
||||||
Dns2, // string: the second, or empty
|
Dns2, // string: the second, or empty
|
||||||
DnsAlways, // bool: use them on Automatic (DHCP) networks too, instead of DHCP's
|
DnsAlways, // bool: use them on Automatic (DHCP) networks too, instead of DHCP's
|
||||||
@@ -36,6 +36,11 @@ enum class Setting : uint8_t {
|
|||||||
HelpTold, // bool: this device has been told about the help key once (issue #69, Q201)
|
HelpTold, // bool: this device has been told about the help key once (issue #69, Q201)
|
||||||
VpnConfig, // string: the WireGuard tunnel as a .conf (wg_config.h), private key included: never shown (issue #8)
|
VpnConfig, // string: the WireGuard tunnel as a .conf (wg_config.h), private key included: never shown (issue #8)
|
||||||
VpnAuto, // bool: the tunnel starts whenever Wi-Fi is connected (Q247: off unless switched on)
|
VpnAuto, // bool: the tunnel starts whenever Wi-Fi is connected (Q247: off unless switched on)
|
||||||
|
SshHosts, // string: the SSH App's saved hosts, one user@host[:port] a line (issue #2, ssh_hosts.h)
|
||||||
|
SshKnown, // string: the fingerprint each server showed first, one "host:port fingerprint" a line
|
||||||
|
SshKey, // string: this device's own SSH private key, as OpenSSH writes one: never shown
|
||||||
|
SshPublic, // string: its public half, the line to put in a server's authorized_keys
|
||||||
|
SshFont, // int: the terminal's font, 0 (smallest) to 4
|
||||||
Count
|
Count
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
#include "scp_args.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace roro::term {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::vector<std::string> words(const std::string& text) {
|
||||||
|
std::vector<std::string> out;
|
||||||
|
for (size_t at = 0; at < text.size();) {
|
||||||
|
size_t end = text.find(' ', at);
|
||||||
|
if (end == std::string::npos) end = text.size();
|
||||||
|
if (end > at) out.push_back(text.substr(at, end - at));
|
||||||
|
at = end + 1;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// user@host:path, as opposed to a path on the card.
|
||||||
|
bool isRemote(const std::string& w) {
|
||||||
|
if (w.empty() || w[0] == '/') return false;
|
||||||
|
size_t at = w.find('@'), colon = w.find(':');
|
||||||
|
return at != std::string::npos && colon != std::string::npos && at < colon;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string baseName(const std::string& path) {
|
||||||
|
size_t slash = path.rfind('/');
|
||||||
|
return slash == std::string::npos ? path : path.substr(slash + 1);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
std::string parseScp(const std::string& args, ScpArgs& out) {
|
||||||
|
static const char* kUsage = "scp [-f] [-P port] <file on the card> user@host:path | scp [-f] [-P port] user@host:path <file on the card>";
|
||||||
|
std::vector<std::string> w = words(args);
|
||||||
|
long port = 0;
|
||||||
|
bool replace = false;
|
||||||
|
while (!w.empty() && w[0][0] == '-') {
|
||||||
|
if (w[0] == "-f") {
|
||||||
|
replace = true;
|
||||||
|
w.erase(w.begin());
|
||||||
|
} else if (w[0] == "-P" && w.size() >= 2) {
|
||||||
|
port = 0;
|
||||||
|
for (char c : w[1]) {
|
||||||
|
if (c < '0' || c > '9' || port > 65535) return "a port from 1 to 65535";
|
||||||
|
port = port * 10 + (c - '0');
|
||||||
|
}
|
||||||
|
if (port < 1 || port > 65535) return "a port from 1 to 65535";
|
||||||
|
w.erase(w.begin(), w.begin() + 2);
|
||||||
|
} else {
|
||||||
|
return kUsage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (w.size() != 2) return kUsage;
|
||||||
|
|
||||||
|
bool firstRemote = isRemote(w[0]), secondRemote = isRemote(w[1]);
|
||||||
|
if (firstRemote == secondRemote) return firstRemote ? "one side has to be on the card, not both on servers" : kUsage;
|
||||||
|
|
||||||
|
ScpArgs a;
|
||||||
|
a.upload = secondRemote;
|
||||||
|
a.replace = replace;
|
||||||
|
const std::string& remote = a.upload ? w[1] : w[0];
|
||||||
|
std::string local = a.upload ? w[0] : w[1];
|
||||||
|
size_t colon = remote.find(':');
|
||||||
|
std::string why = parseSshTarget(remote.substr(0, colon), a.target);
|
||||||
|
if (!why.empty()) return why;
|
||||||
|
if (port) a.target.port = static_cast<uint16_t>(port);
|
||||||
|
a.remote = remote.substr(colon + 1);
|
||||||
|
if (a.remote.empty()) return "say where on " + a.target.host + ": user@host:path";
|
||||||
|
if (local.empty() || local[0] != '/') return "a path on the card starts with a slash";
|
||||||
|
if (local.back() == '/') {
|
||||||
|
if (a.upload) return "that's a folder: scp copies one file";
|
||||||
|
std::string name = baseName(a.remote);
|
||||||
|
if (name.empty()) return "name the file to fetch";
|
||||||
|
local += name;
|
||||||
|
}
|
||||||
|
a.local = local;
|
||||||
|
out = a;
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace roro::term
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "ssh_hosts.h"
|
||||||
|
|
||||||
|
namespace roro::term {
|
||||||
|
|
||||||
|
// What `scp` was asked: one file to the card from a server, or from the card to a server.
|
||||||
|
// scp [-f] [-P port] /notes/a.txt user@host:path (upload)
|
||||||
|
// scp [-f] [-P port] user@host:path /notes/a.txt (download; a destination ending in / gets the remote file's name)
|
||||||
|
// The card's paths start with a slash; the server's are the server's own (relative ones start at the home folder).
|
||||||
|
struct ScpArgs {
|
||||||
|
bool upload = false;
|
||||||
|
bool replace = false; // -f: a download may replace a file on the card
|
||||||
|
SshTarget target;
|
||||||
|
std::string local, remote;
|
||||||
|
};
|
||||||
|
|
||||||
|
// "" or what is wrong with it.
|
||||||
|
std::string parseScp(const std::string& args, ScpArgs& out);
|
||||||
|
|
||||||
|
} // namespace roro::term
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
#include "ssh_hosts.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace roro::term {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::vector<std::string> linesOf(const std::string& text) {
|
||||||
|
std::vector<std::string> out;
|
||||||
|
for (size_t at = 0; at < text.size();) {
|
||||||
|
size_t end = text.find('\n', at);
|
||||||
|
if (end == std::string::npos) end = text.size();
|
||||||
|
if (end > at) out.push_back(text.substr(at, end - at));
|
||||||
|
at = end + 1;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
bool hostChars(const std::string& s) {
|
||||||
|
if (s.empty() || s.size() > 253) return false;
|
||||||
|
for (char c : s)
|
||||||
|
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '.' || c == '-')) return false;
|
||||||
|
return s.front() != '.' && s.front() != '-';
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
std::string SshTarget::text() const { return user + "@" + host + (port == 22 ? "" : ":" + std::to_string(port)); }
|
||||||
|
std::string SshTarget::hostPort() const { return host + ":" + std::to_string(port); }
|
||||||
|
|
||||||
|
std::string parseSshTarget(const std::string& text, SshTarget& out) {
|
||||||
|
size_t at = text.find('@');
|
||||||
|
if (at == std::string::npos || at == 0) return "user@host, please";
|
||||||
|
SshTarget t;
|
||||||
|
t.user = text.substr(0, at);
|
||||||
|
std::string rest = text.substr(at + 1);
|
||||||
|
if (t.user.size() > 32 || t.user.find_first_of(" @:/") != std::string::npos) return "that isn't a user name";
|
||||||
|
size_t colon = rest.rfind(':');
|
||||||
|
if (colon != std::string::npos) {
|
||||||
|
std::string port = rest.substr(colon + 1);
|
||||||
|
long n = 0;
|
||||||
|
if (port.empty() || port.size() > 5) return "a port from 1 to 65535";
|
||||||
|
for (char c : port) {
|
||||||
|
if (c < '0' || c > '9') return "a port from 1 to 65535";
|
||||||
|
n = n * 10 + (c - '0');
|
||||||
|
}
|
||||||
|
if (n < 1 || n > 65535) return "a port from 1 to 65535";
|
||||||
|
t.port = static_cast<uint16_t>(n);
|
||||||
|
rest.resize(colon);
|
||||||
|
}
|
||||||
|
if (!hostChars(rest)) return "that isn't a host";
|
||||||
|
t.host = rest;
|
||||||
|
out = t;
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
SshHosts::SshHosts(const std::string& stored) {
|
||||||
|
for (auto& line : linesOf(stored)) {
|
||||||
|
SshTarget t;
|
||||||
|
if (hosts_.size() < kMax && parseSshTarget(line, t).empty()) hosts_.push_back(t.text());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshHosts::used(const SshTarget& target) {
|
||||||
|
std::string text = target.text();
|
||||||
|
hosts_.erase(std::remove(hosts_.begin(), hosts_.end(), text), hosts_.end());
|
||||||
|
hosts_.insert(hosts_.begin(), text);
|
||||||
|
if (hosts_.size() > kMax) hosts_.resize(kMax);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshHosts::remove(size_t index) {
|
||||||
|
if (index < hosts_.size()) hosts_.erase(hosts_.begin() + static_cast<long>(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SshHosts::stored() const {
|
||||||
|
std::string s;
|
||||||
|
for (auto& h : hosts_) s += h + "\n";
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
SshKnownHosts::SshKnownHosts(const std::string& stored) {
|
||||||
|
for (auto& line : linesOf(stored)) {
|
||||||
|
size_t space = line.find(' ');
|
||||||
|
if (space != std::string::npos && space > 0 && space + 1 < line.size() && known_.size() < kMax) known_.emplace_back(line.substr(0, space), line.substr(space + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SshKnownHosts::fingerprintOf(const std::string& hostPort) const {
|
||||||
|
for (auto& k : known_)
|
||||||
|
if (k.first == hostPort) return k.second;
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshKnownHosts::remember(const std::string& hostPort, const std::string& fingerprint) {
|
||||||
|
known_.erase(std::remove_if(known_.begin(), known_.end(), [&](const std::pair<std::string, std::string>& k) { return k.first == hostPort; }), known_.end());
|
||||||
|
known_.emplace_back(hostPort, fingerprint);
|
||||||
|
if (known_.size() > kMax) known_.erase(known_.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshKnownHosts::forget(const std::string& hostPort) {
|
||||||
|
known_.erase(std::remove_if(known_.begin(), known_.end(), [&](const std::pair<std::string, std::string>& k) { return k.first == hostPort; }), known_.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SshKnownHosts::stored() const {
|
||||||
|
std::string s;
|
||||||
|
for (auto& k : known_) s += k.first + " " + k.second + "\n";
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace roro::term
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// Who the SSH App connects to, and which servers it has met (issue #2, N1 Q262 and Q263): kept
|
||||||
|
// in the device's settings as a few lines of text.
|
||||||
|
namespace roro::term {
|
||||||
|
|
||||||
|
struct SshTarget {
|
||||||
|
std::string user, host;
|
||||||
|
uint16_t port = 22;
|
||||||
|
std::string text() const; // user@host, with :port when it isn't 22
|
||||||
|
std::string hostPort() const; // host:port, always: what a host key is remembered under
|
||||||
|
};
|
||||||
|
// "user@host", "user@host:2222". "" or what is wrong with it.
|
||||||
|
std::string parseSshTarget(const std::string& text, SshTarget& out);
|
||||||
|
|
||||||
|
// Up to eight, the last used first; one a line.
|
||||||
|
class SshHosts {
|
||||||
|
public:
|
||||||
|
static constexpr size_t kMax = 8;
|
||||||
|
explicit SshHosts(const std::string& stored = "");
|
||||||
|
const std::vector<std::string>& list() const { return hosts_; }
|
||||||
|
void used(const SshTarget& target); // to the front, added if it's new
|
||||||
|
void remove(size_t index);
|
||||||
|
std::string stored() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::string> hosts_;
|
||||||
|
};
|
||||||
|
|
||||||
|
// The fingerprint each server showed the first time: "host:port SHA256:...", one a line, sixteen
|
||||||
|
// at most (the oldest goes).
|
||||||
|
class SshKnownHosts {
|
||||||
|
public:
|
||||||
|
static constexpr size_t kMax = 16;
|
||||||
|
explicit SshKnownHosts(const std::string& stored = "");
|
||||||
|
std::string fingerprintOf(const std::string& hostPort) const; // "" if never met
|
||||||
|
void remember(const std::string& hostPort, const std::string& fingerprint);
|
||||||
|
void forget(const std::string& hostPort);
|
||||||
|
std::string stored() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::pair<std::string, std::string>> known_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace roro::term
|
||||||
@@ -0,0 +1,495 @@
|
|||||||
|
#include "terminal.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace roro::term {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// A character the screen's font has, for one it may not.
|
||||||
|
uint8_t glyphFor(uint32_t cp) {
|
||||||
|
if (cp >= 0x20 && cp <= 0x7E) return static_cast<uint8_t>(cp);
|
||||||
|
if (cp >= 0xA0 && cp <= 0xFF) return static_cast<uint8_t>(cp);
|
||||||
|
if (cp >= 0x2500 && cp <= 0x257F) { // box drawing
|
||||||
|
switch (cp) {
|
||||||
|
case 0x2500: case 0x2501: case 0x2504: case 0x2505: case 0x2508: case 0x2509: case 0x254C: case 0x254D: case 0x2550: return '-';
|
||||||
|
case 0x2502: case 0x2503: case 0x2506: case 0x2507: case 0x250A: case 0x250B: case 0x254E: case 0x254F: case 0x2551: return '|';
|
||||||
|
default: return '+';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch (cp) {
|
||||||
|
case 0x2018: case 0x2019: return '\'';
|
||||||
|
case 0x201C: case 0x201D: return '"';
|
||||||
|
case 0x2010: case 0x2011: case 0x2012: case 0x2013: case 0x2014: return '-';
|
||||||
|
case 0x2022: case 0x25CF: return '*';
|
||||||
|
case 0x2026: return '.';
|
||||||
|
case 0x2190: return '<';
|
||||||
|
case 0x2192: return '>';
|
||||||
|
case 0x2191: return '^';
|
||||||
|
case 0x2193: return 'v';
|
||||||
|
case 0x2588: case 0x2593: case 0x2592: case 0x2591: return '#';
|
||||||
|
default: return '?';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The DEC "special graphics" set: lines drawn with the letters j to x.
|
||||||
|
uint8_t lineGlyph(uint8_t c) {
|
||||||
|
switch (c) {
|
||||||
|
case 'q': return '-';
|
||||||
|
case 'x': return '|';
|
||||||
|
case 'j': case 'k': case 'l': case 'm': case 'n': case 't': case 'u': case 'v': case 'w': return '+';
|
||||||
|
case '`': return '*';
|
||||||
|
case 'a': return '#';
|
||||||
|
case '~': return '*';
|
||||||
|
default: return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// One of 256 colours, or a colour given as red, green and blue, as the nearest of the sixteen.
|
||||||
|
int nearest16(int r, int g, int b) {
|
||||||
|
int most = std::max(r, std::max(g, b));
|
||||||
|
if (most < 48) return 0;
|
||||||
|
int half = most / 2;
|
||||||
|
int colour = (r > half ? 1 : 0) | (g > half ? 2 : 0) | (b > half ? 4 : 0);
|
||||||
|
if (colour == 7 && most < 200) return most < 110 ? 8 : 7;
|
||||||
|
return most > 170 ? colour | 8 : colour;
|
||||||
|
}
|
||||||
|
int from256(int n) {
|
||||||
|
if (n < 16) return n;
|
||||||
|
if (n >= 232) return nearest16(8 + (n - 232) * 10, 8 + (n - 232) * 10, 8 + (n - 232) * 10);
|
||||||
|
n -= 16;
|
||||||
|
static const int kSteps[6] = {0, 95, 135, 175, 215, 255};
|
||||||
|
return nearest16(kSteps[n / 36], kSteps[(n / 6) % 6], kSteps[n % 6]);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
void colourRgb(int index, uint8_t& r, uint8_t& g, uint8_t& b) {
|
||||||
|
static const uint8_t kTable[16][3] = {{0, 0, 0}, {205, 49, 49}, {13, 188, 121}, {229, 229, 16}, {36, 114, 200}, {188, 63, 188},
|
||||||
|
{17, 168, 205}, {204, 204, 204}, {102, 102, 102}, {241, 76, 76}, {35, 209, 139}, {245, 245, 67},
|
||||||
|
{59, 142, 234}, {214, 112, 214}, {41, 184, 219}, {255, 255, 255}};
|
||||||
|
r = kTable[index & 15][0];
|
||||||
|
g = kTable[index & 15][1];
|
||||||
|
b = kTable[index & 15][2];
|
||||||
|
}
|
||||||
|
|
||||||
|
Terminal::Terminal(int cols, int rows, int historyLines)
|
||||||
|
: cols_(std::max(2, cols)), rows_(std::max(2, rows)), historyMax_(std::max(0, historyLines)), mainGrid_(static_cast<size_t>(cols_ * rows_)),
|
||||||
|
altGrid_(static_cast<size_t>(cols_ * rows_)), bottom_(rows_ - 1) {}
|
||||||
|
|
||||||
|
Cell Terminal::blank() const {
|
||||||
|
Cell c;
|
||||||
|
c.attr = static_cast<uint8_t>((bg_ << 4) | 7);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Terminal::takeBell() {
|
||||||
|
bool b = bell_;
|
||||||
|
bell_ = false;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Terminal::rowText(int row) const {
|
||||||
|
std::string s;
|
||||||
|
for (int c = 0; c < cols_; c++) s += static_cast<char>(cell(row, c).ch);
|
||||||
|
size_t end = s.find_last_not_of(' ');
|
||||||
|
s.resize(end == std::string::npos ? 0 : end + 1);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Terminal::param(size_t i, int fallback) const { return i < params_.size() && params_[i] > 0 ? params_[i] : fallback; }
|
||||||
|
|
||||||
|
void Terminal::moveTo(int row, int col) {
|
||||||
|
row_ = std::clamp(row, 0, rows_ - 1);
|
||||||
|
col_ = std::clamp(col, 0, cols_ - 1);
|
||||||
|
wrapPending_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Terminal::eraseCells(int row, int from, int to) {
|
||||||
|
Cell b = blank();
|
||||||
|
for (int c = std::max(0, from); c <= std::min(cols_ - 1, to); c++) grid()[static_cast<size_t>(row * cols_ + c)] = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Terminal::scrollUp(int top, int bottom, int n, bool toHistory) {
|
||||||
|
n = std::min(n, bottom - top + 1);
|
||||||
|
auto& g = grid();
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
if (toHistory && !alt_ && top == 0 && historyMax_ > 0) { // off the top of the real screen: kept, as text
|
||||||
|
history_.push_back(rowText(0));
|
||||||
|
if (static_cast<int>(history_.size()) > historyMax_) history_.pop_front();
|
||||||
|
}
|
||||||
|
std::move(g.begin() + (top + 1) * cols_, g.begin() + (bottom + 1) * cols_, g.begin() + top * cols_);
|
||||||
|
eraseCells(bottom, 0, cols_ - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Terminal::scrollDown(int top, int bottom, int n) {
|
||||||
|
n = std::min(n, bottom - top + 1);
|
||||||
|
auto& g = grid();
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
std::move_backward(g.begin() + top * cols_, g.begin() + bottom * cols_, g.begin() + (bottom + 1) * cols_);
|
||||||
|
eraseCells(top, 0, cols_ - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Terminal::lineFeed() {
|
||||||
|
wrapPending_ = false;
|
||||||
|
if (row_ == bottom_) scrollUp(top_, bottom_, 1);
|
||||||
|
else if (row_ < rows_ - 1) row_++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Terminal::reverseIndex() {
|
||||||
|
wrapPending_ = false;
|
||||||
|
if (row_ == top_) scrollDown(top_, bottom_, 1);
|
||||||
|
else if (row_ > 0) row_--;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Terminal::put(uint32_t cp) {
|
||||||
|
uint8_t ch = lineDrawing_ && cp < 0x80 ? lineGlyph(static_cast<uint8_t>(cp)) : glyphFor(cp);
|
||||||
|
if (wrapPending_) {
|
||||||
|
col_ = 0;
|
||||||
|
lineFeed();
|
||||||
|
}
|
||||||
|
uint8_t fg = static_cast<uint8_t>(bold_ && fg_ < 8 ? fg_ | 8 : fg_), bg = bg_;
|
||||||
|
if (inverse_) std::swap(fg, bg);
|
||||||
|
Cell& c = grid()[static_cast<size_t>(row_ * cols_ + col_)];
|
||||||
|
c.ch = ch;
|
||||||
|
c.attr = static_cast<uint8_t>((bg << 4) | (fg & 15));
|
||||||
|
if (col_ == cols_ - 1) wrapPending_ = autoWrap_;
|
||||||
|
else col_++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Terminal::control(uint8_t c) {
|
||||||
|
switch (c) {
|
||||||
|
case 0x07: bell_ = true; break;
|
||||||
|
case 0x08:
|
||||||
|
if (col_ > 0) col_--;
|
||||||
|
wrapPending_ = false;
|
||||||
|
break;
|
||||||
|
case 0x09: moveTo(row_, std::min(cols_ - 1, (col_ / 8 + 1) * 8)); break;
|
||||||
|
case 0x0A: case 0x0B: case 0x0C: lineFeed(); break;
|
||||||
|
case 0x0D:
|
||||||
|
col_ = 0;
|
||||||
|
wrapPending_ = false;
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Terminal::reset() {
|
||||||
|
alt_ = false;
|
||||||
|
Cell b;
|
||||||
|
std::fill(mainGrid_.begin(), mainGrid_.end(), b);
|
||||||
|
std::fill(altGrid_.begin(), altGrid_.end(), b);
|
||||||
|
row_ = col_ = top_ = 0;
|
||||||
|
bottom_ = rows_ - 1;
|
||||||
|
fg_ = 7;
|
||||||
|
bg_ = 0;
|
||||||
|
bold_ = inverse_ = wrapPending_ = appCursor_ = lineDrawing_ = false;
|
||||||
|
autoWrap_ = cursorShown_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Terminal::escape(uint8_t c) {
|
||||||
|
state_ = State::Ground;
|
||||||
|
switch (c) {
|
||||||
|
case '[':
|
||||||
|
state_ = State::Csi;
|
||||||
|
params_.clear();
|
||||||
|
paramStarted_ = private_ = false;
|
||||||
|
break;
|
||||||
|
case ']': case 'P': case '^': case '_': state_ = State::Osc; break; // a title, or something this doesn't read: skipped to its end
|
||||||
|
case '(': case ')': case '*': case '+': state_ = State::Charset; break;
|
||||||
|
case '7':
|
||||||
|
savedRow_ = row_;
|
||||||
|
savedCol_ = col_;
|
||||||
|
savedAttr_ = static_cast<uint8_t>((bg_ << 4) | fg_);
|
||||||
|
break;
|
||||||
|
case '8':
|
||||||
|
moveTo(savedRow_, savedCol_);
|
||||||
|
fg_ = savedAttr_ & 15;
|
||||||
|
bg_ = savedAttr_ >> 4;
|
||||||
|
break;
|
||||||
|
case 'D': lineFeed(); break;
|
||||||
|
case 'E':
|
||||||
|
col_ = 0;
|
||||||
|
lineFeed();
|
||||||
|
break;
|
||||||
|
case 'M': reverseIndex(); break;
|
||||||
|
case 'c': reset(); break;
|
||||||
|
default: break; // = and >, the keypad's modes, among others
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Terminal::sgr() {
|
||||||
|
if (params_.empty()) params_.push_back(0);
|
||||||
|
for (size_t i = 0; i < params_.size(); i++) {
|
||||||
|
int p = params_[i];
|
||||||
|
if (p == 0) {
|
||||||
|
fg_ = 7;
|
||||||
|
bg_ = 0;
|
||||||
|
bold_ = inverse_ = false;
|
||||||
|
} else if (p == 1) bold_ = true;
|
||||||
|
else if (p == 7) inverse_ = true;
|
||||||
|
else if (p == 22) bold_ = false;
|
||||||
|
else if (p == 27) inverse_ = false;
|
||||||
|
else if (p >= 30 && p <= 37) fg_ = static_cast<uint8_t>(p - 30);
|
||||||
|
else if (p == 39) fg_ = 7;
|
||||||
|
else if (p >= 40 && p <= 47) bg_ = static_cast<uint8_t>(p - 40);
|
||||||
|
else if (p == 49) bg_ = 0;
|
||||||
|
else if (p >= 90 && p <= 97) fg_ = static_cast<uint8_t>(p - 90 + 8);
|
||||||
|
else if (p >= 100 && p <= 107) bg_ = static_cast<uint8_t>(p - 100 + 8);
|
||||||
|
else if ((p == 38 || p == 48) && i + 1 < params_.size()) {
|
||||||
|
int colour = -1;
|
||||||
|
if (params_[i + 1] == 5 && i + 2 < params_.size()) {
|
||||||
|
colour = from256(params_[i + 2] & 255);
|
||||||
|
i += 2;
|
||||||
|
} else if (params_[i + 1] == 2 && i + 4 < params_.size()) {
|
||||||
|
colour = nearest16(params_[i + 2] & 255, params_[i + 3] & 255, params_[i + 4] & 255);
|
||||||
|
i += 4;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
(p == 38 ? fg_ : bg_) = static_cast<uint8_t>(colour);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Terminal::mode(bool on) {
|
||||||
|
for (int p : params_) {
|
||||||
|
if (!private_) continue;
|
||||||
|
switch (p) {
|
||||||
|
case 1: appCursor_ = on; break;
|
||||||
|
case 7: autoWrap_ = on; break;
|
||||||
|
case 25: cursorShown_ = on; break;
|
||||||
|
case 47: case 1047: case 1049:
|
||||||
|
if (on == alt_) break;
|
||||||
|
if (on && p == 1049) {
|
||||||
|
savedRow_ = row_;
|
||||||
|
savedCol_ = col_;
|
||||||
|
}
|
||||||
|
alt_ = on;
|
||||||
|
if (on) std::fill(altGrid_.begin(), altGrid_.end(), Cell());
|
||||||
|
top_ = 0;
|
||||||
|
bottom_ = rows_ - 1;
|
||||||
|
if (!on && p == 1049) moveTo(savedRow_, savedCol_);
|
||||||
|
else if (on) moveTo(0, 0);
|
||||||
|
break;
|
||||||
|
default: break; // the mouse, bracketed paste and the rest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Terminal::csi(uint8_t final) {
|
||||||
|
int n = param(0, 1);
|
||||||
|
switch (final) {
|
||||||
|
case 'A': moveTo(std::max(row_ - n, row_ >= top_ ? top_ : 0), col_); break;
|
||||||
|
case 'B': case 'e': moveTo(std::min(row_ + n, row_ <= bottom_ ? bottom_ : rows_ - 1), col_); break;
|
||||||
|
case 'C': case 'a': moveTo(row_, col_ + n); break;
|
||||||
|
case 'D': moveTo(row_, col_ - n); break;
|
||||||
|
case 'E': moveTo(row_ + n, 0); break;
|
||||||
|
case 'F': moveTo(row_ - n, 0); break;
|
||||||
|
case 'G': case '`': moveTo(row_, n - 1); break;
|
||||||
|
case 'd': moveTo(n - 1, col_); break;
|
||||||
|
case 'H': case 'f': moveTo(param(0, 1) - 1, param(1, 1) - 1); break;
|
||||||
|
case 'J': {
|
||||||
|
int what = params_.empty() ? 0 : params_[0];
|
||||||
|
if (what == 0) {
|
||||||
|
eraseCells(row_, col_, cols_ - 1);
|
||||||
|
for (int r = row_ + 1; r < rows_; r++) eraseCells(r, 0, cols_ - 1);
|
||||||
|
} else if (what == 1) {
|
||||||
|
for (int r = 0; r < row_; r++) eraseCells(r, 0, cols_ - 1);
|
||||||
|
eraseCells(row_, 0, col_);
|
||||||
|
} else {
|
||||||
|
for (int r = 0; r < rows_; r++) eraseCells(r, 0, cols_ - 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'K': {
|
||||||
|
int what = params_.empty() ? 0 : params_[0];
|
||||||
|
eraseCells(row_, what == 0 ? col_ : 0, what == 1 ? col_ : cols_ - 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'L':
|
||||||
|
if (row_ >= top_ && row_ <= bottom_) scrollDown(row_, bottom_, n);
|
||||||
|
break;
|
||||||
|
case 'M':
|
||||||
|
if (row_ >= top_ && row_ <= bottom_) scrollUp(row_, bottom_, n, false); // deleted, not scrolled away: not history
|
||||||
|
break;
|
||||||
|
case 'P': {
|
||||||
|
n = std::min(n, cols_ - col_);
|
||||||
|
auto row = grid().begin() + row_ * cols_;
|
||||||
|
std::move(row + col_ + n, row + cols_, row + col_);
|
||||||
|
eraseCells(row_, cols_ - n, cols_ - 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case '@': {
|
||||||
|
n = std::min(n, cols_ - col_);
|
||||||
|
auto row = grid().begin() + row_ * cols_;
|
||||||
|
std::move_backward(row + col_, row + cols_ - n, row + cols_);
|
||||||
|
eraseCells(row_, col_, col_ + n - 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'X': eraseCells(row_, col_, col_ + n - 1); break;
|
||||||
|
case 'S': scrollUp(top_, bottom_, n); break;
|
||||||
|
case 'T': scrollDown(top_, bottom_, n); break;
|
||||||
|
case 'm': sgr(); break;
|
||||||
|
case 'r': {
|
||||||
|
int top = param(0, 1) - 1, bottom = param(1, rows_) - 1;
|
||||||
|
if (top < bottom && bottom < rows_) {
|
||||||
|
top_ = top;
|
||||||
|
bottom_ = bottom;
|
||||||
|
} else {
|
||||||
|
top_ = 0;
|
||||||
|
bottom_ = rows_ - 1;
|
||||||
|
}
|
||||||
|
moveTo(0, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 's':
|
||||||
|
savedRow_ = row_;
|
||||||
|
savedCol_ = col_;
|
||||||
|
break;
|
||||||
|
case 'u': moveTo(savedRow_, savedCol_); break;
|
||||||
|
case 'h': mode(true); break;
|
||||||
|
case 'l': mode(false); break;
|
||||||
|
case 'n':
|
||||||
|
if (!reply) break;
|
||||||
|
if (param(0, 0) == 6) reply("\x1b[" + std::to_string(row_ + 1) + ";" + std::to_string(col_ + 1) + "R");
|
||||||
|
else if (param(0, 0) == 5) reply("\x1b[0n");
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
if (reply && !private_) reply("\x1b[?6c"); // "a VT102"
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Terminal::feed(const uint8_t* data, size_t len) {
|
||||||
|
for (size_t i = 0; i < len; i++) {
|
||||||
|
uint8_t c = data[i];
|
||||||
|
if (state_ == State::Osc || state_ == State::OscEsc) { // skipped: to a bell, or to ESC backslash
|
||||||
|
if (c == 0x07 || (state_ == State::OscEsc && c == '\\')) state_ = State::Ground;
|
||||||
|
else state_ = c == 0x1B ? State::OscEsc : State::Osc;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (c == 0x1B) {
|
||||||
|
state_ = State::Esc;
|
||||||
|
utf8Left_ = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (c < 0x20) { // these act wherever they come, in the middle of a sequence too
|
||||||
|
if (c == 0x0E) lineDrawing_ = true;
|
||||||
|
else if (c == 0x0F) lineDrawing_ = false;
|
||||||
|
else control(c);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
switch (state_) {
|
||||||
|
case State::Esc: escape(c); break;
|
||||||
|
case State::Charset:
|
||||||
|
lineDrawing_ = c == '0';
|
||||||
|
state_ = State::Ground;
|
||||||
|
break;
|
||||||
|
case State::Csi:
|
||||||
|
if (c >= '0' && c <= '9') {
|
||||||
|
if (!paramStarted_) {
|
||||||
|
if (params_.size() < 16) params_.push_back(0);
|
||||||
|
paramStarted_ = true;
|
||||||
|
}
|
||||||
|
if (!params_.empty() && params_.back() < 10000) params_.back() = params_.back() * 10 + (c - '0');
|
||||||
|
} else if (c == ';' || c == ':') {
|
||||||
|
if (!paramStarted_ && params_.size() < 16) params_.push_back(0);
|
||||||
|
paramStarted_ = false;
|
||||||
|
} else if (c == '?' || c == '>' || c == '=' || c == '<') {
|
||||||
|
private_ = true;
|
||||||
|
} else if (c >= 0x40 && c <= 0x7E) {
|
||||||
|
state_ = State::Ground;
|
||||||
|
csi(c);
|
||||||
|
} // anything else is an in-between byte: passed over
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (c == 0x7F) break;
|
||||||
|
if (c < 0x80) {
|
||||||
|
utf8Left_ = 0;
|
||||||
|
put(c);
|
||||||
|
} else if (c >= 0xC0) { // the first byte of a longer character
|
||||||
|
utf8Left_ = c >= 0xF0 ? 3 : c >= 0xE0 ? 2 : 1;
|
||||||
|
utf8_ = c & (c >= 0xF0 ? 0x07 : c >= 0xE0 ? 0x0F : 0x1F);
|
||||||
|
} else if (utf8Left_ > 0) {
|
||||||
|
utf8_ = (utf8_ << 6) | (c & 0x3F);
|
||||||
|
if (--utf8Left_ == 0) put(utf8_);
|
||||||
|
} else {
|
||||||
|
put('?'); // a byte that belongs to nothing
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
revision_++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Terminal::resize(int cols, int rows) {
|
||||||
|
cols = std::max(2, cols);
|
||||||
|
rows = std::max(2, rows);
|
||||||
|
if (cols == cols_ && rows == rows_) return;
|
||||||
|
// The cursor's line stays on screen: what is above it goes to the history if it has to.
|
||||||
|
int shift = alt_ ? 0 : std::max(0, row_ - (rows - 1));
|
||||||
|
if (shift) {
|
||||||
|
int oldTop = top_, oldBottom = bottom_;
|
||||||
|
top_ = 0;
|
||||||
|
bottom_ = rows_ - 1;
|
||||||
|
scrollUp(0, rows_ - 1, shift);
|
||||||
|
top_ = oldTop;
|
||||||
|
bottom_ = oldBottom;
|
||||||
|
}
|
||||||
|
auto copy = [&](std::vector<Cell>& g) {
|
||||||
|
std::vector<Cell> fresh(static_cast<size_t>(cols * rows));
|
||||||
|
for (int r = 0; r < std::min(rows, rows_); r++)
|
||||||
|
for (int c = 0; c < std::min(cols, cols_); c++) fresh[static_cast<size_t>(r * cols + c)] = g[static_cast<size_t>(r * cols_ + c)];
|
||||||
|
g.swap(fresh);
|
||||||
|
};
|
||||||
|
copy(mainGrid_);
|
||||||
|
copy(altGrid_);
|
||||||
|
cols_ = cols;
|
||||||
|
rows_ = rows;
|
||||||
|
top_ = 0;
|
||||||
|
bottom_ = rows_ - 1;
|
||||||
|
moveTo(row_ - shift, col_);
|
||||||
|
savedRow_ = std::min(savedRow_, rows_ - 1);
|
||||||
|
savedCol_ = std::min(savedCol_, cols_ - 1);
|
||||||
|
revision_++;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string encodeKey(TermKey key, uint32_t ch, bool ctrl, bool alt, bool appCursorKeys) {
|
||||||
|
std::string out;
|
||||||
|
auto arrow = [&](char letter) { return std::string(appCursorKeys ? "\x1bO" : "\x1b[") + letter; };
|
||||||
|
switch (key) {
|
||||||
|
case TermKey::Up: out = arrow('A'); break;
|
||||||
|
case TermKey::Down: out = arrow('B'); break;
|
||||||
|
case TermKey::Right: out = arrow('C'); break;
|
||||||
|
case TermKey::Left: out = arrow('D'); break;
|
||||||
|
case TermKey::Enter: out = "\r"; break;
|
||||||
|
case TermKey::Backspace: out = "\x7f"; break;
|
||||||
|
case TermKey::Tab: out = "\t"; break;
|
||||||
|
case TermKey::Escape: out = "\x1b"; break;
|
||||||
|
case TermKey::PageUp: out = "\x1b[5~"; break;
|
||||||
|
case TermKey::PageDown: out = "\x1b[6~"; break;
|
||||||
|
case TermKey::Char:
|
||||||
|
if (ctrl) {
|
||||||
|
uint32_t c = ch >= 'a' && ch <= 'z' ? ch - 32 : ch;
|
||||||
|
if (c >= '@' && c <= '_') out = std::string(1, static_cast<char>(c - '@'));
|
||||||
|
else if (c == ' ' || c == '2') out = std::string(1, '\0');
|
||||||
|
else if (c == '?' || c == '8') out = "\x7f";
|
||||||
|
else if (c == '3') out = "\x1b";
|
||||||
|
else if (c == '4') out = "\x1c";
|
||||||
|
else if (c == '5') out = "\x1d";
|
||||||
|
else if (c == '6') out = "\x1e";
|
||||||
|
else if (c == '7' || c == '/') out = "\x1f";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ch < 0x80) out = std::string(1, static_cast<char>(ch));
|
||||||
|
else if (ch < 0x800) out = {static_cast<char>(0xC0 | (ch >> 6)), static_cast<char>(0x80 | (ch & 0x3F))};
|
||||||
|
else if (ch < 0x10000) out = {static_cast<char>(0xE0 | (ch >> 12)), static_cast<char>(0x80 | ((ch >> 6) & 0x3F)), static_cast<char>(0x80 | (ch & 0x3F))};
|
||||||
|
else out = {static_cast<char>(0xF0 | (ch >> 18)), static_cast<char>(0x80 | ((ch >> 12) & 0x3F)), static_cast<char>(0x80 | ((ch >> 6) & 0x3F)),
|
||||||
|
static_cast<char>(0x80 | (ch & 0x3F))};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (alt && !out.empty() && key != TermKey::Escape) out.insert(0, 1, '\x1b');
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace roro::term
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <deque>
|
||||||
|
#include <functional>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// A terminal's screen (issue #2, N1 Q256): what a remote program's output makes of a grid of
|
||||||
|
// characters. It understands what a shell, `less`, `top`, `nano` and plain `vim` send: the cursor,
|
||||||
|
// erasing, sixteen colours, scroll regions, the alternate screen. No mouse. Characters are kept
|
||||||
|
// as the screen's font has them (Latin-1); what it lacks becomes `?`, and box-drawing lines
|
||||||
|
// become + - |.
|
||||||
|
namespace roro::term {
|
||||||
|
|
||||||
|
struct Cell {
|
||||||
|
uint8_t ch = ' ';
|
||||||
|
uint8_t attr = 0x07; // low four bits: the colour of the character, high four: of what is behind it
|
||||||
|
};
|
||||||
|
|
||||||
|
class Terminal {
|
||||||
|
public:
|
||||||
|
Terminal(int cols, int rows, int historyLines);
|
||||||
|
|
||||||
|
void feed(const uint8_t* data, size_t len);
|
||||||
|
// A new size: what is on screen stays where it is, from the top left; if the cursor would fall
|
||||||
|
// off the bottom, the top lines go to the history.
|
||||||
|
void resize(int cols, int rows);
|
||||||
|
// What the program asked to be told (where the cursor is, what kind of terminal this is).
|
||||||
|
std::function<void(const std::string&)> reply;
|
||||||
|
|
||||||
|
int cols() const { return cols_; }
|
||||||
|
int rows() const { return rows_; }
|
||||||
|
const Cell& cell(int row, int col) const { return grid()[static_cast<size_t>(row * cols_ + col)]; }
|
||||||
|
int cursorRow() const { return row_; }
|
||||||
|
int cursorCol() const { return col_; }
|
||||||
|
bool cursorVisible() const { return cursorShown_; }
|
||||||
|
bool appCursorKeys() const { return appCursor_; } // the arrows are sent another way (vim, less)
|
||||||
|
bool altScreen() const { return alt_; }
|
||||||
|
uint32_t revision() const { return revision_; } // changes whenever the screen may have
|
||||||
|
bool takeBell();
|
||||||
|
|
||||||
|
// Lines that scrolled off the top of the main screen, oldest first; their text only.
|
||||||
|
int historyCount() const { return static_cast<int>(history_.size()); }
|
||||||
|
const std::string& historyLine(int i) const { return history_[static_cast<size_t>(i)]; }
|
||||||
|
|
||||||
|
std::string rowText(int row) const; // without trailing spaces
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum class State { Ground, Esc, Csi, Osc, OscEsc, Charset };
|
||||||
|
|
||||||
|
std::vector<Cell>& grid() { return alt_ ? altGrid_ : mainGrid_; }
|
||||||
|
const std::vector<Cell>& grid() const { return alt_ ? altGrid_ : mainGrid_; }
|
||||||
|
Cell blank() const;
|
||||||
|
void put(uint32_t codePoint);
|
||||||
|
void control(uint8_t c);
|
||||||
|
void escape(uint8_t c);
|
||||||
|
void csi(uint8_t final);
|
||||||
|
void sgr();
|
||||||
|
void mode(bool on);
|
||||||
|
void lineFeed();
|
||||||
|
void reverseIndex();
|
||||||
|
void scrollUp(int top, int bottom, int n, bool toHistory = true);
|
||||||
|
void scrollDown(int top, int bottom, int n);
|
||||||
|
void eraseCells(int row, int from, int to);
|
||||||
|
void moveTo(int row, int col);
|
||||||
|
void reset();
|
||||||
|
int param(size_t i, int fallback) const;
|
||||||
|
|
||||||
|
int cols_, rows_, historyMax_;
|
||||||
|
std::vector<Cell> mainGrid_, altGrid_;
|
||||||
|
std::deque<std::string> history_;
|
||||||
|
bool alt_ = false;
|
||||||
|
int row_ = 0, col_ = 0, top_ = 0, bottom_ = 0;
|
||||||
|
int savedRow_ = 0, savedCol_ = 0;
|
||||||
|
uint8_t savedAttr_ = 0x07;
|
||||||
|
bool wrapPending_ = false, autoWrap_ = true, cursorShown_ = true, appCursor_ = false, lineDrawing_ = false, bell_ = false;
|
||||||
|
uint8_t fg_ = 7, bg_ = 0;
|
||||||
|
bool bold_ = false, inverse_ = false;
|
||||||
|
State state_ = State::Ground;
|
||||||
|
std::vector<int> params_;
|
||||||
|
bool paramStarted_ = false, private_ = false;
|
||||||
|
uint32_t utf8_ = 0;
|
||||||
|
int utf8Left_ = 0;
|
||||||
|
uint32_t revision_ = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// What a key sends to the remote program.
|
||||||
|
enum class TermKey { Char, Up, Down, Left, Right, Enter, Backspace, Tab, Escape, PageUp, PageDown };
|
||||||
|
std::string encodeKey(TermKey key, uint32_t ch, bool ctrl, bool alt, bool appCursorKeys);
|
||||||
|
|
||||||
|
// One of the terminal's sixteen colours as red, green and blue.
|
||||||
|
void colourRgb(int index, uint8_t& r, uint8_t& g, uint8_t& b);
|
||||||
|
|
||||||
|
} // namespace roro::term
|
||||||
@@ -8,8 +8,26 @@
|
|||||||
#define RORO_VERSION "unknown"
|
#define RORO_VERSION "unknown"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __has_include("sdkconfig.h")
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace roro {
|
namespace roro {
|
||||||
|
|
||||||
const char* versionString() { return RORO_VERSION; }
|
const char* versionString() { return RORO_VERSION; }
|
||||||
|
|
||||||
|
const char* architectureString() {
|
||||||
|
#if defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||||
|
return "xtensa-lx7 esp32s3";
|
||||||
|
#elif defined(CONFIG_IDF_TARGET_ESP32)
|
||||||
|
return "xtensa-lx6 esp32";
|
||||||
|
#elif defined(CONFIG_IDF_TARGET)
|
||||||
|
return CONFIG_IDF_TARGET;
|
||||||
|
#else
|
||||||
|
return "host";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string unameString() { return std::string(kProductName) + " " + versionString() + " " + architectureString(); }
|
||||||
|
|
||||||
} // namespace roro
|
} // namespace roro
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace roro {
|
namespace roro {
|
||||||
|
|
||||||
constexpr const char* kProductName = "roro9stack";
|
constexpr const char* kProductName = "roro9stack";
|
||||||
@@ -9,4 +11,10 @@ constexpr const char* kProductName = "roro9stack";
|
|||||||
// that one file, and everything else comes from the build cache (issue #74).
|
// that one file, and everything else comes from the build cache (issue #74).
|
||||||
const char* versionString();
|
const char* versionString();
|
||||||
|
|
||||||
|
// The chip this firmware is built for: "xtensa-lx7 esp32s3". "host" in the native tests.
|
||||||
|
const char* architectureString();
|
||||||
|
|
||||||
|
// What `uname` and IRC's /uname report: "roro9stack v0.22.0 xtensa-lx7 esp32s3".
|
||||||
|
std::string unameString();
|
||||||
|
|
||||||
} // namespace roro
|
} // namespace roro
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ extra_scripts = pre:scripts/version.py
|
|||||||
test_framework = unity
|
test_framework = unity
|
||||||
|
|
||||||
[env:cardputer-adv]
|
[env:cardputer-adv]
|
||||||
|
extra_scripts =
|
||||||
|
${env.extra_scripts}
|
||||||
|
pre:scripts/libssh_filter.py
|
||||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.312/platform-espressif32.zip
|
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.312/platform-espressif32.zip
|
||||||
board = m5stack-stamps3
|
board = m5stack-stamps3
|
||||||
framework = arduino
|
framework = arduino
|
||||||
@@ -22,6 +25,9 @@ lib_deps =
|
|||||||
m5stack/M5Cardputer @ 1.1.1
|
m5stack/M5Cardputer @ 1.1.1
|
||||||
jgromes/RadioLib @ 7.8.1
|
jgromes/RadioLib @ 7.8.1
|
||||||
esphome/wireguard @ 0.4.8
|
esphome/wireguard @ 0.4.8
|
||||||
|
ewpa/LibSSH-ESP32 @ 5.10.0
|
||||||
|
; WireGuard brings libsodium in; 1.10021.12 defines crypto_sign_ed25519_open as LibSSH does, and the two do not link
|
||||||
|
esphome/libsodium @ 1.10021.11
|
||||||
test_ignore = *
|
test_ignore = *
|
||||||
; Smaller TLS buffers (M2): the framework is rebuilt with these settings (pioarduino "hybrid
|
; Smaller TLS buffers (M2): the framework is rebuilt with these settings (pioarduino "hybrid
|
||||||
; compile"). Receive stays 16 KB (servers send full TLS records); send drops to 4 KB (IRC lines are
|
; compile"). Receive stays 16 KB (servers send full TLS records); send drops to 4 KB (IRC lines are
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# libssh ships its own copy of curve25519 (src/external/curve25519_ref.c), whose two functions,
|
||||||
|
# crypto_scalarmult and crypto_scalarmult_base, have the names libsodium's have: and libsodium is
|
||||||
|
# already in the firmware, for WireGuard. Two definitions don't link. libssh's copy is left out
|
||||||
|
# of the build and it uses libsodium's, which is the same function (issue #2, docs/milestones/N1.md).
|
||||||
|
#
|
||||||
|
# A `pre:` script: the libraries are built by the platform's own script, which runs before any `post:` one.
|
||||||
|
Import("env") # noqa: F821 (provided by PlatformIO)
|
||||||
|
|
||||||
|
env.AddBuildMiddleware(lambda env, node: None, "*LibSSH-ESP32*curve25519_ref.c") # noqa: F821
|
||||||
@@ -21,7 +21,7 @@ boot other restart into the other app slot (manual Rollback)
|
|||||||
log level <0-5> ESP-IDF log level (0 none ... 5 verbose)
|
log level <0-5> ESP-IDF log level (0 none ... 5 verbose)
|
||||||
ls [folder] | du <path> | mkdir <path> | rm [-r] [-f] <path> | cp [-f] <from> <to> | mv [-f] <from> <to> | cancel the SD card, with the Storage App's rules (rm -r for a folder; -f: the Shell doesn't ask; * and ? in a name: /notes/*.txt)
|
ls [folder] | du <path> | mkdir <path> | rm [-r] [-f] <path> | cp [-f] <from> <to> | mv [-f] <from> <to> | cancel the SD card, with the Storage App's rules (rm -r for a folder; -f: the Shell doesn't ask; * and ? in a name: /notes/*.txt)
|
||||||
screenshot [seconds] the screen as a PNG in /screenshots on the card, now or after a pause
|
screenshot [seconds] the screen as a PNG in /screenshots on the card, now or after a pause
|
||||||
lora probe | lora status | lora rx on|off | lora preset <name> the LoRa radio, receive only
|
lora probe | lora status | lora rx on|off | lora preset <name> the LoRa radio, receive only; a Meshtastic preset (LongFast...) or MeshCore
|
||||||
lora capture start|stop a LoRa Capture to /captures/lora (pcap, LoRaTap)
|
lora capture start|stop a LoRa Capture to /captures/lora (pcap, LoRaTap)
|
||||||
lora sweep on [from MHz] [to MHz] [step kHz] | lora sweep off | lora sweep dump RSSI across a band (863 870 100)
|
lora sweep on [from MHz] [to MHz] [step kHz] | lora sweep off | lora sweep dump RSSI across a band (863 870 100)
|
||||||
lora custom <MHz> <BW kHz> <SF> <CR 5-8> <sync hex> [preamble] e.g. 868.1 125 7 5 34 8 (LoRaWAN)
|
lora custom <MHz> <BW kHz> <SF> <CR 5-8> <sync hex> [preamble] e.g. 868.1 125 7 5 34 8 (LoRaWAN)
|
||||||
@@ -40,7 +40,11 @@ update check | update list | update status | update install <tag> the project'
|
|||||||
sd card | sd list | cat <path> | log <text> | burst | sound on|off | short | normal
|
sd card | sd list | cat <path> | log <text> | burst | sound on|off | short | normal
|
||||||
Irc | Wifi | Gnss | Gemini | Lora | Storage | Notes | Shell | System | Settings open that App: a capital letter is an App, not a command
|
Irc | Wifi | Gnss | Gemini | Lora | Storage | Notes | Shell | System | Settings open that App: a capital letter is an App, not a command
|
||||||
ping <host> [count] [size] | nslookup <name> [server] | port <host> <port> | traceroute <host> | cancel is it there, does its name resolve, is its port open, which way; one at a time
|
ping <host> [count] [size] | nslookup <name> [server] | port <host> <port> | traceroute <host> | cancel is it there, does its name resolve, is its port open, which way; one at a time
|
||||||
ifconfig | arp the interfaces (Wi-Fi and the VPN), their addresses, the default route and the DNS servers; the neighbours heard
|
tls <host> [port] | ntp [server] a TLS handshake: who the certificate is for, by whom, until when, and whether this device trusts it; a time server's clock against this one
|
||||||
|
ifconfig | arp | netstat the interfaces (Wi-Fi and the VPN), their addresses, the default route and the DNS servers; the neighbours heard; what listens and what is connected
|
||||||
|
uname the firmware, its version and the chip it is built for
|
||||||
|
scp [-f] [-P port] <file on the card> user@host:path | scp [-f] [-P port] user@host:path <file on the card> one file over SSH, with this device's key or, in the Shell, a password, to a server the SSH App already trusts; -f replaces a file on the card; `cancel` stops it
|
||||||
|
ssh user@host[:port] | ssh status | ssh stop a terminal on another machine, in the SSH App; the password is asked there, never here
|
||||||
vpn status | vpn up [seconds] | vpn down | vpn import [path] | vpn forget | vpn auto on|off the WireGuard tunnel (Settings > VPN); import reads /vpn/wg0.conf; with seconds, it goes down by itself
|
vpn status | vpn up [seconds] | vpn down | vpn import [path] | vpn forget | vpn auto on|off the WireGuard tunnel (Settings > VPN); import reads /vpn/wg0.conf; with seconds, it goes down by itself
|
||||||
debug status | debug off [seconds] the Debug Console over Wi-Fi (Settings > Debug Console); with seconds, it comes back
|
debug status | debug off [seconds] the Debug Console over Wi-Fi (Settings > Debug Console); with seconds, it comes back
|
||||||
debug on | debug token <16 to 64 characters> | debug token new (USB serial only) switch it on, set its token
|
debug on | debug token <16 to 64 characters> | debug token new (USB serial only) switch it on, set its token
|
||||||
@@ -56,7 +60,7 @@ get <path> | put <path> <size> <sha256> | screenshot (Debug Console only) bina
|
|||||||
quit close the Debug Console connection
|
quit close the Debug Console connection
|
||||||
```
|
```
|
||||||
|
|
||||||
In **Safe Mode** (see [Crashes and Safe Mode](/dev/debug/crashes/)) only a few run: `help`, `info`, `tasks`, `net`, `reboot`, `boot other`, `wifi status`, and anything starting with `log level`, `crash`, `coredump`, `wifi add`, `debug`. Anything else answers `not available in Safe Mode`.
|
In **Safe Mode** (see [Crashes and Safe Mode](/dev/debug/crashes/)) only a few run: `help`, `uname`, `info`, `tasks`, `net`, `reboot`, `boot other`, `wifi status`, and anything starting with `log level`, `crash`, `coredump`, `wifi add`, `debug`. Anything else answers `not available in Safe Mode`.
|
||||||
|
|
||||||
## What they do
|
## What they do
|
||||||
|
|
||||||
@@ -98,7 +102,7 @@ In **Safe Mode** (see [Crashes and Safe Mode](/dev/debug/crashes/)) only a few r
|
|||||||
| `lora probe` | Finds the radio: chip, oscillator, antenna switch, DIO1 interrupt, noise floor |
|
| `lora probe` | Finds the radio: chip, oscillator, antenna switch, DIO1 interrupt, noise floor |
|
||||||
| `lora status` | Radio settings, who's listening, packet and error counters, noise floor, task stack |
|
| `lora status` | Radio settings, who's listening, packet and error counters, noise floor, task stack |
|
||||||
| `lora rx on` / `lora rx off` | Listens and prints each packet on the console |
|
| `lora rx on` / `lora rx off` | Listens and prints each packet on the console |
|
||||||
| `lora preset <name>` / `lora custom <MHz> <BW kHz> <SF> <CR> <sync hex> [preamble]` | Receive settings: a Meshtastic preset, or anything else (`lora custom 868.1 125 7 5 34 8` for LoRaWAN) |
|
| `lora preset <name>` / `lora custom <MHz> <BW kHz> <SF> <CR> <sync hex> [preamble]` | Receive settings: a Meshtastic preset or `MeshCore`, or anything else (`lora custom 868.1 125 7 5 34 8` for LoRaWAN) |
|
||||||
| `lora capture start` / `lora capture stop` | A LoRa Capture, as `c` in the App |
|
| `lora capture start` / `lora capture stop` | A LoRa Capture, as `c` in the App |
|
||||||
| `lora sweep on [from MHz] [to MHz] [step kHz]` / `lora sweep off` / `lora sweep dump` | Sweep a band (863 870 100 by default), with a summary every 2 s (floor, strongest, peaks), or print the latest pass |
|
| `lora sweep on [from MHz] [to MHz] [step kHz]` / `lora sweep off` / `lora sweep dump` | Sweep a band (863 870 100 by default), with a summary every 2 s (floor, strongest, peaks), or print the latest pass |
|
||||||
| `gnss quiet on` / `gnss quiet off` | The "Pause GNSS for LoRa" setting |
|
| `gnss quiet on` / `gnss quiet off` | The "Pause GNSS for LoRa" setting |
|
||||||
@@ -113,7 +117,11 @@ In **Safe Mode** (see [Crashes and Safe Mode](/dev/debug/crashes/)) only a few r
|
|||||||
| `loop spin on` / `loop spin off` | Make the main loop spin without resting, to compare load and radio noise |
|
| `loop spin on` / `loop spin off` | Make the main loop spin without resting, to compare load and radio noise |
|
||||||
| `crash abort` / `crash wdt` | Crash on purpose, or hang the main loop until the watchdog fires |
|
| `crash abort` / `crash wdt` | Crash on purpose, or hang the main loop until the watchdog fires |
|
||||||
| `ping <host> [count] [size]` / `nslookup <name> [server]` / `port <host> <port>` / `traceroute <host>` / `cancel` | Network troubleshooting (issue #90): does a host answer and how fast; a name's addresses, from which DNS server and in how long; is a TCP port open, refused or silent; the routers on the way. Each runs on a task of its own and prints as it goes, one at a time; `cancel` stops it |
|
| `ping <host> [count] [size]` / `nslookup <name> [server]` / `port <host> <port>` / `traceroute <host>` / `cancel` | Network troubleshooting (issue #90): does a host answer and how fast; a name's addresses, from which DNS server and in how long; is a TCP port open, refused or silent; the routers on the way. Each runs on a task of its own and prints as it goes, one at a time; `cancel` stops it |
|
||||||
| `ifconfig` / `arp` | The interfaces (Wi-Fi and the VPN) with their addresses, MTU, which is the default route, and the DNS servers; the neighbours heard on the Wi-Fi |
|
| `tls <host> [port]` / `ntp [server]` | A TLS handshake that checks nothing, then the certificate said in words: who it is for, who signed it, until when, its SHA-256, and whether this device's roots and the name asked for accept it (about 52 KB of heap while it runs; refused under 70 KB free). A time server's clock against the device's, with the round trip |
|
||||||
|
| `ifconfig` / `arp` / `netstat` | The interfaces (Wi-Fi and the VPN) with their addresses, MTU, which is the default route, and the DNS servers; the neighbours heard on the Wi-Fi; what listens and what is connected |
|
||||||
|
| `ssh user@host[:port]` / `ssh status` / `ssh stop` | Opens the SSH App and connects (the password is asked there, never on a console); the session's state and this device's public key; end the session |
|
||||||
|
| `scp [-f] [-P port] <file> user@host:path` / `scp [-f] [-P port] user@host:path <file>` | One file between the card and a server, with the device's key, or a password asked (masked) in the Shell, to a server the SSH App already trusts; `-f` replaces a file on the card; `cancel` stops it |
|
||||||
|
| `uname` | The firmware, its version and the chip it is built for (IRC has `/uname`) |
|
||||||
| `vpn status` / `vpn up [seconds]` / `vpn down` / `vpn import [path]` / `vpn forget` / `vpn auto on\|off` | The WireGuard tunnel: its state, on (for that many seconds, then off by itself: for trying a configuration from afar), off, read a `.conf` from the card (`/vpn/wg0.conf`), erase it, start with Wi-Fi. No key is ever printed |
|
| `vpn status` / `vpn up [seconds]` / `vpn down` / `vpn import [path]` / `vpn forget` / `vpn auto on\|off` | The WireGuard tunnel: its state, on (for that many seconds, then off by itself: for trying a configuration from afar), off, read a `.conf` from the card (`/vpn/wg0.conf`), erase it, start with Wi-Fi. No key is ever printed |
|
||||||
| `debug status` / `debug off [seconds]` | The Debug Console: whether it's on, has a token and a client; switch it off. With a number of seconds, it comes back by itself after that long |
|
| `debug status` / `debug off [seconds]` | The Debug Console: whether it's on, has a token and a client; switch it off. With a number of seconds, it comes back by itself after that long |
|
||||||
| `debug on` / `debug token <value>` / `debug token new` | USB serial only: switch it on (making a token if there's none), give it a token of 16 to 64 characters, or make a new one. The token is never printed |
|
| `debug on` / `debug token <value>` / `debug token new` | USB serial only: switch it on (making a token if there's none), give it a token of 16 to 64 characters, or make a new one. The token is never printed |
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ tag = "M3"
|
|||||||
| Q92 | A **Radio Service** owns the SX1262: driver, bus lock, IRQ task. The LoRa Scanner uses it in M3; the Mesh Service sits on top of it in M4. |
|
| Q92 | A **Radio Service** owns the SX1262: driver, bus lock, IRQ task. The LoRa Scanner uses it in M3; the Mesh Service sits on top of it in M4. |
|
||||||
| Q93 | Every radio transfer takes the shared bus lock (`SPI.beginTransaction`, as the card does). DIO1's interrupt only wakes the task; no SPI in the ISR. **Done when** a Gemini page streams to the card while the Sniffer receives, with no lost packets and no card errors (`lora status` counters). |
|
| Q93 | Every radio transfer takes the shared bus lock (`SPI.beginTransaction`, as the card does). DIO1's interrupt only wakes the task; no SPI in the ISR. **Done when** a Gemini page streams to the card while the Sniffer receives, with no lost packets and no card errors (`lora status` counters). |
|
||||||
| Q94 | **Receive only:** the Radio Service has no transmit function in M3. It doesn't exist, rather than being unused. |
|
| Q94 | **Receive only:** the Radio Service has no transmit function in M3. It doesn't exist, rather than being unused. |
|
||||||
| Q95 | Sniffer defaults: **EU868 LongFast**, 869.525 MHz, BW 250 kHz, SF 11, CR 4/5, sync word 0x2B, preamble 16 (Q19). The other Meshtastic presets are offered, plus custom settings. |
|
| Q95 | Sniffer defaults: **EU868 LongFast**, 869.525 MHz, BW 250 kHz, SF 11, CR 4/5, sync word 0x2B, preamble 16 (Q19). The other Meshtastic presets are offered, plus custom settings. *Later, the default became is the MeshCore preset (869.618 MHz, BW 62.5 kHz, SF 8, CR 4/8, sync word 0x12): it is what is heard here.* |
|
||||||
| Q96 | The Sniffer lists packets (time, RSSI, SNR, frequency error, length; hex dump on Enter) **and decodes the Meshtastic header**: the first 16 bytes are never encrypted (destination, sender, packet ID, hop limit and hop start, channel hash, next hop, relay node). Host-tested. Payload decryption is M4. |
|
| Q96 | The Sniffer lists packets (time, RSSI, SNR, frequency error, length; hex dump on Enter) **and decodes the Meshtastic header**: the first 16 bytes are never encrypted (destination, sender, packet ID, hop limit and hop start, channel hash, next hop, relay node). Host-tested. Payload decryption is M4. |
|
||||||
| Q97 | A Sniffer **Capture** is pcap with **LoRaTap** headers (link type 270), for Wireshark. Started by hand, Status Bar mark, its own Clean-up category, the 90% rule. |
|
| Q97 | A Sniffer **Capture** is pcap with **LoRaTap** headers (link type 270), for Wireshark. Started by hand, Status Bar mark, its own Clean-up category, the 90% rule. |
|
||||||
| Q98 | **Sweep** steps across the Region's band (863–870 MHz) in 100 kHz steps by default, reading instant RSSI: bars with peak hold, and a waterfall, Wi-Fi Tools style. Optionally CAD on the preset's frequency to tell LoRa traffic from noise. |
|
| Q98 | **Sweep** steps across the Region's band (863–870 MHz) in 100 kHz steps by default, reading instant RSSI: bars with peak hold, and a waterfall, Wi-Fi Tools style. Optionally CAD on the preset's frequency to tell LoRa traffic from noise. |
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ docs = true
|
|||||||
source = "docs/milestones/N1.md"
|
source = "docs/milestones/N1.md"
|
||||||
tag = "N1"
|
tag = "N1"
|
||||||
+++
|
+++
|
||||||
**Status:** in progress. The WireGuard tunnel (issue #8) shipped as **v0.19.0**. The first network troubleshooting commands (issue #90) shipped as **v0.20.0**: `ping`, `nslookup`, `port`, `traceroute`, `ifconfig`, `arp`; `tls`, `ntp` and `netstat` are still to do. SSH (#2) is not started.
|
**Status:** in progress. The WireGuard tunnel (issue #8) shipped as **v0.19.0**. The network troubleshooting commands (issue #90) shipped in two parts: `ping`, `nslookup`, `port`, `traceroute`, `ifconfig` and `arp` as **v0.20.0**; `tls`, `ntp` and `netstat` as **v0.21.0**. The SSH client (issue #2) shipped as **v0.22.0**.
|
||||||
|
|
||||||
**Goal:** reach things from the device that aren't on the Wi-Fi it happens to be on, and keep its traffic private on a network that isn't yours.
|
**Goal:** reach things from the device that aren't on the Wi-Fi it happens to be on, and keep its traffic private on a network that isn't yours.
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ The test keys were made for the purpose and deleted. Two rounds: first with the
|
|||||||
| Memory | 106.1 KB free before, 104.3 KB with the tunnel up, 106.2 KB after |
|
| Memory | 106.1 KB free before, 104.3 KB with the tunnel up, 106.2 KB after |
|
||||||
| Settings > VPN | The four rows, the state and "heard 66 s ago", the server, the address; no key anywhere on it |
|
| Settings > VPN | The four rows, the state and "heard 66 s ago", the server, the address; no key anywhere on it |
|
||||||
|
|
||||||
**Against a real server** (the maintainer's own, 2026-10-08): a configuration uploaded from a phone through the Storage App's sharing (issue #88) and imported in Settings; the server named by host name, on a port of its own, the device's address a /32, everything through the tunnel, "Start with Wi-Fi" on. The tunnel is up, and from another machine the device answers on its tunnel address: pings, and the Debug Console.
|
**Against a real server** (the maintainer's own, 2026-10-08): a configuration put on the card by the maintainer and imported in Settings; the server named by host name, on a port of its own, the device's address a /32, everything through the tunnel, "Start with Wi-Fi" on. The tunnel is up, and from another machine the device answers on its tunnel address: pings, and the Debug Console.
|
||||||
|
|
||||||
**Not checked:** from a network far from the server (the device was on the server's own network, reaching it by its public name). That the MTU is what limits a packet (larger pings were answered too, in pieces). Roaming from one Wi-Fi to another with the tunnel wanted. IRC through the tunnel. A day of uptime.
|
**Not checked:** from a network far from the server (the device was on the server's own network, reaching it by its public name). That the MTU is what limits a packet (larger pings were answered too, in pieces). Roaming from one Wi-Fi to another with the tunnel wanted. IRC through the tunnel. A day of uptime.
|
||||||
|
|
||||||
@@ -129,3 +129,102 @@ With a tunnel, fixed addresses and a file server on the device, "is it the netwo
|
|||||||
**Not checked:** without the VPN (every check went through the tunnel, or to the local network); a network that drops ICMP; the commands in Safe Mode, where they are not offered.
|
**Not checked:** without the VPN (every check went through the tunnel, or to the local network); a network that drops ICMP; the commands in Safe Mode, where they are not offered.
|
||||||
|
|
||||||
**Found on the way:** a refused connection is reported by lwIP as "reset", not "refused"; the first version called it "no route". And the header for the tested half was first given the same name as the service's, which makes a file include itself: the same mistake as an hour before, in the same way.
|
**Found on the way:** a refused connection is reported by lwIP as "reset", not "refused"; the first version called it "no route". And the header for the tested half was first given the same name as the service's, which makes a file include itself: the same mistake as an hour before, in the same way.
|
||||||
|
|
||||||
|
### The rest of the list: `tls`, `ntp`, `netstat` (2026-10-08)
|
||||||
|
|
||||||
|
- **`tls <host> [port]`** makes a handshake that checks nothing, so that a bad certificate can be looked at, and then checks it itself: against this device's roots (`ca_roots.h`, the ones the Update Service trusts) and the name asked for. It says who the certificate is for, who signed it, from when to when with the days left, the verdict with its reasons, and the SHA-256 that a Gemini pin is. It runs on a 12 KB task and isn't tried with less than 70 KB free: a handshake peaks at about 52 KB.
|
||||||
|
- **`ntp [server]`** sends one SNTP request and compares the answer with the device's clock, allowing for half the round trip. With no server it asks the first one in Settings.
|
||||||
|
- **`netstat`** reads lwIP's own lists: what listens, labelled where the firmware knows what it is, what is connected, and the UDP ports in use.
|
||||||
|
- Host tests: the NTP packet and the year 2036, the offset in words, a certificate's name (an old string type that mbedTLS prints as hex included), days between dates. 7 tests in `test/test_net_probe` in all.
|
||||||
|
|
||||||
|
| Check on the device | Result |
|
||||||
|
|---|---|
|
||||||
|
| `tls git.twis.la` | 709 ms; for git.twis.la, 67 days left, "this device trusts it", the SHA-256 |
|
||||||
|
| `tls geminiprotocol.net 1965` | "NOT trusted here: not signed by a root this device has": a capsule signs its own |
|
||||||
|
| `tls expired.badssl.com` | "EXPIRED 4197 days ago" |
|
||||||
|
| `tls wrong.host.badssl.com` | "NOT trusted here: not for that name" |
|
||||||
|
| `tls` to a port that isn't TLS | "no handshake ... An invalid SSL record was received" |
|
||||||
|
| `ntp` | The server, its stratum, 50 ms away; "this clock is right, to 0.1 s" |
|
||||||
|
| `netstat` | The update port and the Debug Console listening, the console's own connection, the UDP ports |
|
||||||
|
| Memory during a `tls` | 44.5 KB free at the lowest, from 104 KB |
|
||||||
|
|
||||||
|
**Not checked:** `tls` with IRC connected (it should refuse for lack of memory); `ntp` against a clock that is wrong; `netstat` while sharing.
|
||||||
|
|
||||||
|
## The SSH client (issue #2)
|
||||||
|
|
||||||
|
A terminal on another machine: one session to a shell, from the SSH App.
|
||||||
|
|
||||||
|
### Measured before deciding (2026-10-08)
|
||||||
|
|
||||||
|
`ewpa/LibSSH-ESP32` 5.10.0 (libssh on mbedTLS) was built into a trial firmware and a session opened against OpenSSH in a container, with a password.
|
||||||
|
|
||||||
|
| | Measured in the trial | As built |
|
||||||
|
|---|---|---|
|
||||||
|
| Flash | 120 KB | **292 KB** |
|
||||||
|
| Static RAM | 1.2 KB | |
|
||||||
|
| The session's task stack | 13 KB used | 13.7 KB used of 20 KB |
|
||||||
|
| Free heap with a session open | | 49 KB of 99 KB: it costs about 50 KB, the stack included |
|
||||||
|
| Lowest free heap during a login | | 30 KB |
|
||||||
|
| Key exchange (curve25519, ed25519 host key) | 227 ms | |
|
||||||
|
|
||||||
|
- **The trial undercounted the flash.** It logged in with a password. Signing with a key of the device's own (Q255) links libssh's table of multiples of the Ed25519 base point: `ge25519.c.o` alone is 109 KB. The rest of the difference is the public-key code, the terminal and three fonts. The firmware is at 71% of its slot.
|
||||||
|
- **libssh carries its own curve25519** (`src/external/curve25519_ref.c`) with the names libsodium uses, and libsodium is already here for WireGuard: two definitions don't link. A build script (`scripts/libssh_filter.py`) leaves libssh's copy out, and it uses libsodium's. It has to be a `pre:` script: libraries are built before any `post:` one runs.
|
||||||
|
- A session and a TLS connection don't fit together: IRC holds 40 KB.
|
||||||
|
|
||||||
|
### Decisions (design round 2026-10-08)
|
||||||
|
|
||||||
|
| # | Decision |
|
||||||
|
|---|---|
|
||||||
|
| Q254 | **LibSSH-ESP32 5.10.0**, with its duplicate curve file left out of the build. |
|
||||||
|
| Q255 | **A password, typed each time and never stored**, or **a key the device makes for itself** (Ed25519, no passphrase, kept in the settings store). Its public half is shown, written to `/ssh/id_ed25519.pub` and printed by `ssh status`. Keys made elsewhere aren't imported. |
|
||||||
|
| Q256 | **A terminal good enough for a shell, `less`, `top`, `nano` and `vim`:** cursor movement, erasing, sixteen colours, scroll regions, the alternate screen, the cursor keys' two modes. `TERM=xterm`. No mouse. |
|
||||||
|
| Q257 | **Five text sizes, changed with Ctrl and + or -** (the user's change to the round: the proposal was a setting). 4x6, 5x8, 6x10, 6x13 and 9x15 pixels: from 60 x 20 to 26 x 8 characters. The far end is told the new size; the choice is kept. |
|
||||||
|
| Q258 | **100 lines of scrollback**, as text, with Alt and up or down, as in the Shell. Not on the alternate screen. |
|
||||||
|
| Q259 | **Keys:** Ctrl with a letter; Tab; the backtick key sends Esc, as it is printed; Alt with it types a backtick; Fn with the arrow keys; Shift with those for Page Up and Down; Ctrl+Alt+q disconnects. Fn with backtick is Home, as everywhere. |
|
||||||
|
| Q260 | **The session outlives the App's time in front.** `SSH` in the Status Bar while one is open. |
|
||||||
|
| Q261 | **Not started under 75 KB free**, with the reason in words. |
|
||||||
|
| Q262 | **Up to eight hosts remembered**, the last used first, once a login has succeeded. Forgetting one forgets its server's fingerprint too, unless another remembered host is the same server. |
|
||||||
|
| Q263 | **Trust on first use,** on the SHA-256 fingerprint; sixteen servers remembered. **A changed key is a warning**, with Cancel selected. |
|
||||||
|
| Q264 | **UTF-8 in, the fonts' Latin-1 out:** what they lack is `?`, box-drawing lines are `+ - \|`. |
|
||||||
|
| Q265 | **`ssh user@host` in the Shell opens the App** and connects there. The password is never asked on a console. |
|
||||||
|
| Q266 | **Not built:** port forwarding, SFTP and scp, jump hosts, agent forwarding, keys with a passphrase, more than one session. |
|
||||||
|
|
||||||
|
### As built
|
||||||
|
|
||||||
|
- **`lib/term`** (host-tested, 12 tests in `test/test_terminal`): `Terminal`, the screen a program's output makes, with its history and the replies a program asks for; `encodeKey`, what a key sends; `SshHosts` and `SshKnownHosts`, the two lists kept in the settings store as lines of text.
|
||||||
|
- **`SshService`** (`src/services/ssh_service`): one session on a task of its own (20 KB of stack). The task and the main loop share the terminal, the bytes to send and the state under one lock. Its questions (is this the right server? the password?) are states it waits in until the App answers; the settings store is only written from the main loop. The password and the private key are overwritten after use.
|
||||||
|
- **`SshApp`** (`src/apps/ssh_app`): the hosts, the entry, the session, the key page. It draws the grid a run of same-coloured cells at a time, at most every 60 ms.
|
||||||
|
- **Keys that aren't characters now say what was held with them** (`lib/input/src/key_mapper.cpp`): the arrows, Enter, Del, Tab and Back carry Shift, Ctrl and Alt. The terminal needs it for Page Up and Alt+backtick. It also makes two documented keys work from the real keyboard, which until now only worked from the Debug Console's `key` command: Ctrl with Fn and up or down in a note, and Shift+Tab in Gemini.
|
||||||
|
- **IRC doesn't try to connect with less than 60 KB free** (`IrcService::kNeedFree`): see below.
|
||||||
|
- Settings: `SshHosts`, `SshKnown`, `SshKey`, `SshPublic`, `SshFont`.
|
||||||
|
|
||||||
|
### Checks on the device (2026-10-08, against OpenSSH 9.7 in a container on the same network)
|
||||||
|
|
||||||
|
| Check | Result |
|
||||||
|
|---|---|
|
||||||
|
| `ssh tester@host:2222` from the Debug Console | The App opens; the fingerprint shown is the one `ssh-keygen -lf` prints on the server |
|
||||||
|
| Trust it, a password | A shell; `stty size` says 15 48, `$TERM` is xterm |
|
||||||
|
| `ls -la`, `top`, `vim` (insert, Esc, `:wq`) | Drawn right: `top`'s reverse-video header, `vim`'s alternate screen and what was there before coming back; the file is on the server |
|
||||||
|
| Ctrl with + and - | `stty size` says 12 40, then 20 60; `top` redraws for it |
|
||||||
|
| `seq 1 60`, Alt with up | The history, in grey, with how far back in the corner |
|
||||||
|
| Fn+backtick, then the App again | The Launcher with `SSH` in the Status Bar; the session as it was |
|
||||||
|
| `sleep 100`, Ctrl+C; Alt+backtick | Interrupted; `` echo `id -u` `` prints 1000 |
|
||||||
|
| Ctrl+Alt+q; `exit` | "Disconnected"; "The session ended" |
|
||||||
|
| This device's key, its public half in `authorized_keys` | "Accepted publickey" in the server's log; no password asked |
|
||||||
|
| The server's host keys replaced | "THE SERVER'S KEY CHANGED" with the new fingerprint, Cancel selected. Cancel: "Not trusted: not connected". Replace: it connects, and doesn't ask again |
|
||||||
|
| A wrong password | "Wrong password", and asked again; Back gives up |
|
||||||
|
| A port nothing listens on | "Nothing listens there: the connection was refused" |
|
||||||
|
| `ssh nobody`, `ssh a@`, a port of 99999 | Refused, each with its reason |
|
||||||
|
| Forgetting a host | Asked, then gone from the list |
|
||||||
|
| `irc start` with a session open | "not enough memory: close the SSH session, retrying in 5 s", and no attempt: the lowest free heap doesn't move |
|
||||||
|
| Memory | 99 KB free before, 49 KB with a session open, 30 KB at the lowest during a login, 99 KB again after |
|
||||||
|
| Stacks | `ssh` 6.8 KB free of 20 KB; `loopTask` 1.9 KB free, as before |
|
||||||
|
|
||||||
|
**Not checked:** the refusal under 75 KB free (it is one comparison, and wasn't provoked). A server on the internet, or through the VPN. Wi-Fi lost in the middle of a session. Servers other than OpenSSH. `nano`, `less`, `htop`, `tmux`. Keyboard-interactive logins (two-factor prompts). A session left open for hours.
|
||||||
|
|
||||||
|
### What went wrong while building it
|
||||||
|
|
||||||
|
- **IRC, started with a session open, took the free heap down to 236 bytes.** A test script's keys went to the Launcher instead of the terminal and opened the IRC App, which connects when opened. Its TLS handshake found no memory, failed, and tried again with its usual back-off, six times; nothing crashed and it never connected, but 236 bytes is no margin at all. IRC now looks at the free heap before each attempt and says "not enough memory: close the SSH session" instead of trying.
|
||||||
|
- **The build script did nothing as a `post:` script:** the libraries were already built when it ran.
|
||||||
|
- **A failed connection was first shown as an empty terminal** with its reason squeezed on the last line, and a host was remembered before anyone had logged in to it. Both changed: the reason has a page, and a host is remembered once a login succeeds.
|
||||||
|
- **The trust question didn't fit its dialog:** the fingerprint is 50 characters. It is now split over two lines, under one line of words.
|
||||||
|
|||||||
|
After Width: | Height: | Size: 4.2 KiB |
@@ -0,0 +1,312 @@
|
|||||||
|
+++
|
||||||
|
title = '''Six releases behind'''
|
||||||
|
description = '''roro9stack gets a WireGuard tunnel, and the tools to find out why a network doesn't work: ping, nslookup, traceroute, a TLS check and the rest. In between, I looked at the project's own website and found that the documentation had stopped keeping up six releases earlier, and nobody had noticed, me included.'''
|
||||||
|
date = 2026-10-08T03:15:00+02:00
|
||||||
|
|
||||||
|
[extra]
|
||||||
|
topics = '''ESP32-S3 · WireGuard · Documentation'''
|
||||||
|
read_label = '''Read what was missing →'''
|
||||||
|
uid = '''<b>ifconfig:</b> vpn 10.9.0.2/32 mtu 1420, up, default route'''
|
||||||
|
dek = "Three more releases of [roro9stack](/devlog/roro9stack/), my firmware for the M5Stack Cardputer: a VPN (v0.19.0) and nine commands for troubleshooting a network from the device itself (v0.20.0 and v0.21.0). The tunnel crashed the device the first time it was started and then turned out to be the easy part. The hard part was noticing that the user guide described a firmware from the day before."
|
||||||
|
byline = '''measured before deciding, for once; then promised more than the network stack could do'''
|
||||||
|
|
||||||
|
[extra.sign]
|
||||||
|
label = "Releases shipped with the documentation behind"
|
||||||
|
note = "v0.13.0 to v0.18.0. Each had its own page updated, and nothing around it."
|
||||||
|
count = "6"
|
||||||
|
tone = "red"
|
||||||
|
|
||||||
|
[[extra.cast]]
|
||||||
|
name = "The tunnel"
|
||||||
|
role = "WireGuard, one peer, IPv4"
|
||||||
|
text = "Costs under 2 KB of memory once it's up, which on this device is close to free. Stopped the device dead the first time it was asked to start."
|
||||||
|
|
||||||
|
[[extra.cast]]
|
||||||
|
name = "lwIP"
|
||||||
|
role = "the network stack"
|
||||||
|
text = "Has a lock, and in this firmware it checks that you hold it. Has no routing table, which I found out after promising one."
|
||||||
|
|
||||||
|
[[extra.cast]]
|
||||||
|
name = "The test peer"
|
||||||
|
role = "a WireGuard server in a container"
|
||||||
|
text = "Could reach the device. The device couldn't reach it. So the server called the client, which WireGuard doesn't mind at all."
|
||||||
|
|
||||||
|
[[extra.cast]]
|
||||||
|
name = "The home page"
|
||||||
|
role = "of this site"
|
||||||
|
text = "Said the Storage App opens text, hex, captures and tracks. It had been showing pictures for four releases and serving files to phones for one."
|
||||||
|
|
||||||
|
[[extra.cast]]
|
||||||
|
name = "ping"
|
||||||
|
role = "and eight friends"
|
||||||
|
text = "nslookup, port, traceroute, tls, ntp, ifconfig, arp, netstat. The first thing I did with them was measure my own tunnel, and learn something."
|
||||||
|
+++
|
||||||
|
|
||||||
|
## TL;DR
|
||||||
|
|
||||||
|
- **A WireGuard VPN** (**v0.19.0**): copy a client `.conf` to the card, import it in Settings, switch it on. One tunnel, to one server. It carries everything, or the tunnel's own subnet.
|
||||||
|
- **It costs 63 KB of flash and under 2 KB of memory.** The library crashed the firmware on its first call; the fix was three lines of ours.
|
||||||
|
- **I promised split tunnels by `AllowedIPs` and couldn't deliver:** the network stack routes by one subnet or by default, nothing finer.
|
||||||
|
- **The documentation was six releases behind.** Every feature had its own page. The home page, Settings, the Status Bar, the how-tos, the glossary and the README's first paragraph had none of it.
|
||||||
|
- **Nine network commands** in the Shell (**v0.20.0**, **v0.21.0**): `ping`, `nslookup`, `port`, `traceroute`, `tls`, `ntp`, `ifconfig`, `arp`, `netstat`.
|
||||||
|
- A ping of 1392 bytes crosses my tunnel and one of 1393 doesn't. I now know my tunnel's MTU to the byte, from a device with a 240-pixel screen.
|
||||||
|
- 546 host tests, 13 more than last time.
|
||||||
|
|
||||||
|
## The cast
|
||||||
|
|
||||||
|
{{ cast() }}
|
||||||
|
|
||||||
|
## Measured first, for once
|
||||||
|
|
||||||
|
The issue for the VPN had a line I'd written days ago and am glad of: *measure both libraries first.* So before any design, a trial firmware with the maintained library in it, a throwaway WireGuard server in a container, and a real tunnel.
|
||||||
|
|
||||||
|
{% table() %}
|
||||||
|
| | Cost |
|
||||||
|
|---|---|
|
||||||
|
| Flash, the library | 43 KB |
|
||||||
|
| Flash, with the service, the Settings page and the commands | 63 KB |
|
||||||
|
| Static RAM | 1.2 KB |
|
||||||
|
| Heap with the tunnel up | 1.8 KB |
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
On a device where a TLS connection takes 52 KB, a VPN for 1.8 is a gift. That number alone decided most of the design round: no memory floors, no "close IRC first", nothing to ration.
|
||||||
|
|
||||||
|
Getting to that number took three surprises.
|
||||||
|
|
||||||
|
### It stopped on the first call
|
||||||
|
|
||||||
|
{% code(caption="The first `wg up`. The crash report named the line.") %}
|
||||||
|
```
|
||||||
|
assert failed: netif_add /IDF/components/lwip/lwip/src/core/netif.c:297
|
||||||
|
(Required to lock TCPIP core functionality!)
|
||||||
|
```
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
The library talks to lwIP, the network stack, through its low-level functions, and takes no lock while it does. Most builds don't mind. This firmware's framework is built with the check switched on, and so the first `netif_add` was the last thing the device did.
|
||||||
|
|
||||||
|
The fix isn't in the library. Every call into it is made with the lock held, on our side: a three-line guard object. The library is used exactly as published.
|
||||||
|
|
||||||
|
### The server had to call the client
|
||||||
|
|
||||||
|
My device was on a guest Wi-Fi. The test server was on another network, and the guest network doesn't let its devices open connections inward. No handshake. For a while it looked like the library didn't work.
|
||||||
|
|
||||||
|
It worked fine. WireGuard doesn't have clients and servers, only peers, and either can call the other. I gave the device a fixed port to listen on, told the *server* where the device was, and the server started the handshake. Twenty-five pings of twenty-five, through a tunnel set up backwards.
|
||||||
|
|
||||||
|
(Later, on a network where the device could reach out, the normal direction worked first time. And then against my real server, which is the test that counts.)
|
||||||
|
|
||||||
|
### "What AllowedIPs say"
|
||||||
|
|
||||||
|
In the design round I'd agreed to this: *what goes through the tunnel is what the file's `AllowedIPs` line says.* Home subnets through the tunnel, the rest out over Wi-Fi. That's what every WireGuard client does.
|
||||||
|
|
||||||
|
Then I read how lwIP decides where a packet goes. It has two rules: the packet is for an interface's own subnet, or it goes to the default interface. There is no routing table to add "192.168.1.0/24 via the tunnel" to.
|
||||||
|
|
||||||
|
So the firmware does one of two things, and says which when you import a file:
|
||||||
|
|
||||||
|
{% table() %}
|
||||||
|
| The file says | What happens |
|
||||||
|
|---|---|
|
||||||
|
| `AllowedIPs = 0.0.0.0/0` | Everything goes through the tunnel |
|
||||||
|
| Anything else | The one subnet the device's tunnel address is in |
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
A home network *behind* the server needs the first kind. An import with more ranges than that says so: "through it 10.9.0.0/24, not 1 other range". I'd rather the screen admit a limit than the documentation.
|
||||||
|
|
||||||
|
It also changed an answer I'd given about a kill switch. I'd said there wouldn't be one. With everything routed into the tunnel, there is: while the server is silent the default route still points into a tunnel that has nowhere to send, and nothing leaves. Not by decision. By construction.
|
||||||
|
|
||||||
|
{{ figure(src="vpn.png", alt="The Cardputer's Settings, VPN page at 2x: VPN On, Start with Wi-Fi On, Import /vpn/wg0.conf, Forget it; then in blue It is up, heard 66 s ago, and in grey the server's address and This device 10.9.0.2, through it everything. The Status Bar shows VPN in blue.", width=480, height=270, caption="Settings → VPN, against the test server. No key appears on this page, or anywhere else: the private key goes in with the file and is never shown again.") }}
|
||||||
|
|
||||||
|
## Taking it down took my connection with it
|
||||||
|
|
||||||
|
One more, because it's the kind of bug that only shows when you test the way you work.
|
||||||
|
|
||||||
|
The tunnel puts its own DNS servers in while it's up, and has to give the old ones back when it stops. The Wi-Fi settings already had a way to get DHCP's servers back: ask for a new lease. So I called that.
|
||||||
|
|
||||||
|
A new lease reconnects Wi-Fi. Reconnecting Wi-Fi drops every connection, including the Debug Console session I had just typed `vpn down` into. The command worked and I never saw it say so.
|
||||||
|
|
||||||
|
The tunnel now remembers what was there and puts it back. It also notices when a DHCP renewal replaces its servers mid-flight, puts its own back in, and keeps the renewed ones for later.
|
||||||
|
|
||||||
|
## Six releases behind
|
||||||
|
|
||||||
|
With the tunnel working against my real server, I went to the website to see how it read. And then I went through the rest of the site, and it got worse with every page.
|
||||||
|
|
||||||
|
- The **home page** described a Storage App that opens "text, hex, captures, tracks and update files". It had been showing pictures since v0.16.0 and serving the card to phones since v0.18.0.
|
||||||
|
- The **Notes** card didn't say that a note can be any size, which it can since v0.15.0.
|
||||||
|
- **Settings**, in the guide, had no VPN row. The **Status Bar** table had no `VPN`.
|
||||||
|
- There was **no how-to** for anything built since: nothing on moving files with a phone, nothing on screenshots.
|
||||||
|
- The **README** opened by calling this "a Meshtastic-compatible mesh messenger". It listens to a mesh. It has never sent a message.
|
||||||
|
- Every milestone document had a **status line** from days ago. One still said a feature was "in a pull request" that had long been merged and released.
|
||||||
|
|
||||||
|
None of this was neglect in the usual sense. Each feature *had* been documented: its own guide page, its section in the README, its design notes. That was the trap. Every pull request looked finished because the page about the new thing was there. Nobody was looking at the pages about the old things, which is where a reader starts.
|
||||||
|
|
||||||
|
Six releases went out like that.
|
||||||
|
|
||||||
|
What changed isn't a resolution to be more careful, which lasts a week. It's a list, the same one every time: the home page's cards, every Settings row, the Status Bar, a how-to for anything a person would want to do, the FAQ, the glossary, the README's opening, the status lines, a screenshot of each new screen. A feature isn't done until each of those has been asked "does the new thing show here?"
|
||||||
|
|
||||||
|
The catch-up went into the same pull request as the VPN: three new how-tos, five new screenshots, and a README that starts with what the firmware does today.
|
||||||
|
|
||||||
|
The two releases after it were documented as they were built. That's two. Ask me again at twenty.
|
||||||
|
|
||||||
|
## Nine commands for a bad network day
|
||||||
|
|
||||||
|
A VPN, addresses you can set by hand, a file server: this device now has enough networking to have network problems. And until today, the only thing it could tell you was `wifi status`.
|
||||||
|
|
||||||
|
{% table() %}
|
||||||
|
| Command | Tells you |
|
||||||
|
|---|---|
|
||||||
|
| `ping` | Does it answer, and how fast |
|
||||||
|
| `nslookup` | A name's addresses, which DNS server answered, in how long |
|
||||||
|
| `port` | A TCP port: open, refused, or silent |
|
||||||
|
| `traceroute` | The routers on the way |
|
||||||
|
| `tls` | A certificate: who for, who by, until when, and whether *this device* trusts it |
|
||||||
|
| `ntp` | A time server's clock against this one |
|
||||||
|
| `ifconfig` | The interfaces, and **which one is the default route** |
|
||||||
|
| `arp` | The neighbours on the Wi-Fi |
|
||||||
|
| `netstat` | What the device itself listens on |
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
They run in the Shell and over both consoles. The slow ones each get a task of their own and print as they go; `cancel` stops one.
|
||||||
|
|
||||||
|
{{ figure(src="shell.png", alt="The Shell at 2x with VPN in the Status Bar: ping: 1 4 ms, 2 7 ms, 3 4 ms, then ping: 3 sent, 3 back, 0% lost, 4/5/7 with ms wrapped onto the next line; then nslookup roro9stack.net, 10.9.0.1 answered in 6 ms, 65.21.233.110.", width=480, height=270, caption="The first build, in the Shell. The ping summary is one character too long for the screen and drops its `ms` onto a line of its own. It reads `3/3 back, 0% lost, 4/5/7 ms` now.") }}
|
||||||
|
|
||||||
|
Three things I like about them.
|
||||||
|
|
||||||
|
**`nslookup` asks the server itself.** The system's resolver gives you an address and nothing else. This sends its own question over UDP, so it can say *which* server answered and how long it took, and it can ask a different server to compare. When a name doesn't resolve, that's the whole diagnosis.
|
||||||
|
|
||||||
|
**`tls` checks nothing, then checks everything.** IRC, Gemini and updates all fail with "TLS error" and no way to see why. `tls` makes a handshake that accepts any certificate, so that a bad one can be looked at, and then judges it itself against the roots this device actually trusts:
|
||||||
|
|
||||||
|
{% code(caption="Four servers, four verdicts.") %}
|
||||||
|
```
|
||||||
|
tls: for git.twis.la, by YE2
|
||||||
|
tls: valid 2026-09-15 to 2026-12-14, 67 days left
|
||||||
|
tls: this device trusts it
|
||||||
|
|
||||||
|
tls: for geminiprotocol.net, by geminiprotocol.net
|
||||||
|
tls: NOT trusted here: not signed by a root this device has
|
||||||
|
|
||||||
|
tls: valid 2015-04-09 to 2015-04-12, EXPIRED 4197 days ago
|
||||||
|
tls: NOT trusted here: expired, not signed by a root this device has
|
||||||
|
|
||||||
|
tls: for *.badssl.com, by YR1
|
||||||
|
tls: NOT trusted here: not for that name
|
||||||
|
```
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
The second one is fine, by the way: a Gemini capsule signs its own certificate, and the browser trusts it on first sight.
|
||||||
|
|
||||||
|
**A ping with a size finds a tunnel's MTU.** This is the one I didn't expect to use within the hour:
|
||||||
|
|
||||||
|
{% code(caption="Through my tunnel. 1392 bytes plus 28 of headers is 1420, WireGuard's usual.") %}
|
||||||
|
```
|
||||||
|
$ ping 9.9.9.9 2 1392
|
||||||
|
ping: 2/2 back, 0% lost, 27/30/33 ms
|
||||||
|
$ ping 9.9.9.9 2 1393
|
||||||
|
ping: 0/2 back, 100% lost
|
||||||
|
```
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
One byte. And `ifconfig` on the same device, same minute:
|
||||||
|
|
||||||
|
{% code() %}
|
||||||
|
```
|
||||||
|
ifconfig: vpn 10.9.0.2/32 mtu 1420, up, default route
|
||||||
|
ifconfig: wifi 172.16.42.25/21 gw 172.16.42.1 mtu 1500, up
|
||||||
|
ifconfig: dns 10.9.0.1
|
||||||
|
```
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
"default route" on the `vpn` line is the answer to the first question anybody has with a VPN up.
|
||||||
|
|
||||||
|
## All of them, on the device
|
||||||
|
|
||||||
|
Typed on the Cardputer's own keyboard, in the Shell, with the tunnel up. `VPN` in the Status Bar is the tunnel; everything below went through it.
|
||||||
|
|
||||||
|
{{ figure(src="ifconfig.png", alt="The Shell: ifconfig prints vpn 10.9.0.2/32 mtu 1420, up, default route; wifi 172.16.42.25/21 gw 172.16.42.1 mtu 1500, up; dns 10.9.0.1.", width=480, height=270, caption="`ifconfig`. The first line answers the first question: with the tunnel up, everything leaves through it.") }}
|
||||||
|
|
||||||
|
{{ figure(src="ping.png", alt="The Shell: ping 9.9.9.9 3 prints 9.9.9.9, 56 bytes, then 1 25 ms, 2 25 ms, 3 33 ms, and 3/3 back, 0% lost, 25/27/33 ms.", width=480, height=270, caption="`ping`, with a count. The summary fits on one line now.") }}
|
||||||
|
|
||||||
|
{{ figure(src="nslookup.png", alt="The Shell: nslookup www.wikipedia.org prints 10.9.0.1 answered in 293 ms, www.wikipedia.org is dyna.wikimedia.org, and 185.15.59.224.", width=480, height=270, caption="`nslookup`. Which server answered, how long it took, the alias the name really is, and the address.") }}
|
||||||
|
|
||||||
|
{{ figure(src="port.png", alt="The Shell: port git.twis.la 443 prints 65.21.233.110:443 open, 48 ms.", width=480, height=270, caption="`port`. Open, in 48 ms. The other two answers are `refused` and nothing at all for five seconds.") }}
|
||||||
|
|
||||||
|
{{ figure(src="tls.png", alt="The Shell after tls git.twis.la: for git.twis.la, by YE2; valid 2026-09-15 to 2026-12-14, 67 days left; this device trusts it; sha256 and 64 hexadecimal digits over two lines.", width=480, height=270, caption="`tls`. The verdict, and the fingerprint that a Gemini pin is made of. The first line scrolled off: the handshake took 0.7 s.") }}
|
||||||
|
|
||||||
|
{{ figure(src="ntp.png", alt="The Shell: ntp prints pool.ntp.org (162.159.200.123), stratum 3, 23 ms away, and this clock is right, to 0.1 s.", width=480, height=270, caption="`ntp`. The clock gates TLS and the VPN, so it's worth being able to ask.") }}
|
||||||
|
|
||||||
|
{{ figure(src="netstat.png", alt="The Shell: netstat prints tcp 2323 listens (Debug Console), tcp 3232 listens (updates), tcp 172.16.42.25:2323 - 172.16.42.249:51552, udp 49974, udp 49973, udp 68 (DHCP).", width=480, height=270, caption="`netstat`. What the device offers the network right now. The one connection is the Debug Console session that pressed these keys.") }}
|
||||||
|
|
||||||
|
No picture of `traceroute` or `arp`: the first would list my provider's routers and the second my machines' hardware addresses, and neither belongs on a website. The traceroute through the tunnel was nine hops, my own server first.
|
||||||
|
|
||||||
|
## The same mistake, twice, in three hours
|
||||||
|
|
||||||
|
For the file sharing, the testable half of the code went in a file called `web_share.h`, and the service that uses it in another file called `web_share.h`, in another folder. One included the other by name and got itself. I wrote that up in [the last post](/devlog/roro9stack-share/) as one of the two things that went wrong.
|
||||||
|
|
||||||
|
For the network commands, the testable half went in `net_tools.h`, and the service in `net_tools.h`.
|
||||||
|
|
||||||
|
Same error message. Same fix. I'd like to say the second time took less long to spot.
|
||||||
|
|
||||||
|
Two smaller ones:
|
||||||
|
|
||||||
|
- **A refused connection isn't called refused.** lwIP reports it as "reset". My first `port` command told me a port on my own PC had "no route to it".
|
||||||
|
- **My test tool lied about concurrency.** The script that sends commands waits "until the console is quiet". A ping prints every second, so the console was never quiet, so my "second command while a ping runs" was sent after the ping had finished. It ran, and I briefly believed the one-at-a-time guard didn't work.
|
||||||
|
|
||||||
|
## What I didn't check
|
||||||
|
|
||||||
|
- **From far away.** My real server answered, but the device was on the server's own network, reaching it by its public name.
|
||||||
|
- **Roaming** from one Wi-Fi to another with the tunnel wanted.
|
||||||
|
- **IRC through the tunnel.**
|
||||||
|
- `tls` with IRC connected, when there shouldn't be the memory and it should say so.
|
||||||
|
- The network commands **without** the VPN: every test went through the tunnel or to the local network.
|
||||||
|
|
||||||
|
## By the numbers
|
||||||
|
|
||||||
|
{% table() %}
|
||||||
|
| | |
|
||||||
|
|---|---|
|
||||||
|
| Releases | 3 |
|
||||||
|
| Heap a WireGuard tunnel costs | 1.8 KB |
|
||||||
|
| Flash it costs | 63 KB |
|
||||||
|
| Calls into the library before the device stopped | 1 |
|
||||||
|
| Lines to fix that | 3 |
|
||||||
|
| Ways lwIP can route a packet | 2 |
|
||||||
|
| Releases that shipped with the docs behind | 6 |
|
||||||
|
| How-tos written in one sitting to catch up | 3 |
|
||||||
|
| Network commands | 9 |
|
||||||
|
| Flash they cost | 20 KB |
|
||||||
|
| Bytes between a ping that crosses my tunnel and one that doesn't | 1 |
|
||||||
|
| Times I gave two headers the same name | 2 |
|
||||||
|
| Host tests | 546 |
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
## Where it stands
|
||||||
|
|
||||||
|
{% steps() %}
|
||||||
|
1. ~~M0 and M1: the skeleton, Wi-Fi, IRC, Wi-Fi Tools.~~ v0.1.0 to v0.2.1, [the first post](/devlog/roro9stack/).
|
||||||
|
|
||||||
|
2. ~~Updates and debugging over the air.~~ v0.3.0, [Look, no cables](/devlog/roro9stack-ota/).
|
||||||
|
|
||||||
|
3. ~~M2: GNSS.~~ v0.4.0, [Seventeen satellites](/devlog/roro9stack-gnss/).
|
||||||
|
|
||||||
|
4. ~~G1: Gemini.~~ v0.5.0, [A browser in the RAM IRC left over](/devlog/roro9stack-gemini/).
|
||||||
|
|
||||||
|
5. ~~M3: the LoRa radio, listening.~~ v0.6.0, [The loudest thing it hears is itself](/devlog/roro9stack-lora/).
|
||||||
|
|
||||||
|
6. ~~S1: the card, fixed addresses, the System App.~~ v0.6.1 to v0.8.1, [One byte too early](/devlog/roro9stack-s1/).
|
||||||
|
|
||||||
|
7. ~~F1 and the start of R1: files, notes, signed releases, updates from Gitea.~~ v0.9.0 to v0.11.0, [836 bytes](/devlog/roro9stack-f1-r1/).
|
||||||
|
|
||||||
|
8. ~~W1: the website, and one firmware with the Debug Console in it.~~ v0.12.0, [It was off](/devlog/roro9stack-console/).
|
||||||
|
|
||||||
|
9. ~~A help key, the Shell, notes of any size.~~ v0.13.0 to v0.15.0, [It said "No"](/devlog/roro9stack-shell/).
|
||||||
|
|
||||||
|
10. ~~Pictures, a screenshot key, the card in a phone's browser.~~ v0.16.0 to v0.18.0, [Press w](/devlog/roro9stack-share/).
|
||||||
|
|
||||||
|
11. ~~A WireGuard tunnel, and the documentation caught up.~~ v0.19.0, this post.
|
||||||
|
|
||||||
|
12. ~~Nine commands for a bad network day.~~ v0.20.0 and v0.21.0, this post.
|
||||||
|
|
||||||
|
13. Next: M4, the mesh, which still wants a second node. And maybe SSH, now that there is a tunnel to reach things through.
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
{% signoff() %}
|
||||||
|
The VPN took a library, a lock and an evening. The documentation took a look. I'd spent a day shipping features to a website that described yesterday's firmware, with every pull request looking complete because its own page was there. The tunnel carries exactly 1420 bytes, and I know that because the device told me.
|
||||||
|
{% end %}
|
||||||
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
@@ -12,7 +12,7 @@ Press **<kbd>Fn</kbd> + <kbd>h</kbd>**, on any screen: it lists the keys that wo
|
|||||||
|
|
||||||
## Can I send messages over the mesh?
|
## Can I send messages over the mesh?
|
||||||
|
|
||||||
**Not yet.** The LoRa Scanner **listens** to Meshtastic traffic and shows what it hears, but nothing is transmitted. A mesh messenger is the goal and is planned in two milestones, one for receiving and one for transmitting; it waits for a second node to test against.
|
**Not yet.** The LoRa Scanner **listens** to Meshtastic or MeshCore traffic and shows what it hears, but nothing is transmitted. A mesh messenger is the goal and is planned in two milestones, one for receiving and one for transmitting; it waits for a second node to test against.
|
||||||
|
|
||||||
## Is this Meshtastic?
|
## Is this Meshtastic?
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ Yes: it is [open source](https://git.twis.la/twisla/roro9stack) (GPL-3.0). The d
|
|||||||
|
|
||||||
**The firmware contacts the project's server once a day,** to see whether a new release exists: **Settings → Check for updates**, on by default, only when Wi-Fi is up and the clock is set. It installs nothing by itself, and you can switch it off. Besides that, the device talks to what you ask it to: the IRC server and Gemini capsules you open, DNS servers (9.9.9.9 and 1.1.1.1 by default) and time servers (pool.ntp.org and time.cloudflare.com by default), all of which you can change. There is no account, no analytics and no telemetry.
|
**The firmware contacts the project's server once a day,** to see whether a new release exists: **Settings → Check for updates**, on by default, only when Wi-Fi is up and the clock is set. It installs nothing by itself, and you can switch it off. Besides that, the device talks to what you ask it to: the IRC server and Gemini capsules you open, DNS servers (9.9.9.9 and 1.1.1.1 by default) and time servers (pool.ntp.org and time.cloudflare.com by default), all of which you can change. There is no account, no analytics and no telemetry.
|
||||||
|
|
||||||
**It listens on the network only for what you switched on:** the port that receives signed firmware updates, always; the Debug Console, the card shared with a browser and the VPN, only while you have them on.
|
**It listens on the network only for what you switched on:** the port that receives signed firmware updates, always; the Debug Console, the card shared with a browser and the VPN, only while you have them on. The SSH App connects out to the server you name and listens for nothing.
|
||||||
|
|
||||||
**This website** sets no cookies and has no analytics, loads nothing from other sites, and its server logs keep only a masked part of visitors' addresses. The Install page asks the project's own server for the latest release.
|
**This website** sets no cookies and has no analytics, loads nothing from other sites, and its server logs keep only a masked part of visitors' addresses. The Install page asks the project's own server for the latest release.
|
||||||
|
|
||||||
@@ -65,6 +65,10 @@ A secure connection takes about 52 KB of the 107 KB the device has, and IRC's ta
|
|||||||
|
|
||||||
Yes, WireGuard: one tunnel to one server, set up by copying the client's `.conf` to the SD card and importing it in Settings. It can carry everything, or just the VPN's own subnet. See [VPN](/guide/vpn/).
|
Yes, WireGuard: one tunnel to one server, set up by copying the client's `.conf` to the SD card and importing it in Settings. It can carry everything, or just the VPN's own subnet. See [VPN](/guide/vpn/).
|
||||||
|
|
||||||
|
## Can it log in to my server?
|
||||||
|
|
||||||
|
Yes, over SSH: the [SSH App](/guide/ssh/) is a terminal on another machine, with a password or with a key the device makes for itself. `vim`, `top` and `less` work. One session at a time, and not at the same time as IRC: there isn't the memory for both. `scp` in the [Shell](/guide/shell/) copies a file between the card and a server.
|
||||||
|
|
||||||
## How do I copy files to and from my phone?
|
## How do I copy files to and from my phone?
|
||||||
|
|
||||||
In the Storage App, press <kbd>w</kbd>: the device serves a small web page to any browser on the same Wi-Fi. Scan the QR code it shows, type the code, and upload or download. Nothing to install. See [From a phone](/guide/storage/#from-a-phone).
|
In the Storage App, press <kbd>w</kbd>: the device serves a small web page to any browser on the same Wi-Fi. Scan the QR code it shows, type the code, and upload or download. Nothing to install. See [From a phone](/guide/storage/#from-a-phone).
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ This guide says what the firmware does **today** and nothing else. Start with th
|
|||||||
|
|
||||||
**Three things work on every screen:** <kbd>Fn</kbd> + <kbd>h</kbd> for the keys, <kbd>Fn</kbd> + <kbd>p</kbd> for a screenshot, and <kbd>Fn</kbd> + <kbd>`</kbd> to go back to the Launcher.
|
**Three things work on every screen:** <kbd>Fn</kbd> + <kbd>h</kbd> for the keys, <kbd>Fn</kbd> + <kbd>p</kbd> for a screenshot, and <kbd>Fn</kbd> + <kbd>`</kbd> to go back to the Launcher.
|
||||||
|
|
||||||
|
**Two things keep running when you leave their App:** IRC stays connected, and an [SSH](/guide/ssh/) session stays open.
|
||||||
|
|
||||||
Looking for a recipe or a quick answer? There are [how-tos](/howto/) and a [FAQ](/faq/).
|
Looking for a recipe or a quick answer? There are [how-tos](/howto/) and a [FAQ](/faq/).
|
||||||
|
|
||||||
Something missing or wrong? Write to the [issue tracker](https://git.twis.la/twisla/roro9stack/issues) or to contact@roro9stack.net.
|
Something missing or wrong? Write to the [issue tracker](https://git.twis.la/twisla/roro9stack/issues) or to contact@roro9stack.net.
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ A strip at the top of every screen: the name of the App on the left, and on the
|
|||||||
| `97%` | The battery (in the warning colour at 15% and under) |
|
| `97%` | The battery (in the warning colour at 15% and under) |
|
||||||
| `SD` | A card is in; the warning colour at 80% full |
|
| `SD` | A card is in; the warning colour at 80% full |
|
||||||
| bars and `W` | Wi-Fi connected, with its signal; `W?` is searching; `MON` is the Wi-Fi radio in its monitoring mode, which pauses IRC |
|
| bars and `W` | Wi-Fi connected, with its signal; `W?` is searching; `MON` is the Wi-Fi radio in its monitoring mode, which pauses IRC |
|
||||||
|
| `SSH` | An [SSH session](/guide/ssh/) is open, whatever App is in front |
|
||||||
| `VPN` | The [WireGuard tunnel](/guide/vpn/) is wanted; brighter once the server has answered |
|
| `VPN` | The [WireGuard tunnel](/guide/vpn/) is wanted; brighter once the server has answered |
|
||||||
| `DBG` | The Debug Console is switched on (Settings → Debug Console); brighter while a PC is connected to it |
|
| `DBG` | The Debug Console is switched on (Settings → Debug Console); brighter while a PC is connected to it |
|
||||||
| `REC` | A GNSS Track is being recorded |
|
| `REC` | A GNSS Track is being recorded |
|
||||||
|
|||||||
@@ -31,10 +31,13 @@ You type at the bottom; <kbd>Enter</kbd> sends. A line starting with `/` is a co
|
|||||||
| `/nick newnick` | Changes your nick |
|
| `/nick newnick` | Changes your nick |
|
||||||
| `/topic [text]` | Shows or sets the channel topic |
|
| `/topic [text]` | Shows or sets the channel topic |
|
||||||
| `/names [#channel]` | Lists who is there |
|
| `/names [#channel]` | Lists who is there |
|
||||||
|
| `/uname` | Shows the firmware, its version and the chip, in this buffer only: nothing is sent |
|
||||||
| `/quit [message]` | Disconnects and **stays disconnected** until you type something again |
|
| `/quit [message]` | Disconnects and **stays disconnected** until you type something again |
|
||||||
| `/raw …` (or `/quote`) | Sends a line to the server as it is |
|
| `/raw …` (or `/quote`) | Sends a line to the server as it is |
|
||||||
| `/settings` | The settings page |
|
| `/settings` | The settings page |
|
||||||
|
|
||||||
|
Anyone who asks the device for its CTCP `VERSION` (`/ctcp roro VERSION` in most clients) is told `roro9stack` and the firmware version.
|
||||||
|
|
||||||
Each server, channel and private chat is a **buffer**. <kbd>Tab</kbd> moves to the next one, each shows how many messages are unread, and your own lines are in the accent colour. Scroll back with <kbd>Alt</kbd> + <kbd>;</kbd> (older) and <kbd>Alt</kbd> + <kbd>.</kbd> (newer). The up and down arrows (<kbd>Fn</kbd> + <kbd>;</kbd> and <kbd>.</kbd>) recall lines you sent.
|
Each server, channel and private chat is a **buffer**. <kbd>Tab</kbd> moves to the next one, each shows how many messages are unread, and your own lines are in the accent colour. Scroll back with <kbd>Alt</kbd> + <kbd>;</kbd> (older) and <kbd>Alt</kbd> + <kbd>.</kbd> (newer). The up and down arrows (<kbd>Fn</kbd> + <kbd>;</kbd> and <kbd>.</kbd>) recall lines you sent.
|
||||||
|
|
||||||
## Mentions and the unread count
|
## Mentions and the unread count
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
+++
|
+++
|
||||||
title = "Every key"
|
title = "Every key"
|
||||||
description = "The keys of every screen of the firmware, as the help panel lists them on the device: one table for each screen and state."
|
description = "The keys of every screen of the firmware, as the help panel lists them on the device: one table for each screen and state."
|
||||||
weight = 14
|
weight = 15
|
||||||
[extra]
|
[extra]
|
||||||
tag = "Reference"
|
tag = "Reference"
|
||||||
+++
|
+++
|
||||||
|
|||||||
@@ -13,14 +13,45 @@ The Scanner uses the **Cap LoRa-1262**. It **never transmits**: it listens and s
|
|||||||
|
|
||||||
The first view lists what the radio hears, newest first: the time, the RSSI (signal strength, in dBm) and the SNR (signal over noise, in dB). For a **Meshtastic** packet it also shows the sender and the receiver (the last four hex digits of their numbers) and the number of hops.
|
The first view lists what the radio hears, newest first: the time, the RSSI (signal strength, in dBm) and the SNR (signal over noise, in dB). For a **Meshtastic** packet it also shows the sender and the receiver (the last four hex digits of their numbers) and the number of hops.
|
||||||
|
|
||||||
|
For a **MeshCore** packet it shows what the packet is, who it concerns and how many repeaters are in its path:
|
||||||
|
|
||||||
|
| Row | Is |
|
||||||
|
|---|---|
|
||||||
|
| `adv Brussels-R1 2h` | A node saying who it is, by its name, heard through 2 repeaters |
|
||||||
|
| `txt a3>7f` | A private message from the node whose key starts with `a3` to the one starting with `7f` (`req`, `rsp` and `path` look the same) |
|
||||||
|
| `Alice: hello 1h` | A message on the **public channel**, read: who says they sent it, and the start of what it says |
|
||||||
|
| `chan #5c 1h` | A message on another channel, still encrypted; `#5c` is the channel's byte |
|
||||||
|
| `who's there?` | Someone nearby searching for nodes (repeaters, usually) |
|
||||||
|
| `here 18a6` | A node answering that search; `18a6` starts its key |
|
||||||
|
| `ack`, `anon`, `trace`, `ctl` | An acknowledgement, a login, a trace, other control packets |
|
||||||
|
|
||||||
| Key | Does |
|
| Key | Does |
|
||||||
|---|---|
|
|---|---|
|
||||||
| <kbd>Enter</kbd> | The details of a packet: the Meshtastic header, which is never encrypted, and a hex dump |
|
| <kbd>Enter</kbd> | The details of a packet: what is never encrypted (below), and a hex dump |
|
||||||
| <kbd>p</kbd> | Picks one of the 7 Meshtastic presets allowed in EU868 (LongFast by default) |
|
| <kbd>p</kbd> | Picks what to listen to: **MeshCore** (the default), or one of the 7 Meshtastic presets allowed in EU868 |
|
||||||
| <kbd>c</kbd> | Starts or stops a **capture** |
|
| <kbd>c</kbd> | Starts or stops a **capture** |
|
||||||
| <kbd>Tab</kbd> | Switches to the Sweep |
|
| <kbd>Tab</kbd> | Switches to the Sweep |
|
||||||
|
|
||||||
The Scanner shows the header and the bytes; it does not decrypt the message itself, which Meshtastic encrypts with the channel's key.
|
The Scanner shows the header and the bytes. Meshtastic and MeshCore both encrypt the message itself, and the Scanner reads only one kind: what is said on MeshCore's public channel, whose key is published.
|
||||||
|
|
||||||
|
**One network at a time.** The radio listens on one frequency with one setting, and the two networks share neither: on a Meshtastic preset no MeshCore packet is heard, and the other way round.
|
||||||
|
|
||||||
|
### MeshCore
|
||||||
|
|
||||||
|
The **MeshCore** preset is the setting its networks use in Europe, "EU/UK (Narrow)": 869.618 MHz, 62.5 kHz wide, SF8, coding rate 4/8. A network set up differently needs `lora custom` in the [Shell](/guide/shell/).
|
||||||
|
|
||||||
|
<kbd>Enter</kbd> on a MeshCore packet shows:
|
||||||
|
|
||||||
|
- what it is and how it travels: **flood** (every repeater passes it on, and adds itself to the path) or **direct** (it carries the route to follow);
|
||||||
|
- the path, one repeater a hop, each named by the first byte of its key;
|
||||||
|
- for an **advert**, which is signed and never encrypted: the node's name, its kind (chat node, repeater, room server, sensor), the start of its key, and its position if it gives one;
|
||||||
|
- for a **search** and its **answers**, also in clear: what kind of node is wanted; and in an answer the node's kind, the start of its key, and how well it heard the search;
|
||||||
|
- for a message on the **public channel**: the name the sender gives, when the sender's clock says it was sent (UTC), and the text;
|
||||||
|
- for any other message: the first byte of the sender's and the receiver's keys, or the channel's byte, and how many bytes are encrypted.
|
||||||
|
|
||||||
|
The public channel is the one every MeshCore node starts with, and its key is the same everywhere, so anyone listening can read it. Private messages and other channels stay encrypted. The sender's name is part of the message and is not signed: anyone can write any name. Letters outside plain ASCII (accents, emoji) show as `?`.
|
||||||
|
|
||||||
|
A byte is all a packet says about who it is from: two nodes can share it. The name comes only with a node's advert, which a node sends now and then, so a quiet network can take a while to show its names.
|
||||||
|
|
||||||
## Capture
|
## Capture
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ Type a command and press <kbd>Enter</kbd>. `help` lists them all; the [command r
|
|||||||
| `wifi status` | The network, the address, and where the DNS and time servers came from |
|
| `wifi status` | The network, the address, and where the DNS and time servers came from |
|
||||||
| `ls /notes` | A folder of the SD card, with sizes and dates |
|
| `ls /notes` | A folder of the SD card, with sizes and dates |
|
||||||
| `crash` | The last crash, if there was one |
|
| `crash` | The last crash, if there was one |
|
||||||
|
| `uname` | The firmware, its version and the chip it is built for: `roro9stack v0.22.0 xtensa-lx7 esp32s3` |
|
||||||
| `update check` | Whether a newer release exists |
|
| `update check` | Whether a newer release exists |
|
||||||
| `lora status` | What the radio is set to and what it has heard |
|
| `lora status` | What the radio is set to and what it has heard |
|
||||||
|
|
||||||
@@ -39,13 +40,13 @@ Type a command and press <kbd>Enter</kbd>. `help` lists them all; the [command r
|
|||||||
|
|
||||||
Type an App's name **with a capital letter** to open it, without going back to the Launcher:
|
Type an App's name **with a capital letter** to open it, without going back to the Launcher:
|
||||||
|
|
||||||
`Irc` `Wifi` `Gnss` `Gemini` `Lora` `Storage` `Notes` `System` `Settings`
|
`Irc` `Wifi` `Gnss` `Gemini` `Lora` `Storage` `Notes` `Ssh` `System` `Settings`
|
||||||
|
|
||||||
The capital is the difference: every command is in small letters, every App starts with a capital. <kbd>Tab</kbd> completes them too.
|
The capital is the difference: every command is in small letters, every App starts with a capital. <kbd>Tab</kbd> completes them too.
|
||||||
|
|
||||||
## The network
|
## The network
|
||||||
|
|
||||||
For the day the network doesn't do what it should. Each of the first four takes a moment and prints as it goes; one runs at a time, and `cancel` stops it.
|
For the day the network doesn't do what it should. Each of the first six takes a moment and prints as it goes, and so does `scp`; one runs at a time, and `cancel` stops it.
|
||||||
|
|
||||||
| Command | Tells you |
|
| Command | Tells you |
|
||||||
|---|---|
|
|---|---|
|
||||||
@@ -53,8 +54,13 @@ For the day the network doesn't do what it should. Each of the first four takes
|
|||||||
| `nslookup roro9stack.net` | A name's addresses, which DNS server answered and in how long. Another server may follow: `nslookup roro9stack.net 9.9.9.9` |
|
| `nslookup roro9stack.net` | A name's addresses, which DNS server answered and in how long. Another server may follow: `nslookup roro9stack.net 9.9.9.9` |
|
||||||
| `port git.twis.la 443` | Whether a TCP port is **open**, **refused** (the host is there, nothing listens) or silent (down, or filtered) |
|
| `port git.twis.la 443` | Whether a TCP port is **open**, **refused** (the host is there, nothing listens) or silent (down, or filtered) |
|
||||||
| `traceroute 9.9.9.9` | The routers on the way, one a line |
|
| `traceroute 9.9.9.9` | The routers on the way, one a line |
|
||||||
|
| `tls git.twis.la` | A secure connection's certificate: who it is for, who signed it, until when, and **whether this device trusts it**. A port may follow (443 if not) |
|
||||||
|
| `ntp` | A time server's clock against this device's, and how far the server is. Another server may follow |
|
||||||
|
| `ssh user@host` | Opens the [SSH App](/guide/ssh/) and connects; `ssh status` and `ssh stop` for the session |
|
||||||
|
| `scp /notes/a.txt user@host:docs/` | One file between the card and a server, over [SSH](/guide/ssh/#copying-a-file-scp): with the device's key, or a password asked in the Shell, masked. `cancel` stops it |
|
||||||
| `ifconfig` | The interfaces (Wi-Fi, and the [VPN](/guide/vpn/) when it is up), their addresses, **which one is the default route**, and the DNS servers |
|
| `ifconfig` | The interfaces (Wi-Fi, and the [VPN](/guide/vpn/) when it is up), their addresses, **which one is the default route**, and the DNS servers |
|
||||||
| `arp` | The neighbours heard on the Wi-Fi: is the gateway there at all |
|
| `arp` | The neighbours heard on the Wi-Fi: is the gateway there at all |
|
||||||
|
| `netstat` | What the device **listens** on (updates, the Debug Console, sharing) and what is connected to it now |
|
||||||
|
|
||||||
A host can be a name or an address. [When the network doesn't work](/howto/network-check/) puts them in order.
|
A host can be a name or an address. [When the network doesn't work](/howto/network-check/) puts them in order.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,126 @@
|
|||||||
|
+++
|
||||||
|
title = "SSH"
|
||||||
|
description = "A terminal on another machine: log in to a server with a password or with the device's own key, and run a shell, vim or top on the Cardputer's screen."
|
||||||
|
weight = 13
|
||||||
|
[extra]
|
||||||
|
tag = "SSH"
|
||||||
|
screens = ["ssh.png", "ssh-trust.png", "ssh-terminal.png", "ssh-key.png", "ssh-changed.png"]
|
||||||
|
+++
|
||||||
|
|
||||||
|
The SSH App opens a **terminal on another machine**: a server, a Raspberry Pi, a router. What you type goes there, and what its programs print is drawn here: a shell, `less`, `top`, `nano`, `vim`.
|
||||||
|
|
||||||
|
It is a client and nothing more: one session at a time, to a shell. No port forwarding, no jump hosts. Files go one at a time with [`scp` from the Shell](#copying-a-file-scp).
|
||||||
|
|
||||||
|
## Connecting
|
||||||
|
|
||||||
|
The App opens on the hosts it has connected to before, the last one first, then **New connection** and **This device's key**.
|
||||||
|
|
||||||
|
1. Choose **New connection** (or press <kbd>n</kbd>) and type **`user@host`**, or `user@host:port` when the port isn't 22. The host is a name or an address.
|
||||||
|
2. **The first time, it shows the server's fingerprint** and asks whether that is the right server. Compare it with what the server's owner gives you (`ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub` on the server prints it), and choose **Trust it**. It is remembered, and not asked again.
|
||||||
|
3. **Type the password** when it asks. It is used for this login and kept nowhere: not in the device, not on the card.
|
||||||
|
|
||||||
|
A host you logged in to is kept in the list: <kbd>Enter</kbd> connects to it again, <kbd>d</kbd> forgets it, and its fingerprint with it. Up to eight are kept.
|
||||||
|
|
||||||
|
From the [Shell](/guide/shell/), `ssh user@host` does the same and opens this App.
|
||||||
|
|
||||||
|
## If the server has changed
|
||||||
|
|
||||||
|
A server that shows **a different key than the one remembered** gets a warning instead of a question: **THE SERVER'S KEY CHANGED**. Either the server was reinstalled, or something between you and it is answering in its place. The safe answer, **Cancel**, is the one selected. Choose **Replace** only when you know why the key changed.
|
||||||
|
|
||||||
|
## Without a password: this device's key
|
||||||
|
|
||||||
|
**This device's key** makes a key pair for the device (Ed25519). The private half stays inside the device and is never shown. The public half is one line of text:
|
||||||
|
|
||||||
|
- it is shown on that page,
|
||||||
|
- written to the card as **`/ssh/id_ed25519.pub`**,
|
||||||
|
- and printed by `ssh status` in the Shell.
|
||||||
|
|
||||||
|
Add that line to `~/.ssh/authorized_keys` on a server, and the device logs in there with no password. See [Log in to a server without a password](/howto/ssh-key/).
|
||||||
|
|
||||||
|
Making a **new key** replaces the old one: servers that knew the old one ask for a password again.
|
||||||
|
|
||||||
|
The key has no passphrase, so **whoever holds the device can log in wherever its key is accepted**. Keys made elsewhere can't be imported.
|
||||||
|
|
||||||
|
## In the terminal
|
||||||
|
|
||||||
|
Every key goes to the other machine, with these differences:
|
||||||
|
|
||||||
|
| Key | Does |
|
||||||
|
|---|---|
|
||||||
|
| <kbd>`</kbd> | **Esc** (the key is printed "esc") |
|
||||||
|
| <kbd>Alt</kbd> + <kbd>`</kbd> | types a backtick |
|
||||||
|
| <kbd>Fn</kbd> + <kbd>;</kbd> <kbd>.</kbd> <kbd>,</kbd> <kbd>/</kbd> | the arrows |
|
||||||
|
| <kbd>Fn</kbd> + <kbd>Shift</kbd> + <kbd>;</kbd> <kbd>.</kbd> | Page Up, Page Down |
|
||||||
|
| <kbd>Ctrl</kbd> + a letter | Ctrl+C, Ctrl+D, Ctrl+Z and the rest |
|
||||||
|
| <kbd>Alt</kbd> + a key | that key with Alt (Esc first) |
|
||||||
|
| <kbd>Alt</kbd> + <kbd>;</kbd> <kbd>.</kbd> | scroll back and forward through the last 100 lines |
|
||||||
|
| <kbd>Ctrl</kbd> + <kbd>+</kbd> <kbd>-</kbd> | larger and smaller text |
|
||||||
|
| <kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>q</kbd> | disconnect |
|
||||||
|
| <kbd>Fn</kbd> + <kbd>`</kbd> | back to the Launcher, **leaving the session running** |
|
||||||
|
|
||||||
|
**Leaving doesn't disconnect.** Go to the Launcher or to another App and the session goes on; `SSH` shows in the [Status Bar](/guide/basics/#the-status-bar) for as long as it does. Open the SSH App again and you are back in it. `exit` on the other machine, or <kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>q</kbd> here, ends it.
|
||||||
|
|
||||||
|
### The size of the text
|
||||||
|
|
||||||
|
Five sizes, changed with <kbd>Ctrl</kbd> + <kbd>+</kbd> and <kbd>Ctrl</kbd> + <kbd>-</kbd>; the other machine is told the new size at once, and the choice is kept.
|
||||||
|
|
||||||
|
| Text | Columns × rows |
|
||||||
|
|---|---|
|
||||||
|
| tiny | 60 × 20 |
|
||||||
|
| small (to start with) | 48 × 15 |
|
||||||
|
| medium | 40 × 12 |
|
||||||
|
| normal | 40 × 9 |
|
||||||
|
| large | 26 × 8 |
|
||||||
|
|
||||||
|
A terminal is usually 80 columns wide, and this screen isn't: long lines wrap, and programs that want 80 columns look cramped. `top`, `vim` and `less` adapt.
|
||||||
|
|
||||||
|
### What it shows, and what it doesn't
|
||||||
|
|
||||||
|
- Sixteen colours, bold as a brighter colour, reverse video.
|
||||||
|
- Western European letters (é, ñ, ü). Other characters show as `?`, and box-drawing lines as `+`, `-` and `|`.
|
||||||
|
- No mouse.
|
||||||
|
|
||||||
|
## Memory
|
||||||
|
|
||||||
|
A session takes about **50 KB** of the device's 100 KB while it is open, and gives it back when it ends. That is too much to share with a secure connection:
|
||||||
|
|
||||||
|
- **It doesn't start with less than 75 KB free.** With IRC connected, or a Gemini page open, it says "Not enough memory: close IRC or a Gemini page".
|
||||||
|
- **While a session is open, IRC doesn't connect:** it says so in its buffer and tries again later.
|
||||||
|
|
||||||
|
See [When a connection says "not enough memory"](/howto/not-enough-memory/).
|
||||||
|
|
||||||
|
## Copying a file: scp
|
||||||
|
|
||||||
|
From the [Shell](/guide/shell/), `scp` copies **one file** between the SD card and a server, over the same SSH:
|
||||||
|
|
||||||
|
```
|
||||||
|
scp /notes/a.txt user@host:docs/a.txt the card to the server
|
||||||
|
scp user@host:/var/log/syslog /logs/ the server to the card, keeping its name
|
||||||
|
scp -P 2222 /notes/a.txt user@host: another port (-P first); a path is needed after the colon
|
||||||
|
scp -f user@host:x.txt /notes/x.txt replace a file that is on the card already
|
||||||
|
```
|
||||||
|
|
||||||
|
Paths on the card start with a slash. A path on the server is the server's own, and starts in the user's home folder when it has no slash. Only a file: no folders, no `*`.
|
||||||
|
|
||||||
|
- **The server has to be one you have already trusted** in this App (the fingerprint question above). `scp` can't ask that question, and refuses a server it doesn't know, or one whose key changed.
|
||||||
|
- **It logs in with the device's key, and asks for the password** if the server doesn't accept the key: the Shell shows the question and what you type is masked (<kbd>Back</kbd> cancels). The password is asked only in the Shell, not from a PC on the USB port or the Debug Console.
|
||||||
|
- **A download arrives under a temporary name** and takes its real one when it is all there, so a cut connection never leaves half a file. A file already there is not replaced without `-f`.
|
||||||
|
- It prints how long it took. `cancel` stops it. It needs the same 75 KB of free memory as a session, and **not while a session is open**.
|
||||||
|
|
||||||
|
See [Copy a file to or from a server](/howto/scp/).
|
||||||
|
|
||||||
|
## From the Shell
|
||||||
|
|
||||||
|
```
|
||||||
|
ssh user@host connect, in the SSH App
|
||||||
|
ssh user@host:2222 on another port
|
||||||
|
ssh status the session, and this device's public key
|
||||||
|
ssh stop end the session
|
||||||
|
scp ... copy one file, see above
|
||||||
|
```
|
||||||
|
|
||||||
|
## Keys
|
||||||
|
|
||||||
|
What <kbd>Fn</kbd> + <kbd>h</kbd> shows on these screens. These tables are generated from the firmware's own lists, so they are always the current ones.
|
||||||
|
|
||||||
|
{{ keys(scopes=["ssh", "ssh-terminal", "ssh-key"]) }}
|
||||||
@@ -36,7 +36,7 @@ The App says why when it refuses.
|
|||||||
|
|
||||||
- **Text** (`.txt`, `.log`, `.gmi`, `.csv`, and anything that looks like text): only a screenful is read from the card, so a file of any size opens at once, and logs open at the end. Up and down move a line, left and right a page, <kbd>t</kbd> and <kbd>b</kbd> go to the top and the end, and <kbd>e</kbd> edits it, whatever its size (as in [Notes](/guide/notes/)).
|
- **Text** (`.txt`, `.log`, `.gmi`, `.csv`, and anything that looks like text): only a screenful is read from the card, so a file of any size opens at once, and logs open at the end. Up and down move a line, left and right a page, <kbd>t</kbd> and <kbd>b</kbd> go to the top and the end, and <kbd>e</kbd> edits it, whatever its size (as in [Notes](/guide/notes/)).
|
||||||
- **Pictures** (`.png`, `.jpg`, `.bmp`, `.gif`): see [Pictures](#pictures) below.
|
- **Pictures** (`.png`, `.jpg`, `.bmp`, `.gif`): see [Pictures](#pictures) below.
|
||||||
- **Captures** (`.pcap`): the packets as the [LoRa Scanner](/guide/lora-scanner/) lists them; <kbd>Enter</kbd> shows one with its Meshtastic header and bytes.
|
- **Captures** (`.pcap`): the packets as the [LoRa Scanner](/guide/lora-scanner/) lists them; <kbd>Enter</kbd> shows one with its Meshtastic or MeshCore header and bytes.
|
||||||
- **Tracks** (`.gpx`): the number of points, the start, the duration and the distance.
|
- **Tracks** (`.gpx`): the number of points, the start, the duration and the distance.
|
||||||
- **Update files** (`.ota`): the version, and whether the file would install: it is checked as an install checks it, signature and contents, without writing anything. <kbd>Enter</kbd> then installs it (see [Updates](/guide/updates/)).
|
- **Update files** (`.ota`): the version, and whether the file would install: it is checked as an install checks it, signature and contents, without writing anything. <kbd>Enter</kbd> then installs it (see [Updates](/guide/updates/)).
|
||||||
- **Anything else:** a hex dump.
|
- **Anything else:** a hex dump.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
+++
|
+++
|
||||||
title = "Updates"
|
title = "Updates"
|
||||||
description = "How the device updates itself from the project's releases, from the SD card or from a PC, and how it protects itself when an update goes wrong."
|
description = "How the device updates itself from the project's releases, from the SD card or from a PC, and how it protects itself when an update goes wrong."
|
||||||
weight = 13
|
weight = 14
|
||||||
[extra]
|
[extra]
|
||||||
tag = "Firmware"
|
tag = "Firmware"
|
||||||
screens = ["update.png"]
|
screens = ["update.png"]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
+++
|
+++
|
||||||
title = "How-tos"
|
title = "How-tos"
|
||||||
description = "Short recipes for things you will want to do: move files with your phone, set up the VPN, take a screenshot, find out why the network doesn't work, record a track, capture radio packets, and what to try when something does not work."
|
description = "Short recipes for things you will want to do: move files with your phone, set up the VPN, log in to a server with the device's SSH key, copy a file to or from a server, take a screenshot, find out why the network doesn't work, record a track, capture radio packets, and what to try when something does not work."
|
||||||
template = "guide-index.html"
|
template = "guide-index.html"
|
||||||
page_template = "guide-page.html"
|
page_template = "guide-page.html"
|
||||||
sort_by = "weight"
|
sort_by = "weight"
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ tag = "LoRa Scanner"
|
|||||||
The radio only **listens**: nothing is transmitted. You need the **Cap LoRa-1262** and an **SD card**.
|
The radio only **listens**: nothing is transmitted. You need the **Cap LoRa-1262** and an **SD card**.
|
||||||
|
|
||||||
1. **Open the LoRa Scanner.** The Status Bar shows `L` while the radio listens.
|
1. **Open the LoRa Scanner.** The Status Bar shows `L` while the radio listens.
|
||||||
2. **Pick a preset with <kbd>p</kbd>.** The Scanner offers the 7 Meshtastic presets allowed in EU868; LongFast is the default.
|
2. **Pick a preset with <kbd>p</kbd>.** The Scanner offers MeshCore (the default) and the 7 Meshtastic presets allowed in EU868.
|
||||||
3. **Wait for packets.** Each line is a packet: the time, RSSI and SNR, and for a Meshtastic packet the sender, the receiver and the hops. <kbd>Enter</kbd> shows a packet's header and its bytes.
|
3. **Wait for packets.** Each line is a packet: the time, RSSI and SNR, and for a Meshtastic packet the sender, the receiver and the hops. <kbd>Enter</kbd> shows a packet's header and its bytes.
|
||||||
4. **Press <kbd>c</kbd> to start a capture.** The Status Bar shows `CAP`. It keeps recording with the App closed.
|
4. **Press <kbd>c</kbd> to start a capture.** The Status Bar shows `CAP`. It keeps recording with the App closed.
|
||||||
5. **Press <kbd>c</kbd> again to stop.**
|
5. **Press <kbd>c</kbd> again to stop.**
|
||||||
6. **Get the file.** It is in `/captures/lora/`, a `.pcap` with LoRaTap headers. In the [Storage App](/guide/storage/) you can already look at its packets; on a computer, open it in Wireshark.
|
6. **Get the file.** It is in `/captures/lora/`, a `.pcap` with LoRaTap headers. In the [Storage App](/guide/storage/) you can already look at its packets; on a computer, open it in Wireshark.
|
||||||
|
|
||||||
**What you will and will not see.** Meshtastic's header is never encrypted, so who sent a packet and how far it hopped is visible. The message itself is encrypted with the channel's key, and the Scanner does not decrypt it.
|
**What you will and will not see.** Meshtastic's header is never encrypted, so who sent a packet and how far it hopped is visible. The message itself is encrypted with the channel's key, and the Scanner does not decrypt it. MeshCore's public channel is the exception: its key is published, and the Scanner [reads what is said there](/guide/lora-scanner/#meshcore).
|
||||||
|
|
||||||
**Hearing nothing is normal** if no node is in range, or if the preset does not match what the nodes nearby use. The [Sweep](/guide/lora-scanner/) (<kbd>Tab</kbd>) shows whether anything is on the air at all across 863 to 870 MHz.
|
**Hearing nothing is normal** if no node is in range, or if the preset does not match what the nodes nearby use. The [Sweep](/guide/lora-scanner/) (<kbd>Tab</kbd>) shows whether anything is on the air at all across 863 to 870 MHz.
|
||||||
|
|||||||
@@ -41,6 +41,36 @@ Open the [Shell](/guide/shell/) and go down this list. Each step says what a goo
|
|||||||
|
|
||||||
6. **`traceroute <host>`**: where does it stop? The last router that answers is the last one that works.
|
6. **`traceroute <host>`**: where does it stop? The last router that answers is the last one that works.
|
||||||
|
|
||||||
|
7. **`tls <host>`**: a secure connection fails ("TLS error")? This shows the certificate and the verdict:
|
||||||
|
|
||||||
|
```
|
||||||
|
tls: git.twis.la:443 answered in 709 ms
|
||||||
|
tls: for git.twis.la, by YE2
|
||||||
|
tls: valid 2026-09-15 to 2026-12-14, 67 days left
|
||||||
|
tls: this device trusts it
|
||||||
|
```
|
||||||
|
|
||||||
|
"NOT trusted here" comes with the reason: **expired**, **not for that name**, or **not signed by a root this device has**. The last is normal for a Gemini capsule, which signs its own certificate, and a problem for an update server. It needs about 70 KB of free memory: close IRC first if it says so.
|
||||||
|
|
||||||
|
8. **`ntp`**: is the clock right? A clock that is wrong by more than a few minutes breaks secure connections and the VPN.
|
||||||
|
|
||||||
|
```
|
||||||
|
ntp: pool.ntp.org (195.72.61.39), stratum 2, 50 ms away
|
||||||
|
ntp: this clock is right, to 0.1 s
|
||||||
|
```
|
||||||
|
|
||||||
|
## What is the device itself offering?
|
||||||
|
|
||||||
|
`netstat` lists what it listens on, and who is connected:
|
||||||
|
|
||||||
|
```
|
||||||
|
netstat: tcp 3232 listens (updates)
|
||||||
|
netstat: tcp 2323 listens (Debug Console)
|
||||||
|
netstat: tcp 172.16.42.25:2323 - 172.16.42.249:51858
|
||||||
|
```
|
||||||
|
|
||||||
|
The update port is always there (updates are signed). The Debug Console and sharing appear only while you have them on.
|
||||||
|
|
||||||
## With the VPN up
|
## With the VPN up
|
||||||
|
|
||||||
- `ifconfig` shows the `vpn` line, and "default route" on it if everything goes through.
|
- `ifconfig` shows the `vpn` line, and "default route" on it if everything goes through.
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ tag = "Memory"
|
|||||||
|
|
||||||
## What you see
|
## What you see
|
||||||
|
|
||||||
Opening a Gemini page fails with *not enough memory: stop IRC or retry*. Or an update check or install makes IRC disconnect for a moment.
|
Opening a Gemini page fails with *not enough memory: stop IRC or retry*. Or SSH says *Not enough memory: close IRC or a Gemini page*, or IRC says *not enough memory: close the SSH session*. Or an update check or install makes IRC disconnect for a moment.
|
||||||
|
|
||||||
## What to do
|
## What to do
|
||||||
|
|
||||||
@@ -26,6 +26,7 @@ Small next to a secure connection, but they add up when memory is already short:
|
|||||||
|
|
||||||
| | While it is in use |
|
| | While it is in use |
|
||||||
|---|---|
|
|---|---|
|
||||||
|
| An [SSH](/guide/ssh/) session, from login until it ends | 50 KB: IRC waits while it is open, and it doesn't start under 75 KB free |
|
||||||
| A note open in the editor, whatever its size | 17 KB |
|
| A note open in the editor, whatever its size | 17 KB |
|
||||||
| Sharing the card with a browser | 13 KB |
|
| Sharing the card with a browser | 13 KB |
|
||||||
| The Shell | 7 KB |
|
| The Shell | 7 KB |
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
+++
|
||||||
|
title = "Copy a file to or from a server"
|
||||||
|
description = "Send a note from the SD card to a server, or fetch a log from it, with scp in the Shell."
|
||||||
|
weight = 14
|
||||||
|
[extra]
|
||||||
|
tag = "SSH"
|
||||||
|
+++
|
||||||
|
|
||||||
|
One file at a time, between the SD card and a server you can log in to over SSH.
|
||||||
|
|
||||||
|
1. **Connect to the server once in the SSH App** (**SSH → New connection**, `user@host`) and trust its fingerprint. `scp` can't ask that question, so it only goes to servers it has met there.
|
||||||
|
2. For no password to type, put the device's key on the server: [Log in to a server without a password](/howto/ssh-key/). Without it, `scp` asks for the password.
|
||||||
|
3. Open the **Shell** and type, for a file going **to** the server:
|
||||||
|
|
||||||
|
```
|
||||||
|
scp /notes/a.txt user@host:docs/a.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
or one coming **from** it, into a folder on the card (it keeps its name):
|
||||||
|
|
||||||
|
```
|
||||||
|
scp user@host:/var/log/syslog /logs/
|
||||||
|
```
|
||||||
|
|
||||||
|
You should see `scp: ... (1234 bytes) to ...`, then `scp: sent 1234 bytes in 310 ms` (or `received`).
|
||||||
|
4. If it says `password for host`, type it and press <kbd>Enter</kbd>: it shows as stars and is kept nowhere. <kbd>Back</kbd> cancels.
|
||||||
|
|
||||||
|
## If it doesn't work
|
||||||
|
|
||||||
|
| It says | Do |
|
||||||
|
|---|---|
|
||||||
|
| `is not a server this device trusts yet` | Step 1: connect once in the SSH App |
|
||||||
|
| `showed a different key than the one remembered` | The server was reinstalled, or something answers in its place. Check in the SSH App, which asks what to do |
|
||||||
|
| `exists already` | The file is on the card: add `-f` (`scp -f user@host:x /notes/x`) to replace it |
|
||||||
|
| `An SSH session is open` or `Not enough memory` | End the session (`ssh stop`), or close IRC or a Gemini page: [not enough memory](/howto/not-enough-memory/) |
|
||||||
|
| `not logged in`, `wrong password` | Three tries, then it stops. Check the user, or the key on the server |
|
||||||
|
| `a password is only asked in the Shell` | You typed it from a PC on the USB port or the Debug Console: use the Shell, or put the key on the server |
|
||||||
|
| `that isn't a plain file` | `scp` copies one file, not a folder |
|
||||||
|
|
||||||
|
Another port goes first: `scp -P 2222 /notes/a.txt user@host:a.txt`. `cancel` stops a copy that is running.
|
||||||
@@ -20,6 +20,7 @@ Everything the firmware writes goes in a folder at the top of the card. To get a
|
|||||||
| Files saved from Gemini that are not text | `/gemini/downloads` | whatever they were |
|
| Files saved from Gemini that are not text | `/gemini/downloads` | whatever they were |
|
||||||
| Update files | `/updates` | `.ota` |
|
| Update files | `/updates` | `.ota` |
|
||||||
| [Screenshots](/howto/screenshot/) (<kbd>Fn</kbd> + <kbd>p</kbd>) | `/screenshots` | `.png`, named by date and time |
|
| [Screenshots](/howto/screenshot/) (<kbd>Fn</kbd> + <kbd>p</kbd>) | `/screenshots` | `.png`, named by date and time |
|
||||||
|
| The public half of the device's [SSH key](/guide/ssh/#without-a-password-this-device-s-key) | `/ssh/id_ed25519.pub` | one line, for a server's `authorized_keys`; safe to copy anywhere |
|
||||||
| A VPN configuration waiting to be imported | `/vpn/wg0.conf` | you put it there; delete it once imported |
|
| A VPN configuration waiting to be imported | `/vpn/wg0.conf` | you put it there; delete it once imported |
|
||||||
|
|
||||||
## Rules worth knowing
|
## Rules worth knowing
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
+++
|
||||||
|
title = "Log in to a server without a password"
|
||||||
|
description = "Make the Cardputer's own SSH key, put its public half on a server, and connect with no password to type."
|
||||||
|
weight = 13
|
||||||
|
[extra]
|
||||||
|
tag = "SSH"
|
||||||
|
+++
|
||||||
|
|
||||||
|
Typing a password on a small keyboard, every time, gets old. With a key, the server recognises the device.
|
||||||
|
|
||||||
|
1. On the Cardputer, open **SSH → This device's key** and press <kbd>Enter</kbd>. It makes the key and shows its **public half**: one line starting with `ssh-ed25519`.
|
||||||
|
2. Get that line to the server. It was also written to the card as **`/ssh/id_ed25519.pub`**, so the easy way is the phone: in **Storage** press <kbd>w</kbd>, open the page ([Move files with your phone](/howto/phone-files/)) and download the file. Or log in to the server with your password, from the Cardputer or anything else, and paste it.
|
||||||
|
3. On the server, add the line to the end of **`~/.ssh/authorized_keys`** of the user you log in as:
|
||||||
|
|
||||||
|
```
|
||||||
|
cat id_ed25519.pub >> ~/.ssh/authorized_keys
|
||||||
|
chmod 600 ~/.ssh/authorized_keys
|
||||||
|
```
|
||||||
|
|
||||||
|
4. On the Cardputer, connect: **SSH → New connection**, `user@host`. It logs in without asking for anything. The same key is what [`scp`](/howto/scp/) uses.
|
||||||
|
|
||||||
|
## If it still asks for a password
|
||||||
|
|
||||||
|
| Check | How |
|
||||||
|
|---|---|
|
||||||
|
| The line is whole, on one line | `ssh-ed25519`, a long word, then `roro9stack` |
|
||||||
|
| The file's permissions | `chmod 700 ~/.ssh` and `chmod 600 ~/.ssh/authorized_keys`: OpenSSH ignores a file others can write |
|
||||||
|
| It is the right user's file | the `user` of `user@host` |
|
||||||
|
| The server takes keys | `PubkeyAuthentication yes` in its `sshd_config` (the default) |
|
||||||
|
| You made a new key since | a new key replaces the old one: put the new line on the server |
|
||||||
|
|
||||||
|
## Worth knowing
|
||||||
|
|
||||||
|
The private half never leaves the device and has no passphrase: **whoever holds the Cardputer can log in wherever its key is accepted**. If the device is lost, remove its line from `authorized_keys` on your servers. More in the [SSH](/guide/ssh/) page.
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
num = "01"
|
num = "01"
|
||||||
tag = "LoRa Scanner"
|
tag = "LoRa Scanner"
|
||||||
title = "See what is on the air"
|
title = "See what is on the air"
|
||||||
text = "Lists every packet it hears with time, RSSI, SNR, sender and hops, reading the Meshtastic header. A Sweep shows signal strength from 863 to 870 MHz. Capture to a pcap for Wireshark."
|
text = "Lists every packet it hears with time, RSSI, SNR, sender and hops, reading the Meshtastic or MeshCore header. A Sweep shows signal strength from 863 to 870 MHz. Capture to a pcap for Wireshark."
|
||||||
fact = "Only listens, never transmits"
|
fact = "Only listens, never transmits"
|
||||||
icon = 1
|
icon = 1
|
||||||
|
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ title = "LoRa Scanner, the packets"
|
|||||||
rows = [
|
rows = [
|
||||||
["; .", "up, down"],
|
["; .", "up, down"],
|
||||||
["Enter", "the packet's details"],
|
["Enter", "the packet's details"],
|
||||||
["p", "pick a Meshtastic preset"],
|
["p", "pick a preset"],
|
||||||
["c", "start a Capture, or stop it"],
|
["c", "start a Capture, or stop it"],
|
||||||
["Tab", "the Sweep"],
|
["Tab", "the Sweep"],
|
||||||
]
|
]
|
||||||
@@ -365,6 +365,40 @@ rows = [
|
|||||||
["; .", "up, down"],
|
["; .", "up, down"],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[scope]]
|
||||||
|
id = "ssh"
|
||||||
|
title = "SSH, the hosts"
|
||||||
|
rows = [
|
||||||
|
["Enter", "connect, open"],
|
||||||
|
["; .", "up, down"],
|
||||||
|
["n", "a new connection"],
|
||||||
|
["d", "forget this host"],
|
||||||
|
]
|
||||||
|
|
||||||
|
[[scope]]
|
||||||
|
id = "ssh-terminal"
|
||||||
|
title = "SSH, the terminal"
|
||||||
|
rows = [
|
||||||
|
["`", "Esc"],
|
||||||
|
["Alt `", "a backtick"],
|
||||||
|
["Fn ; . , /", "the arrows"],
|
||||||
|
["Fn Shift ; .", "Page Up, Page Down"],
|
||||||
|
["Ctrl a..z", "Ctrl+C and the rest"],
|
||||||
|
["Alt ; .", "scroll back, forward"],
|
||||||
|
["Ctrl + -", "larger, smaller text"],
|
||||||
|
["Ctrl Alt q", "disconnect"],
|
||||||
|
["Fn `", "leave it running"],
|
||||||
|
]
|
||||||
|
|
||||||
|
[[scope]]
|
||||||
|
id = "ssh-key"
|
||||||
|
title = "SSH, this device's key"
|
||||||
|
rows = [
|
||||||
|
["Enter", "make a key, or a new one"],
|
||||||
|
["w", "write the public half to the card"],
|
||||||
|
["`", "back"],
|
||||||
|
]
|
||||||
|
|
||||||
[[scope]]
|
[[scope]]
|
||||||
id = "notes"
|
id = "notes"
|
||||||
title = "Notes, the list"
|
title = "Notes, the list"
|
||||||
|
|||||||
@@ -59,6 +59,31 @@ file = "vpn.png"
|
|||||||
alt = "Settings, VPN: VPN On, Start with Wi-Fi On, Import /vpn/wg0.conf, Forget it; then It is up, heard 66 s ago, the server's address, and This device 10.9.0.2, through it everything. VPN shows in the Status Bar"
|
alt = "Settings, VPN: VPN On, Start with Wi-Fi On, Import /vpn/wg0.conf, Forget it; then It is up, heard 66 s ago, the server's address, and This device 10.9.0.2, through it everything. VPN shows in the Status Bar"
|
||||||
caption = "Settings, VPN"
|
caption = "Settings, VPN"
|
||||||
|
|
||||||
|
[[screen]]
|
||||||
|
file = "ssh.png"
|
||||||
|
alt = "The SSH App's list: a saved host, tester at 172.16.42.249 port 2222, then New connection and This device's key"
|
||||||
|
caption = "SSH, the hosts"
|
||||||
|
|
||||||
|
[[screen]]
|
||||||
|
file = "ssh-trust.png"
|
||||||
|
alt = "A dialog over the SSH App: A server not met before, the address 172.16.42.249, and a SHA256 fingerprint on two lines; buttons Cancel, selected, and Trust it"
|
||||||
|
caption = "SSH, a server met for the first time"
|
||||||
|
|
||||||
|
[[screen]]
|
||||||
|
file = "ssh-terminal.png"
|
||||||
|
alt = "The SSH App's terminal showing top on a remote machine: uptime, tasks, memory, then a reverse-video header and five processes. SSH shows in the Status Bar"
|
||||||
|
caption = "SSH, top on another machine"
|
||||||
|
|
||||||
|
[[screen]]
|
||||||
|
file = "ssh-key.png"
|
||||||
|
alt = "This device's key: its public half, for a server's authorized_keys file, a line starting ssh-ed25519; it is also in /ssh/id_ed25519.pub, and the private half never leaves"
|
||||||
|
caption = "SSH, this device's key"
|
||||||
|
|
||||||
|
[[screen]]
|
||||||
|
file = "ssh-changed.png"
|
||||||
|
alt = "A dialog over the SSH App: THE SERVER'S KEY CHANGED. Someone in between? Now it is, and a SHA256 fingerprint; buttons Cancel, selected, and Replace"
|
||||||
|
caption = "SSH, a server whose key changed"
|
||||||
|
|
||||||
[[screen]]
|
[[screen]]
|
||||||
file = "help.png"
|
file = "help.png"
|
||||||
alt = "The help panel over the Launcher: Keys: Launcher, up and down, Enter opens the App, then Everywhere: back, home, the arrows, Fn h for these keys and Fn p for a screenshot"
|
alt = "The help panel over the Launcher: Keys: Launcher, up and down, Enter opens the App, then Everywhere: back, home, the arrows, Fn h for these keys and Fn p for a screenshot"
|
||||||
|
|||||||
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 5.5 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
@@ -68,7 +68,7 @@
|
|||||||
</article>
|
</article>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<p class="cards-note">Plus a <a class="accent-link" href="/guide/shell/">Shell</a> that runs the firmware's commands on the device, a <a class="accent-link" href="/guide/vpn/">WireGuard VPN</a>, a screenshot key that works on every screen, and Settings, with its Wi-Fi and Firmware pages. Every App has a page in the <a class="accent-link" href="/guide/">user guide</a>.</p>
|
<p class="cards-note">Plus a <a class="accent-link" href="/guide/shell/">Shell</a> that runs the firmware's commands on the device, an <a class="accent-link" href="/guide/ssh/">SSH client</a> with a real terminal, a <a class="accent-link" href="/guide/vpn/">WireGuard VPN</a>, a screenshot key that works on every screen, and Settings, with its Wi-Fi and Firmware pages. Every App has a page in the <a class="accent-link" href="/guide/">user guide</a>.</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="wrap" id="screens" aria-labelledby="screens-title">
|
<section class="wrap" id="screens" aria-labelledby="screens-title">
|
||||||
|
|||||||
@@ -264,10 +264,9 @@ void FileViewer::openPacket(int index) {
|
|||||||
if (tap) {
|
if (tap) {
|
||||||
std::snprintf(line, sizeof line, "%.0f dBm, SNR %.1f dB, noise %.0f", rx.rssi, rx.snr, rx.noiseFloor);
|
std::snprintf(line, sizeof line, "%.0f dBm, SNR %.1f dB, noise %.0f", rx.rssi, rx.snr, rx.noiseFloor);
|
||||||
details_.push_back(line);
|
details_.push_back(line);
|
||||||
std::snprintf(line, sizeof line, "%.4f MHz, SF%u, %.0f kHz", rx.frequencyHz / 1e6, rx.spreadingFactor, rx.bandwidthKHz);
|
std::snprintf(line, sizeof line, "%.4f MHz, SF%u, %g kHz", rx.frequencyHz / 1e6, rx.spreadingFactor, rx.bandwidthKHz);
|
||||||
details_.push_back(line);
|
details_.push_back(line);
|
||||||
if (rx.syncWord == meshtastic::kSyncWord)
|
for (auto& l : lora::headerLines(body + skip, have - skip, lora::protocolOf(rx.syncWord))) details_.push_back(l);
|
||||||
for (auto& l : lora::headerLines(body + skip, have - skip)) details_.push_back(l);
|
|
||||||
}
|
}
|
||||||
for (auto& l : lora::hexDump(body + skip, have - skip)) details_.push_back(l);
|
for (auto& l : lora::hexDump(body + skip, have - skip)) details_.push_back(l);
|
||||||
if (have < r.length) details_.push_back("(the first bytes only)");
|
if (have < r.length) details_.push_back("(the first bytes only)");
|
||||||
@@ -391,7 +390,7 @@ void FileViewer::refresh() {
|
|||||||
size_t have = std::min<size_t>(r.length, n - files::kPcapRecordSize);
|
size_t have = std::min<size_t>(r.length, n - files::kPcapRecordSize);
|
||||||
if (tap && files::parseLoraTap(body, have, rx)) {
|
if (tap && files::parseLoraTap(body, have, rx)) {
|
||||||
shown_.push_back(lora::row({body + lora::kLoraTapSize, have - lora::kLoraTapSize, rx.rssi, rx.snr, true,
|
shown_.push_back(lora::row({body + lora::kLoraTapSize, have - lora::kLoraTapSize, rx.rssi, rx.snr, true,
|
||||||
rx.syncWord == meshtastic::kSyncWord},
|
lora::protocolOf(rx.syncWord)},
|
||||||
clockTime(r.seconds)));
|
clockTime(r.seconds)));
|
||||||
} else {
|
} else {
|
||||||
shown_.push_back(clockTime(r.seconds) + " " + std::to_string(r.length) + " bytes");
|
shown_.push_back(clockTime(r.seconds) + " " + std::to_string(r.length) + " bytes");
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
#include "meshtastic_presets.h"
|
#include "scan_presets.h"
|
||||||
#include "packet_view.h"
|
#include "packet_view.h"
|
||||||
#include "sweep_view.h"
|
#include "sweep_view.h"
|
||||||
#include "ui/canvas.h"
|
#include "ui/canvas.h"
|
||||||
@@ -21,8 +21,8 @@ constexpr uint32_t kMessageMs = 4000;
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LoraScannerApp::onEnter() {
|
void LoraScannerApp::onEnter() {
|
||||||
int i = std::clamp<int>(settings_.getInt(Setting::LoraPreset), 0, meshtastic::kEu868PresetCount - 1);
|
int i = std::clamp<int>(settings_.getInt(Setting::LoraPreset), 0, lora::scanPresetCount() - 1);
|
||||||
const meshtastic::Preset& p = meshtastic::kEu868Presets[i];
|
lora::ScanPreset p = lora::scanPreset(i);
|
||||||
if (std::string(radio_.config().name) != p.name) radio_.setPreset(p);
|
if (std::string(radio_.config().name) != p.name) radio_.setPreset(p);
|
||||||
radio_.listen(RadioService::App, true);
|
radio_.listen(RadioService::App, true);
|
||||||
view_ = View::Packets;
|
view_ = View::Packets;
|
||||||
@@ -48,7 +48,7 @@ void LoraScannerApp::showSweep(bool on) {
|
|||||||
requestRedraw();
|
requestRedraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoraScannerApp::meshtasticSettings() const { return radio_.config().syncWord == meshtastic::kSyncWord; }
|
lora::Protocol LoraScannerApp::protocol() const { return lora::protocolOf(radio_.config().syncWord); }
|
||||||
|
|
||||||
void LoraScannerApp::say(const std::string& text) {
|
void LoraScannerApp::say(const std::string& text) {
|
||||||
message_ = text;
|
message_ = text;
|
||||||
@@ -83,8 +83,8 @@ bool LoraScannerApp::onKey(const KeyEvent& e) {
|
|||||||
else if (e.key == Key::Select) {
|
else if (e.key == Key::Select) {
|
||||||
int i = presets_.selected();
|
int i = presets_.selected();
|
||||||
settings_.setInt(Setting::LoraPreset, i);
|
settings_.setInt(Setting::LoraPreset, i);
|
||||||
radio_.setPreset(meshtastic::kEu868Presets[i]);
|
radio_.setPreset(lora::scanPreset(i));
|
||||||
say(std::string("Listening on ") + meshtastic::kEu868Presets[i].name);
|
say(std::string("Listening on ") + lora::scanPreset(i).name);
|
||||||
view_ = View::Packets;
|
view_ = View::Packets;
|
||||||
} else if (e.key == Key::Back) view_ = View::Packets;
|
} else if (e.key == Key::Back) view_ = View::Packets;
|
||||||
else return true;
|
else return true;
|
||||||
@@ -104,7 +104,7 @@ bool LoraScannerApp::onKey(const KeyEvent& e) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (e.key == Key::Char && (e.ch == 'p' || e.ch == 'P')) {
|
if (e.key == Key::Char && (e.ch == 'p' || e.ch == 'P')) {
|
||||||
presets_.setCount(meshtastic::kEu868PresetCount);
|
presets_.setCount(lora::scanPresetCount());
|
||||||
presets_.select(settings_.getInt(Setting::LoraPreset));
|
presets_.select(settings_.getInt(Setting::LoraPreset));
|
||||||
view_ = View::Presets;
|
view_ = View::Presets;
|
||||||
requestRedraw();
|
requestRedraw();
|
||||||
@@ -133,8 +133,8 @@ void LoraScannerApp::openDetails() {
|
|||||||
details_.push_back(line);
|
details_.push_back(line);
|
||||||
std::snprintf(line, sizeof line, "%.4f MHz, off by %.0f Hz", p.rx.frequencyHz / 1e6, p.frequencyError);
|
std::snprintf(line, sizeof line, "%.4f MHz, off by %.0f Hz", p.rx.frequencyHz / 1e6, p.frequencyError);
|
||||||
details_.push_back(line);
|
details_.push_back(line);
|
||||||
if (meshtasticSettings())
|
if (p.crcOk)
|
||||||
for (auto& l : lora::headerLines(p.data, p.len)) details_.push_back(l);
|
for (auto& l : lora::headerLines(p.data, p.len, lora::protocolOf(p.rx.syncWord))) details_.push_back(l);
|
||||||
for (auto& l : lora::hexDump(p.data, p.len)) details_.push_back(l);
|
for (auto& l : lora::hexDump(p.data, p.len)) details_.push_back(l);
|
||||||
detailsTop_ = 0;
|
detailsTop_ = 0;
|
||||||
view_ = View::Details;
|
view_ = View::Details;
|
||||||
@@ -238,10 +238,12 @@ void LoraScannerApp::drawPackets(Canvas& c) {
|
|||||||
c.setFont(&fonts::body);
|
c.setFont(&fonts::body);
|
||||||
c.setTextColor(theme::kMuted);
|
c.setTextColor(theme::kMuted);
|
||||||
c.drawString("No packets yet.", 4, list.y + 4);
|
c.drawString("No packets yet.", 4, list.y + 4);
|
||||||
c.drawString(meshtasticSettings() ? "Meshtastic nodes in range show here." : "Custom settings.", 4,
|
lora::Protocol heard = protocol();
|
||||||
|
c.drawString(heard == lora::Protocol::Meshtastic ? "Meshtastic nodes in range show here."
|
||||||
|
: heard == lora::Protocol::MeshCore ? "MeshCore nodes in range show here." : "Custom settings.", 4,
|
||||||
list.y + 4 + theme::kLineHeight);
|
list.y + 4 + theme::kLineHeight);
|
||||||
} else {
|
} else {
|
||||||
bool mesh = meshtasticSettings();
|
lora::Protocol mesh = protocol();
|
||||||
widgets::list(c, packets_, list, [&](int i) {
|
widgets::list(c, packets_, list, [&](int i) {
|
||||||
RadioPacket p;
|
RadioPacket p;
|
||||||
if (!radio_.packet(newest - i, p)) return std::string("(gone)");
|
if (!radio_.packet(newest - i, p)) return std::string("(gone)");
|
||||||
@@ -265,14 +267,14 @@ void LoraScannerApp::drawPresets(Canvas& c) {
|
|||||||
const auto& area = theme::kContent;
|
const auto& area = theme::kContent;
|
||||||
c.setFont(&fonts::small);
|
c.setFont(&fonts::small);
|
||||||
c.setTextColor(theme::kMuted);
|
c.setTextColor(theme::kMuted);
|
||||||
c.drawString("Meshtastic presets allowed in EU868", 4, area.y + 2);
|
c.drawString("Meshtastic in EU868, and MeshCore", 4, area.y + 2);
|
||||||
widgets::list(
|
widgets::list(
|
||||||
c, presets_, {area.x, area.y + 12, area.w, (kListRows + 1) * theme::kLineHeight},
|
c, presets_, {area.x, area.y + 12, area.w, (kListRows + 1) * theme::kLineHeight},
|
||||||
[](int i) { return std::string(meshtastic::kEu868Presets[i].name); },
|
[](int i) { return std::string(lora::scanPreset(i).name); },
|
||||||
[](int i) {
|
[](int i) {
|
||||||
char v[24];
|
char v[24];
|
||||||
const auto& p = meshtastic::kEu868Presets[i];
|
lora::ScanPreset p = lora::scanPreset(i);
|
||||||
std::snprintf(v, sizeof v, "SF%u %.0fk %.3f", p.sf, p.bwKHz, meshtastic::eu868FrequencyHz(p) / 1e6);
|
std::snprintf(v, sizeof v, "SF%u %gk %.3f", p.sf, p.bwKHz, p.frequencyHz / 1e6);
|
||||||
return std::string(v);
|
return std::string(v);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
namespace roro {
|
namespace roro {
|
||||||
|
|
||||||
// The LoRa Scanner (docs/milestones/M3.md). Sniffer: the packets the radio hears, newest first,
|
// The LoRa Scanner (docs/milestones/M3.md). Sniffer: the packets the radio hears, newest first,
|
||||||
// with the Meshtastic header read (Q96) and a hex dump on Enter; p picks the preset (Q95), c starts
|
// with the Meshtastic or MeshCore header read (Q96) and a hex dump on Enter; p picks the preset (Q95), c starts
|
||||||
// or stops a Capture (Q97). The radio listens while the App is open (Q100). Tab: Sweep, the band's
|
// or stops a Capture (Q97). The radio listens while the App is open (Q100). Tab: Sweep, the band's
|
||||||
// RSSI as bars with peak hold and a waterfall (Q98); it pauses the Sniffer while shown (Q99).
|
// RSSI as bars with peak hold and a waterfall (Q98); it pauses the Sniffer while shown (Q99).
|
||||||
class LoraScannerApp : public App {
|
class LoraScannerApp : public App {
|
||||||
@@ -40,7 +40,7 @@ class LoraScannerApp : public App {
|
|||||||
void showSweep(bool on);
|
void showSweep(bool on);
|
||||||
void openDetails();
|
void openDetails();
|
||||||
std::string timeOf(const RadioPacket& p) const;
|
std::string timeOf(const RadioPacket& p) const;
|
||||||
bool meshtasticSettings() const;
|
lora::Protocol protocol() const; // whose packets the radio is set for
|
||||||
void say(const std::string& text); // a line in the footer for a few seconds
|
void say(const std::string& text); // a line in the footer for a few seconds
|
||||||
|
|
||||||
RadioService& radio_;
|
RadioService& radio_;
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ void ShellApp::onEnter() {
|
|||||||
|
|
||||||
// Nothing is kept once it's left: the ring, the lines and the list of commands all go (Q207).
|
// Nothing is kept once it's left: the ring, the lines and the list of commands all go (Q207).
|
||||||
void ShellApp::onExit() {
|
void ShellApp::onExit() {
|
||||||
|
if (password_ && abort) abort();
|
||||||
|
password_ = false;
|
||||||
|
input_.setText("");
|
||||||
console.closeShellRing();
|
console.closeShellRing();
|
||||||
console.shellShowsAll(false);
|
console.shellShowsAll(false);
|
||||||
open_ = false;
|
open_ = false;
|
||||||
@@ -49,6 +52,11 @@ void ShellApp::update(uint32_t) {
|
|||||||
if (skipped) log_.add("[... " + std::to_string(skipped) + " bytes lost: more was printed than fits]");
|
if (skipped) log_.add("[... " + std::to_string(skipped) + " bytes lost: more was printed than fits]");
|
||||||
log_.feed(reinterpret_cast<const char*>(buf), n);
|
log_.feed(reinterpret_cast<const char*>(buf), n);
|
||||||
}
|
}
|
||||||
|
if (!password_ && asking && asking()) { // after the question has been printed above
|
||||||
|
password_ = true;
|
||||||
|
input_.setText("");
|
||||||
|
requestRedraw();
|
||||||
|
}
|
||||||
if (log_.revision() != seenRevision_) {
|
if (log_.revision() != seenRevision_) {
|
||||||
seenRevision_ = log_.revision();
|
seenRevision_ = log_.revision();
|
||||||
requestRedraw();
|
requestRedraw();
|
||||||
@@ -114,6 +122,23 @@ bool ShellApp::onKey(const KeyEvent& e) {
|
|||||||
log_.add(console.shellShowsAll() ? "Showing everything the console prints." : "Showing only the replies to your commands.");
|
log_.add(console.shellShowsAll() ? "Showing everything the console prints." : "Showing only the replies to your commands.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (password_) { // masked, kept nowhere: not in the history, not in the log
|
||||||
|
switch (e.key) {
|
||||||
|
case Key::Char: input_.insert(e.ch); break;
|
||||||
|
case Key::Delete: input_.backspace(); break;
|
||||||
|
case Key::Select: {
|
||||||
|
std::string typed = input_.text();
|
||||||
|
input_.setText("");
|
||||||
|
password_ = false;
|
||||||
|
log_.add("> " + std::string(typed.size(), '*'));
|
||||||
|
if (answer) answer(typed);
|
||||||
|
typed.assign(typed.size(), '\0');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: return false; // Back leaves the Shell, which cancels the copy
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
std::string recalled;
|
std::string recalled;
|
||||||
switch (e.key) {
|
switch (e.key) {
|
||||||
case Key::Char: input_.insert(e.ch); break;
|
case Key::Char: input_.insert(e.ch); break;
|
||||||
@@ -197,7 +222,13 @@ void ShellApp::draw(Canvas& c) {
|
|||||||
}
|
}
|
||||||
c.setTextDatum(top_left);
|
c.setTextDatum(top_left);
|
||||||
|
|
||||||
widgets::lineEditor(c, input_, {2, area.y + area.h - inputH, area.w - 4, 0});
|
if (password_) {
|
||||||
|
LineEditor stars(240);
|
||||||
|
stars.setText(std::string(input_.text().size(), '*'));
|
||||||
|
widgets::lineEditor(c, stars, {2, area.y + area.h - inputH, area.w - 4, 0});
|
||||||
|
} else {
|
||||||
|
widgets::lineEditor(c, input_, {2, area.y + area.h - inputH, area.w - 4, 0});
|
||||||
|
}
|
||||||
if (confirm_) widgets::dialog(c, "Delete?", question_, *confirm_);
|
if (confirm_) widgets::dialog(c, "Delete?", question_, *confirm_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ class ShellApp : public App {
|
|||||||
ShellApp(Run run, Probe probe, List list, Count count, const char* helpText, AppManager& apps)
|
ShellApp(Run run, Probe probe, List list, Count count, const char* helpText, AppManager& apps)
|
||||||
: run_(std::move(run)), probe_(std::move(probe)), list_(std::move(list)), count_(std::move(count)), helpText_(helpText), apps_(apps) {}
|
: run_(std::move(run)), probe_(std::move(probe)), list_(std::move(list)), count_(std::move(count)), helpText_(helpText), apps_(apps) {}
|
||||||
|
|
||||||
|
// `scp` asking for a password: while asking() is true, the next line typed is masked and goes to
|
||||||
|
// answer() instead of the console; leaving the Shell calls abort().
|
||||||
|
std::function<bool()> asking;
|
||||||
|
std::function<void(const std::string&)> answer;
|
||||||
|
std::function<void()> abort;
|
||||||
|
|
||||||
void onEnter() override;
|
void onEnter() override;
|
||||||
void onExit() override;
|
void onExit() override;
|
||||||
bool onKey(const KeyEvent& e) override;
|
bool onKey(const KeyEvent& e) override;
|
||||||
@@ -63,6 +69,7 @@ class ShellApp : public App {
|
|||||||
uint32_t ringPos_ = 0, seenRevision_ = 0;
|
uint32_t ringPos_ = 0, seenRevision_ = 0;
|
||||||
int scroll_ = 0; // wrapped lines scrolled back from the bottom
|
int scroll_ = 0; // wrapped lines scrolled back from the bottom
|
||||||
bool open_ = false;
|
bool open_ = false;
|
||||||
|
bool password_ = false; // the line being typed is a password
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace roro
|
} // namespace roro
|
||||||
|
|||||||
@@ -0,0 +1,510 @@
|
|||||||
|
#include "apps/ssh_app.h"
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <SD.h>
|
||||||
|
|
||||||
|
#include "app_keys.h"
|
||||||
|
#include "text_wrap.h"
|
||||||
|
#include "ui/fonts.h"
|
||||||
|
#include "ui/theme.h"
|
||||||
|
#include "ui/widgets.h"
|
||||||
|
|
||||||
|
namespace roro {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr uint32_t kMessageMs = 4000;
|
||||||
|
constexpr uint32_t kFrameMs = 60; // a busy terminal is drawn this often at most
|
||||||
|
|
||||||
|
std::string masked(size_t n) { return std::string(n, '*'); }
|
||||||
|
|
||||||
|
// The terminal keeps characters as the fonts have them, one byte each; drawing wants UTF-8.
|
||||||
|
void appendUtf8(std::string& out, uint8_t ch) {
|
||||||
|
if (ch < 0x80) out += static_cast<char>(ch);
|
||||||
|
else {
|
||||||
|
out += static_cast<char>(0xC0 | (ch >> 6));
|
||||||
|
out += static_cast<char>(0x80 | (ch & 0x3F));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alt with ; and . looks back and forward, as in the Shell (Q258): lines to move, or 0.
|
||||||
|
int scrollStep(const KeyEvent& e) {
|
||||||
|
if (!e.alt || e.ctrl) return 0;
|
||||||
|
if (e.key == Key::Up || (e.key == Key::Char && e.ch == ';')) return 4;
|
||||||
|
if (e.key == Key::Down || (e.key == Key::Char && e.ch == '.')) return -4;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t colour(int index) {
|
||||||
|
uint8_t r, g, b;
|
||||||
|
term::colourRgb(index, r, g, b);
|
||||||
|
return lgfx::color565(r, g, b);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
// Ctrl with + and - step through these (Q257): from 60 columns by 20 rows to 26 by 8.
|
||||||
|
const SshApp::Font SshApp::kFonts[5] = {{&fonts::tiny, 4, 6}, {&fonts::small, 5, 8}, {&fonts::medium, 6, 10}, {&fonts::body, 6, 13}, {&fonts::large, 9, 15}};
|
||||||
|
|
||||||
|
void SshApp::grid(int& cols, int& rows) const {
|
||||||
|
const auto& area = theme::kContent;
|
||||||
|
cols = area.w / kFonts[font_].w;
|
||||||
|
rows = area.h / kFonts[font_].h;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshApp::say(const std::string& text) {
|
||||||
|
message_ = text;
|
||||||
|
messageMs_ = millis();
|
||||||
|
requestRedraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshApp::onEnter() {
|
||||||
|
font_ = settings_.getInt(Setting::SshFont);
|
||||||
|
hosts_ = term::SshHosts(settings_.getString(Setting::SshHosts)).list();
|
||||||
|
list_.setCount(static_cast<int>(hosts_.size()) + 2);
|
||||||
|
dialog_.reset();
|
||||||
|
ask_ = Ask::None;
|
||||||
|
message_.clear();
|
||||||
|
scroll_ = 0;
|
||||||
|
// A session that was left running is found again.
|
||||||
|
SshService::State s = ssh_.state();
|
||||||
|
view_ = s == SshService::State::Idle || (s == SshService::State::Ended && view_ != View::Session) ? View::Hosts : View::Session;
|
||||||
|
shownState_ = SshService::State::Idle;
|
||||||
|
requestRedraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshApp::connect(const term::SshTarget& target) {
|
||||||
|
int cols, rows;
|
||||||
|
grid(cols, rows);
|
||||||
|
std::string why = ssh_.connect(target, cols, rows);
|
||||||
|
if (!why.empty()) return say(why);
|
||||||
|
password_ = LineEditor(96);
|
||||||
|
scroll_ = 0;
|
||||||
|
view_ = View::Session;
|
||||||
|
shownState_ = SshService::State::Idle;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SshApp::connectTo(const std::string& text) {
|
||||||
|
term::SshTarget target;
|
||||||
|
std::string why = term::parseSshTarget(text, target);
|
||||||
|
if (!why.empty()) return why;
|
||||||
|
if (ssh_.state() != SshService::State::Idle && ssh_.state() != SshService::State::Ended) return "a session is open already";
|
||||||
|
font_ = settings_.getInt(Setting::SshFont);
|
||||||
|
message_.clear();
|
||||||
|
connect(target);
|
||||||
|
return view_ == View::Session ? "" : message_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshApp::setFont(int index) {
|
||||||
|
index = std::clamp(index, 0, 4);
|
||||||
|
if (index == font_) return;
|
||||||
|
font_ = index;
|
||||||
|
settings_.setInt(Setting::SshFont, font_);
|
||||||
|
int cols, rows;
|
||||||
|
grid(cols, rows);
|
||||||
|
ssh_.resize(cols, rows); // the far end is told, and redraws for the new size
|
||||||
|
scroll_ = 0;
|
||||||
|
say(std::to_string(cols) + " x " + std::to_string(rows));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshApp::writePublicKey() {
|
||||||
|
std::string line = ssh_.publicKey() + "\n";
|
||||||
|
storage_.runJob([line]() {
|
||||||
|
if (!SD.exists("/ssh")) SD.mkdir("/ssh");
|
||||||
|
File f = SD.open(kPublicKeyPath, FILE_WRITE);
|
||||||
|
if (f) {
|
||||||
|
f.write(reinterpret_cast<const uint8_t*>(line.data()), line.size());
|
||||||
|
f.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshApp::help(std::vector<KeyHelp>& out) const {
|
||||||
|
if (dialog_) return keys::add(out, keys::kDialog);
|
||||||
|
switch (view_) {
|
||||||
|
case View::Hosts: return keys::add(out, keys::kSsh);
|
||||||
|
case View::Entry: return keys::add(out, keys::kText);
|
||||||
|
case View::Key: return keys::add(out, keys::kSshKey);
|
||||||
|
case View::Session:
|
||||||
|
if (ssh_.state() == SshService::State::AskPassword) return keys::add(out, keys::kText);
|
||||||
|
return keys::add(out, keys::kSshTerminal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* SshApp::helpTitle() const {
|
||||||
|
switch (view_) {
|
||||||
|
case View::Entry: return "SSH: a host";
|
||||||
|
case View::Key: return "SSH: this device's key";
|
||||||
|
case View::Session: return "SSH: the terminal";
|
||||||
|
default: return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SshApp::sessionKey(const KeyEvent& e) {
|
||||||
|
SshService::State state = ssh_.state();
|
||||||
|
if (state == SshService::State::AskPassword) {
|
||||||
|
switch (e.key) {
|
||||||
|
case Key::Char: password_.insert(e.ch); break;
|
||||||
|
case Key::Delete: password_.backspace(); break;
|
||||||
|
case Key::Back:
|
||||||
|
ssh_.disconnect();
|
||||||
|
break;
|
||||||
|
case Key::Select: {
|
||||||
|
std::string typed = password_.text();
|
||||||
|
password_ = LineEditor(96);
|
||||||
|
ssh_.answerPassword(typed);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (state == SshService::State::Connecting) {
|
||||||
|
if (e.key == Key::Back) ssh_.disconnect();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (state == SshService::State::Ended || state == SshService::State::Idle) {
|
||||||
|
if (int step = scrollStep(e)) { // what it said last can still be read
|
||||||
|
int history = 0;
|
||||||
|
ssh_.withTerminal([&](term::Terminal& t) { history = t.altScreen() ? 0 : t.historyCount(); });
|
||||||
|
scroll_ = std::clamp(scroll_ + step, 0, history);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
ssh_.clear(); // read: its memory goes back
|
||||||
|
view_ = View::Hosts;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Open: every key is the far end's, but these few.
|
||||||
|
if (e.key == Key::Char && e.ctrl && e.alt && (e.ch == 'q' || e.ch == 'Q')) return ssh_.disconnect(), true;
|
||||||
|
if (e.key == Key::Char && e.ctrl && (e.ch == '=' || e.ch == '+')) return setFont(font_ + 1), true;
|
||||||
|
if (e.key == Key::Char && e.ctrl && (e.ch == '-' || e.ch == '_')) return setFont(font_ - 1), true;
|
||||||
|
if (int step = scrollStep(e)) {
|
||||||
|
int history = 0;
|
||||||
|
ssh_.withTerminal([&](term::Terminal& t) { history = t.altScreen() ? 0 : t.historyCount(); });
|
||||||
|
scroll_ = std::clamp(scroll_ + step, 0, history);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool app = false;
|
||||||
|
ssh_.withTerminal([&](term::Terminal& t) { app = t.appCursorKeys(); });
|
||||||
|
std::string bytes;
|
||||||
|
switch (e.key) {
|
||||||
|
case Key::Char: bytes = term::encodeKey(term::TermKey::Char, e.ch, e.ctrl, e.alt, app); break;
|
||||||
|
case Key::Select: bytes = term::encodeKey(term::TermKey::Enter, 0, false, e.alt, app); break;
|
||||||
|
case Key::Delete: bytes = term::encodeKey(term::TermKey::Backspace, 0, false, e.alt, app); break;
|
||||||
|
case Key::Tab: bytes = term::encodeKey(term::TermKey::Tab, 0, false, false, app); break;
|
||||||
|
// The key is printed "esc", and here that is what it is. With Alt it types the backtick it also carries.
|
||||||
|
case Key::Back: bytes = e.alt ? "`" : term::encodeKey(term::TermKey::Escape, 0, false, false, app); break;
|
||||||
|
case Key::Up: bytes = term::encodeKey(e.shift ? term::TermKey::PageUp : term::TermKey::Up, 0, false, false, app); break;
|
||||||
|
case Key::Down: bytes = term::encodeKey(e.shift ? term::TermKey::PageDown : term::TermKey::Down, 0, false, false, app); break;
|
||||||
|
case Key::Left: bytes = term::encodeKey(term::TermKey::Left, 0, false, false, app); break;
|
||||||
|
case Key::Right: bytes = term::encodeKey(term::TermKey::Right, 0, false, false, app); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
if (!bytes.empty()) {
|
||||||
|
scroll_ = 0;
|
||||||
|
ssh_.send(bytes);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SshApp::onKey(const KeyEvent& e) {
|
||||||
|
requestRedraw();
|
||||||
|
if (dialog_) {
|
||||||
|
dialog_->onKey(e);
|
||||||
|
int result = dialog_->result();
|
||||||
|
if (result == DialogModel::kPending) return true;
|
||||||
|
Ask asked = ask_;
|
||||||
|
ask_ = Ask::None;
|
||||||
|
dialog_.reset();
|
||||||
|
if (asked == Ask::Trust) ssh_.answerTrust(result == 1);
|
||||||
|
else if (asked == Ask::NewKey && result == 1) {
|
||||||
|
std::string why = ssh_.makeKey();
|
||||||
|
if (why.empty()) writePublicKey();
|
||||||
|
say(why.empty() ? std::string("Made, and written to ") + kPublicKeyPath : why);
|
||||||
|
} else if (asked == Ask::Forget && result == 1) {
|
||||||
|
term::SshHosts saved(settings_.getString(Setting::SshHosts));
|
||||||
|
term::SshTarget gone, other;
|
||||||
|
term::parseSshTarget(hosts_[static_cast<size_t>(list_.selected())], gone);
|
||||||
|
saved.remove(static_cast<size_t>(list_.selected()));
|
||||||
|
settings_.setString(Setting::SshHosts, saved.stored());
|
||||||
|
// Its fingerprint goes too, unless another saved host is the same server: met again, it is asked about again.
|
||||||
|
bool shared = false;
|
||||||
|
for (auto& h : saved.list()) shared = shared || (term::parseSshTarget(h, other).empty() && other.hostPort() == gone.hostPort());
|
||||||
|
if (!shared) {
|
||||||
|
term::SshKnownHosts known(settings_.getString(Setting::SshKnown));
|
||||||
|
known.forget(gone.hostPort());
|
||||||
|
settings_.setString(Setting::SshKnown, known.stored());
|
||||||
|
}
|
||||||
|
hosts_ = saved.list();
|
||||||
|
list_.setCount(static_cast<int>(hosts_.size()) + 2);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch (view_) {
|
||||||
|
case View::Session: return sessionKey(e);
|
||||||
|
case View::Entry:
|
||||||
|
switch (e.key) {
|
||||||
|
case Key::Char: entry_.insert(e.ch); break;
|
||||||
|
case Key::Delete: entry_.backspace(); break;
|
||||||
|
case Key::Left: entry_.left(); break;
|
||||||
|
case Key::Right: entry_.right(); break;
|
||||||
|
case Key::Back: view_ = View::Hosts; break;
|
||||||
|
case Key::Select: {
|
||||||
|
term::SshTarget target;
|
||||||
|
std::string why = term::parseSshTarget(entry_.text(), target);
|
||||||
|
if (!why.empty()) say(why);
|
||||||
|
else connect(target);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case View::Key:
|
||||||
|
if (e.key == Key::Back) view_ = View::Hosts;
|
||||||
|
else if (e.key == Key::Select || (e.key == Key::Char && (e.ch == 'n' || e.ch == 'N'))) {
|
||||||
|
if (!ssh_.hasKey()) {
|
||||||
|
std::string why = ssh_.makeKey();
|
||||||
|
if (why.empty()) writePublicKey();
|
||||||
|
say(why.empty() ? std::string("Made, and written to ") + kPublicKeyPath : why);
|
||||||
|
} else {
|
||||||
|
ask_ = Ask::NewKey;
|
||||||
|
dialog_.reset(new DialogModel({"Cancel", "New key"}));
|
||||||
|
}
|
||||||
|
} else if (e.key == Key::Char && (e.ch == 'w' || e.ch == 'W') && ssh_.hasKey()) {
|
||||||
|
writePublicKey();
|
||||||
|
say(std::string("Written to ") + kPublicKeyPath);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case View::Hosts: {
|
||||||
|
int count = static_cast<int>(hosts_.size());
|
||||||
|
switch (e.key) {
|
||||||
|
case Key::Up: list_.up(); break;
|
||||||
|
case Key::Down: list_.down(); break;
|
||||||
|
case Key::Back: return false;
|
||||||
|
case Key::Select: {
|
||||||
|
int i = list_.selected();
|
||||||
|
if (i < count) {
|
||||||
|
term::SshTarget target;
|
||||||
|
if (term::parseSshTarget(hosts_[static_cast<size_t>(i)], target).empty()) connect(target);
|
||||||
|
} else if (i == count) {
|
||||||
|
entry_ = LineEditor(96);
|
||||||
|
view_ = View::Entry;
|
||||||
|
} else {
|
||||||
|
view_ = View::Key;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Key::Char:
|
||||||
|
if ((e.ch == 'd' || e.ch == 'D') && list_.selected() < count) {
|
||||||
|
ask_ = Ask::Forget;
|
||||||
|
dialog_.reset(new DialogModel({"Cancel", "Forget"}));
|
||||||
|
} else if (e.ch == 'n' || e.ch == 'N') {
|
||||||
|
entry_ = LineEditor(96);
|
||||||
|
view_ = View::Entry;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshApp::update(uint32_t nowMs) {
|
||||||
|
if (!message_.empty() && nowMs - messageMs_ >= kMessageMs) {
|
||||||
|
message_.clear();
|
||||||
|
requestRedraw();
|
||||||
|
}
|
||||||
|
if (view_ != View::Session) return;
|
||||||
|
SshService::State state = ssh_.state();
|
||||||
|
if (state != shownState_) {
|
||||||
|
shownState_ = state;
|
||||||
|
if (state == SshService::State::AskTrust && !dialog_) {
|
||||||
|
ask_ = Ask::Trust;
|
||||||
|
dialog_.reset(new DialogModel({"Cancel", ssh_.remembered().empty() ? "Trust it" : "Replace"}));
|
||||||
|
} else if (state != SshService::State::AskTrust && ask_ == Ask::Trust) {
|
||||||
|
dialog_.reset();
|
||||||
|
ask_ = Ask::None;
|
||||||
|
}
|
||||||
|
if (state == SshService::State::Open) { // it got in: a host worth remembering (Q262)
|
||||||
|
term::SshHosts saved(settings_.getString(Setting::SshHosts));
|
||||||
|
saved.used(ssh_.target());
|
||||||
|
settings_.setString(Setting::SshHosts, saved.stored());
|
||||||
|
hosts_ = saved.list();
|
||||||
|
list_.setCount(static_cast<int>(hosts_.size()) + 2);
|
||||||
|
list_.select(0);
|
||||||
|
}
|
||||||
|
requestRedraw();
|
||||||
|
}
|
||||||
|
uint32_t revision = ssh_.revision();
|
||||||
|
if (revision != shownRevision_ && nowMs - lastDrawMs_ >= kFrameMs) {
|
||||||
|
shownRevision_ = revision;
|
||||||
|
requestRedraw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshApp::drawHosts(Canvas& c) {
|
||||||
|
const auto& area = theme::kContent;
|
||||||
|
int count = static_cast<int>(hosts_.size());
|
||||||
|
widgets::list(
|
||||||
|
c, list_, {area.x, area.y, area.w, 8 * theme::kLineHeight},
|
||||||
|
[&](int i) -> std::string { return i < count ? hosts_[static_cast<size_t>(i)] : i == count ? "New connection" : "This device's key"; },
|
||||||
|
[&](int i) -> std::string { return i < count ? "" : i == count ? ">" : ssh_.hasKey() ? ">" : "none yet"; });
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshApp::drawKey(Canvas& c) {
|
||||||
|
const auto& area = theme::kContent;
|
||||||
|
c.setFont(&fonts::body);
|
||||||
|
c.setTextColor(theme::kMuted);
|
||||||
|
if (!ssh_.hasKey()) {
|
||||||
|
c.drawString("This device has no key yet.", 4, area.y + 4);
|
||||||
|
c.drawString("With one, servers that know it", 4, area.y + 4 + 2 * theme::kLineHeight);
|
||||||
|
c.drawString("ask for no password.", 4, area.y + 4 + 3 * theme::kLineHeight);
|
||||||
|
c.setTextColor(theme::kText);
|
||||||
|
c.drawString("Enter makes one.", 4, area.y + 4 + 5 * theme::kLineHeight);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
c.drawString("Its public half, for a server's", 4, area.y + 2);
|
||||||
|
c.drawString("authorized_keys file:", 4, area.y + 2 + theme::kLineHeight);
|
||||||
|
c.setFont(&fonts::small);
|
||||||
|
c.setTextColor(theme::kText);
|
||||||
|
std::string pub = ssh_.publicKey();
|
||||||
|
int y = area.y + 2 + 2 * theme::kLineHeight + 3;
|
||||||
|
for (size_t at = 0; at < pub.size() && y < area.y + area.h - 30; at += 46, y += 9) c.drawString(pub.substr(at, 46).c_str(), 4, y);
|
||||||
|
c.setFont(&fonts::small);
|
||||||
|
c.setTextColor(theme::kMuted);
|
||||||
|
c.drawString((std::string("It is also in ") + kPublicKeyPath + " (w writes it").c_str(), 4, area.y + area.h - 28);
|
||||||
|
c.drawString("again). The private half never leaves.", 4, area.y + area.h - 19);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshApp::drawTerminal(Canvas& c) {
|
||||||
|
const auto& area = theme::kContent;
|
||||||
|
const Font& f = kFonts[font_];
|
||||||
|
c.setFont(f.font);
|
||||||
|
c.setTextDatum(top_left);
|
||||||
|
ssh_.withTerminal([&](term::Terminal& t) {
|
||||||
|
int rows = std::min(t.rows(), area.h / f.h), cols = std::min(t.cols(), area.w / f.w);
|
||||||
|
int history = t.altScreen() ? 0 : t.historyCount(), back = std::min(scroll_, history);
|
||||||
|
for (int r = 0; r < rows; r++) {
|
||||||
|
int y = area.y + r * f.h, line = r - back; // negative: a line of the history
|
||||||
|
if (line < 0) {
|
||||||
|
const std::string& text = t.historyLine(history + line);
|
||||||
|
std::string shown;
|
||||||
|
for (size_t i = 0; i < text.size() && static_cast<int>(i) < cols; i++) appendUtf8(shown, static_cast<uint8_t>(text[i]));
|
||||||
|
c.setTextColor(theme::kMuted);
|
||||||
|
c.drawString(shown.c_str(), area.x, y);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (int col = 0; col < cols;) { // one run of the same colours at a time
|
||||||
|
uint8_t attr = t.cell(line, col).attr;
|
||||||
|
std::string run;
|
||||||
|
int from = col;
|
||||||
|
while (col < cols && t.cell(line, col).attr == attr) appendUtf8(run, t.cell(line, col++).ch);
|
||||||
|
if (attr >> 4) c.fillRect(area.x + from * f.w, y, (col - from) * f.w, f.h, colour(attr >> 4));
|
||||||
|
if (run.find_first_not_of(' ') == std::string::npos) continue;
|
||||||
|
c.setTextColor(colour(attr & 15));
|
||||||
|
c.drawString(run.c_str(), area.x + from * f.w, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The cursor: its cell with the colours swapped.
|
||||||
|
int row = t.cursorRow() + back;
|
||||||
|
if (t.cursorVisible() && row < rows && t.cursorCol() < cols && ssh_.state() == SshService::State::Open) {
|
||||||
|
const term::Cell& cell = t.cell(t.cursorRow(), t.cursorCol());
|
||||||
|
int x = area.x + t.cursorCol() * f.w, y = area.y + row * f.h;
|
||||||
|
c.fillRect(x, y, f.w, f.h, colour(cell.attr & 15));
|
||||||
|
std::string ch;
|
||||||
|
appendUtf8(ch, cell.ch);
|
||||||
|
c.setTextColor(colour(cell.attr >> 4));
|
||||||
|
if (cell.ch != ' ') c.drawString(ch.c_str(), x, y);
|
||||||
|
}
|
||||||
|
if (back) { // looking back: how far
|
||||||
|
std::string where = "-" + std::to_string(back);
|
||||||
|
c.setFont(&fonts::small);
|
||||||
|
c.setTextDatum(top_right);
|
||||||
|
c.fillRect(area.x + area.w - 5 * static_cast<int>(where.size()) - 3, area.y, 5 * static_cast<int>(where.size()) + 3, 9, theme::kAccent);
|
||||||
|
c.setTextColor(0x0000);
|
||||||
|
c.drawString(where.c_str(), area.x + area.w - 1, area.y + 1);
|
||||||
|
c.setTextDatum(top_left);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshApp::drawSession(Canvas& c) {
|
||||||
|
const auto& area = theme::kContent;
|
||||||
|
SshService::State state = ssh_.state();
|
||||||
|
if (state == SshService::State::Open || (state == SshService::State::Ended && ssh_.opened())) {
|
||||||
|
drawTerminal(c);
|
||||||
|
if (state == SshService::State::Ended) {
|
||||||
|
std::string why = ssh_.status() + ". Any key.";
|
||||||
|
if (why.size() > 47) why = ssh_.status();
|
||||||
|
c.setFont(&fonts::small);
|
||||||
|
c.fillRect(area.x, area.y + area.h - 11, area.w, 11, theme::kBackground);
|
||||||
|
c.setTextColor(theme::kWarning);
|
||||||
|
c.drawString(why.c_str(), 4, area.y + area.h - 9);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
c.setFont(&fonts::body);
|
||||||
|
c.setTextColor(theme::kMuted);
|
||||||
|
c.drawString(ssh_.target().text().c_str(), 4, area.y + 4);
|
||||||
|
if (state == SshService::State::AskPassword) {
|
||||||
|
std::string again = ssh_.status();
|
||||||
|
c.setTextColor(again.empty() ? theme::kText : theme::kWarning);
|
||||||
|
c.drawString(again.empty() ? "Password" : again.c_str(), 4, area.y + 4 + 2 * theme::kLineHeight);
|
||||||
|
LineEditor stars(96);
|
||||||
|
stars.setText(masked(password_.text().size()));
|
||||||
|
widgets::lineEditor(c, stars, {4, area.y + 4 + 3 * theme::kLineHeight + 4, area.w - 8, 0});
|
||||||
|
c.setFont(&fonts::small);
|
||||||
|
c.setTextColor(theme::kMuted);
|
||||||
|
c.drawString("It isn't kept. ` gives up.", 4, area.y + area.h - 10);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Connecting, or it never got as far as a shell: what it is doing, or why not.
|
||||||
|
bool ended = state == SshService::State::Ended;
|
||||||
|
c.setTextColor(ended ? theme::kWarning : theme::kText);
|
||||||
|
auto lines = wrapText(ssh_.status(), area.w - 8, widgets::bodyMeasure(c));
|
||||||
|
for (size_t i = 0; i < lines.size() && i < 4; i++) c.drawString(lines[i].c_str(), 4, area.y + 4 + static_cast<int>(2 + i) * theme::kLineHeight);
|
||||||
|
if (ended) {
|
||||||
|
c.setFont(&fonts::small);
|
||||||
|
c.setTextColor(theme::kMuted);
|
||||||
|
c.drawString("Any key.", 4, area.y + area.h - 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshApp::draw(Canvas& c) {
|
||||||
|
lastDrawMs_ = millis();
|
||||||
|
const auto& area = theme::kContent;
|
||||||
|
c.setTextDatum(top_left);
|
||||||
|
switch (view_) {
|
||||||
|
case View::Hosts: drawHosts(c); break;
|
||||||
|
case View::Entry:
|
||||||
|
c.setFont(&fonts::body);
|
||||||
|
c.setTextColor(theme::kMuted);
|
||||||
|
c.drawString("Who, and where", 4, area.y + 4);
|
||||||
|
widgets::lineEditor(c, entry_, {4, area.y + 22, area.w - 8, 0});
|
||||||
|
c.drawString("user@host, or user@host:port", 4, area.y + 44);
|
||||||
|
break;
|
||||||
|
case View::Key: drawKey(c); break;
|
||||||
|
case View::Session: drawSession(c); break;
|
||||||
|
}
|
||||||
|
if (!message_.empty() && !dialog_) {
|
||||||
|
c.setFont(&fonts::small);
|
||||||
|
c.fillRect(area.x, area.y + area.h - 11, area.w, 11, theme::kBackground);
|
||||||
|
c.setTextColor(theme::kWarning);
|
||||||
|
c.drawString(message_.c_str(), 4, area.y + area.h - 9);
|
||||||
|
}
|
||||||
|
if (dialog_ && ask_ == Ask::Trust) {
|
||||||
|
std::string was = ssh_.remembered(), now = ssh_.fingerprint();
|
||||||
|
// Three lines: one of words, and the fingerprint in two halves, since it is longer than a line.
|
||||||
|
std::string shown = now.size() > 25 ? now.substr(0, 25) + " " + now.substr(25) : now;
|
||||||
|
std::string host = ssh_.target().host.size() > 30 ? ssh_.target().host.substr(0, 28) + ".." : ssh_.target().host;
|
||||||
|
if (was.empty()) widgets::dialog(c, "A server not met before", host + " " + shown, *dialog_);
|
||||||
|
else widgets::dialog(c, "THE SERVER'S KEY CHANGED", "Someone in between? Now it is " + shown, *dialog_);
|
||||||
|
} else if (dialog_ && ask_ == Ask::NewKey) {
|
||||||
|
widgets::dialog(c, "A new key?", "Servers that know the old one will ask for a password again.", *dialog_);
|
||||||
|
} else if (dialog_ && ask_ == Ask::Forget) {
|
||||||
|
widgets::dialog(c, "Forget this host?", hosts_[static_cast<size_t>(std::min<int>(list_.selected(), static_cast<int>(hosts_.size()) - 1))], *dialog_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace roro
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "app.h"
|
||||||
|
#include "dialog_model.h"
|
||||||
|
#include "line_editor.h"
|
||||||
|
#include "list_model.h"
|
||||||
|
#include "services/ssh_service.h"
|
||||||
|
#include "services/storage_service.h"
|
||||||
|
#include "settings.h"
|
||||||
|
#include "ui/canvas.h"
|
||||||
|
|
||||||
|
namespace roro {
|
||||||
|
|
||||||
|
// The SSH App (issue #2, docs/milestones/N1.md): the saved hosts, and a terminal on the one that
|
||||||
|
// is connected. Leaving it with Home doesn't end the session; coming back finds it.
|
||||||
|
class SshApp : public App {
|
||||||
|
public:
|
||||||
|
static constexpr const char* kPublicKeyPath = "/ssh/id_ed25519.pub";
|
||||||
|
|
||||||
|
SshApp(SshService& ssh, Settings& settings, StorageService& storage) : ssh_(ssh), settings_(settings), storage_(storage) {}
|
||||||
|
|
||||||
|
void onEnter() override;
|
||||||
|
bool onKey(const KeyEvent& e) override;
|
||||||
|
bool textEntryActive() const override { return view_ == View::Entry || (view_ == View::Session && !dialog_); }
|
||||||
|
void help(std::vector<KeyHelp>& out) const override;
|
||||||
|
const char* helpTitle() const override;
|
||||||
|
void update(uint32_t nowMs) override;
|
||||||
|
void draw(Canvas& c) override;
|
||||||
|
|
||||||
|
// `ssh user@host` from the Shell or a console: "" or why not.
|
||||||
|
std::string connectTo(const std::string& target);
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum class View { Hosts, Entry, Session, Key };
|
||||||
|
struct Font {
|
||||||
|
const lgfx::IFont* font;
|
||||||
|
int w, h;
|
||||||
|
};
|
||||||
|
static const Font kFonts[5];
|
||||||
|
|
||||||
|
void grid(int& cols, int& rows) const;
|
||||||
|
void connect(const term::SshTarget& target);
|
||||||
|
void setFont(int index);
|
||||||
|
bool sessionKey(const KeyEvent& e);
|
||||||
|
void drawHosts(Canvas& c);
|
||||||
|
void drawSession(Canvas& c);
|
||||||
|
void drawTerminal(Canvas& c);
|
||||||
|
void drawKey(Canvas& c);
|
||||||
|
void say(const std::string& text);
|
||||||
|
void writePublicKey();
|
||||||
|
|
||||||
|
SshService& ssh_;
|
||||||
|
Settings& settings_;
|
||||||
|
StorageService& storage_;
|
||||||
|
View view_ = View::Hosts;
|
||||||
|
ListModel list_{8};
|
||||||
|
std::vector<std::string> hosts_;
|
||||||
|
LineEditor entry_{96}, password_{96};
|
||||||
|
std::unique_ptr<DialogModel> dialog_;
|
||||||
|
enum class Ask { None, Trust, NewKey, Forget } ask_ = Ask::None;
|
||||||
|
SshService::State shownState_ = SshService::State::Idle;
|
||||||
|
std::string message_;
|
||||||
|
uint32_t messageMs_ = 0, shownRevision_ = 0, lastDrawMs_ = 0;
|
||||||
|
int font_ = 1, scroll_ = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace roro
|
||||||
@@ -12,7 +12,10 @@
|
|||||||
#include "apps/demo_app.h"
|
#include "apps/demo_app.h"
|
||||||
#include "apps/note_editor.h"
|
#include "apps/note_editor.h"
|
||||||
#include "apps/shell_app.h"
|
#include "apps/shell_app.h"
|
||||||
|
#include "apps/ssh_app.h"
|
||||||
#include "services/net_tools.h"
|
#include "services/net_tools.h"
|
||||||
|
#include "services/scp_service.h"
|
||||||
|
#include "services/ssh_service.h"
|
||||||
#include "services/vpn_service.h"
|
#include "services/vpn_service.h"
|
||||||
#include "services/web_share.h"
|
#include "services/web_share.h"
|
||||||
#include "apps/gemini_app.h"
|
#include "apps/gemini_app.h"
|
||||||
@@ -61,6 +64,7 @@
|
|||||||
#include "storage_paths.h"
|
#include "storage_paths.h"
|
||||||
#include "ui/notifier.h"
|
#include "ui/notifier.h"
|
||||||
#include "ui/screen.h"
|
#include "ui/screen.h"
|
||||||
|
#include "scp_args.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
using namespace roro;
|
using namespace roro;
|
||||||
@@ -91,6 +95,10 @@ static UpdateService* update;
|
|||||||
static DebugConsole* debugConsole;
|
static DebugConsole* debugConsole;
|
||||||
static VpnService* vpnService; // not in Safe Mode
|
static VpnService* vpnService; // not in Safe Mode
|
||||||
static NetTools netTools; // ping, nslookup and the rest (issue #90)
|
static NetTools netTools; // ping, nslookup and the rest (issue #90)
|
||||||
|
static SshService* sshService; // not in Safe Mode (issue #2)
|
||||||
|
static SshApp* sshApp;
|
||||||
|
static ShellApp* shellApp;
|
||||||
|
static ScpService* scpService; // not in Safe Mode
|
||||||
static Notifier* notifier;
|
static Notifier* notifier;
|
||||||
static LauncherApp launcher;
|
static LauncherApp launcher;
|
||||||
static AppManager* apps;
|
static AppManager* apps;
|
||||||
@@ -139,6 +147,7 @@ static StatusInfo currentStatus() {
|
|||||||
s.capturing = loraCapture && loraCapture->capturing();
|
s.capturing = loraCapture && loraCapture->capturing();
|
||||||
if (vpnService && vpnService->wanted())
|
if (vpnService && vpnService->wanted())
|
||||||
s.vpn = vpnService->state() == VpnService::State::Up ? StatusInfo::Vpn::Up : StatusInfo::Vpn::Trying;
|
s.vpn = vpnService->state() == VpnService::State::Up ? StatusInfo::Vpn::Up : StatusInfo::Vpn::Trying;
|
||||||
|
s.ssh = sshService && sshService->active();
|
||||||
s.debug = !debugConsole->on() ? StatusInfo::Debug::Off : debugConsole->clientConnected() ? StatusInfo::Debug::Client : StatusInfo::Debug::On;
|
s.debug = !debugConsole->on() ? StatusInfo::Debug::Off : debugConsole->clientConnected() ? StatusInfo::Debug::Client : StatusInfo::Debug::On;
|
||||||
using WifiState = WifiController::State;
|
using WifiState = WifiController::State;
|
||||||
switch (wifi->state()) {
|
switch (wifi->state()) {
|
||||||
@@ -228,9 +237,18 @@ void setup() {
|
|||||||
apps->registerApp({"lora", "LoRa Scanner", false, new LoraScannerApp(*radioService, *loraCapture, settings, *clockService)});
|
apps->registerApp({"lora", "LoRa Scanner", false, new LoraScannerApp(*radioService, *loraCapture, settings, *clockService)});
|
||||||
apps->registerApp({"storage", "Storage", false, new StorageApp(*fileOps, *storageService, *clockService, *update, *power, bus, *new WebShare(*storageService, *fileOps, *wifi))});
|
apps->registerApp({"storage", "Storage", false, new StorageApp(*fileOps, *storageService, *clockService, *update, *power, bus, *new WebShare(*storageService, *fileOps, *wifi))});
|
||||||
apps->registerApp({"notes", "Notes", false, new NotesApp(*fileOps, *storageService, *clockService, *power)});
|
apps->registerApp({"notes", "Notes", false, new NotesApp(*fileOps, *storageService, *clockService, *power)});
|
||||||
apps->registerApp({"shell", "Shell", false, new ShellApp(shellRun, shellProbe, shellList, shellCount, helpText(), *apps)});
|
sshService = new SshService(settings);
|
||||||
|
sshApp = new SshApp(*sshService, settings, *storageService);
|
||||||
|
scpService = new ScpService(settings, *storageService, *fileOps);
|
||||||
|
apps->registerApp({"ssh", "SSH", false, sshApp});
|
||||||
|
shellApp = new ShellApp(shellRun, shellProbe, shellList, shellCount, helpText(), *apps);
|
||||||
|
apps->registerApp({"shell", "Shell", false, shellApp});
|
||||||
|
shellApp->asking = [] { return scpService->asking(); };
|
||||||
|
shellApp->answer = [](const std::string& password) { scpService->answer(password); };
|
||||||
|
shellApp->abort = [] { scpService->cancel(); };
|
||||||
// Leaving the foreground App makes it save: a note being typed, when the device is powered off.
|
// Leaving the foreground App makes it save: a note being typed, when the device is powered off.
|
||||||
power->beforePowerOff = []() { apps->home(); };
|
power->beforePowerOff = []() { apps->home(); };
|
||||||
|
netTools.ntpServer = []() { return settings.getString(Setting::Ntp1); };
|
||||||
// A long note being rewritten (issue #47): the editor waits for the card, so it draws from there.
|
// A long note being rewritten (issue #47): the editor waits for the card, so it draws from there.
|
||||||
NoteEditor::onProgress = [](const std::string& name, int percent) { screen.renderUpdate("Saving", name, percent); };
|
NoteEditor::onProgress = [](const std::string& name, int percent) { screen.renderUpdate("Saving", name, percent); };
|
||||||
apps->registerApp({"system", "System", false,
|
apps->registerApp({"system", "System", false,
|
||||||
@@ -658,7 +676,7 @@ static const char* const kHelp =
|
|||||||
"log level <0-5> ESP-IDF log level (0 none ... 5 verbose)\n"
|
"log level <0-5> ESP-IDF log level (0 none ... 5 verbose)\n"
|
||||||
"ls [folder] | du <path> | mkdir <path> | rm [-r] [-f] <path> | cp [-f] <from> <to> | mv [-f] <from> <to> | cancel the SD card, with the Storage App's rules (rm -r for a folder; -f: the Shell doesn't ask; * and ? in a name: /notes/*.txt)\n"
|
"ls [folder] | du <path> | mkdir <path> | rm [-r] [-f] <path> | cp [-f] <from> <to> | mv [-f] <from> <to> | cancel the SD card, with the Storage App's rules (rm -r for a folder; -f: the Shell doesn't ask; * and ? in a name: /notes/*.txt)\n"
|
||||||
"screenshot [seconds] the screen as a PNG in /screenshots on the card, now or after a pause\n"
|
"screenshot [seconds] the screen as a PNG in /screenshots on the card, now or after a pause\n"
|
||||||
"lora probe | lora status | lora rx on|off | lora preset <name> the LoRa radio, receive only\n"
|
"lora probe | lora status | lora rx on|off | lora preset <name> the LoRa radio, receive only; a Meshtastic preset (LongFast...) or MeshCore\n"
|
||||||
"lora capture start|stop a LoRa Capture to /captures/lora (pcap, LoRaTap)\n"
|
"lora capture start|stop a LoRa Capture to /captures/lora (pcap, LoRaTap)\n"
|
||||||
"lora sweep on [from MHz] [to MHz] [step kHz] | lora sweep off | lora sweep dump RSSI across a band (863 870 100)\n"
|
"lora sweep on [from MHz] [to MHz] [step kHz] | lora sweep off | lora sweep dump RSSI across a band (863 870 100)\n"
|
||||||
"lora custom <MHz> <BW kHz> <SF> <CR 5-8> <sync hex> [preamble] e.g. 868.1 125 7 5 34 8 (LoRaWAN)\n"
|
"lora custom <MHz> <BW kHz> <SF> <CR 5-8> <sync hex> [preamble] e.g. 868.1 125 7 5 34 8 (LoRaWAN)\n"
|
||||||
@@ -677,7 +695,11 @@ static const char* const kHelp =
|
|||||||
"sd card | sd list | cat <path> | log <text> | burst | sound on|off | short | normal\n"
|
"sd card | sd list | cat <path> | log <text> | burst | sound on|off | short | normal\n"
|
||||||
"Irc | Wifi | Gnss | Gemini | Lora | Storage | Notes | Shell | System | Settings open that App: a capital letter is an App, not a command\n"
|
"Irc | Wifi | Gnss | Gemini | Lora | Storage | Notes | Shell | System | Settings open that App: a capital letter is an App, not a command\n"
|
||||||
"ping <host> [count] [size] | nslookup <name> [server] | port <host> <port> | traceroute <host> | cancel is it there, does its name resolve, is its port open, which way; one at a time\n"
|
"ping <host> [count] [size] | nslookup <name> [server] | port <host> <port> | traceroute <host> | cancel is it there, does its name resolve, is its port open, which way; one at a time\n"
|
||||||
"ifconfig | arp the interfaces (Wi-Fi and the VPN), their addresses, the default route and the DNS servers; the neighbours heard\n"
|
"tls <host> [port] | ntp [server] a TLS handshake: who the certificate is for, by whom, until when, and whether this device trusts it; a time server's clock against this one\n"
|
||||||
|
"ifconfig | arp | netstat the interfaces (Wi-Fi and the VPN), their addresses, the default route and the DNS servers; the neighbours heard; what listens and what is connected\n"
|
||||||
|
"uname the firmware, its version and the chip it is built for\n"
|
||||||
|
"scp [-f] [-P port] <file on the card> user@host:path | scp [-f] [-P port] user@host:path <file on the card> one file over SSH, with this device's key or, in the Shell, a password, to a server the SSH App already trusts; -f replaces a file on the card; `cancel` stops it\n"
|
||||||
|
"ssh user@host[:port] | ssh status | ssh stop a terminal on another machine, in the SSH App; the password is asked there, never here\n"
|
||||||
"vpn status | vpn up [seconds] | vpn down | vpn import [path] | vpn forget | vpn auto on|off the WireGuard tunnel (Settings > VPN); import reads /vpn/wg0.conf; with seconds, it goes down by itself\n"
|
"vpn status | vpn up [seconds] | vpn down | vpn import [path] | vpn forget | vpn auto on|off the WireGuard tunnel (Settings > VPN); import reads /vpn/wg0.conf; with seconds, it goes down by itself\n"
|
||||||
"debug status | debug off [seconds] the Debug Console over Wi-Fi (Settings > Debug Console); with seconds, it comes back\n"
|
"debug status | debug off [seconds] the Debug Console over Wi-Fi (Settings > Debug Console); with seconds, it comes back\n"
|
||||||
"debug on | debug token <16 to 64 characters> | debug token new (USB serial only) switch it on, set its token\n"
|
"debug on | debug token <16 to 64 characters> | debug token new (USB serial only) switch it on, set its token\n"
|
||||||
@@ -738,6 +760,38 @@ static void saveScreenshot() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `ssh ...` (issue #2, Q265): the session is the SSH App's; this opens it there.
|
||||||
|
static void sshCommand(const String& arg) {
|
||||||
|
if (!sshService) return (void)console.println("ssh: not available in Safe Mode");
|
||||||
|
SshService& s = *sshService;
|
||||||
|
if (arg == "status") {
|
||||||
|
bool live = s.state() != SshService::State::Idle && s.state() != SshService::State::Ended;
|
||||||
|
if (s.state() == SshService::State::Idle) console.println("ssh: no session");
|
||||||
|
else console.printf("ssh: %s%s%s\n", s.target().text().c_str(), live ? ", " : ": ", s.state() == SshService::State::Open ? "open" : s.status().c_str());
|
||||||
|
console.printf("ssh: this device's key: %s\n", s.hasKey() ? s.publicKey().c_str() : "none (the SSH App makes one)");
|
||||||
|
} else if (arg == "stop") {
|
||||||
|
s.disconnect();
|
||||||
|
console.println("ssh: stopped");
|
||||||
|
} else if (arg.indexOf('@') > 0) {
|
||||||
|
std::string why = sshApp->connectTo(arg.c_str());
|
||||||
|
if (!why.empty()) return (void)console.printf("ssh: error %s\n", why.c_str());
|
||||||
|
if (!apps->open("ssh")) return (void)console.println("ssh: connecting, but Setup is running");
|
||||||
|
console.printf("ssh: connecting to %s, in the SSH App\n", s.target().text().c_str());
|
||||||
|
} else {
|
||||||
|
console.println("ssh: user@host[:port] | status | stop");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// `scp ...`: see ScpService. It needs the key and the trusted server the SSH App sets up.
|
||||||
|
static void scpCommand(const String& arg) {
|
||||||
|
if (!scpService) return (void)console.println("scp: not available in Safe Mode");
|
||||||
|
term::ScpArgs args;
|
||||||
|
std::string why = term::parseScp(arg.c_str(), args);
|
||||||
|
if (!why.empty()) return (void)console.printf("scp: %s\n", why.c_str());
|
||||||
|
why = scpService->start(args, sshService && sshService->state() != SshService::State::Idle && sshService->state() != SshService::State::Ended);
|
||||||
|
if (!why.empty()) console.printf("scp: error %s\n", why.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
// `vpn ...` (issue #8). Nothing here prints a key.
|
// `vpn ...` (issue #8). Nothing here prints a key.
|
||||||
static void vpnCommand(const String& arg) {
|
static void vpnCommand(const String& arg) {
|
||||||
if (!vpnService) return (void)console.println("vpn: not available in Safe Mode");
|
if (!vpnService) return (void)console.println("vpn: not available in Safe Mode");
|
||||||
@@ -807,7 +861,7 @@ static void screenshotStep() {
|
|||||||
|
|
||||||
// Commands that only touch what Safe Mode starts.
|
// Commands that only touch what Safe Mode starts.
|
||||||
static bool safeModeCommand(const String& line) {
|
static bool safeModeCommand(const String& line) {
|
||||||
return line == "help" || line == "info" || line == "tasks" || line == "net" || line == "reboot" || line == "boot other" ||
|
return line == "help" || line == "uname" || line == "info" || line == "tasks" || line == "net" || line == "reboot" || line == "boot other" ||
|
||||||
line.startsWith("log level ") || line.startsWith("crash") || line.startsWith("coredump") ||
|
line.startsWith("log level ") || line.startsWith("crash") || line.startsWith("coredump") ||
|
||||||
line == "wifi status" || line.startsWith("wifi add ") || line.startsWith("debug ");
|
line == "wifi status" || line.startsWith("wifi add ") || line.startsWith("debug ");
|
||||||
}
|
}
|
||||||
@@ -872,6 +926,10 @@ static void runCommand(String line, bool fromSerial = false) {
|
|||||||
}
|
}
|
||||||
if (netTools.command(line.c_str())) return;
|
if (netTools.command(line.c_str())) return;
|
||||||
if (line == "cancel") netTools.cancel(); // and a copy or a delete, below
|
if (line == "cancel") netTools.cancel(); // and a copy or a delete, below
|
||||||
|
if (line == "uname" || line == "uname -a") return (void)console.println(unameString().c_str());
|
||||||
|
if (line.startsWith("scp ")) return scpCommand(line.substring(4));
|
||||||
|
if (line == "cancel" && scpService) scpService->cancel();
|
||||||
|
if (line == "ssh" || line.startsWith("ssh ")) return sshCommand(line.length() > 4 ? line.substring(4) : String("status"));
|
||||||
if (line == "vpn" || line.startsWith("vpn ")) return vpnCommand(line.length() > 4 ? line.substring(4) : String("status"));
|
if (line == "vpn" || line.startsWith("vpn ")) return vpnCommand(line.length() > 4 ? line.substring(4) : String("status"));
|
||||||
if (line.startsWith("debug ")) return debugCommand(line.substring(6), fromSerial);
|
if (line.startsWith("debug ")) return debugCommand(line.substring(6), fromSerial);
|
||||||
if (line == "screenshot" || line.startsWith("screenshot ")) {
|
if (line == "screenshot" || line.startsWith("screenshot ")) {
|
||||||
@@ -1075,9 +1133,10 @@ static void runCommand(String line, bool fromSerial = false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (line.startsWith("lora preset ") && radioService) {
|
if (line.startsWith("lora preset ") && radioService) {
|
||||||
const meshtastic::Preset* p = meshtastic::findPreset(line.substring(12).c_str());
|
lora::ScanPreset p;
|
||||||
if (p) radioService->setPreset(*p);
|
bool found = lora::findScanPreset(line.substring(12).c_str(), p);
|
||||||
console.printf("lora preset: %s\n", p ? p->name : "unknown (LongFast LongSlow MediumSlow MediumFast ShortSlow ShortFast LongMod)");
|
if (found) radioService->setPreset(p);
|
||||||
|
console.printf("lora preset: %s\n", found ? p.name : "unknown (LongFast LongSlow MediumSlow MediumFast ShortSlow ShortFast LongMod MeshCore)");
|
||||||
}
|
}
|
||||||
if (line == "gnss quiet on" || line == "gnss quiet off") { // Settings > Pause GNSS for LoRa (issue #20)
|
if (line == "gnss quiet on" || line == "gnss quiet off") { // Settings > Pause GNSS for LoRa (issue #20)
|
||||||
settings.setBool(Setting::GnssQuietForLora, line.endsWith("on"));
|
settings.setBool(Setting::GnssQuietForLora, line.endsWith("on"));
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#include "platform/libssh_util.h"
|
||||||
|
|
||||||
|
#include <libssh_esp32.h>
|
||||||
|
|
||||||
|
namespace roro::sshutil {
|
||||||
|
|
||||||
|
std::string fingerprintOf(ssh_session s) {
|
||||||
|
ssh_key key = nullptr;
|
||||||
|
unsigned char* hash = nullptr;
|
||||||
|
size_t len = 0;
|
||||||
|
std::string out;
|
||||||
|
if (ssh_get_server_publickey(s, &key) == SSH_OK && ssh_get_publickey_hash(key, SSH_PUBLICKEY_HASH_SHA256, &hash, &len) == SSH_OK) {
|
||||||
|
if (char* text = ssh_get_fingerprint_hash(SSH_PUBLICKEY_HASH_SHA256, hash, len)) {
|
||||||
|
out = text; // "SHA256:..."
|
||||||
|
ssh_string_free_char(text);
|
||||||
|
}
|
||||||
|
ssh_clean_pubkey_hash(&hash);
|
||||||
|
}
|
||||||
|
if (key) ssh_key_free(key);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
void startLibrary() {
|
||||||
|
static bool started = false;
|
||||||
|
if (!started) libssh_begin();
|
||||||
|
started = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace roro::sshutil
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <libssh/libssh.h>
|
||||||
|
|
||||||
|
// What the SSH Service and the Scp Service both do with libssh.
|
||||||
|
namespace roro::sshutil {
|
||||||
|
|
||||||
|
// libssh_begin(), once.
|
||||||
|
void startLibrary();
|
||||||
|
// "SHA256:..." of the key the server showed, or "".
|
||||||
|
std::string fingerprintOf(ssh_session s);
|
||||||
|
|
||||||
|
} // namespace roro::sshutil
|
||||||
@@ -238,7 +238,10 @@ void IrcService::loop() {
|
|||||||
retryAtMs_ = now; // reconnect as soon as Wi-Fi is back
|
retryAtMs_ = now; // reconnect as soon as Wi-Fi is back
|
||||||
} else if (!open_) {
|
} else if (!open_) {
|
||||||
if (static_cast<int32_t>(now - retryAtMs_) >= 0) {
|
if (static_cast<int32_t>(now - retryAtMs_) >= 0) {
|
||||||
if (!open()) scheduleRetry("could not connect to " + draftConfig().host);
|
// A secure connection peaks at 52 KB. Under an open SSH session there isn't that much, and
|
||||||
|
// trying anyway takes the heap down to nothing (seen on the device, issue #2).
|
||||||
|
if (esp_get_free_heap_size() < kNeedFree) scheduleRetry("not enough memory: close the SSH session");
|
||||||
|
else if (!open()) scheduleRetry("could not connect to " + draftConfig().host);
|
||||||
}
|
}
|
||||||
} else if (!conn_->connected()) {
|
} else if (!conn_->connected()) {
|
||||||
close("");
|
close("");
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace roro {
|
|||||||
// session is shared with the IRC App under a lock.
|
// session is shared with the IRC App under a lock.
|
||||||
class IrcService : public Service {
|
class IrcService : public Service {
|
||||||
public:
|
public:
|
||||||
|
static constexpr size_t kNeedFree = 60 * 1024; // free memory a connection attempt wants
|
||||||
enum class Status { Stopped, WaitingForWifi, Connecting, Registering, Online, Paused, Retrying };
|
enum class Status { Stopped, WaitingForWifi, Connecting, Registering, Online, Paused, Retrying };
|
||||||
|
|
||||||
IrcService(KeyValueStore& store, const std::string& defaultNick, WifiService& wifi, StorageService& storage,
|
IrcService(KeyValueStore& store, const std::string& defaultNick, WifiService& wifi, StorageService& storage,
|
||||||
|
|||||||
@@ -2,12 +2,18 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include <NetworkClientSecure.h>
|
||||||
|
|
||||||
#include <lwip/etharp.h>
|
#include <lwip/etharp.h>
|
||||||
#include <lwip/dns.h>
|
#include <lwip/dns.h>
|
||||||
#include <lwip/netdb.h>
|
#include <lwip/netdb.h>
|
||||||
#include <lwip/netif.h>
|
#include <lwip/netif.h>
|
||||||
|
#include <lwip/priv/tcp_priv.h>
|
||||||
#include <lwip/sockets.h>
|
#include <lwip/sockets.h>
|
||||||
#include <lwip/tcpip.h>
|
#include <lwip/tcpip.h>
|
||||||
|
#include <lwip/udp.h>
|
||||||
|
#include <mbedtls/x509_crt.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include <esp_random.h>
|
#include <esp_random.h>
|
||||||
|
|
||||||
@@ -16,12 +22,15 @@
|
|||||||
|
|
||||||
#include "ipv4.h"
|
#include "ipv4.h"
|
||||||
#include "net_probe.h"
|
#include "net_probe.h"
|
||||||
|
#include "platform/ca_roots.h"
|
||||||
|
|
||||||
namespace roro {
|
namespace roro {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr int kMaxHops = 20;
|
constexpr int kMaxHops = 20;
|
||||||
constexpr uint32_t kPingEveryMs = 1000, kPingWaitMs = 1000, kHopWaitMs = 2000, kPortWaitMs = 5000, kDnsWaitMs = 3000;
|
constexpr uint32_t kPingEveryMs = 1000, kPingWaitMs = 1000, kHopWaitMs = 2000, kPortWaitMs = 5000, kDnsWaitMs = 3000;
|
||||||
|
// A TLS handshake peaks at about 52 KB of heap; below this it isn't tried.
|
||||||
|
constexpr size_t kTlsNeedsFree = 70 * 1024;
|
||||||
|
|
||||||
struct LwipLock {
|
struct LwipLock {
|
||||||
LwipLock() { LOCK_TCPIP_CORE(); }
|
LwipLock() { LOCK_TCPIP_CORE(); }
|
||||||
@@ -53,7 +62,7 @@ void waitMs(int socket, uint32_t ms) {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
struct NetTools::Job {
|
struct NetTools::Job {
|
||||||
enum class Kind { Ping, Trace, Port, Lookup } kind;
|
enum class Kind { Ping, Trace, Port, Lookup, Tls, Ntp } kind;
|
||||||
NetTools* owner;
|
NetTools* owner;
|
||||||
Console::Origin from;
|
Console::Origin from;
|
||||||
net::PingArgs ping;
|
net::PingArgs ping;
|
||||||
@@ -68,6 +77,8 @@ struct NetTools::Job {
|
|||||||
void runTrace();
|
void runTrace();
|
||||||
void runPort();
|
void runPort();
|
||||||
void runLookup();
|
void runLookup();
|
||||||
|
void runTls();
|
||||||
|
void runNtp();
|
||||||
};
|
};
|
||||||
|
|
||||||
int NetTools::Job::echo(int socket, uint32_t to, uint16_t id, uint16_t seq, int size, uint32_t waitFor, uint32_t& from, net::IcmpAnswer::Kind& kind) {
|
int NetTools::Job::echo(int socket, uint32_t to, uint16_t id, uint16_t seq, int size, uint32_t waitFor, uint32_t& from, net::IcmpAnswer::Kind& kind) {
|
||||||
@@ -223,6 +234,103 @@ void NetTools::Job::runLookup() {
|
|||||||
else if (result.addresses.empty()) console.printf("nslookup: %s has no IPv4 address%s\n", lookup.name.c_str(), result.truncated ? " in a first packet" : "");
|
else if (result.addresses.empty()) console.printf("nslookup: %s has no IPv4 address%s\n", lookup.name.c_str(), result.truncated ? " in a first packet" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A handshake that checks nothing, to see the certificate whatever it is; then the certificate is
|
||||||
|
// checked here, against this device's own roots and the name asked for, and the answer is said in
|
||||||
|
// words. It is what the Update Service's connection would have decided.
|
||||||
|
void NetTools::Job::runTls() {
|
||||||
|
if (ESP.getFreeHeap() < kTlsNeedsFree)
|
||||||
|
return (void)console.printf("tls: not enough memory (%u KB free, %u needed): close IRC or a Gemini page\n", (unsigned)(ESP.getFreeHeap() / 1024),
|
||||||
|
(unsigned)(kTlsNeedsFree / 1024));
|
||||||
|
NetworkClientSecure tls;
|
||||||
|
tls.setInsecure();
|
||||||
|
uint32_t started = millis();
|
||||||
|
if (!tls.connect(port.host.c_str(), port.port, 8000)) {
|
||||||
|
char why[100] = "";
|
||||||
|
tls.lastError(why, sizeof why);
|
||||||
|
return (void)console.printf("tls: no handshake with %s:%u in %lu ms: %s\n", port.host.c_str(), (unsigned)port.port, (unsigned long)(millis() - started),
|
||||||
|
why[0] ? why : "no connection");
|
||||||
|
}
|
||||||
|
console.printf("tls: %s:%u answered in %lu ms\n", port.host.c_str(), (unsigned)port.port, (unsigned long)(millis() - started));
|
||||||
|
const mbedtls_x509_crt* cert = tls.getPeerCertificate();
|
||||||
|
if (!cert) {
|
||||||
|
tls.stop();
|
||||||
|
return (void)console.println("tls: it showed no certificate");
|
||||||
|
}
|
||||||
|
char dn[200];
|
||||||
|
std::string subject = mbedtls_x509_dn_gets(dn, sizeof dn, &cert->subject) > 0 ? net::certName(dn) : "?";
|
||||||
|
std::string issuer = mbedtls_x509_dn_gets(dn, sizeof dn, &cert->issuer) > 0 ? net::certName(dn) : "?";
|
||||||
|
console.printf("tls: for %s, by %s\n", subject.c_str(), issuer.c_str());
|
||||||
|
const mbedtls_x509_time& from = cert->valid_from;
|
||||||
|
const mbedtls_x509_time& to = cert->valid_to;
|
||||||
|
time_t now = time(nullptr);
|
||||||
|
struct tm today;
|
||||||
|
gmtime_r(&now, &today);
|
||||||
|
bool clock = today.tm_year + 1900 >= 2024;
|
||||||
|
int left = net::daysBetween(today.tm_year + 1900, today.tm_mon + 1, today.tm_mday, to.year, to.mon, to.day);
|
||||||
|
console.printf("tls: valid %04d-%02d-%02d to %04d-%02d-%02d", from.year, from.mon, from.day, to.year, to.mon, to.day);
|
||||||
|
if (!clock) console.println(" (this clock isn't set)");
|
||||||
|
else if (left >= 0) console.printf(", %d days left\n", left);
|
||||||
|
else console.printf(", EXPIRED %d days ago\n", -left);
|
||||||
|
|
||||||
|
mbedtls_x509_crt roots;
|
||||||
|
mbedtls_x509_crt_init(&roots);
|
||||||
|
uint32_t flags = 0;
|
||||||
|
bool parsed = mbedtls_x509_crt_parse(&roots, reinterpret_cast<const unsigned char*>(kTrustedRootsPem), sizeof kTrustedRootsPem) == 0;
|
||||||
|
int verdict = parsed ? mbedtls_x509_crt_verify(const_cast<mbedtls_x509_crt*>(cert), &roots, nullptr, port.host.c_str(), &flags, nullptr, nullptr) : -1;
|
||||||
|
mbedtls_x509_crt_free(&roots);
|
||||||
|
if (verdict == 0) console.println("tls: this device trusts it");
|
||||||
|
else {
|
||||||
|
std::string why;
|
||||||
|
if ((flags & MBEDTLS_X509_BADCERT_EXPIRED) || (clock && left < 0)) why += ", expired";
|
||||||
|
if (flags & MBEDTLS_X509_BADCERT_FUTURE) why += ", not valid yet";
|
||||||
|
if (flags & MBEDTLS_X509_BADCERT_CN_MISMATCH) why += ", not for that name";
|
||||||
|
if (flags & MBEDTLS_X509_BADCERT_NOT_TRUSTED) why += ", not signed by a root this device has";
|
||||||
|
if (why.empty()) why = ", it doesn't check out";
|
||||||
|
console.printf("tls: NOT trusted here: %s\n", why.c_str() + 2);
|
||||||
|
}
|
||||||
|
uint8_t sha[32];
|
||||||
|
if (tls.getFingerprintSHA256(sha)) {
|
||||||
|
char hex[65];
|
||||||
|
for (int i = 0; i < 32; i++) std::snprintf(hex + i * 2, 3, "%02x", sha[i]);
|
||||||
|
console.printf("tls: sha256 %s\n", hex);
|
||||||
|
}
|
||||||
|
tls.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asks a time server and compares with this device's clock, allowing for half the round trip.
|
||||||
|
void NetTools::Job::runNtp() {
|
||||||
|
uint32_t to;
|
||||||
|
if (!resolve(port.host, to)) return (void)console.printf("ntp: %s doesn't resolve\n", port.host.c_str());
|
||||||
|
int s = lwip_socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
if (s < 0) return (void)console.println("ntp: error no socket");
|
||||||
|
uint8_t packet[net::kNtpPacket];
|
||||||
|
net::buildNtpRequest(packet);
|
||||||
|
struct sockaddr_in dest = {};
|
||||||
|
dest.sin_family = AF_INET;
|
||||||
|
dest.sin_port = lwip_htons(123);
|
||||||
|
dest.sin_addr.s_addr = to;
|
||||||
|
uint32_t sent = micros();
|
||||||
|
net::NtpAnswer answer;
|
||||||
|
bool got = false;
|
||||||
|
struct timeval own = {};
|
||||||
|
if (lwip_sendto(s, packet, sizeof packet, 0, reinterpret_cast<struct sockaddr*>(&dest), sizeof dest) >= 0) {
|
||||||
|
while (!got && !stopped() && (micros() - sent) / 1000 < kDnsWaitMs) {
|
||||||
|
waitMs(s, 200);
|
||||||
|
int n = lwip_recv(s, packet, sizeof packet, 0);
|
||||||
|
if (n <= 0) continue;
|
||||||
|
gettimeofday(&own, nullptr);
|
||||||
|
got = net::parseNtpAnswer(packet, static_cast<size_t>(n), answer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uint32_t tripMs = (micros() - sent) / 1000;
|
||||||
|
lwip_close(s);
|
||||||
|
if (!got) return (void)console.printf("ntp: no answer from %s (%s) in %lu s\n", port.host.c_str(), text(to).c_str(), (unsigned long)(kDnsWaitMs / 1000));
|
||||||
|
console.printf("ntp: %s (%s), stratum %d, %lu ms away\n", port.host.c_str(), text(to).c_str(), answer.stratum, (unsigned long)tripMs);
|
||||||
|
int64_t ownMs = static_cast<int64_t>(own.tv_sec) * 1000 + own.tv_usec / 1000, serverMs = answer.seconds * 1000 + answer.millis + tripMs / 2;
|
||||||
|
if (own.tv_sec < 1700000000) console.println("ntp: this clock isn't set");
|
||||||
|
else console.printf("ntp: this clock is %s\n", net::clockOffset(ownMs, serverMs).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
void NetTools::task(void* arg) {
|
void NetTools::task(void* arg) {
|
||||||
Job* job = static_cast<Job*>(arg);
|
Job* job = static_cast<Job*>(arg);
|
||||||
{
|
{
|
||||||
@@ -232,6 +340,8 @@ void NetTools::task(void* arg) {
|
|||||||
case Job::Kind::Trace: job->runTrace(); break;
|
case Job::Kind::Trace: job->runTrace(); break;
|
||||||
case Job::Kind::Port: job->runPort(); break;
|
case Job::Kind::Port: job->runPort(); break;
|
||||||
case Job::Kind::Lookup: job->runLookup(); break;
|
case Job::Kind::Lookup: job->runLookup(); break;
|
||||||
|
case Job::Kind::Tls: job->runTls(); break;
|
||||||
|
case Job::Kind::Ntp: job->runNtp(); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NetTools* owner = job->owner;
|
NetTools* owner = job->owner;
|
||||||
@@ -245,7 +355,8 @@ void NetTools::start(Job* job) {
|
|||||||
job->from = console.origin();
|
job->from = console.origin();
|
||||||
stop_ = false;
|
stop_ = false;
|
||||||
busy_ = true;
|
busy_ = true;
|
||||||
if (xTaskCreate(task, "nettool", 6144, job, 1, nullptr) != pdPASS) {
|
// A TLS handshake needs far more stack than a ping.
|
||||||
|
if (xTaskCreate(task, "nettool", job->kind == Job::Kind::Tls ? 12288 : 6144, job, 1, nullptr) != pdPASS) {
|
||||||
busy_ = false;
|
busy_ = false;
|
||||||
delete job;
|
delete job;
|
||||||
console.println("net: error not enough memory for it");
|
console.println("net: error not enough memory for it");
|
||||||
@@ -289,7 +400,23 @@ bool NetTools::command(const std::string& line) {
|
|||||||
if (!found) console.println("arp: nobody heard yet on this network");
|
if (!found) console.println("arp: nobody heard yet on this network");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (name != "ping" && name != "traceroute" && name != "port" && name != "nslookup") return false;
|
if (name == "netstat") {
|
||||||
|
LwipLock lock;
|
||||||
|
for (struct tcp_pcb_listen* p = tcp_listen_pcbs.listen_pcbs; p; p = p->next) {
|
||||||
|
const char* label = net::portLabel(p->local_port, true);
|
||||||
|
console.printf("netstat: tcp %u listens%s%s%s\n", (unsigned)p->local_port, *label ? " (" : "", label, *label ? ")" : "");
|
||||||
|
}
|
||||||
|
for (struct tcp_pcb* p = tcp_active_pcbs; p; p = p->next) {
|
||||||
|
std::string local = IP_IS_V4(&p->local_ip) ? text(ip_2_ip4(&p->local_ip)->addr) : "::", remote = IP_IS_V4(&p->remote_ip) ? text(ip_2_ip4(&p->remote_ip)->addr) : "::";
|
||||||
|
console.printf("netstat: tcp %s:%u - %s:%u\n", local.c_str(), (unsigned)p->local_port, remote.c_str(), (unsigned)p->remote_port);
|
||||||
|
}
|
||||||
|
for (struct udp_pcb* p = udp_pcbs; p; p = p->next) {
|
||||||
|
const char* label = net::portLabel(p->local_port, false);
|
||||||
|
console.printf("netstat: udp %u%s%s%s\n", (unsigned)p->local_port, *label ? " (" : "", label, *label ? ")" : "");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (name != "ping" && name != "traceroute" && name != "port" && name != "nslookup" && name != "tls" && name != "ntp") return false;
|
||||||
std::unique_ptr<Job> job(new Job());
|
std::unique_ptr<Job> job(new Job());
|
||||||
std::string why;
|
std::string why;
|
||||||
if (name == "ping") {
|
if (name == "ping") {
|
||||||
@@ -302,6 +429,15 @@ bool NetTools::command(const std::string& line) {
|
|||||||
} else if (name == "port") {
|
} else if (name == "port") {
|
||||||
job->kind = Job::Kind::Port;
|
job->kind = Job::Kind::Port;
|
||||||
why = net::parsePort(args, job->port);
|
why = net::parsePort(args, job->port);
|
||||||
|
} else if (name == "tls") { // the port may be left out: 443
|
||||||
|
job->kind = Job::Kind::Tls;
|
||||||
|
bool onlyHost = !args.empty() && args.find(' ') == std::string::npos && args.find(':') == std::string::npos;
|
||||||
|
why = net::parsePort(onlyHost ? args + " 443" : args, job->port);
|
||||||
|
if (!why.empty() && why.find("port <") == 0) why = "tls <host> [port]";
|
||||||
|
} else if (name == "ntp") { // the server may be left out: the first one in use
|
||||||
|
job->kind = Job::Kind::Ntp;
|
||||||
|
job->port.host = !args.empty() ? args : ntpServer ? ntpServer() : "";
|
||||||
|
if (job->port.host.empty() || !net::validHost(job->port.host)) why = "ntp [server]";
|
||||||
} else {
|
} else {
|
||||||
job->kind = Job::Kind::Lookup;
|
job->kind = Job::Kind::Lookup;
|
||||||
why = net::parseLookup(args, job->lookup);
|
why = net::parseLookup(args, job->lookup);
|
||||||
|
|||||||
@@ -1,22 +1,25 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "platform/console.h"
|
#include "platform/console.h"
|
||||||
|
|
||||||
namespace roro {
|
namespace roro {
|
||||||
|
|
||||||
// The network troubleshooting commands (issue #90): ping, nslookup, port, traceroute, ifconfig,
|
// The network troubleshooting commands (issue #90): ping, nslookup, port, traceroute, tls, ntp,
|
||||||
// arp. The first four take time, so each runs on a task of its own and prints its lines as they
|
// and ifconfig, arp, netstat. The first six take time, so each runs on a task of its own and
|
||||||
// come, to the console that asked; one at a time, and `cancel` stops it. The other two answer at
|
// prints its lines as they come, to the console that asked; one at a time, and `cancel` stops it.
|
||||||
// once. The packets and their meaning are lib/net/src/net_probe.h, which is host-tested.
|
// The other three answer at once. The packets and their meaning are lib/net/src/net_probe.h, which is host-tested.
|
||||||
class NetTools {
|
class NetTools {
|
||||||
public:
|
public:
|
||||||
// True if `line` was one of its commands (answered, started, or refused with a reason).
|
// True if `line` was one of its commands (answered, started, or refused with a reason).
|
||||||
bool command(const std::string& line);
|
bool command(const std::string& line);
|
||||||
bool busy() const { return busy_; }
|
bool busy() const { return busy_; }
|
||||||
void cancel() { stop_ = true; }
|
void cancel() { stop_ = true; }
|
||||||
|
// The time server `ntp` asks when none is named: the first one in Settings.
|
||||||
|
std::function<std::string()> ntpServer;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Job;
|
struct Job;
|
||||||
|
|||||||
@@ -39,9 +39,8 @@ constexpr float kDeafBelow = -108.0f;
|
|||||||
RadioService* RadioService::instance_ = nullptr;
|
RadioService* RadioService::instance_ = nullptr;
|
||||||
|
|
||||||
RadioService::RadioService() : lock_(xSemaphoreCreateMutex()) {
|
RadioService::RadioService() : lock_(xSemaphoreCreateMutex()) {
|
||||||
const meshtastic::Preset& p = meshtastic::kEu868Presets[0]; // LongFast (Q95)
|
lora::ScanPreset p = lora::scanPreset(lora::kDefaultScanPreset);
|
||||||
config_ = {meshtastic::eu868FrequencyHz(p), p.bwKHz, p.sf, p.cr, meshtastic::kSyncWord, meshtastic::kPreambleLength,
|
config_ = {p.frequencyHz, p.bwKHz, p.sf, p.cr, p.syncWord, p.preamble, p.name};
|
||||||
p.name};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioService::start() {
|
void RadioService::start() {
|
||||||
@@ -334,10 +333,9 @@ RadioService::Config RadioService::config() const {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioService::setPreset(const meshtastic::Preset& p) {
|
void RadioService::setPreset(const lora::ScanPreset& p) {
|
||||||
xSemaphoreTake(lock_, portMAX_DELAY);
|
xSemaphoreTake(lock_, portMAX_DELAY);
|
||||||
config_ = {meshtastic::eu868FrequencyHz(p), p.bwKHz, p.sf, p.cr, meshtastic::kSyncWord, meshtastic::kPreambleLength,
|
config_ = {p.frequencyHz, p.bwKHz, p.sf, p.cr, p.syncWord, p.preamble, p.name};
|
||||||
p.name};
|
|
||||||
xSemaphoreGive(lock_);
|
xSemaphoreGive(lock_);
|
||||||
configChanged_ = true;
|
configChanged_ = true;
|
||||||
wake(kRequest);
|
wake(kRequest);
|
||||||
@@ -374,7 +372,14 @@ void RadioService::tick(uint32_t nowMs) {
|
|||||||
console.printf("lora: #%lu %u B %.1f dBm SNR %.1f dB%s", (unsigned long)p.seq, p.len, p.rx.rssi, p.rx.snr,
|
console.printf("lora: #%lu %u B %.1f dBm SNR %.1f dB%s", (unsigned long)p.seq, p.len, p.rx.rssi, p.rx.snr,
|
||||||
p.crcOk ? "" : " (bad CRC)");
|
p.crcOk ? "" : " (bad CRC)");
|
||||||
meshtastic::PacketHeader h;
|
meshtastic::PacketHeader h;
|
||||||
if (meshtastic::parseHeader(p.data, p.len, h))
|
lora::Protocol protocol = lora::protocolOf(p.rx.syncWord);
|
||||||
|
if (protocol == lora::Protocol::MeshCore && p.crcOk) { // what the Scanner's details show, on one line
|
||||||
|
const char* sep = " | ";
|
||||||
|
for (auto& l : lora::headerLines(p.data, p.len, protocol)) {
|
||||||
|
console.printf("%s%s", sep, l.c_str());
|
||||||
|
sep = "; ";
|
||||||
|
}
|
||||||
|
} else if (protocol == lora::Protocol::Meshtastic && meshtastic::parseHeader(p.data, p.len, h))
|
||||||
console.printf(" | %s > %s, ch 0x%02X, hops %d/%u%s", meshtastic::nodeId(h.from).c_str(),
|
console.printf(" | %s > %s, ch 0x%02X, hops %d/%u%s", meshtastic::nodeId(h.from).c_str(),
|
||||||
meshtastic::nodeId(h.to).c_str(), h.channelHash, h.hopsAway(), h.hopStart(),
|
meshtastic::nodeId(h.to).c_str(), h.channelHash, h.hopsAway(), h.hopStart(),
|
||||||
h.viaMqtt() ? ", via MQTT" : "");
|
h.viaMqtt() ? ", via MQTT" : "");
|
||||||
@@ -400,7 +405,7 @@ void RadioService::printStatus(Print& out) const {
|
|||||||
Counters n = counters();
|
Counters n = counters();
|
||||||
out.printf("radio: %s, %s, antenna switch %s\n", present_ ? "SX1262" : "no radio",
|
out.printf("radio: %s, %s, antenna switch %s\n", present_ ? "SX1262" : "no radio",
|
||||||
tcxo_ > 0 ? "TCXO 1.8 V" : "crystal", expander_ ? "on (expander 0x43 P0)" : "expander missing");
|
tcxo_ > 0 ? "TCXO 1.8 V" : "crystal", expander_ ? "on (expander 0x43 P0)" : "expander missing");
|
||||||
out.printf("radio: %s, %s %.3f MHz, BW %.0f kHz, SF %u, CR 4/%u, sync 0x%02X, preamble %u\n",
|
out.printf("radio: %s, %s %.3f MHz, BW %g kHz, SF %u, CR 4/%u, sync 0x%02X, preamble %u\n",
|
||||||
sweeping_ ? "sweeping" : listening_ ? "listening" : "asleep", c.name, c.frequencyHz / 1e6, c.bandwidthKHz, c.spreadingFactor,
|
sweeping_ ? "sweeping" : listening_ ? "listening" : "asleep", c.name, c.frequencyHz / 1e6, c.bandwidthKHz, c.spreadingFactor,
|
||||||
c.codingRate, c.syncWord, c.preamble);
|
c.codingRate, c.syncWord, c.preamble);
|
||||||
out.printf("radio: clients%s%s%s%s\n", clients_ ? "" : " none", clients_ & App ? " App" : "",
|
out.printf("radio: clients%s%s%s%s\n", clients_ ? "" : " none", clients_ & App ? " App" : "",
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "loratap.h"
|
#include "loratap.h"
|
||||||
#include "meshtastic_presets.h"
|
#include "scan_presets.h"
|
||||||
#include "service.h"
|
#include "service.h"
|
||||||
|
|
||||||
class SX1262;
|
class SX1262;
|
||||||
@@ -74,7 +74,7 @@ class RadioService : public Service {
|
|||||||
bool listening() const { return listening_; }
|
bool listening() const { return listening_; }
|
||||||
void listen(Client client, bool on);
|
void listen(Client client, bool on);
|
||||||
Config config() const;
|
Config config() const;
|
||||||
void setPreset(const meshtastic::Preset& preset);
|
void setPreset(const lora::ScanPreset& preset);
|
||||||
void setConfig(const Config& config); // custom settings (Q95), named "Custom"
|
void setConfig(const Config& config); // custom settings (Q95), named "Custom"
|
||||||
|
|
||||||
uint32_t received() const { return seq_; } // seq of the newest packet
|
uint32_t received() const { return seq_; } // seq of the newest packet
|
||||||
|
|||||||
@@ -0,0 +1,269 @@
|
|||||||
|
#include "services/scp_service.h"
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <SD.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <libssh/libssh.h>
|
||||||
|
|
||||||
|
#include "platform/libssh_util.h"
|
||||||
|
|
||||||
|
namespace roro {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr uint32_t kStack = 20480; // as the SSH Service's
|
||||||
|
constexpr size_t kPiece = 4096;
|
||||||
|
|
||||||
|
std::string baseName(const std::string& path) {
|
||||||
|
size_t slash = path.rfind('/');
|
||||||
|
return slash == std::string::npos ? path : path.substr(slash + 1);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
struct ScpService::Job {
|
||||||
|
ScpService* owner;
|
||||||
|
Console::Origin from;
|
||||||
|
term::ScpArgs args;
|
||||||
|
std::string privateKey, known;
|
||||||
|
|
||||||
|
bool stopped() const { return owner->stop_; }
|
||||||
|
bool onCard(const std::function<void()>& work) { return owner->storage_.runAndWait(work); }
|
||||||
|
void run();
|
||||||
|
bool login(ssh_session s);
|
||||||
|
void upload(ssh_session s);
|
||||||
|
void download(ssh_session s);
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string ScpService::start(const term::ScpArgs& args, bool sshOpen) {
|
||||||
|
if (busy_) return "A copy is running: `cancel` stops it";
|
||||||
|
if (sshOpen) return "An SSH session is open: close it first, there isn't memory for both";
|
||||||
|
if (ESP.getFreeHeap() < kNeedFree) return "Not enough memory: close IRC or a Gemini page";
|
||||||
|
std::string key = settings_.getString(Setting::SshKey);
|
||||||
|
if (!args.upload) {
|
||||||
|
if (std::string why = files_.whyReadOnly(args.local, false); !why.empty()) return why;
|
||||||
|
bool exists = false;
|
||||||
|
if (!storage_.runAndWait([&]() { exists = SD.exists(args.local.c_str()); })) return "The card isn't answering";
|
||||||
|
if (exists && !args.replace) return args.local + " exists already: scp -f replaces it";
|
||||||
|
}
|
||||||
|
auto* job = new Job{this, console.origin(), args, key, term::SshKnownHosts(settings_.getString(Setting::SshKnown)).fingerprintOf(args.target.hostPort())};
|
||||||
|
stop_ = asking_ = answered_ = false;
|
||||||
|
busy_ = true;
|
||||||
|
if (xTaskCreate(task, "scp", kStack, job, 1, nullptr) != pdPASS) {
|
||||||
|
busy_ = false;
|
||||||
|
job->privateKey.assign(job->privateKey.size(), '\0');
|
||||||
|
delete job;
|
||||||
|
return "Not enough memory for it";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScpService::task(void* arg) {
|
||||||
|
Job* job = static_cast<Job*>(arg);
|
||||||
|
{
|
||||||
|
Console::As as(job->from);
|
||||||
|
job->run();
|
||||||
|
}
|
||||||
|
job->privateKey.assign(job->privateKey.size(), '\0');
|
||||||
|
ScpService* owner = job->owner;
|
||||||
|
delete job;
|
||||||
|
owner->busy_ = false;
|
||||||
|
vTaskDelete(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScpService::answer(const std::string& password) {
|
||||||
|
if (!asking_) return;
|
||||||
|
password_ = password;
|
||||||
|
asking_ = false;
|
||||||
|
answered_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This device's key first, then the password, three tries: asked in the Shell that typed the command.
|
||||||
|
bool ScpService::Job::login(ssh_session s) {
|
||||||
|
int rc = ssh_userauth_none(s, nullptr);
|
||||||
|
if (rc == SSH_AUTH_SUCCESS) return true;
|
||||||
|
int methods = ssh_userauth_list(s, nullptr);
|
||||||
|
if (!privateKey.empty() && (methods & SSH_AUTH_METHOD_PUBLICKEY)) {
|
||||||
|
ssh_key key = nullptr;
|
||||||
|
if (ssh_pki_import_privkey_base64(privateKey.c_str(), nullptr, nullptr, nullptr, &key) == SSH_OK) {
|
||||||
|
rc = ssh_userauth_publickey(s, nullptr, key);
|
||||||
|
ssh_key_free(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
privateKey.assign(privateKey.size(), '\0');
|
||||||
|
if (rc == SSH_AUTH_SUCCESS) return true;
|
||||||
|
if (!(methods & (SSH_AUTH_METHOD_PASSWORD | SSH_AUTH_METHOD_INTERACTIVE))) {
|
||||||
|
console.println("scp: error the server takes neither this device's key nor a password");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (from != Console::Origin::Shell) {
|
||||||
|
console.println("scp: error the server doesn't know this device's key, and a password is only asked in the Shell");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int tries = 0; tries < 3 && !stopped(); tries++) {
|
||||||
|
console.printf("scp: %s's password for %s (Back cancels):\n", args.target.user.c_str(), args.target.host.c_str());
|
||||||
|
owner->answered_ = false;
|
||||||
|
owner->asking_ = true;
|
||||||
|
while (!owner->answered_ && !stopped()) vTaskDelay(pdMS_TO_TICKS(50));
|
||||||
|
owner->asking_ = false;
|
||||||
|
if (stopped()) break;
|
||||||
|
std::string password;
|
||||||
|
password.swap(owner->password_);
|
||||||
|
if (methods & SSH_AUTH_METHOD_PASSWORD) rc = ssh_userauth_password(s, nullptr, password.c_str());
|
||||||
|
else { // asked as questions: every one gets the password
|
||||||
|
rc = ssh_userauth_kbdint(s, nullptr, nullptr);
|
||||||
|
for (int round = 0; rc == SSH_AUTH_INFO && round < 4; round++) {
|
||||||
|
int n = ssh_userauth_kbdint_getnprompts(s);
|
||||||
|
for (int i = 0; i < n; i++) ssh_userauth_kbdint_setanswer(s, static_cast<unsigned>(i), password.c_str());
|
||||||
|
rc = ssh_userauth_kbdint(s, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
password.assign(password.size(), '\0');
|
||||||
|
if (rc == SSH_AUTH_SUCCESS) return true;
|
||||||
|
if (rc == SSH_AUTH_ERROR) break;
|
||||||
|
console.println("scp: wrong password");
|
||||||
|
}
|
||||||
|
console.println(stopped() ? "scp: stopped" : "scp: error not logged in");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScpService::Job::run() {
|
||||||
|
sshutil::startLibrary();
|
||||||
|
ssh_session s = ssh_new();
|
||||||
|
if (!s) return (void)console.println("scp: error not enough memory");
|
||||||
|
int verbosity = SSH_LOG_NOLOG, port = args.target.port;
|
||||||
|
long timeout = 10;
|
||||||
|
ssh_options_set(s, SSH_OPTIONS_HOST, args.target.host.c_str());
|
||||||
|
ssh_options_set(s, SSH_OPTIONS_PORT, &port);
|
||||||
|
ssh_options_set(s, SSH_OPTIONS_USER, args.target.user.c_str());
|
||||||
|
ssh_options_set(s, SSH_OPTIONS_TIMEOUT, &timeout);
|
||||||
|
ssh_options_set(s, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
|
||||||
|
if (ssh_connect(s) != SSH_OK) {
|
||||||
|
console.printf("scp: error no connection to %s: %s\n", args.target.hostPort().c_str(), ssh_get_error(s));
|
||||||
|
} else if (known.empty()) {
|
||||||
|
console.printf("scp: error %s is not a server this device trusts yet: connect with the SSH App once\n", args.target.hostPort().c_str());
|
||||||
|
} else if (sshutil::fingerprintOf(s) != known) {
|
||||||
|
console.printf("scp: error %s showed a different key than the one remembered: not connected\n", args.target.hostPort().c_str());
|
||||||
|
} else if (login(s)) {
|
||||||
|
if (args.upload) upload(s);
|
||||||
|
else download(s);
|
||||||
|
}
|
||||||
|
ssh_disconnect(s);
|
||||||
|
ssh_free(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScpService::Job::upload(ssh_session s) {
|
||||||
|
// The remote path is where the file goes; the name pushed is only used if that is a folder.
|
||||||
|
ssh_scp scp = ssh_scp_new(s, SSH_SCP_WRITE, args.remote.c_str());
|
||||||
|
if (!scp || ssh_scp_init(scp) != SSH_OK) {
|
||||||
|
console.printf("scp: error %s\n", ssh_get_error(s));
|
||||||
|
if (scp) ssh_scp_free(scp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
File f;
|
||||||
|
size_t size = 0;
|
||||||
|
bool opened = onCard([&]() {
|
||||||
|
f = SD.open(args.local.c_str());
|
||||||
|
if (f && !f.isDirectory()) size = f.size();
|
||||||
|
else if (f) f.close();
|
||||||
|
});
|
||||||
|
if (!opened || !f) {
|
||||||
|
console.printf("scp: error cannot read %s\n", args.local.c_str());
|
||||||
|
ssh_scp_close(scp);
|
||||||
|
ssh_scp_free(scp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.printf("scp: %s (%u bytes) to %s:%s\n", args.local.c_str(), (unsigned)size, args.target.text().c_str(), args.remote.c_str());
|
||||||
|
bool ok = ssh_scp_push_file(scp, baseName(args.local).c_str(), size, 0644) == SSH_OK;
|
||||||
|
uint8_t buf[kPiece];
|
||||||
|
uint32_t started = millis();
|
||||||
|
size_t sent = 0;
|
||||||
|
while (ok && sent < size && !stopped()) {
|
||||||
|
int n = 0;
|
||||||
|
onCard([&]() { n = f.read(buf, std::min(sizeof buf, size - sent)); });
|
||||||
|
if (n <= 0) {
|
||||||
|
console.printf("scp: error the card stopped reading at %u of %u\n", (unsigned)sent, (unsigned)size);
|
||||||
|
ok = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ssh_scp_write(scp, buf, static_cast<size_t>(n)) != SSH_OK) {
|
||||||
|
console.printf("scp: error %s\n", ssh_get_error(s));
|
||||||
|
ok = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sent += static_cast<size_t>(n);
|
||||||
|
}
|
||||||
|
onCard([&]() { f.close(); });
|
||||||
|
if (ok && stopped()) console.printf("scp: stopped at %u of %u bytes\n", (unsigned)sent, (unsigned)size);
|
||||||
|
else if (ok) console.printf("scp: sent %u bytes in %lu ms\n", (unsigned)sent, (unsigned long)(millis() - started));
|
||||||
|
else if (!ok && sent == 0) console.printf("scp: error the server refused it: %s\n", ssh_get_error(s));
|
||||||
|
ssh_scp_close(scp);
|
||||||
|
ssh_scp_free(scp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScpService::Job::download(ssh_session s) {
|
||||||
|
ssh_scp scp = ssh_scp_new(s, SSH_SCP_READ, args.remote.c_str());
|
||||||
|
if (!scp || ssh_scp_init(scp) != SSH_OK) {
|
||||||
|
console.printf("scp: error %s\n", ssh_get_error(s));
|
||||||
|
if (scp) ssh_scp_free(scp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Into a part file, renamed once it is all there: a failure never leaves half a file under the real name.
|
||||||
|
std::string part = args.local + ".part";
|
||||||
|
File f;
|
||||||
|
bool ok = false;
|
||||||
|
size_t got = 0, size = 0;
|
||||||
|
uint32_t started = millis();
|
||||||
|
if (ssh_scp_pull_request(scp) != SSH_SCP_REQUEST_NEWFILE) {
|
||||||
|
const char* why = ssh_get_error(s);
|
||||||
|
console.printf("scp: error %s\n", why && *why ? why : "that isn't a plain file: scp copies one file");
|
||||||
|
} else {
|
||||||
|
size = static_cast<size_t>(ssh_scp_request_get_size64(scp));
|
||||||
|
ssh_scp_accept_request(scp);
|
||||||
|
console.printf("scp: %s:%s (%u bytes) to %s\n", args.target.text().c_str(), args.remote.c_str(), (unsigned)size, args.local.c_str());
|
||||||
|
bool opened = false;
|
||||||
|
onCard([&]() {
|
||||||
|
size_t slash = args.local.rfind('/');
|
||||||
|
if (slash > 0 && !SD.exists(args.local.substr(0, slash).c_str())) SD.mkdir(args.local.substr(0, slash).c_str());
|
||||||
|
if (SD.exists(part.c_str())) SD.remove(part.c_str());
|
||||||
|
f = SD.open(part.c_str(), FILE_WRITE);
|
||||||
|
opened = static_cast<bool>(f);
|
||||||
|
});
|
||||||
|
if (!opened) console.printf("scp: error cannot write %s\n", args.local.c_str());
|
||||||
|
ok = opened;
|
||||||
|
uint8_t buf[kPiece];
|
||||||
|
while (ok && got < size && !stopped()) {
|
||||||
|
int n = ssh_scp_read(scp, buf, std::min(sizeof buf, size - got));
|
||||||
|
if (n <= 0) {
|
||||||
|
console.printf("scp: error the connection ended at %u of %u bytes\n", (unsigned)got, (unsigned)size);
|
||||||
|
ok = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
size_t written = 0;
|
||||||
|
onCard([&]() { written = f.write(buf, static_cast<size_t>(n)); });
|
||||||
|
if (written != static_cast<size_t>(n)) {
|
||||||
|
console.println("scp: error the card refused the write: is it full?");
|
||||||
|
ok = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
got += static_cast<size_t>(n);
|
||||||
|
}
|
||||||
|
if (ok && got < size) ok = false, console.printf("scp: stopped at %u of %u bytes\n", (unsigned)got, (unsigned)size);
|
||||||
|
}
|
||||||
|
bool renamed = false;
|
||||||
|
onCard([&]() {
|
||||||
|
if (f) f.close();
|
||||||
|
if (ok) {
|
||||||
|
if (SD.exists(args.local.c_str())) SD.remove(args.local.c_str());
|
||||||
|
renamed = SD.rename(part.c_str(), args.local.c_str());
|
||||||
|
} else if (SD.exists(part.c_str())) {
|
||||||
|
SD.remove(part.c_str());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (ok && !renamed) console.println("scp: error the card refused the new name");
|
||||||
|
else if (ok) console.printf("scp: received %u bytes in %lu ms\n", (unsigned)got, (unsigned long)(millis() - started));
|
||||||
|
ssh_scp_close(scp);
|
||||||
|
ssh_scp_free(scp);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace roro
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "platform/console.h"
|
||||||
|
#include "scp_args.h"
|
||||||
|
#include "services/file_ops.h"
|
||||||
|
#include "services/storage_service.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
|
namespace roro {
|
||||||
|
|
||||||
|
// `scp`: one file between the card and a server, over SSH (libssh's SCP), on a task of its own that
|
||||||
|
// prints to the console that asked. It logs in with this device's key and, if the server doesn't
|
||||||
|
// know it, asks for the password: but only when the command was typed in the Shell, which draws
|
||||||
|
// the question masked (asking(), answer()). It goes only to servers the SSH App has already been
|
||||||
|
// told to trust. One at a time, and not while an SSH session is open (they don't fit in memory
|
||||||
|
// together).
|
||||||
|
class ScpService {
|
||||||
|
public:
|
||||||
|
static constexpr size_t kNeedFree = 75 * 1024;
|
||||||
|
|
||||||
|
ScpService(Settings& settings, StorageService& storage, FileOps& files) : settings_(settings), storage_(storage), files_(files) {}
|
||||||
|
|
||||||
|
// "" when it started, or why not.
|
||||||
|
std::string start(const term::ScpArgs& args, bool sshOpen);
|
||||||
|
void cancel() {
|
||||||
|
stop_ = true;
|
||||||
|
asking_ = false;
|
||||||
|
answered_ = true; // whatever it was waiting for
|
||||||
|
}
|
||||||
|
bool busy() const { return busy_; }
|
||||||
|
// The password is wanted (for user@host, in `who`); the Shell calls answer() with what was typed.
|
||||||
|
bool asking() const { return asking_; }
|
||||||
|
void answer(const std::string& password);
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Job;
|
||||||
|
static void task(void* arg);
|
||||||
|
|
||||||
|
Settings& settings_;
|
||||||
|
StorageService& storage_;
|
||||||
|
FileOps& files_;
|
||||||
|
std::atomic<bool> busy_{false}, stop_{false}, asking_{false}, answered_{false};
|
||||||
|
std::string password_; // written by answer() before answered_ is set, read by the task after
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace roro
|
||||||
@@ -0,0 +1,346 @@
|
|||||||
|
#include "services/ssh_service.h"
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include <libssh_esp32.h>
|
||||||
|
#include <libssh/libssh.h>
|
||||||
|
|
||||||
|
#include "platform/libssh_util.h"
|
||||||
|
|
||||||
|
namespace roro {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr uint32_t kStack = 20480; // a session used 13 KB of it at most (measured)
|
||||||
|
constexpr int kPasswordTries = 3;
|
||||||
|
|
||||||
|
struct Locked {
|
||||||
|
explicit Locked(void* lock) : lock_(static_cast<SemaphoreHandle_t>(lock)) { xSemaphoreTake(lock_, portMAX_DELAY); }
|
||||||
|
~Locked() { xSemaphoreGive(lock_); }
|
||||||
|
SemaphoreHandle_t lock_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
struct SshService::Run {
|
||||||
|
SshService* service;
|
||||||
|
std::string host, user, privateKey, known;
|
||||||
|
int port, cols, rows;
|
||||||
|
};
|
||||||
|
|
||||||
|
SshService::SshService(Settings& settings) : settings_(settings), lock_(xSemaphoreCreateMutex()) {}
|
||||||
|
|
||||||
|
std::string SshService::status() const {
|
||||||
|
Locked l(lock_);
|
||||||
|
return status_;
|
||||||
|
}
|
||||||
|
std::string SshService::fingerprint() const {
|
||||||
|
Locked l(lock_);
|
||||||
|
return fingerprint_;
|
||||||
|
}
|
||||||
|
std::string SshService::remembered() const {
|
||||||
|
Locked l(lock_);
|
||||||
|
return remembered_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshService::say(const std::string& what) {
|
||||||
|
Locked l(lock_);
|
||||||
|
status_ = what;
|
||||||
|
revision_++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshService::end(const std::string& why) {
|
||||||
|
{
|
||||||
|
Locked l(lock_);
|
||||||
|
status_ = why;
|
||||||
|
password_.assign(password_.size(), '\0');
|
||||||
|
password_.clear();
|
||||||
|
outgoing_.clear();
|
||||||
|
}
|
||||||
|
state_ = State::Ended;
|
||||||
|
revision_++;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SshService::connect(const term::SshTarget& target, int cols, int rows) {
|
||||||
|
if (running_) return "A session is still closing: a moment";
|
||||||
|
if (ESP.getFreeHeap() < kNeedFree) return "Not enough memory: close IRC or a Gemini page";
|
||||||
|
target_ = target;
|
||||||
|
{
|
||||||
|
Locked l(lock_);
|
||||||
|
term_.reset(new term::Terminal(cols, rows, kHistory));
|
||||||
|
term_->reply = [this](const std::string& s) { outgoing_ += s; }; // called with the lock held, from feed()
|
||||||
|
status_ = "Connecting to " + target.host;
|
||||||
|
fingerprint_.clear();
|
||||||
|
remembered_.clear();
|
||||||
|
outgoing_.clear();
|
||||||
|
resized_ = false;
|
||||||
|
}
|
||||||
|
stop_ = answered_ = trusted_ = opened_ = false;
|
||||||
|
auto* run = new Run{this, target.host, target.user, settings_.getString(Setting::SshKey),
|
||||||
|
term::SshKnownHosts(settings_.getString(Setting::SshKnown)).fingerprintOf(target.hostPort()), target.port, cols, rows};
|
||||||
|
state_ = State::Connecting;
|
||||||
|
running_ = true;
|
||||||
|
if (xTaskCreate(task, "ssh", kStack, run, 1, nullptr) != pdPASS) {
|
||||||
|
running_ = false;
|
||||||
|
delete run;
|
||||||
|
end("Not enough memory for the session");
|
||||||
|
return "Not enough memory for the session";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshService::clear() {
|
||||||
|
if (state_ != State::Ended || running_) return;
|
||||||
|
Locked l(lock_);
|
||||||
|
term_.reset();
|
||||||
|
status_.clear();
|
||||||
|
state_ = State::Idle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshService::disconnect() {
|
||||||
|
stop_ = true;
|
||||||
|
answered_ = true; // whatever it was waiting for
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshService::answerTrust(bool yes) {
|
||||||
|
if (state_ != State::AskTrust) return;
|
||||||
|
if (yes) { // remembered from here on; on the main loop, where settings are written
|
||||||
|
term::SshKnownHosts known(settings_.getString(Setting::SshKnown));
|
||||||
|
known.remember(target_.hostPort(), fingerprint());
|
||||||
|
settings_.setString(Setting::SshKnown, known.stored());
|
||||||
|
}
|
||||||
|
trusted_ = yes;
|
||||||
|
answered_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshService::answerPassword(const std::string& password) {
|
||||||
|
if (state_ != State::AskPassword) return;
|
||||||
|
{
|
||||||
|
Locked l(lock_);
|
||||||
|
password_ = password;
|
||||||
|
}
|
||||||
|
answered_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshService::withTerminal(const std::function<void(term::Terminal&)>& use) {
|
||||||
|
Locked l(lock_);
|
||||||
|
if (term_) use(*term_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshService::send(const std::string& bytes) {
|
||||||
|
if (state_ != State::Open) return;
|
||||||
|
Locked l(lock_);
|
||||||
|
if (outgoing_.size() < 4096) outgoing_ += bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshService::resize(int cols, int rows) {
|
||||||
|
Locked l(lock_);
|
||||||
|
if (term_) term_->resize(cols, rows);
|
||||||
|
wantCols_ = cols;
|
||||||
|
wantRows_ = rows;
|
||||||
|
resized_ = true;
|
||||||
|
revision_++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshService::task(void* arg) {
|
||||||
|
std::unique_ptr<Run> run(static_cast<Run*>(arg));
|
||||||
|
SshService* self = run->service;
|
||||||
|
self->session(*run);
|
||||||
|
run.reset();
|
||||||
|
self->running_ = false;
|
||||||
|
vTaskDelete(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SshService::session(Run& run) {
|
||||||
|
sshutil::startLibrary();
|
||||||
|
ssh_session s = ssh_new();
|
||||||
|
if (!s) return end("Not enough memory for the session");
|
||||||
|
int verbosity = SSH_LOG_NOLOG;
|
||||||
|
long timeout = 10;
|
||||||
|
ssh_options_set(s, SSH_OPTIONS_HOST, run.host.c_str());
|
||||||
|
ssh_options_set(s, SSH_OPTIONS_PORT, &run.port);
|
||||||
|
ssh_options_set(s, SSH_OPTIONS_USER, run.user.c_str());
|
||||||
|
ssh_options_set(s, SSH_OPTIONS_TIMEOUT, &timeout);
|
||||||
|
ssh_options_set(s, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
|
||||||
|
auto fail = [&](const std::string& what) {
|
||||||
|
std::string why = what;
|
||||||
|
const char* detail = ssh_get_error(s);
|
||||||
|
if (detail && *detail && what.back() == ':') {
|
||||||
|
// lwIP reports a refused connection as one reset by the peer.
|
||||||
|
std::string d = detail;
|
||||||
|
if (d.find("reset by peer") != std::string::npos || d.find("refused") != std::string::npos) why = "Nothing listens there: the connection was refused";
|
||||||
|
else if (d.find("imeout") != std::string::npos || d.find("timed out") != std::string::npos) why = "No answer from " + run.host;
|
||||||
|
else why += " " + d;
|
||||||
|
}
|
||||||
|
ssh_disconnect(s);
|
||||||
|
ssh_free(s);
|
||||||
|
end(why);
|
||||||
|
};
|
||||||
|
auto waitForAnswer = [&]() {
|
||||||
|
while (!answered_ && !stop_) vTaskDelay(pdMS_TO_TICKS(50));
|
||||||
|
answered_ = false;
|
||||||
|
return !stop_;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (ssh_connect(s) != SSH_OK) return fail("No connection:");
|
||||||
|
if (stop_) return fail("Stopped");
|
||||||
|
|
||||||
|
// Is it the server it was last time? The first time, and when it has changed, the user decides.
|
||||||
|
std::string seen = sshutil::fingerprintOf(s);
|
||||||
|
if (seen.empty()) return fail("The server showed no key");
|
||||||
|
if (seen != run.known) {
|
||||||
|
{
|
||||||
|
Locked l(lock_);
|
||||||
|
fingerprint_ = seen;
|
||||||
|
remembered_ = run.known;
|
||||||
|
}
|
||||||
|
say("Is this the right server?");
|
||||||
|
state_ = State::AskTrust;
|
||||||
|
revision_++;
|
||||||
|
if (!waitForAnswer() || !trusted_) return fail(stop_ ? "Stopped" : "Not trusted: not connected");
|
||||||
|
state_ = State::Connecting;
|
||||||
|
}
|
||||||
|
say("Logging in as " + run.user);
|
||||||
|
|
||||||
|
// This device's key first, if it has one and the server takes keys; then a password.
|
||||||
|
int rc = ssh_userauth_none(s, nullptr);
|
||||||
|
int methods = ssh_userauth_list(s, nullptr);
|
||||||
|
if (rc != SSH_AUTH_SUCCESS && !run.privateKey.empty() && (methods & SSH_AUTH_METHOD_PUBLICKEY)) {
|
||||||
|
ssh_key key = nullptr;
|
||||||
|
if (ssh_pki_import_privkey_base64(run.privateKey.c_str(), nullptr, nullptr, nullptr, &key) == SSH_OK) {
|
||||||
|
rc = ssh_userauth_publickey(s, nullptr, key);
|
||||||
|
ssh_key_free(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
run.privateKey.assign(run.privateKey.size(), '\0');
|
||||||
|
for (int tries = 0; rc != SSH_AUTH_SUCCESS && tries < kPasswordTries; tries++) {
|
||||||
|
if (!(methods & (SSH_AUTH_METHOD_PASSWORD | SSH_AUTH_METHOD_INTERACTIVE))) return fail("The server takes neither this key nor a password");
|
||||||
|
say(tries ? "Wrong password" : "");
|
||||||
|
state_ = State::AskPassword;
|
||||||
|
revision_++;
|
||||||
|
if (!waitForAnswer()) return fail("Stopped");
|
||||||
|
state_ = State::Connecting;
|
||||||
|
say("Logging in as " + run.user);
|
||||||
|
std::string password;
|
||||||
|
{
|
||||||
|
Locked l(lock_);
|
||||||
|
password.swap(password_);
|
||||||
|
}
|
||||||
|
if (methods & SSH_AUTH_METHOD_PASSWORD) rc = ssh_userauth_password(s, nullptr, password.c_str());
|
||||||
|
else { // asked as questions: every one that hides its answer gets the password
|
||||||
|
rc = ssh_userauth_kbdint(s, nullptr, nullptr);
|
||||||
|
for (int round = 0; rc == SSH_AUTH_INFO && round < 4; round++) {
|
||||||
|
int n = ssh_userauth_kbdint_getnprompts(s);
|
||||||
|
for (int i = 0; i < n; i++) ssh_userauth_kbdint_setanswer(s, static_cast<unsigned>(i), password.c_str());
|
||||||
|
rc = ssh_userauth_kbdint(s, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
password.assign(password.size(), '\0');
|
||||||
|
if (rc == SSH_AUTH_ERROR) return fail("Login failed:");
|
||||||
|
}
|
||||||
|
if (rc != SSH_AUTH_SUCCESS) return fail("Wrong password, three times");
|
||||||
|
|
||||||
|
ssh_channel ch = ssh_channel_new(s);
|
||||||
|
int cols, rows;
|
||||||
|
{
|
||||||
|
Locked l(lock_);
|
||||||
|
cols = resized_ ? wantCols_ : run.cols;
|
||||||
|
rows = resized_ ? wantRows_ : run.rows;
|
||||||
|
resized_ = false;
|
||||||
|
}
|
||||||
|
if (!ch || ssh_channel_open_session(ch) != SSH_OK || ssh_channel_request_pty_size(ch, "xterm", cols, rows) != SSH_OK ||
|
||||||
|
ssh_channel_request_shell(ch) != SSH_OK) {
|
||||||
|
if (ch) ssh_channel_free(ch);
|
||||||
|
return fail("No shell:");
|
||||||
|
}
|
||||||
|
say("");
|
||||||
|
opened_ = true;
|
||||||
|
state_ = State::Open;
|
||||||
|
revision_++;
|
||||||
|
|
||||||
|
std::string why = "The session ended";
|
||||||
|
uint8_t buf[512];
|
||||||
|
while (!stop_) {
|
||||||
|
int waiting = ssh_channel_poll_timeout(ch, 20, 0); // also where it sleeps when nothing happens
|
||||||
|
if (waiting == SSH_ERROR || waiting == SSH_EOF) break;
|
||||||
|
bool busy = false;
|
||||||
|
for (int std_err = 0; std_err < 2; std_err++) {
|
||||||
|
int n = ssh_channel_read_nonblocking(ch, buf, sizeof buf, std_err);
|
||||||
|
if (n > 0) {
|
||||||
|
Locked l(lock_);
|
||||||
|
term_->feed(buf, static_cast<size_t>(n));
|
||||||
|
revision_++;
|
||||||
|
busy = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::string out;
|
||||||
|
int newCols = 0, newRows = 0;
|
||||||
|
{
|
||||||
|
Locked l(lock_);
|
||||||
|
out.swap(outgoing_);
|
||||||
|
if (resized_) {
|
||||||
|
newCols = wantCols_;
|
||||||
|
newRows = wantRows_;
|
||||||
|
resized_ = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (newCols) ssh_channel_change_pty_size(ch, newCols, newRows);
|
||||||
|
if (!out.empty() && ssh_channel_write(ch, out.data(), static_cast<uint32_t>(out.size())) < 0) {
|
||||||
|
why = "The connection was lost";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ssh_channel_is_eof(ch) || !ssh_channel_is_open(ch)) break;
|
||||||
|
if (!ssh_is_connected(s)) {
|
||||||
|
why = "The connection was lost";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!busy && out.empty()) vTaskDelay(pdMS_TO_TICKS(5));
|
||||||
|
}
|
||||||
|
if (stop_) why = "Disconnected";
|
||||||
|
ssh_channel_close(ch);
|
||||||
|
ssh_channel_free(ch);
|
||||||
|
ssh_disconnect(s);
|
||||||
|
ssh_free(s);
|
||||||
|
end(why);
|
||||||
|
}
|
||||||
|
|
||||||
|
// On a task of its own for its stack; the main loop waits the moment it takes.
|
||||||
|
std::string SshService::makeKey() {
|
||||||
|
struct Made {
|
||||||
|
std::string priv, pub, why;
|
||||||
|
std::atomic<bool> done{false};
|
||||||
|
};
|
||||||
|
auto made = std::make_shared<Made>();
|
||||||
|
auto* arg = new std::shared_ptr<Made>(made);
|
||||||
|
auto work = [](void* p) {
|
||||||
|
std::shared_ptr<Made> m = *static_cast<std::shared_ptr<Made>*>(p);
|
||||||
|
delete static_cast<std::shared_ptr<Made>*>(p);
|
||||||
|
sshutil::startLibrary();
|
||||||
|
ssh_key key = nullptr, pub = nullptr;
|
||||||
|
char *b64 = nullptr, *pub64 = nullptr;
|
||||||
|
if (ssh_pki_generate(SSH_KEYTYPE_ED25519, 0, &key) != SSH_OK) m->why = "The key couldn't be made";
|
||||||
|
else if (ssh_pki_export_privkey_base64(key, nullptr, nullptr, nullptr, &b64) != SSH_OK || ssh_pki_export_privkey_to_pubkey(key, &pub) != SSH_OK ||
|
||||||
|
ssh_pki_export_pubkey_base64(pub, &pub64) != SSH_OK)
|
||||||
|
m->why = "The key couldn't be written out";
|
||||||
|
else {
|
||||||
|
m->priv = b64;
|
||||||
|
m->pub = std::string("ssh-ed25519 ") + pub64 + " roro9stack";
|
||||||
|
}
|
||||||
|
if (b64) ssh_string_free_char(b64);
|
||||||
|
if (pub64) ssh_string_free_char(pub64);
|
||||||
|
if (pub) ssh_key_free(pub);
|
||||||
|
if (key) ssh_key_free(key);
|
||||||
|
m->done = true;
|
||||||
|
vTaskDelete(nullptr);
|
||||||
|
};
|
||||||
|
if (xTaskCreate(work, "sshkey", 16384, arg, 1, nullptr) != pdPASS) {
|
||||||
|
delete arg;
|
||||||
|
return "Not enough memory to make a key";
|
||||||
|
}
|
||||||
|
for (int waited = 0; !made->done && waited < 10000; waited += 20) delay(20);
|
||||||
|
if (!made->done) return "Making the key took too long";
|
||||||
|
if (!made->why.empty()) return made->why;
|
||||||
|
if (!settings_.setString(Setting::SshKey, made->priv) || !settings_.setString(Setting::SshPublic, made->pub)) return "The key couldn't be stored";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace roro
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "event_bus.h"
|
||||||
|
#include "settings.h"
|
||||||
|
#include "ssh_hosts.h"
|
||||||
|
#include "terminal.h"
|
||||||
|
|
||||||
|
namespace roro {
|
||||||
|
|
||||||
|
// One SSH session to a shell (issue #2, docs/milestones/N1.md): the protocol is libssh's, on a
|
||||||
|
// task of its own; what it prints goes into a term::Terminal, which the SSH App draws. The
|
||||||
|
// session lasts until the far end closes it or disconnect() is called, whether the App is in
|
||||||
|
// front or not.
|
||||||
|
//
|
||||||
|
// The task and the main loop share the terminal, the bytes waiting to be sent and the state,
|
||||||
|
// under one lock. Questions for the user (is this the right server? what is the password?) are
|
||||||
|
// states the task waits in until the App answers.
|
||||||
|
class SshService {
|
||||||
|
public:
|
||||||
|
enum class State { Idle, Connecting, AskTrust, AskPassword, Open, Ended };
|
||||||
|
static constexpr size_t kNeedFree = 75 * 1024; // a session peaks at about 63 KB (measured)
|
||||||
|
static constexpr int kHistory = 100;
|
||||||
|
|
||||||
|
explicit SshService(Settings& settings);
|
||||||
|
|
||||||
|
// "" when the connection is on its way, or why not.
|
||||||
|
std::string connect(const term::SshTarget& target, int cols, int rows);
|
||||||
|
void disconnect(); // from any state; the terminal stays to be read until the next connect
|
||||||
|
void clear(); // Ended, and read: the terminal and its history are given back
|
||||||
|
State state() const { return state_; }
|
||||||
|
bool active() const { return state_ == State::Open; } // for the Status Bar
|
||||||
|
bool opened() const { return opened_; } // this session got as far as a shell
|
||||||
|
std::string status() const; // what it is doing, or why it ended
|
||||||
|
const term::SshTarget& target() const { return target_; }
|
||||||
|
|
||||||
|
// AskTrust: the server's fingerprint, and the one remembered if this is a different one.
|
||||||
|
std::string fingerprint() const;
|
||||||
|
std::string remembered() const;
|
||||||
|
void answerTrust(bool yes);
|
||||||
|
// AskPassword.
|
||||||
|
void answerPassword(const std::string& password);
|
||||||
|
|
||||||
|
// Open (and Ended, to read what is left).
|
||||||
|
bool hasTerminal() const { return static_cast<bool>(term_); }
|
||||||
|
void withTerminal(const std::function<void(term::Terminal&)>& use);
|
||||||
|
uint32_t revision() const { return revision_; }
|
||||||
|
void send(const std::string& bytes);
|
||||||
|
void resize(int cols, int rows);
|
||||||
|
|
||||||
|
// This device's own key: made once, its public half is what goes on servers.
|
||||||
|
bool hasKey() const { return !settings_.getString(Setting::SshKey).empty(); }
|
||||||
|
std::string publicKey() const { return settings_.getString(Setting::SshPublic); }
|
||||||
|
std::string makeKey(); // "" or why not
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Run; // what one connection's task works with
|
||||||
|
static void task(void* arg);
|
||||||
|
void session(Run& run);
|
||||||
|
void end(const std::string& why);
|
||||||
|
void say(const std::string& what);
|
||||||
|
|
||||||
|
Settings& settings_;
|
||||||
|
void* lock_; // SemaphoreHandle_t
|
||||||
|
std::atomic<State> state_{State::Idle};
|
||||||
|
std::atomic<bool> stop_{false}, answered_{false}, trusted_{false}, running_{false}, opened_{false};
|
||||||
|
std::atomic<uint32_t> revision_{0};
|
||||||
|
term::SshTarget target_;
|
||||||
|
std::unique_ptr<term::Terminal> term_;
|
||||||
|
std::string status_, fingerprint_, remembered_, password_, outgoing_;
|
||||||
|
int wantCols_ = 0, wantRows_ = 0;
|
||||||
|
bool resized_ = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace roro
|
||||||
@@ -221,4 +221,202 @@ const uint8_t _5x8_tf[1715] =
|
|||||||
"\3\374\11\64b\23\63\212f\32\375\13D^[\343(\323\210I\1\376\12<^\223\363\212#\345\14\377"
|
"\3\374\11\64b\23\63\212f\32\375\13D^[\343(\323\210I\1\376\12<^\223\363\212#\345\14\377"
|
||||||
"\14<^\23\63\212\62\215\230\24\0\0\0\0\4\377\377\0";
|
"\14<^\23\63\212\62\215\230\24\0\0\0\0\4\377\377\0";
|
||||||
|
|
||||||
|
// For the terminal (issue #2): three more sizes of the same family, from the same file.
|
||||||
|
const uint8_t _4x6_tf[1451] =
|
||||||
|
"\277\0\2\2\3\3\2\4\4\4\6\0\377\5\377\5\377\0\351\1\323\5\216 \5\200\315\0!\6\351\310"
|
||||||
|
"\254\0\42\6\223\313$\25#\12\254\310\244\64T\32*\1$\11\263\307\245\241GJ\0%\10\253\310d"
|
||||||
|
"\324F\1&\11\254\310\305\24\253\230\2'\5\321\313\10(\7\362\307\251f\0)\10\262\307\304T)\0"
|
||||||
|
"*\7\253\310\244j\65+\10\253\310\305\264b\2,\6\222\307)\0-\5\213\312\14.\5\311\310\4/"
|
||||||
|
"\7\253\310Ve\4\60\10\253\310UCU\0\61\7\253\310%Y\15\62\7\253\310\65S\32\63\10\253\310"
|
||||||
|
"\314\224\27\0\64\10\253\310$\65b\1\65\10\253\310\214\250\27\0\66\7\253\310M\325\2\67\10\253\310\314"
|
||||||
|
"TF\0\70\7\253\310\255\326\2\71\7\253\310\265\344\2:\6\341\310\304\0;\7\252\307e\250\0<\7"
|
||||||
|
"\253\310\246\272\0=\6\233\311\354\1>\7\253\310\344\252\4\77\10\253\310\350\224a\2@\6\253\310-["
|
||||||
|
"A\10\253\310UC\251\0B\10\253\310\250\264\322\2C\10\253\310U\62U\0D\10\253\310\250d-\0"
|
||||||
|
"E\10\253\310\214\250\342\0F\10\253\310\214\250b\4G\10\253\310\315\244\222\0H\10\253\310$\65\224\12"
|
||||||
|
"I\7\253\310\254X\15J\7\253\310\226\252\2K\10\253\310$\265\222\12L\7\253\310\304\346\0M\10\253"
|
||||||
|
"\310\244\61\224\12N\10\253\310\252\241$\0O\7\253\310UV\5P\10\253\310\250\264b\4Q\7\263\307"
|
||||||
|
"UV\35R\10\253\310\250\264\222\12S\7\253\310\355\274\0T\7\253\310\254\330\2U\7\253\310$\327\10"
|
||||||
|
"V\10\253\310$k\244\4W\10\253\310$\65\206\12X\10\253\310$\325R\1Y\10\253\310$UV\0"
|
||||||
|
"Z\7\253\310\314T\16[\6\352\310\254J\134\7\253\310\304\134\6]\6\252\310\250j^\5\223\313\65_"
|
||||||
|
"\5\213\307\14`\6\322\313\304\0a\7\243\310-\225\4b\10\253\310D\225\324\2c\6\243\310\315,d"
|
||||||
|
"\10\253\310\246\245\222\0e\6\243\310USf\10\253\310\246\264b\2g\10\253\307\255$\27\0h\10\253"
|
||||||
|
"\310D\225\254\0i\10\253\310e$\323\0j\10\263\307fX.\0k\10\253\310\304\264\222\12l\7\253"
|
||||||
|
"\310\310\326\0m\10\243\310\244\241T\0n\7\243\310\250d\5o\7\243\310U\252\2p\10\253\307\250\264"
|
||||||
|
"b\4q\10\253\307-\225d\0r\10\243\310\244\25#\0s\7\243\310\215\274\0t\10\253\310\245\25s"
|
||||||
|
"\0u\7\243\310$+\11v\7\243\310$\253\2w\10\243\310$\65T\0x\7\243\310\244\62\25y\10"
|
||||||
|
"\253\307$\225\344\2z\7\243\310\314\224\6{\10\263\307\246$\353\0|\6\351\310\14\1}\11\263\307\344"
|
||||||
|
"\250b\212\0~\7\224\313%\225\0\240\5\200\315\0\241\6\351\310\244\1\242\10\253\310\245\21W\2\243\7"
|
||||||
|
"\253\310\246\250\32\244\10\244\310\304$U\14\245\10\253\310\244j\305\4\246\6\351\310(\1\247\10\263\307\215"
|
||||||
|
"T\311\5\250\6\213\314\244\0\251\11\264\307\251\270\226L\12\252\7\253\310\255\244\7\253\10\234\311%\25S"
|
||||||
|
"\0\254\6\223\311\314\0\255\5\213\312\14\256\10\244\311\251\261\222\2\257\5\213\314\14\260\6\233\312u\1\261"
|
||||||
|
"\10\253\310\245\225\321\0\262\6\242\311(\3\263\7\252\310(\251\0\264\6\322\313)\0\265\10\253\307$k"
|
||||||
|
"E\0\266\7\254\310\15\265z\267\5\311\312\4\270\6\322\310)\0\271\6\242\311\255\2\272\7\253\310u\243"
|
||||||
|
"\1\273\10\234\311\244\230T\2\274\10\264\307\344\32U;\275\10\264\307\344J\307,\276\11\264\307\350\230Q"
|
||||||
|
"\262\3\277\10\253\310e\230\262\0\300\10\253\310\344\224\206\12\301\10\253\310\246j\250\0\302\10\253\310\310\224"
|
||||||
|
"\206\12\303\10\253\310\215\224\206\12\304\10\253\310\244\326P\1\305\10\253\310\305\224\206\12\306\11\254\310\215\224"
|
||||||
|
"\206\252\4\307\10\263\307U\62\65\1\310\10\253\310\304\241\342\0\311\7\253\310\216\25\7\312\10\253\310\215\221"
|
||||||
|
"\342\0\313\10\253\310\244\261\342\0\314\10\253\310\304\25\323\0\315\10\253\310\216\24\323\0\316\10\253\310\245\25"
|
||||||
|
"\323\0\317\7\253\310\244\262\32\320\11\254\310\314\264\252\221\0\321\10\254\310%\225\256\12\322\10\253\310\344\224"
|
||||||
|
"T\5\323\10\253\310\246JU\0\324\10\253\310\305\224T\5\325\10\254\310\215\325\31\1\326\10\253\310\244\226"
|
||||||
|
"\252\0\327\6\233\311\244\16\330\7\253\310\35j\1\331\10\253\310\344\224\324\10\332\10\253\310\246J\215\0\333"
|
||||||
|
"\10\253\310e\224\324\10\334\10\253\310\244\234\324\10\335\10\253\310\346T&\0\336\10\253\310D\225V\4\337"
|
||||||
|
"\10\263\307U+\15\11\340\10\253\310\344\270\222\0\341\10\253\310\246\270\222\0\342\10\253\310i\264\222\0\343"
|
||||||
|
"\11\254\310%\25U\251\0\344\10\253\310\244\214V\22\345\10\253\310e\270\222\0\346\10\244\310\215\264\342\0"
|
||||||
|
"\347\10\253\307UZ%\0\350\10\253\310\344\224\246\0\351\7\253\310\246j\12\352\10\253\310\310\224\246\0\353"
|
||||||
|
"\7\253\310\244\326\24\354\7\253\310\344X\15\355\6\253\310\316j\356\7\253\310u\246\1\357\10\253\310\244,"
|
||||||
|
"\323\0\360\10\253\310\244rU\0\361\11\254\310%\225dj\1\362\10\253\310\344\230Z\0\363\10\253\310\246"
|
||||||
|
"\230Z\0\364\10\253\310e\230Z\0\365\7\253\310l\324\5\366\10\253\310\244\214\272\0\367\10\253\310e\264"
|
||||||
|
"Q\2\370\7\243\310-\265\0\371\10\253\310\344\224T\22\372\10\253\310\246J%\1\373\10\253\310e\224T"
|
||||||
|
"\22\374\10\253\310\244\234T\22\375\10\263\307\246j\304\5\376\11\263\307\304\250\322\212\0\377\11\263\307\244\234"
|
||||||
|
"F\134\0\0\0\0\4\377\377\0";
|
||||||
|
|
||||||
|
const uint8_t _6x10_tf[2000] =
|
||||||
|
"\277\0\2\2\3\4\3\5\4\6\12\0\376\7\376\7\0\1B\2\222\7\263 \5\0b\7!\7\71C"
|
||||||
|
"g\250\0\42\7\233R'Y\1#\15=B\257Li\250j\250\62%\0$\13=B\67\257z\247\264"
|
||||||
|
"#\0%\13=B/\252\356\252%\23\0&\14=B/\247\230r\225dT\1'\5\31Sg(\10"
|
||||||
|
"\273B\67\225u\1)\10\273B'\227U\11*\12-F'\247j\250v\0+\12-F\67\243\70d"
|
||||||
|
"F\21,\7\233>O\225\0-\6\15Ng\10.\7\233>/\255\4/\13=B\37e\224\273QF"
|
||||||
|
"\0\60\12=B\67\247\332Nu\4\61\14=B\67\313\224QF\31\305!\62\14=Bo\345\214\242\314"
|
||||||
|
"\31\15\1\63\14=Bgh\224\263\206:-\0\64\14=B\77\313T\246\241\63J\0\65\13=B\347"
|
||||||
|
"F\311\314H\247\5\66\13=BW\346\214\222\251\323\2\67\14=Bgh\224\63\312\65\312\0\70\13="
|
||||||
|
"Boe\235V\326i\1\71\14=Boe\251TF\71J\0:\12\273>/\255\14\323J\0;\11"
|
||||||
|
"\273>/\255\14U\11<\12\274B\77\266QF\31\5=\10\35Jgh\70\4>\13\274B'\243\214"
|
||||||
|
"\62\212m\0\77\12=Bo\345\66\312t\4@\13=Boe\271\222\225\341\2A\13=B\67\247Z"
|
||||||
|
"\217\221u\0B\14=Bg\304*\246Y\305\241\0C\14=Boe\215\62\312(\247\5D\15=B"
|
||||||
|
"g\304*\246\230b\212C\1E\14=B\347F\31\215\224QFCF\15=B\347F\31\215\224QF"
|
||||||
|
"\31\1G\14=Boe\215\62\212;-\0H\11=B'\333cd;I\10\273Bg\305\256\1J"
|
||||||
|
"\14=Bwg\224QFe\224\0K\13=B'\313T\352\24\253\34L\16=B'\243\214\62\312("
|
||||||
|
"\243\214\206\0M\12=B'\353\265\222\266\3N\12=B'\353\251\222\334:O\11=Boe\357\264"
|
||||||
|
"\0P\15=Bg\244\254\207\312(\243\214\0Q\12E>oe\257j\303\0R\13=Bg\244\254\207"
|
||||||
|
"*\253\34S\13=Boe\15\67\324i\1T\16=Bg\310\214\62\312(\243\214\42\0U\10=B"
|
||||||
|
"'\373N\13V\13=B'\333\251L\61\345\10W\12=B'\273\222Jw\0X\12=B'\353T"
|
||||||
|
"W\265\16Y\14=B'\353Tg\224QF\21Z\12=Bgh\224\273\321\20[\10\273Bg\304\316"
|
||||||
|
"\1\134\15=B'\243\14\63\314\60\303\214\2]\10\273Bgv\216\0^\7\35R\67\247:_\6\15"
|
||||||
|
">g\10`\6\22['\6a\12-Bo\303\64t\32\1b\14=B'\243\214\222\251\247R\0c"
|
||||||
|
"\12-Boe\215rZ\0d\13=B\37e\224\314-\225\12e\12-Bo\345\61\62\134\0f\14"
|
||||||
|
"=BWVy\304\214\62\312\0g\14=:oh\235FF:-\0h\13=B'\243\214\222\251\355"
|
||||||
|
"\0i\10\273B/#\331\32j\13\314:\77c]K\231\24\0k\14=B'\243\214\262L\263\312\1"
|
||||||
|
"l\7\273BG\366\32m\12-BG\265TRI\7n\10-B'\231\332\16o\11-Boe;"
|
||||||
|
"-\0p\14=:'\231z*\225QF\0q\13=:\317\334R\251\214\62\12r\13-B'\231\32"
|
||||||
|
"e\224\21\0s\12-Boe\270\341P\0t\15=B/\243<bF\31\305\250\0u\10-B'"
|
||||||
|
";\225\12v\12-B'\353T\246\34\1w\11-B'[Iu\1x\11-B'\247\272\252\3y"
|
||||||
|
"\13=:'\233Je\244\323\2z\10-Bg\350\366\20{\13\274BWe\224\64\212\31\11|\6\71"
|
||||||
|
"C\347\10}\14\274BG\243\230\221\312(I\0~\11\35R/\252$\23\0\240\5\0b\7\241\7\71"
|
||||||
|
"C'\15\1\242\14=>\67\17\25SLy\304\10\243\13=BWVyg\24\225\2\244\12-B'"
|
||||||
|
"\247\231\342\312\1\245\15E>'\353T\307!\63\312(\2\246\6\71Cg\15\247\13E>oe\64;"
|
||||||
|
"\67J\13\250\6\213^'\5\251\14=Boe\225\246J:-\0\252\12\264FoD\245j\64\2\253"
|
||||||
|
"\13.B\267\212)\346\230c\0\254\7\224Jg\344\0\255\6\214Ng\4\256\13=Bo\345\221\346\324"
|
||||||
|
"i\1\257\6\15^g\10\260\6\233R\257\13\261\13\65B\67\243\70dFq\10\262\10\254NO\305\346"
|
||||||
|
"\10\263\12\254Ng\243\244\321H\0\264\6\22[O\1\265\12\65>'\333S\251\214\0\266\16=Bo"
|
||||||
|
"\214\64RR\61\305\24S\0\267\5\11O'\270\6\22;O\1\271\7\253N/\311j\272\12\264FO"
|
||||||
|
"E\231\64\34\1\273\14.B'\346\230c\212)F\0\274\20N>/#\15\63\314hf\244S\34\31"
|
||||||
|
"\6\275\20N>/#\15\63\314heT\303\214\62\32\276\16M>G\303\234a\224Y\246\64\62\12\277"
|
||||||
|
"\12=B\67\323\31\345\326\2\300\14EB/\303\274\262\36#\353\0\301\13EB\277^Y\217\221u\0"
|
||||||
|
"\302\14EB\67\247\270\262\36#\353\0\303\14EB/*\271\262\36#\353\0\304\13EB\257\246V\326"
|
||||||
|
"cd\35\305\14EB\67\247\270\262\36#\353\0\306\13>Bw\244\262\71Fl\16\307\15M:oe"
|
||||||
|
"\215\62\312(\247]\3\310\16EB/\217\215\62\32)\243\214\206\0\311\16EB\77\215\215\62\32)\243"
|
||||||
|
"\214\206\0\312\16EB\67\216\215\62\32)\243\214\206\0\313\16EB\257\32\33e\64RF\31\15\1\314"
|
||||||
|
"\11\303B'\247\25[\3\315\11\303B\67\245\25[\3\316\11\303B\257\32)\266\6\317\11\303B'\345"
|
||||||
|
"\25[\3\320\15=Bg\304*\216T\246\70\24\0\321\13EB\67uO\225\344\326\1\322\13EB/"
|
||||||
|
"\303\274\262;-\0\323\12EB\277^\331\235\26\0\324\13EB\67\247\270\262;-\0\325\12EB\67"
|
||||||
|
"\65Wv\247\5\326\12EB\257\246Vv\247\5\327\11-B'\247\272\252\3\330\13=Bo\305+\315"
|
||||||
|
"\231\26\0\331\12EB/\303\332;-\0\332\11EB\277\314\336i\1\333\13EB\67\247\214\263;-"
|
||||||
|
"\0\334\12EB\257\306\331;-\0\335\14EB\277\314:\325\31e\24\1\336\16=B'\243\221\362P"
|
||||||
|
"\31e\224\21\0\337\13=Boe\231\312*+\5\340\14EB/\303Ln\230\206N#\341\13EB"
|
||||||
|
"\277&\67LC\247\21\342\14EB\67\247Lm\230\206N#\343\14EB\67\265\251\15\323\320i\4\344"
|
||||||
|
"\13=B\257\246\66LC\247\21\345\14EB\67\247\234\67LC\247\21\346\13.BodT\215\231\207"
|
||||||
|
"\0\347\13=:oe\215r\332\65\0\350\14EB/\303L\256<F\206\13\351\13EB\277&W\36"
|
||||||
|
"#\303\5\352\14EB\67\247L\255<F\206\13\353\13=B\257\246V\36#\303\5\354\11\303B'g"
|
||||||
|
"$[\3\355\10\303B\257\206\262\65\356\10\303B\257-[\3\357\10\273B'e\331\32\360\13=BG"
|
||||||
|
"C\271\262\235\26\0\361\12EB\67\265q\62\265\35\362\13EB/\303L\256l\247\5\363\12EB\277"
|
||||||
|
"&W\266\323\2\364\13EB\67\247L\255l\247\5\365\13EB\67\265\251\225\355\264\0\366\12=B\257"
|
||||||
|
"\246V\266\323\2\367\11-F\67SCS\21\370\12-Bo\310\225\346P\0\371\13EB/\303Le"
|
||||||
|
"\247R\1\372\12EB\277\246\262S\251\0\373\13EB\67\247\214\263S\251\0\374\12=B\257\306\331\251"
|
||||||
|
"T\0\375\14M:\277\314\246R\31\351\264\0\376\15E:'\243\221\262=TF\31\1\377\15M:\257"
|
||||||
|
"\306\331T*#\235\26\0\0\0\0\4\377\377\0";
|
||||||
|
|
||||||
|
const uint8_t _9x15_tf[2606] =
|
||||||
|
"\277\0\3\2\4\4\4\5\5\11\17\0\375\12\375\13\377\1\223\3*\12\21 \5\0\310\63!\10\261\14"
|
||||||
|
"\63\16\221\0\42\10\64{\63\42S\0#\16\206\31s\242\226a\211Z\206%j\1$\24\267\371\362\302"
|
||||||
|
"A\211\42)L\322\65\11#\251\62\210\31\0%\21\247\11sB%JJ\255q\32\265\224\22\61\1&"
|
||||||
|
"\22\247\11s\304(\213\262(T\65)\251E\225H\13'\6\61|\63\6(\14\303\373\262\222(\211z"
|
||||||
|
"\213\262\0)\14\303\373\62\262(\213z\211\222\10*\15w\71\363J\225\266-i\252e\0+\13w\31"
|
||||||
|
"\363\342\332\60dq\15,\11R\334\62\206$Q\0-\7\27I\63\16\1.\7\42\14\63\206\0/\14"
|
||||||
|
"\247\11\263\323\70-\247\345\64\6\60\15\247\11\263\266J\352k\222e\23\0\61\15\247\11\363R\61\311\242"
|
||||||
|
"\270\267a\10\62\14\247\11s\6%U\373y\30\2\63\16\247\11\63\16qZ\335\343XM\6\5\64\21"
|
||||||
|
"\247\11sS\61\311\242Z\22&\303\220\306\25\0\65\17\247\11\63\16reH\304\270\254&\203\2\66\20"
|
||||||
|
"\247\11\263\206(\215+C\42\252\326dP\0\67\16\247\11\63\16q\32\247q\32\247q\10\70\21\247\11"
|
||||||
|
"\263\266J\232d\331VI\325$\313&\0\71\17\247\11s\6%uT\206$\256FC\4:\10r\14"
|
||||||
|
"\63\206x\10;\12\242\334\62\206xH\22\5<\11\245\12\63\263\216i\7=\12G)\63\16\71>\14"
|
||||||
|
"\1>\12\245\12\63\322\216YG\0\77\16\247\11s\6%U\343\264\71\207\63\0@\21\247\11s\6%"
|
||||||
|
"\65\15J\246D\223\42\347\203\2A\15\247\11\363\322$\253\244\326\341j\15B\22\247\11\63\6)LR"
|
||||||
|
"\61\31\244\60I\215\311 \1C\15\247\11s\6%\225\373\232\14\12\0D\15\247\11\63\6)LR\77"
|
||||||
|
"&\203\4E\15\247\11\63\16ry\220\342\346a\10F\14\247\11\63\16ry\220\342\316\0G\17\247\11"
|
||||||
|
"s\6%\225\333\206\324\232\14\12\0H\12\247\11\63R\327\341\352\65I\12\245\12\63\6)\354\247AJ"
|
||||||
|
"\15\250\11\363\6\65\357S\230\15\31\0K\21\247\11\63R\61\311\242\332\230\204QV\12\223\64L\12\247"
|
||||||
|
"\11\63\342\376<\14\1M\20\247\11\63Ru[*JE\212\244H\265\6N\17\247\11\63RuT\62"
|
||||||
|
")\322\22q\265\6O\14\247\11s\6%\365\327dP\0P\15\247\11\63.\251u\30\222\270\63\0Q"
|
||||||
|
"\16\307\351r\6%\365K&U\6\65\27R\20\247\11\63.\251u\30\222(+\205I\252\6S\16\247"
|
||||||
|
"\11s\6%\265\357V\65\31\24\0T\12\247\11\63\16Y\334\337\0U\13\247\11\63R\377\232\14\12\0"
|
||||||
|
"V\21\247\11\63Rk\222EY\224U\302$L\322\14W\20\247\11\63RO\221\24I\221\24)\335\22"
|
||||||
|
"\0X\20\247\11\63R\65\311*i\234&Y%U\3Y\15\247\11\63R\65\311*i\334\33\0Z\14"
|
||||||
|
"\247\11\63\16q\332\347x\30\2[\12\304\373\62\6\255\177\33\2\134\13\247\11\63\362\70/\347\345<]"
|
||||||
|
"\12\304\372\62\206\254\177\33\4^\12Gi\363\322$\253\244\1_\7\30\370\62\16\2`\7\63\213\63\262"
|
||||||
|
"\2a\16w\11s\6=N\206!\25\225!\11b\17\247\11\63\342\226!\21U\353\250\14\11\0c\14"
|
||||||
|
"w\11s\6%\225[\223A\1d\15\247\11\263[\206D\134\35\225!\11e\15w\11s\6%U\207"
|
||||||
|
"s>(\0f\16\247\11\363\266R\26\305\341 \306\215\0g\23\247\331r\206DL\302$\214\206(\37"
|
||||||
|
"\224TM\6\5h\14\247\11\63\342\226!\21U\257\1i\12\245\12stt\354i\20j\15\326\331\62"
|
||||||
|
"u\312\332U\64&C\2k\17\247\11\63\342VMI\64\65\321\62%\15l\11\245\12\63\306\376\64\10"
|
||||||
|
"m\20w\11\63\26%\212\244H\212\244H\212\324\0n\13w\11\63\222!\21U\257\1o\14w\11s"
|
||||||
|
"\6%\365\232\14\12\0p\17\247\331\62\222!\21U\353\250\14I\134\6q\15\247\331r\206D\134\35\225"
|
||||||
|
"!\211\33r\14w\11\63\242IK\302$n\5s\15w\11s\6%\325\7]M\6\5t\14\227\11"
|
||||||
|
"\263\342p\330\342n\331\2u\20w\11\63\302$L\302$L\302$\214\206$v\16w\11\63R\65\311"
|
||||||
|
"\242\254\22&i\6w\16w\11\63RS$ER\244tK\0x\15w\11\63\322$\253\244\225\254\222"
|
||||||
|
"\6y\15\246\331\62B\337\224%\25\223!\1z\12w\11\63\16i\257\303\20{\15\305\373\262\226\260\32"
|
||||||
|
"ij\26V\7|\6\301\374\62>}\16\305\371\62\326\260\226jR\32V&\0~\12\67ys\64)"
|
||||||
|
"\322\24\0\240\5\0\310\63\241\10\261\14\63\244a\10\242\21\206\11\63\243!\211\22\251\222%Q\62D!"
|
||||||
|
"\0\243\21\247\11\363\266R\34\16b\234\212I\226$\13\0\244\16g\71\63\322d\220\262(\213\6%\15"
|
||||||
|
"\245\20\247\11\63R\65\311*\331 \206\203\30\327\0\246\10\261\374\62\6e\20\247\16\264\372r\224HT"
|
||||||
|
"\42S\42J\211\2\250\7%\232\63\62-\251\25\230\30\263\206,L\42K\224(\241\22%\222\224\204\331"
|
||||||
|
"\20\1\252\14u\71s\244\322\22EC:\10\253\15\207\31\363\242~\213\302(\214\302(\254\7F)\63"
|
||||||
|
"\256\15\255\7\25J\63\6\1\256\25\230\30\263\206,L\222I\211\22eRJJ\224\24\263!\2\257\6"
|
||||||
|
"\26\231\63\16\260\12Dks\224HJ\24\0\261\16\227\31\363\342\332\60dq\35\33\206\0\262\13dI"
|
||||||
|
"s\224(K\224l\10\263\13dIs\224\250(%\12\0\264\10\63\213\263\222\22\0\265\14\227\351\62R"
|
||||||
|
"\257\333\262\310\61\0\266\26\247\11s\206!K\264DK\222!\11\223\60\11\223\60\11\223\0\267\7\42L"
|
||||||
|
"\63\206\0\270\10\64\332\262\246D\1\271\10cIs\22\251e\272\12eIs\226LK\346A\273\16\207"
|
||||||
|
"\31\63\242\60\12\243\60\312\242~\3\274\17\247\11sR\271q\210\304$\213\62%\25\275\16\247\11sR"
|
||||||
|
"\271I\31\242\70\24\343!\276\21\247\11s\304(\315\263\250\42\211I\26eJ*\277\15\247\11\363r\270"
|
||||||
|
"\332\234\252\311\240\0\300\16\307\11s\362:\272URu\270Z\3\301\15\307\11s\333\321\255\222\252\303\325"
|
||||||
|
"\32\302\17\307\11\363\322$\253c[%U\207\253\65\303\17\267\11s\64i\307\266J\252\16Wk\0\304"
|
||||||
|
"\17\267\11s\262(\313\261\255\222\252\303\325\32\305\17\267\11\263\266\332\230d\225T\35\256\326\0\306\25\247"
|
||||||
|
"\11s\224!\312\242,\312\242lX\242,\312\242,\32\2\307\20\327\331r\6%\225\373\232\14\242\26\205"
|
||||||
|
"\32\0\310\21\307\11s\362:\66\14I\34\17Y\134\35\206\0\311\20\307\11s\333\261aH\342x\310\342"
|
||||||
|
"\352\60\4\312\22\307\11\363\322$\253#\303\220\304\361\220\305\325a\10\313\22\267\11s\262(\313\221aH"
|
||||||
|
"\342x\310\342\352\60\4\314\14\305\12\63\322\372 \205=\15\2\315\14\305\12\63\263\372 \205=\15\2\316"
|
||||||
|
"\15\305\12\263\262\244\226\16R\330\323 \317\14\265\12\63\62-\35\244\260\247A\320\25\250\10s\6-\214"
|
||||||
|
"\322$\35\302$M\322$M\302h\220\0\321\22\267\11s\64iG\322Q\311\244H\212\264D\134\3\322"
|
||||||
|
"\16\307\11s\362:\70(\251\257\311\240\0\323\15\307\11s\333\301AI}M\6\5\324\20\307\11\363\322"
|
||||||
|
"$\253C\203\222\372\232\14\12\0\325\17\267\11s\64i\207\6%\365\65\31\24\0\326\17\267\11s\262("
|
||||||
|
"\313\241AI}M\6\5\327\15w\31\63\322$\253\244\225\254\222\6\330\26\307\371\262\223A\11\267DK"
|
||||||
|
"\244H\212\224L\311\306dPb\0\331\15\307\11s\362:\226\372\65\31\24\0\332\14\307\11s\333\261\324"
|
||||||
|
"\257\311\240\0\333\16\307\11\363\322$\253#\251_\223A\1\334\16\267\11s\262(\313\221\324\257\311\240\0"
|
||||||
|
"\335\16\307\11s\333\261TM\262J\32\267\1\336\16\247\11\63\342xXR\353\60$q\31\337\24\246\11"
|
||||||
|
"\263\246,\311\222(Q\262\250\226dI\226$\12\0\340\21\267\11\263\362:\66\350q\62\14\251\250\14I"
|
||||||
|
"\0\341\20\267\11s\333\301A\217\223aHEeH\2\342\22\267\11\363\322$\253C\203\36'\303\220\212"
|
||||||
|
"\312\220\4\343\22\247\11\263\244$\322\241A\217\223aHEeH\2\344\22\247\11s\262(\313\241A\217"
|
||||||
|
"\223aHEeH\2\345\22\267\11\363\304(\324\261A\217\223aHEeH\2\346\17w\11s,Q"
|
||||||
|
"-J\6%\312\242\212\62\347\17\247\331r\6%\225[\223A\324\242P\3\350\17\267\11s\362:\70("
|
||||||
|
"\251:\234\363A\1\351\17\267\11s\333\301AI\325\341\234\17\12\0\352\21\267\11\363\322$\253C\203\222"
|
||||||
|
"\252\303\71\37\24\0\353\21\247\11s\262(\313\241AI\325\341\234\17\12\0\354\12\265\12\63\322\372\330\323"
|
||||||
|
" \355\12\265\12\363\332\221\261\247A\356\15\266\11\263\302$\312rd\355m\20\357\14\245\12\63\242$\212"
|
||||||
|
"\307\236\6\1\360\20\267\11s\242PL\362lPR\257\311\240\0\361\16\247\11s\64iG\222!\21U"
|
||||||
|
"\257\1\362\16\267\11s\362:\70(\251\327dP\0\363\15\267\11s\333\301AI\275&\203\2\364\17\267"
|
||||||
|
"\11\363\322$\253C\203\222zM\6\5\365\17\247\11s\64i\207\6%\365\232\14\12\0\366\17\247\11s"
|
||||||
|
"\262(\313\241AI\275&\203\2\367\16\227\11\363\322\65\307\206!\307\322\65\3\370\23\227\371\262\223A\311"
|
||||||
|
"\22-\221\42%S\262dPb\0\371\23\267\11s\362:\26&a\22&a\22&a\64$\1\372\22"
|
||||||
|
"\267\11s\333\261\60\11\223\60\11\223\60\11\243!\11\373\24\267\11\363\322$\253#a\22&a\22&a"
|
||||||
|
"\22FC\22\374\24\247\11s\242,\312\241\60\11\223\60\11\223\60\11\243!\11\375\17\346\331\62\333\241\320"
|
||||||
|
"\67eI\305dH\0\376\20\307\331\62\342\226!\21UuT\206$.\3\377\17\326\331r\242\366\320\67"
|
||||||
|
"eI\305dH\0\0\0\0\4\377\377\0";
|
||||||
|
|
||||||
} // namespace roro::fontdata
|
} // namespace roro::fontdata
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ namespace fontdata {
|
|||||||
extern const uint8_t _6x13_tf[];
|
extern const uint8_t _6x13_tf[];
|
||||||
extern const uint8_t _6x13B_tf[];
|
extern const uint8_t _6x13B_tf[];
|
||||||
extern const uint8_t _5x8_tf[];
|
extern const uint8_t _5x8_tf[];
|
||||||
|
extern const uint8_t _4x6_tf[];
|
||||||
|
extern const uint8_t _6x10_tf[];
|
||||||
|
extern const uint8_t _9x15_tf[];
|
||||||
} // namespace fontdata
|
} // namespace fontdata
|
||||||
|
|
||||||
// Latin-1 bitmap fonts (accented letters included).
|
// Latin-1 bitmap fonts (accented letters included).
|
||||||
@@ -15,6 +18,9 @@ namespace fonts {
|
|||||||
inline const lgfx::U8g2font body(fontdata::_6x13_tf); // 6x13
|
inline const lgfx::U8g2font body(fontdata::_6x13_tf); // 6x13
|
||||||
inline const lgfx::U8g2font bold(fontdata::_6x13B_tf); // 6x13 bold
|
inline const lgfx::U8g2font bold(fontdata::_6x13B_tf); // 6x13 bold
|
||||||
inline const lgfx::U8g2font small(fontdata::_5x8_tf); // 5x8, Status Bar
|
inline const lgfx::U8g2font small(fontdata::_5x8_tf); // 5x8, Status Bar
|
||||||
|
inline const lgfx::U8g2font tiny(fontdata::_4x6_tf); // 4x6: the terminal's smallest (issue #2)
|
||||||
|
inline const lgfx::U8g2font medium(fontdata::_6x10_tf); // 6x10
|
||||||
|
inline const lgfx::U8g2font large(fontdata::_9x15_tf); // 9x15
|
||||||
} // namespace fonts
|
} // namespace fonts
|
||||||
|
|
||||||
} // namespace roro
|
} // namespace roro
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ void statusBar(Canvas& c, const StatusInfo& info) {
|
|||||||
case StatusInfo::Vpn::Up: right("VPN", kAccent); break;
|
case StatusInfo::Vpn::Up: right("VPN", kAccent); break;
|
||||||
case StatusInfo::Vpn::Off: break;
|
case StatusInfo::Vpn::Off: break;
|
||||||
}
|
}
|
||||||
|
if (info.ssh) right("SSH", kAccent); // Q260: a session goes on, whatever App is in front
|
||||||
switch (info.debug) { // Q190: there while the console listens, bright with someone connected
|
switch (info.debug) { // Q190: there while the console listens, bright with someone connected
|
||||||
case StatusInfo::Debug::On: right("DBG", kMuted); break;
|
case StatusInfo::Debug::On: right("DBG", kMuted); break;
|
||||||
case StatusInfo::Debug::Client: right("DBG", kAccent); break;
|
case StatusInfo::Debug::Client: right("DBG", kAccent); break;
|
||||||
|
|||||||
@@ -32,12 +32,13 @@ struct StatusInfo {
|
|||||||
bool capturing = false; // a LoRa Capture is recording (Q97)
|
bool capturing = false; // a LoRa Capture is recording (Q97)
|
||||||
enum class Debug { Off, On, Client } debug = Debug::Off; // the Debug Console listens (ADR 0010, Q190)
|
enum class Debug { Off, On, Client } debug = Debug::Off; // the Debug Console listens (ADR 0010, Q190)
|
||||||
enum class Vpn { Off, Trying, Up } vpn = Vpn::Off; // the WireGuard tunnel (issue #8, Q252)
|
enum class Vpn { Off, Trying, Up } vpn = Vpn::Off; // the WireGuard tunnel (issue #8, Q252)
|
||||||
|
bool ssh = false; // an SSH session is open (issue #2, Q260)
|
||||||
|
|
||||||
bool operator==(const StatusInfo& o) const {
|
bool operator==(const StatusInfo& o) const {
|
||||||
return title == o.title && batteryPercent == o.batteryPercent && clock == o.clock &&
|
return title == o.title && batteryPercent == o.batteryPercent && clock == o.clock &&
|
||||||
sdPresent == o.sdPresent && sdLevel == o.sdLevel && compose == o.compose && wifi == o.wifi &&
|
sdPresent == o.sdPresent && sdLevel == o.sdLevel && compose == o.compose && wifi == o.wifi &&
|
||||||
wifiBars == o.wifiBars && unread == o.unread && gnss == o.gnss && gnssSatellites == o.gnssSatellites &&
|
wifiBars == o.wifiBars && unread == o.unread && gnss == o.gnss && gnssSatellites == o.gnssSatellites &&
|
||||||
tracking == o.tracking && radio == o.radio && capturing == o.capturing && debug == o.debug && vpn == o.vpn;
|
tracking == o.tracking && radio == o.radio && capturing == o.capturing && debug == o.debug && vpn == o.vpn && ssh == o.ssh;
|
||||||
}
|
}
|
||||||
bool operator!=(const StatusInfo& o) const { return !(*this == o); }
|
bool operator!=(const StatusInfo& o) const { return !(*this == o); }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "../memory_store.h"
|
#include "../memory_store.h"
|
||||||
#include "irc_session.h"
|
#include "irc_session.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
using namespace roro;
|
using namespace roro;
|
||||||
|
|
||||||
@@ -326,7 +327,19 @@ void test_action_and_ctcp_version() {
|
|||||||
f.take();
|
f.take();
|
||||||
f.recv(":alice!u@h PRIVMSG roro :\x01VERSION\x01");
|
f.recv(":alice!u@h PRIVMSG roro :\x01VERSION\x01");
|
||||||
f.take();
|
f.take();
|
||||||
TEST_ASSERT_TRUE(f.sent("NOTICE alice :\x01VERSION roro9stack\x01"));
|
TEST_ASSERT_TRUE(f.sent(std::string("NOTICE alice :\x01VERSION roro9stack ") + versionString() + "\x01"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_uname_shows_the_firmware_here_and_sends_nothing() {
|
||||||
|
Fixture f;
|
||||||
|
f.registerNow();
|
||||||
|
f.recv(":roro!u@h JOIN #roro");
|
||||||
|
f.take();
|
||||||
|
f.session->input(f.buffer("#roro"), "/uname", 0);
|
||||||
|
const auto& line = f.session->buffer(f.buffer("#roro")).lines.back();
|
||||||
|
TEST_ASSERT_EQUAL(static_cast<int>(IrcLine::Kind::Info), static_cast<int>(line.kind));
|
||||||
|
TEST_ASSERT_EQUAL_STRING(unameString().c_str(), line.text.c_str());
|
||||||
|
TEST_ASSERT_EQUAL(0, f.take().send.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_topic_is_kept() {
|
void test_topic_is_kept() {
|
||||||
@@ -491,6 +504,7 @@ int main() {
|
|||||||
RUN_TEST(test_private_message_opens_a_query_buffer_and_notifies);
|
RUN_TEST(test_private_message_opens_a_query_buffer_and_notifies);
|
||||||
RUN_TEST(test_no_notification_while_viewing_that_buffer);
|
RUN_TEST(test_no_notification_while_viewing_that_buffer);
|
||||||
RUN_TEST(test_action_and_ctcp_version);
|
RUN_TEST(test_action_and_ctcp_version);
|
||||||
|
RUN_TEST(test_uname_shows_the_firmware_here_and_sends_nothing);
|
||||||
RUN_TEST(test_topic_is_kept);
|
RUN_TEST(test_topic_is_kept);
|
||||||
RUN_TEST(test_input_message_and_commands);
|
RUN_TEST(test_input_message_and_commands);
|
||||||
RUN_TEST(test_j_is_short_for_join);
|
RUN_TEST(test_j_is_short_for_join);
|
||||||
|
|||||||
@@ -231,6 +231,35 @@ void test_fn_h_is_help_in_both_modes() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue #2: a key that isn't a character says what was held with it. A terminal sends Page Up for
|
||||||
|
// Shift with the up arrow, and a note jumps to its start for Ctrl with it.
|
||||||
|
void test_arrows_enter_and_tab_carry_what_was_held() {
|
||||||
|
KeyMapper m;
|
||||||
|
m.setTextEntry(true);
|
||||||
|
RawKeys r = withFn({';'});
|
||||||
|
r.shift = true;
|
||||||
|
auto ev = press(m, r);
|
||||||
|
TEST_ASSERT_EQUAL(static_cast<int>(Key::Up), static_cast<int>(ev[0].key));
|
||||||
|
TEST_ASSERT_TRUE(ev[0].shift);
|
||||||
|
TEST_ASSERT_FALSE(ev[0].ctrl);
|
||||||
|
|
||||||
|
KeyMapper m2;
|
||||||
|
RawKeys tab;
|
||||||
|
tab.tab = true;
|
||||||
|
tab.shift = true;
|
||||||
|
ev = press(m2, tab);
|
||||||
|
TEST_ASSERT_EQUAL(static_cast<int>(Key::Tab), static_cast<int>(ev[0].key));
|
||||||
|
TEST_ASSERT_TRUE(ev[0].shift);
|
||||||
|
|
||||||
|
KeyMapper m3;
|
||||||
|
m3.setTextEntry(true);
|
||||||
|
RawKeys back = chars({'`'});
|
||||||
|
back.alt = true;
|
||||||
|
ev = press(m3, back);
|
||||||
|
TEST_ASSERT_EQUAL(static_cast<int>(Key::Back), static_cast<int>(ev[0].key));
|
||||||
|
TEST_ASSERT_TRUE(ev[0].alt);
|
||||||
|
}
|
||||||
|
|
||||||
// Issue #83: Fn+p everywhere.
|
// Issue #83: Fn+p everywhere.
|
||||||
void test_fn_p_is_a_screenshot_in_both_modes() {
|
void test_fn_p_is_a_screenshot_in_both_modes() {
|
||||||
for (bool typing : {true, false}) {
|
for (bool typing : {true, false}) {
|
||||||
@@ -294,6 +323,7 @@ int main() {
|
|||||||
RUN_TEST(test_other_characters_still_type_when_not_typing);
|
RUN_TEST(test_other_characters_still_type_when_not_typing);
|
||||||
RUN_TEST(test_shifted_arrow_keys_type_their_symbols_when_not_typing);
|
RUN_TEST(test_shifted_arrow_keys_type_their_symbols_when_not_typing);
|
||||||
RUN_TEST(test_fn_h_is_help_in_both_modes);
|
RUN_TEST(test_fn_h_is_help_in_both_modes);
|
||||||
|
RUN_TEST(test_arrows_enter_and_tab_carry_what_was_held);
|
||||||
RUN_TEST(test_fn_p_is_a_screenshot_in_both_modes);
|
RUN_TEST(test_fn_p_is_a_screenshot_in_both_modes);
|
||||||
RUN_TEST(test_plain_h_still_types);
|
RUN_TEST(test_plain_h_still_types);
|
||||||
RUN_TEST(test_question_mark_is_help_only_when_not_typing);
|
RUN_TEST(test_question_mark_is_help_only_when_not_typing);
|
||||||
|
|||||||
@@ -0,0 +1,286 @@
|
|||||||
|
#include <unity.h>
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "aes128.h"
|
||||||
|
#include "meshcore_channel.h"
|
||||||
|
#include "meshcore_packet.h"
|
||||||
|
#include "packet_view.h"
|
||||||
|
#include "scan_presets.h"
|
||||||
|
|
||||||
|
using namespace roro;
|
||||||
|
using namespace roro::meshcore;
|
||||||
|
|
||||||
|
void setUp() {}
|
||||||
|
void tearDown() {}
|
||||||
|
|
||||||
|
// A flood advert relayed by two repeaters (1-byte hashes), from a repeater that says where it is.
|
||||||
|
static std::vector<uint8_t> advert(const char* name, bool location = true, uint8_t pathByte = 2) {
|
||||||
|
std::vector<uint8_t> v = {static_cast<uint8_t>(0x04 << 2 | 0x01), pathByte};
|
||||||
|
for (int i = 0; i < (pathByte & 0x3F) * ((pathByte >> 6) + 1); ++i) v.push_back(static_cast<uint8_t>(0xa3 + i));
|
||||||
|
for (int i = 0; i < 32; ++i) v.push_back(static_cast<uint8_t>(0xc0 + i)); // key
|
||||||
|
v.insert(v.end(), {0x00, 0x5e, 0xd0, 0x68}); // timestamp
|
||||||
|
v.insert(v.end(), 64, 0x55); // signature
|
||||||
|
v.push_back(static_cast<uint8_t>(0x80 | (location ? 0x10 : 0) | 0x02)); // named, repeater
|
||||||
|
if (location) {
|
||||||
|
int32_t lat = 50860320, lon = 4300480;
|
||||||
|
for (int i = 0; i < 4; ++i) v.push_back(static_cast<uint8_t>(lat >> (8 * i)));
|
||||||
|
for (int i = 0; i < 4; ++i) v.push_back(static_cast<uint8_t>(lon >> (8 * i)));
|
||||||
|
}
|
||||||
|
v.insert(v.end(), name, name + std::strlen(name));
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_header_route_type_and_path() {
|
||||||
|
auto v = advert("Brussels-R1");
|
||||||
|
Packet p;
|
||||||
|
TEST_ASSERT_TRUE(parsePacket(v.data(), v.size(), p));
|
||||||
|
TEST_ASSERT_TRUE(p.route == Route::Flood);
|
||||||
|
TEST_ASSERT_TRUE(p.type == Payload::Advert);
|
||||||
|
TEST_ASSERT_FALSE(p.hasTransport);
|
||||||
|
TEST_ASSERT_EQUAL(2, p.hops);
|
||||||
|
TEST_ASSERT_EQUAL(1, p.hashSize);
|
||||||
|
TEST_ASSERT_EQUAL_HEX8(0xa3, p.path[0]);
|
||||||
|
TEST_ASSERT_EQUAL_HEX8(0xc0, p.payload[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_transport_codes_and_wider_hashes() {
|
||||||
|
// Direct in a region, a text message, two hops of 2 bytes each.
|
||||||
|
const uint8_t v[] = {0x02 << 2 | 0x03, 0x2b, 0x1a, 0x00, 0x00, 0x40 | 2, 0x11, 0x22, 0x33, 0x44, 0x7f, 0xa3, 0xde, 0xad, 1, 2, 3};
|
||||||
|
Packet p;
|
||||||
|
TEST_ASSERT_TRUE(parsePacket(v, sizeof v, p));
|
||||||
|
TEST_ASSERT_TRUE(p.route == Route::TransportDirect);
|
||||||
|
TEST_ASSERT_TRUE(p.hasTransport);
|
||||||
|
TEST_ASSERT_EQUAL_HEX16(0x1a2b, p.transport[0]);
|
||||||
|
TEST_ASSERT_EQUAL(2, p.hops);
|
||||||
|
TEST_ASSERT_EQUAL(2, p.hashSize);
|
||||||
|
TEST_ASSERT_EQUAL_size_t(7, p.payloadLen);
|
||||||
|
TEST_ASSERT_EQUAL_HEX8(0x7f, p.payload[0]);
|
||||||
|
TEST_ASSERT_TRUE(p.addressed());
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_what_is_not_a_meshcore_packet() {
|
||||||
|
Packet p;
|
||||||
|
const uint8_t version[] = {0x40 | 0x05, 0x00, 1, 2}; // a version that doesn't exist yet
|
||||||
|
const uint8_t reserved[] = {0x0c << 2 | 0x01, 0x00, 1, 2}; // a reserved type
|
||||||
|
const uint8_t longPath[] = {0x05, 0x09, 1, 2, 3}; // nine hops, three bytes left
|
||||||
|
const uint8_t badHash[] = {0x05, 0xc1, 1, 2, 3, 4}; // 4-byte hashes aren't defined
|
||||||
|
TEST_ASSERT_FALSE(parsePacket(version, sizeof version, p));
|
||||||
|
TEST_ASSERT_FALSE(parsePacket(reserved, sizeof reserved, p));
|
||||||
|
TEST_ASSERT_FALSE(parsePacket(longPath, sizeof longPath, p));
|
||||||
|
TEST_ASSERT_FALSE(parsePacket(badHash, sizeof badHash, p));
|
||||||
|
TEST_ASSERT_FALSE(parsePacket(version, 1, p));
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_advert() {
|
||||||
|
auto v = advert("Brussels-R1");
|
||||||
|
Packet p;
|
||||||
|
Advert a;
|
||||||
|
TEST_ASSERT_TRUE(parsePacket(v.data(), v.size(), p));
|
||||||
|
TEST_ASSERT_TRUE(parseAdvert(p, a));
|
||||||
|
TEST_ASSERT_EQUAL_STRING("Brussels-R1", a.name.c_str());
|
||||||
|
TEST_ASSERT_EQUAL(2, a.kind);
|
||||||
|
TEST_ASSERT_TRUE(a.hasLocation);
|
||||||
|
TEST_ASSERT_EQUAL_INT32(50860320, a.latE6);
|
||||||
|
TEST_ASSERT_EQUAL_INT32(4300480, a.lonE6);
|
||||||
|
TEST_ASSERT_EQUAL_HEX32(0x68d05e00, a.timestamp);
|
||||||
|
TEST_ASSERT_EQUAL_HEX8(0xc0, a.key[0]);
|
||||||
|
|
||||||
|
auto plain = advert("n", false, 0);
|
||||||
|
TEST_ASSERT_TRUE(parsePacket(plain.data(), plain.size(), p));
|
||||||
|
TEST_ASSERT_TRUE(parseAdvert(p, a));
|
||||||
|
TEST_ASSERT_FALSE(a.hasLocation);
|
||||||
|
TEST_ASSERT_EQUAL_STRING("n", a.name.c_str());
|
||||||
|
|
||||||
|
v.resize(60); // cut short: still a packet, not an advert that can be read
|
||||||
|
TEST_ASSERT_TRUE(parsePacket(v.data(), v.size(), p));
|
||||||
|
TEST_ASSERT_FALSE(parseAdvert(p, a));
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_rows() {
|
||||||
|
auto v = advert("Brussels-R1");
|
||||||
|
lora::PacketSummary s{v.data(), v.size(), -97.4f, 6.25f, true, lora::Protocol::MeshCore};
|
||||||
|
TEST_ASSERT_EQUAL_STRING("21:45:07 -97 6.2 adv Brussels-R1 2h", lora::row(s, "21:45:07").c_str());
|
||||||
|
auto longName = advert("A repeater with a very long name");
|
||||||
|
lora::PacketSummary l{longName.data(), longName.size(), -117.0f, -12.25f, true, lora::Protocol::MeshCore};
|
||||||
|
TEST_ASSERT_TRUE(lora::row(l, "21:45:07").size() <= 38);
|
||||||
|
|
||||||
|
const uint8_t text[] = {0x02 << 2 | 0x02, 0x00, 0x7f, 0xa3, 0xde, 0xad, 1, 2, 3};
|
||||||
|
lora::PacketSummary t{text, sizeof text, -80.0f, 9.0f, true, lora::Protocol::MeshCore};
|
||||||
|
TEST_ASSERT_EQUAL_STRING("21:45:07 -80 9.0 txt a3>7f", lora::row(t, "21:45:07").c_str());
|
||||||
|
|
||||||
|
const uint8_t group[] = {0x05 << 2 | 0x01, 0x01, 0x42, 0x11, 0xbe, 0xef, 1, 2, 3, 4};
|
||||||
|
lora::PacketSummary g{group, sizeof group, -80.0f, 9.0f, true, lora::Protocol::MeshCore};
|
||||||
|
TEST_ASSERT_EQUAL_STRING("21:45:07 -80 9.0 chan #11 1h", lora::row(g, "21:45:07").c_str());
|
||||||
|
|
||||||
|
// Not MeshCore after all (sync word 0x12 is anyone's): the bytes are counted, no more.
|
||||||
|
const uint8_t other[] = {0xff, 0x00, 1, 2};
|
||||||
|
lora::PacketSummary o{other, sizeof other, -80.0f, 9.0f, true, lora::Protocol::MeshCore};
|
||||||
|
TEST_ASSERT_EQUAL_STRING("21:45:07 -80 9.0 4 B", lora::row(o, "21:45:07").c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_detail_lines() {
|
||||||
|
auto v = advert("Brussels-R1");
|
||||||
|
auto lines = lora::headerLines(v.data(), v.size(), lora::Protocol::MeshCore);
|
||||||
|
TEST_ASSERT_EQUAL_size_t(5, lines.size());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("MeshCore advert, flood", lines[0].c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("Through a3 a4", lines[1].c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("Repeater Brussels-R1", lines[2].c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("Key c0c1c2c3c4c5c6c7...", lines[3].c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("At 50.86032, 4.30048", lines[4].c_str());
|
||||||
|
|
||||||
|
const uint8_t group[] = {0x05 << 2 | 0x01, 0x00, 0x11, 0xbe, 0xef, 1, 2, 3, 4};
|
||||||
|
lines = lora::headerLines(group, sizeof group, lora::Protocol::MeshCore);
|
||||||
|
TEST_ASSERT_EQUAL_size_t(3, lines.size());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("MeshCore channel message, flood", lines[0].c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("Heard first hand: no repeater yet", lines[1].c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("Channel 0x11 (public?), 4 B encrypted", lines[2].c_str());
|
||||||
|
|
||||||
|
const uint8_t text[] = {0x02 << 2 | 0x02, 0x01, 0x42, 0x7f, 0xa3, 0xde, 0xad, 1, 2, 3};
|
||||||
|
lines = lora::headerLines(text, sizeof text, lora::Protocol::MeshCore);
|
||||||
|
TEST_ASSERT_EQUAL_STRING("MeshCore text message, direct", lines[0].c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("Route 42", lines[1].c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("From ..a3 to ..7f, 3 B encrypted", lines[2].c_str());
|
||||||
|
|
||||||
|
for (auto& l : lines) TEST_ASSERT_TRUE(l.size() <= 38);
|
||||||
|
TEST_ASSERT_EQUAL_size_t(0, lora::headerLines(text, sizeof text, lora::Protocol::None).size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// As received near Brussels on 2026-10-09: a search for repeaters, and one answering.
|
||||||
|
void test_discover_as_heard() {
|
||||||
|
const uint8_t ask[] = {0x2e, 0x00, 0x80, 0x04, 0xbb, 0xdd, 0x5f, 0x5a, 0x00, 0x00, 0x00, 0x00};
|
||||||
|
const uint8_t answer[] = {0x2e, 0x00, 0x92, 0x2d, 0xbb, 0xdd, 0x5f, 0x5a, 0x18, 0xa6, 0x3f, 0xae, 0xf4, 0x01, 0x9b, 0xee,
|
||||||
|
0xd0, 0x4f, 0xfd, 0xd3, 0xd1, 0x72, 0x65, 0xba, 0x4b, 0x9e, 0xeb, 0xd0, 0xdf, 0xb0, 0xb2, 0xc4,
|
||||||
|
0x94, 0xec, 0x50, 0x5b, 0x03, 0x20, 0x59, 0x9d};
|
||||||
|
Packet p;
|
||||||
|
Discover d;
|
||||||
|
TEST_ASSERT_TRUE(parsePacket(ask, sizeof ask, p));
|
||||||
|
TEST_ASSERT_TRUE(p.route == Route::Direct);
|
||||||
|
TEST_ASSERT_TRUE(p.type == Payload::Control);
|
||||||
|
TEST_ASSERT_TRUE(parseDiscover(p, d));
|
||||||
|
TEST_ASSERT_FALSE(d.response);
|
||||||
|
TEST_ASSERT_EQUAL_HEX8(0x04, d.kinds);
|
||||||
|
TEST_ASSERT_EQUAL_HEX32(0x5a5fddbb, d.tag);
|
||||||
|
TEST_ASSERT_TRUE(parsePacket(answer, sizeof answer, p));
|
||||||
|
TEST_ASSERT_TRUE(parseDiscover(p, d));
|
||||||
|
TEST_ASSERT_TRUE(d.response);
|
||||||
|
TEST_ASSERT_EQUAL(2, d.kind);
|
||||||
|
TEST_ASSERT_EQUAL_FLOAT(11.25f, d.snr);
|
||||||
|
TEST_ASSERT_EQUAL_HEX32(0x5a5fddbb, d.tag);
|
||||||
|
TEST_ASSERT_EQUAL_size_t(32, d.idLen);
|
||||||
|
|
||||||
|
lora::PacketSummary a{ask, sizeof ask, -107.0f, -7.0f, true, lora::Protocol::MeshCore};
|
||||||
|
TEST_ASSERT_EQUAL_STRING("20:44:01 -107 -7.0 who's there?", lora::row(a, "20:44:01").c_str());
|
||||||
|
lora::PacketSummary r{answer, sizeof answer, -96.0f, 3.0f, true, lora::Protocol::MeshCore};
|
||||||
|
TEST_ASSERT_EQUAL_STRING("20:44:02 -96 3.0 here 18a6", lora::row(r, "20:44:02").c_str());
|
||||||
|
|
||||||
|
auto lines = lora::headerLines(ask, sizeof ask, lora::Protocol::MeshCore);
|
||||||
|
TEST_ASSERT_EQUAL_size_t(4, lines.size());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("MeshCore control, direct", lines[0].c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("No route in it: to a neighbour", lines[1].c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("A search for nodes nearby", lines[2].c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("Wanted: Repeater", lines[3].c_str());
|
||||||
|
lines = lora::headerLines(answer, sizeof answer, lora::Protocol::MeshCore);
|
||||||
|
TEST_ASSERT_EQUAL_size_t(5, lines.size());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("Repeater answering a search", lines[2].c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("Key 18a63faef4019bee...", lines[3].c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("It heard the search at 11.2 dB SNR", lines[4].c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_aes128_decrypts_the_standard_block() { // FIPS 197, appendix C.1
|
||||||
|
uint8_t key[16], in[16] = {0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a}, out[16];
|
||||||
|
for (int i = 0; i < 16; ++i) key[i] = static_cast<uint8_t>(i);
|
||||||
|
Aes128(key).decryptBlock(in, out);
|
||||||
|
for (int i = 0; i < 16; ++i) TEST_ASSERT_EQUAL_HEX8(i * 0x11, out[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Messages on the public channel, relayed twice, encrypted and signed with openssl:
|
||||||
|
// "Alice: hello from Brussels" and "Zo\xc3\xa9: \xc3\xa7a va ?", both sent at 1791575000.
|
||||||
|
static const uint8_t kHello[] = {0x15, 0x02, 0xa3, 0x7f, 0x11, 0x20, 0x14, 0x90, 0xb7, 0xe1, 0x1d, 0x46, 0x5f,
|
||||||
|
0x3f, 0xac, 0x4f, 0x98, 0xa8, 0xc6, 0x07, 0x79, 0x4c, 0x96, 0x19, 0x5e, 0x54,
|
||||||
|
0x60, 0x67, 0x2b, 0x2e, 0xec, 0x0e, 0xe4, 0x6a, 0xbc, 0x8b, 0x51, 0x38, 0xfd};
|
||||||
|
static const uint8_t kAccents[] = {0x15, 0x02, 0xa3, 0x7f, 0x11, 0x19, 0xdd, 0x85, 0x58, 0xc5, 0x73, 0x2d, 0x55,
|
||||||
|
0x4d, 0xf4, 0xfd, 0x02, 0x47, 0xdc, 0xfa, 0xa2, 0xce, 0x3b, 0xcb, 0xb1, 0x8e,
|
||||||
|
0x8f, 0x66, 0xc7, 0xd6, 0x61, 0x30, 0x3c, 0xbe, 0x29, 0xd7, 0xb8, 0x08, 0x26};
|
||||||
|
|
||||||
|
void test_public_channel_message() {
|
||||||
|
TEST_ASSERT_EQUAL_HEX8(kPublicChannelHash, channelHash(channel(0)));
|
||||||
|
Packet p;
|
||||||
|
ChannelText t;
|
||||||
|
TEST_ASSERT_TRUE(parsePacket(kHello, sizeof kHello, p));
|
||||||
|
TEST_ASSERT_TRUE(readChannelText(p, t));
|
||||||
|
TEST_ASSERT_EQUAL_STRING("Public", t.channel);
|
||||||
|
TEST_ASSERT_EQUAL_UINT32(1791575000, t.timestamp);
|
||||||
|
TEST_ASSERT_EQUAL_STRING("Alice", t.sender.c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("hello from Brussels", t.text.c_str());
|
||||||
|
|
||||||
|
TEST_ASSERT_TRUE(parsePacket(kAccents, sizeof kAccents, p));
|
||||||
|
TEST_ASSERT_TRUE(readChannelText(p, t));
|
||||||
|
TEST_ASSERT_EQUAL_STRING("Zo?", t.sender.c_str()); // one '?' for a character outside ASCII
|
||||||
|
TEST_ASSERT_EQUAL_STRING("?a va ?", t.text.c_str());
|
||||||
|
|
||||||
|
// One bit wrong and the check fails: nothing is made up from it.
|
||||||
|
std::vector<uint8_t> bad(kHello, kHello + sizeof kHello);
|
||||||
|
bad[20] ^= 1;
|
||||||
|
TEST_ASSERT_TRUE(parsePacket(bad.data(), bad.size(), p));
|
||||||
|
TEST_ASSERT_FALSE(readChannelText(p, t));
|
||||||
|
// Another channel with the same first byte, or not whole blocks: left encrypted.
|
||||||
|
bad.assign(kHello, kHello + sizeof kHello - 1);
|
||||||
|
TEST_ASSERT_TRUE(parsePacket(bad.data(), bad.size(), p));
|
||||||
|
TEST_ASSERT_FALSE(readChannelText(p, t));
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_public_channel_message_shown() {
|
||||||
|
lora::PacketSummary s{kHello, sizeof kHello, -97, 6.2f, true, lora::Protocol::MeshCore};
|
||||||
|
std::string row = lora::row(s, "21:45:07");
|
||||||
|
TEST_ASSERT_EQUAL_STRING("21:45:07 -97 6.2 Alice: hello from 2h", row.c_str());
|
||||||
|
TEST_ASSERT_LESS_OR_EQUAL(38, row.size());
|
||||||
|
auto lines = lora::headerLines(kHello, sizeof kHello, lora::Protocol::MeshCore);
|
||||||
|
TEST_ASSERT_EQUAL_size_t(5, lines.size());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("MeshCore channel message, flood", lines[0].c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("Through a3 7f", lines[1].c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("On the Public channel, from Alice", lines[2].c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("Sent 2026-10-09 19:43:20 UTC", lines[3].c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("hello from Brussels", lines[4].c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_scan_presets() {
|
||||||
|
TEST_ASSERT_EQUAL_size_t(8, lora::scanPresetCount());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("MeshCore", lora::scanPreset(lora::kDefaultScanPreset).name);
|
||||||
|
lora::ScanPreset p = lora::scanPreset(0); // the order stays: a preset is stored by number
|
||||||
|
TEST_ASSERT_EQUAL_STRING("LongFast", p.name);
|
||||||
|
TEST_ASSERT_EQUAL_UINT32(869525000u, p.frequencyHz);
|
||||||
|
TEST_ASSERT_EQUAL_HEX8(0x2B, p.syncWord);
|
||||||
|
TEST_ASSERT_TRUE(lora::findScanPreset("meshcore", p));
|
||||||
|
TEST_ASSERT_EQUAL_STRING("MeshCore", p.name);
|
||||||
|
TEST_ASSERT_EQUAL_UINT32(869618000u, p.frequencyHz);
|
||||||
|
TEST_ASSERT_EQUAL_FLOAT(62.5f, p.bwKHz);
|
||||||
|
TEST_ASSERT_EQUAL(8, p.sf);
|
||||||
|
TEST_ASSERT_EQUAL(8, p.cr);
|
||||||
|
TEST_ASSERT_EQUAL_HEX8(0x12, p.syncWord);
|
||||||
|
TEST_ASSERT_EQUAL(16, p.preamble);
|
||||||
|
TEST_ASSERT_TRUE(p.protocol == lora::Protocol::MeshCore);
|
||||||
|
TEST_ASSERT_TRUE(lora::protocolOf(0x12) == lora::Protocol::MeshCore);
|
||||||
|
TEST_ASSERT_TRUE(lora::protocolOf(0x2B) == lora::Protocol::Meshtastic);
|
||||||
|
TEST_ASSERT_TRUE(lora::protocolOf(0x34) == lora::Protocol::None);
|
||||||
|
TEST_ASSERT_FALSE(lora::findScanPreset("ShortTurbo", p));
|
||||||
|
TEST_ASSERT_FALSE(lora::findScanPreset("MeshCor", p));
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
UNITY_BEGIN();
|
||||||
|
RUN_TEST(test_header_route_type_and_path);
|
||||||
|
RUN_TEST(test_transport_codes_and_wider_hashes);
|
||||||
|
RUN_TEST(test_what_is_not_a_meshcore_packet);
|
||||||
|
RUN_TEST(test_advert);
|
||||||
|
RUN_TEST(test_rows);
|
||||||
|
RUN_TEST(test_detail_lines);
|
||||||
|
RUN_TEST(test_discover_as_heard);
|
||||||
|
RUN_TEST(test_aes128_decrypts_the_standard_block);
|
||||||
|
RUN_TEST(test_public_channel_message);
|
||||||
|
RUN_TEST(test_public_channel_message_shown);
|
||||||
|
RUN_TEST(test_scan_presets);
|
||||||
|
return UNITY_END();
|
||||||
|
}
|
||||||
@@ -143,6 +143,66 @@ void test_a_dns_answer() {
|
|||||||
TEST_ASSERT_FALSE(parseDnsAnswer(loop, sizeof loop, 0x1234, a));
|
TEST_ASSERT_FALSE(parseDnsAnswer(loop, sizeof loop, 0x1234, a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_ntp() {
|
||||||
|
uint8_t req[kNtpPacket];
|
||||||
|
buildNtpRequest(req);
|
||||||
|
TEST_ASSERT_EQUAL_HEX8(0x23, req[0]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0, req[47]);
|
||||||
|
// A server's answer: stratum 2, transmit time 2026-10-08 00:45:12.5 UTC.
|
||||||
|
uint8_t ans[kNtpPacket] = {0x24, 2};
|
||||||
|
uint32_t secs = 1791420312u + 2208988800u;
|
||||||
|
ans[40] = static_cast<uint8_t>(secs >> 24);
|
||||||
|
ans[41] = static_cast<uint8_t>(secs >> 16);
|
||||||
|
ans[42] = static_cast<uint8_t>(secs >> 8);
|
||||||
|
ans[43] = static_cast<uint8_t>(secs);
|
||||||
|
ans[44] = 0x80; // half a second
|
||||||
|
NtpAnswer a;
|
||||||
|
TEST_ASSERT_TRUE(parseNtpAnswer(ans, sizeof ans, a));
|
||||||
|
TEST_ASSERT_EQUAL_INT(2, a.stratum);
|
||||||
|
TEST_ASSERT_TRUE(a.seconds == 1791420312);
|
||||||
|
TEST_ASSERT_EQUAL_UINT32(500, a.millis);
|
||||||
|
TEST_ASSERT_FALSE(parseNtpAnswer(ans, 40, a)); // cut short
|
||||||
|
ans[1] = 0;
|
||||||
|
TEST_ASSERT_FALSE(parseNtpAnswer(ans, sizeof ans, a)); // "go away"
|
||||||
|
ans[1] = 2;
|
||||||
|
ans[0] = 0x23;
|
||||||
|
TEST_ASSERT_FALSE(parseNtpAnswer(ans, sizeof ans, a)); // a client's packet, not a server's
|
||||||
|
// After 2036 the count starts again from zero.
|
||||||
|
ans[0] = 0x24;
|
||||||
|
ans[40] = ans[41] = ans[42] = 0;
|
||||||
|
ans[43] = 10;
|
||||||
|
TEST_ASSERT_TRUE(parseNtpAnswer(ans, sizeof ans, a));
|
||||||
|
TEST_ASSERT_TRUE(a.seconds == 4294967296LL + 10 - 2208988800LL);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_STRING("right, to 0.1 s", clockOffset(1000000, 1000040).c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("0.3 s ahead", clockOffset(1000300, 1000000).c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("2.5 s behind", clockOffset(1000000, 1002500).c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("45 s behind", clockOffset(0, 45000).c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("3 min ahead", clockOffset(180000, 0).c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("5 h behind", clockOffset(0, 18000000).c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("20552 days behind", clockOffset(0, 1775700000000LL).c_str()); // a clock still in 1970
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_certificates_and_ports() {
|
||||||
|
TEST_ASSERT_EQUAL_STRING("R11", certName("C=US, O=Let's Encrypt, CN=R11").c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("git.twis.la", certName("CN=git.twis.la").c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("Example Org", certName("C=BE, O=Example Org").c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("C=BE", certName("C=BE").c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("x", certName("O=Not this, DCN=nor this, CN=x").c_str());
|
||||||
|
TEST_ASSERT_EQUAL_STRING("*.badssl.com", certName("OU=PositiveSSL Wildcard, CN=#140C2A2E62616473736C2E636F6D").c_str()); // an old kind of string
|
||||||
|
TEST_ASSERT_EQUAL_STRING("#14zz", certName("CN=#14zz").c_str());
|
||||||
|
TEST_ASSERT_EQUAL_INT(1, daysBetween(2026, 10, 7, 2026, 10, 8));
|
||||||
|
TEST_ASSERT_EQUAL_INT(53, daysBetween(2026, 10, 8, 2026, 11, 30));
|
||||||
|
TEST_ASSERT_EQUAL_INT(-8, daysBetween(2026, 10, 8, 2026, 9, 30));
|
||||||
|
TEST_ASSERT_EQUAL_INT(366, daysBetween(2028, 1, 1, 2029, 1, 1)); // a leap year
|
||||||
|
TEST_ASSERT_EQUAL_INT(365, daysBetween(2100, 1, 1, 2101, 1, 1)); // and a year that isn't one
|
||||||
|
TEST_ASSERT_EQUAL_STRING("updates", portLabel(3232, true));
|
||||||
|
TEST_ASSERT_EQUAL_STRING("Debug Console", portLabel(2323, true));
|
||||||
|
TEST_ASSERT_EQUAL_STRING("sharing", portLabel(80, true));
|
||||||
|
TEST_ASSERT_EQUAL_STRING("", portLabel(80, false));
|
||||||
|
TEST_ASSERT_EQUAL_STRING("DHCP", portLabel(68, false));
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
UNITY_BEGIN();
|
UNITY_BEGIN();
|
||||||
RUN_TEST(test_what_was_typed);
|
RUN_TEST(test_what_was_typed);
|
||||||
@@ -150,5 +210,7 @@ int main() {
|
|||||||
RUN_TEST(test_the_summary);
|
RUN_TEST(test_the_summary);
|
||||||
RUN_TEST(test_a_dns_query);
|
RUN_TEST(test_a_dns_query);
|
||||||
RUN_TEST(test_a_dns_answer);
|
RUN_TEST(test_a_dns_answer);
|
||||||
|
RUN_TEST(test_ntp);
|
||||||
|
RUN_TEST(test_certificates_and_ports);
|
||||||
return UNITY_END();
|
return UNITY_END();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,30 +17,30 @@ static const uint8_t kMeshtastic[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void test_row_for_a_meshtastic_packet() {
|
void test_row_for_a_meshtastic_packet() {
|
||||||
PacketSummary p{kMeshtastic, sizeof kMeshtastic, -97.4f, 6.25f, true, true};
|
PacketSummary p{kMeshtastic, sizeof kMeshtastic, -97.4f, 6.25f, true, Protocol::Meshtastic};
|
||||||
// Time, RSSI, SNR, then who sent it to whom (by default short name: the last 4 hex digits,
|
// Time, RSSI, SNR, then who sent it to whom (by default short name: the last 4 hex digits,
|
||||||
// as Meshtastic names a Node) and how far it came. Fits 40 columns with two node numbers.
|
// as Meshtastic names a Node) and how far it came. Fits 40 columns with two node numbers.
|
||||||
TEST_ASSERT_EQUAL_STRING("21:45:07 -97 6.2 5678>all 1/3", row(p, "21:45:07").c_str());
|
TEST_ASSERT_EQUAL_STRING("21:45:07 -97 6.2 5678>all 1/3", row(p, "21:45:07").c_str());
|
||||||
const uint8_t direct[] = {0x0a, 0x0b, 0x0c, 0x0d, 0xc4, 0xd3, 0xb2, 0xa1, 1, 2, 3, 4, 0x6a, 8, 0, 0xaa};
|
const uint8_t direct[] = {0x0a, 0x0b, 0x0c, 0x0d, 0xc4, 0xd3, 0xb2, 0xa1, 1, 2, 3, 4, 0x6a, 8, 0, 0xaa};
|
||||||
PacketSummary d{direct, sizeof direct, -117.0f, -9.25f, true, true};
|
PacketSummary d{direct, sizeof direct, -117.0f, -9.25f, true, Protocol::Meshtastic};
|
||||||
TEST_ASSERT_EQUAL_STRING("21:45:07 -117 -9.2 d3c4>0b0a 1/3", row(d, "21:45:07").c_str());
|
TEST_ASSERT_EQUAL_STRING("21:45:07 -117 -9.2 d3c4>0b0a 1/3", row(d, "21:45:07").c_str());
|
||||||
TEST_ASSERT_TRUE(row(d, "21:45:07").size() <= 38);
|
TEST_ASSERT_TRUE(row(d, "21:45:07").size() <= 38);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_row_for_something_else() {
|
void test_row_for_something_else() {
|
||||||
const uint8_t data[] = {0x40, 0x01, 0x02};
|
const uint8_t data[] = {0x40, 0x01, 0x02};
|
||||||
PacketSummary p{data, sizeof data, -120.6f, -7.5f, true, false};
|
PacketSummary p{data, sizeof data, -120.6f, -7.5f, true, Protocol::None};
|
||||||
TEST_ASSERT_EQUAL_STRING("21:45:07 -121 -7.5 3 B", row(p, "21:45:07").c_str());
|
TEST_ASSERT_EQUAL_STRING("21:45:07 -121 -7.5 3 B", row(p, "21:45:07").c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not on Meshtastic settings (LoRaWAN, say): the same bytes aren't read as a Meshtastic header.
|
// Not on Meshtastic settings (LoRaWAN, say): the same bytes aren't read as a Meshtastic header.
|
||||||
void test_row_not_meshtastic() {
|
void test_row_not_meshtastic() {
|
||||||
PacketSummary p{kMeshtastic, sizeof kMeshtastic, -97.0f, 6.0f, true, false};
|
PacketSummary p{kMeshtastic, sizeof kMeshtastic, -97.0f, 6.0f, true, Protocol::None};
|
||||||
TEST_ASSERT_EQUAL_STRING("21:45:07 -97 6.0 19 B", row(p, "21:45:07").c_str());
|
TEST_ASSERT_EQUAL_STRING("21:45:07 -97 6.0 19 B", row(p, "21:45:07").c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_row_with_a_bad_crc() {
|
void test_row_with_a_bad_crc() {
|
||||||
PacketSummary p{kMeshtastic, sizeof kMeshtastic, -97.0f, 6.0f, false, true};
|
PacketSummary p{kMeshtastic, sizeof kMeshtastic, -97.0f, 6.0f, false, Protocol::Meshtastic};
|
||||||
TEST_ASSERT_EQUAL_STRING("21:45:07 -97 6.0 bad CRC, 19 B", row(p, "21:45:07").c_str());
|
TEST_ASSERT_EQUAL_STRING("21:45:07 -97 6.0 bad CRC, 19 B", row(p, "21:45:07").c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||