diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 972d2d0..5bd4140 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -57,36 +57,67 @@ jobs: DMODEM_SSH_TEST_PPK="$RUNNER_TEMP/key.ppk" DMODEM_SSH_TEST_AGENT="$RUNNER_TEMP/agent.sock" \ build/ssh/dmodemssh_test + # Both Windows builds use clang-retro (https://clang-retro.github.io/), + # its toolchain package from its setup-toolchain action, on Linux windows-9x: - name: Windows 95 and later (Open Watcom) + name: Windows 95 and later (clang-retro, win32-picolibc) runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - - uses: open-watcom/setup-watcom@v0 - with: - version: "2.0" + - uses: clang-retro/dos-sdk/.github/actions/setup-toolchain@main + id: clang-dos + - name: Packages + run: | + sudo dpkg --add-architecture i386 + sudo apt-get update + sudo apt-get install -y --no-install-recommends ninja-build wine wine32:i386 - name: Build - run: sh windows/build-watcom.sh build/watcom + run: | + cmake -S . -B build/win9x -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_TOOLCHAIN_FILE=cmake/clang-retro.cmake -DCLANG_RETRO_CONFIG=win32-picolibc \ + -DCMAKE_CROSSCOMPILING_EMULATOR=wine + cmake --build build/win9x + - name: Test (Wine) + run: | + export WINEDEBUG=-all WINEPREFIX="$RUNNER_TEMP/wine" + wineboot -i >/dev/null 2>&1 || true + ctest --test-dir build/win9x --output-on-failure + - name: Imports (Windows 95, 98 and ME, and NT 4.0) + run: | + python3 "$CLANG_DOS/share/clang-dos/check-imports.py" build/win9x/windows/dmodem.exe + python3 "$CLANG_DOS/share/clang-dos/check-imports.py" --nt 4.0 build/win9x/windows/dmodem.exe - uses: actions/upload-artifact@v4 with: name: dmodem-windows-9x - path: build/watcom/dmodem.exe + path: build/win9x/windows/dmodem.exe windows: - name: Windows (MSVC) - runs-on: windows-latest + name: Windows 7 and later (clang-retro, with SSH) + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 + - uses: clang-retro/dos-sdk/.github/actions/setup-toolchain@main + id: clang-dos + - name: Packages + run: | + sudo dpkg --add-architecture i386 + sudo apt-get update + sudo apt-get install -y --no-install-recommends ninja-build wine wine32:i386 - name: Build run: | - cmake -S . -B build -A Win32 - cmake --build build --config Release - - name: Test - run: ctest --test-dir build -C Release --output-on-failure + cmake -S . -B build/win7 -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_TOOLCHAIN_FILE=cmake/clang-retro.cmake -DCLANG_RETRO_CONFIG=win7 \ + -DDMODEM_GUI_SSH=ON -DCMAKE_CROSSCOMPILING_EMULATOR=wine + cmake --build build/win7 + - name: Test (Wine) + run: | + export WINEDEBUG=-all WINEPREFIX="$RUNNER_TEMP/wine" + wineboot -i >/dev/null 2>&1 || true + ctest --test-dir build/win7 --output-on-failure - uses: actions/upload-artifact@v4 with: name: dmodem-windows - path: build/windows/Release/dmodem.exe + path: build/win7/windows/dmodem.exe macos: name: macOS (SwiftUI) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8fc16f..4094946 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,7 @@ # D-Modem's desktop apps: the shared C core (libdmodemctl), and the # Linux app (GTK 4 and libadwaita) when its libraries are there, or the -# Windows app with MinGW or MSVC. The Windows 95 build of the Windows -# app (windows/build-watcom.sh) and the macOS app (macos/) build with -# their own tools and take the core from here. +# Windows app with clang-retro (cmake/clang-retro.cmake), MinGW or MSVC. +# The macOS app (macos/) builds with Xcode and takes the core from here. cmake_minimum_required(VERSION 3.16) project(dmodem-gui VERSION 1.0.0 LANGUAGES C) @@ -10,11 +9,21 @@ set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) option(DMODEM_GUI_LINUX "Build the GTK 4 app (linux/)" ON) +# (clang-retro, cmake/clang-retro.cmake: the Windows 95 build, which has +# no libssh, as mbedTLS and libssh need Windows Vista) +if(CLANG_DOS) + set(_ssh_default OFF) +else() + set(_ssh_default ON) +endif() +option(DMODEM_GUI_SSH "Build libdmodemssh (libssh) for the Remote page" ${_ssh_default}) add_subdirectory(core) enable_testing() add_subdirectory(core/test) -add_subdirectory(ssh) +if(DMODEM_GUI_SSH) + add_subdirectory(ssh) +endif() if(WIN32) add_subdirectory(windows) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 21440d9..b53cdac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,9 @@ # Contributing -Contributions are welcome: issues, fixes and features alike. Before -sending a change, build it on the platforms it affects ([README.md](README.md)). +We accept contributions: issues, fixes and features. Before you send a +change, build it on the platforms that it affects ([README.md](README.md)). + +Write all technical documentation in ASD-STE100 Simplified Technical English. Follow docs/STYLE.md. ## The contributor agreement @@ -50,9 +52,9 @@ does it): It says that you agree to the above for that commit. A contribution without it cannot be merged. -A check on each pull request looks for that line, with the commit -author's email, on every commit. If it's missing, `git rebase --signoff -main` (or `git commit --amend -s` for the last commit) adds it; then -force-push. Pull requests from the D-Modem Authors themselves (the -repository's owner and the D-Modem organization's members) are not -checked. +A check on each pull request looks for that line, with the email of the +commit author, on each commit. If the line is missing, use +`git rebase --signoff main` to add it. For the last commit only, you can +use `git commit --amend -s`. Then force-push. The check does not examine +pull requests from the D-Modem Authors (the owner of the repository and +the members of the D-Modem organization). diff --git a/README.md b/README.md index aa433ef..9309c08 100644 --- a/README.md +++ b/README.md @@ -4,27 +4,27 @@ Native apps for D-Modem on Windows, macOS and Linux. -Each app starts dmodemd (or reaches one that already runs), and shows the -modem as a desktop program should: dial and answer from a window, change -its settings without AT commands, and see how the last call went. All three -are thin native shells over one small C library, libdmodemctl, so they -behave the same. +Each app starts dmodemd (or connects to a dmodemd that already runs). It +shows the modem as a desktop program. You can dial and answer from a window, +change the settings without AT commands, and see the results of the last +call. All three apps are thin native shells over one small C library, +libdmodemctl. Thus they operate in the same way. -- **Modem**: the call's state, dial, answer and hang up, and the line it uses +- **Modem**: the state of the call, dial, answer and hang up, and the line that the modem uses - **Phone**: voice calls through the sound card (dial, answer, keypad), and an - answering machine that takes messages on this computer when turned on (off by default) -- **Terminal**: the AT console, and the modem's own setup screens (AT!CF, AT!CT) -- **Remote**: log in to a server by SSH (built in, on libssh: OpenSSH's keys, agent, config and known hosts; PuTTY's `.ppk` keys used or imported; Pageant on Windows, an ssh-agent on Linux and macOS), Telnet or rlogin, in a terminal of its own -- **Terminal types**: both terminals are the D-Modem app's emulator, ported to C: - xterm, DEC's VT52 to VT525, ANSI-BBS (with Avatar, RIPscrip and Amiga ANSI), - the Commodores' PETSCII, the Atari 8-bit's ATASCII and the ST, Viewdata, - the Minitel and the Tektronix 4014, with sixel, ReGIS and Tektronix - graphics, and each machine's own font (SyncTERM's copies of their ROMs, + answering machine that takes messages on this computer when you enable it (disabled by default) +- **Terminal**: the AT console, and the setup screens of the modem (AT!CF, AT!CT) +- **Remote**: log in to a server by SSH, Telnet or rlogin, in a separate terminal. SSH is built in, on libssh: it uses the keys, agent, config and known hosts of OpenSSH. It can use or import the `.ppk` keys of PuTTY. It uses Pageant on Windows, and an ssh-agent on Linux and macOS +- **Terminal types**: the two terminals use the emulator of the D-Modem app, ported to C: + xterm, the VT52 to VT525 of DEC, ANSI-BBS (with Avatar, RIPscrip and Amiga ANSI), + the PETSCII of the Commodores, the ATASCII of the Atari 8-bit and the ST, Viewdata, + the Minitel and the Tektronix 4014. They have sixel, ReGIS and Tektronix + graphics, and the font of each machine (the SyncTERM copies of their ROMs, LGPL-2.0-or-later: `core/licenses/syncterm-fonts-LGPL-2.0.txt`) -- **Settings**: every modem setting as a native control, from AT!M -- **Call Stats**: the last call's rate, modulation, error control and line figures (AT#UD, ATI11) -- **Line settings**: a SIP account, a USB modem, or a modem that already runs -- **Windows 95 and later**: plain Win32, built with Open Watcom; on Windows 9x it reaches a modem over TCP or a COM port +- **Settings**: each modem setting as a native control, from AT!M +- **Call Stats**: the rate, modulation, error control and line figures of the last call (AT#UD, ATI11) +- **Line settings**: a SIP account, a USB modem, or a modem that already runs (dmodemd, or a hardware modem such as the MultiTech MT9234MU) +- **Windows 95 and later**: plain Win32, built with [clang-retro](https://clang-retro.github.io/). On Windows 9x, the app connects to a modem through TCP or a COM port | | Windows | macOS | Linux | | --- | --- | --- | --- | @@ -43,22 +43,41 @@ Linux: libsndfile1-dev cmake -S . -B build && cmake --build build && ./build/linux/dmodem-gui -Windows: `cmake -S . -B build -A Win32 && cmake --build build --config Release`, -or for Windows 95 and later, `windows/build-watcom.sh` with Open Watcom 2.0. +Windows: we build the Windows app with clang-retro. Get its toolchain +package (`clang-dos-linux-x86_64.tar.xz` or `clang-dos-windows-x86_64.zip`, +from the [nightly release](https://github.com/clang-retro/dos-sdk/releases/tag/nightly)). +Then set `CLANG_DOS` to the directory of the package: -macOS: `cmake -S . -B build -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DCMAKE_OSX_DEPLOYMENT_TARGET=13.0 && cmake --build build` -(libssh, for SSH), then `brew install xcodegen && cd macos && xcodegen && open DModem.xcodeproj`. + # Windows 95, 98, ME, NT 4.0 and later (no SSH, no C runtime DLL) + cmake -S . -B build/win9x -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DCLANG_DOS=/opt/clang-dos -DCMAKE_TOOLCHAIN_FILE=cmake/clang-retro.cmake + cmake --build build/win9x -The first CMake build downloads libssh and mbedTLS for SSH (Windows and -macOS always; Linux when the system's libssh is older than 0.11). + # Windows 7 and later, with SSH + cmake -S . -B build/win7 -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DCLANG_DOS=/opt/clang-dos -DCMAKE_TOOLCHAIN_FILE=cmake/clang-retro.cmake \ + -DCLANG_RETRO_CONFIG=win7 -DDMODEM_GUI_SSH=ON + cmake --build build/win7 -The Settings page needs a dmodemd with AT!M (D-Modem's main branch since -D-Modem/D-Modem#103); the other pages work with any D-Modem 1.0. +The app is in `windows/dmodem.exe` of the build directory. MSVC +(`cmake -S . -B build -A Win32`) and MinGW also build the same code. + +macOS: first use `cmake -S . -B build -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DCMAKE_OSX_DEPLOYMENT_TARGET=13.0 && cmake --build build` +(this builds libssh, for SSH). Then use `brew install xcodegen && cd macos && xcodegen && open DModem.xcodeproj`. + +The first CMake build downloads libssh and mbedTLS for SSH. This always +occurs on Windows (when SSH is on) and macOS. On Linux, it occurs if the libssh of the system +is older than 0.11. + +The Settings page needs a dmodemd with AT!M (the main branch of D-Modem +since D-Modem/D-Modem#103). The other pages operate with all versions of +D-Modem 1.0. ## Documentation -- [Design](docs/design.md): how the apps are built, what they share, and the Windows 9x notes -- [libdmodemctl](core/include/dmodemctl.h): the library's API +- [Design](docs/design.md): how the apps are built, what they share, hardware modems (the MultiTech MT9234MU), and the Windows 9x notes +- [libdmodemctl](core/include/dmodemctl.h): the API of the library +- [Documentation style](docs/STYLE.md): the rules for ASD-STE100 Simplified Technical English ## The D-Modem suite diff --git a/cmake/clang-retro.cmake b/cmake/clang-retro.cmake new file mode 100644 index 0000000..3214294 --- /dev/null +++ b/cmake/clang-retro.cmake @@ -0,0 +1,46 @@ +# CMake toolchain file for clang-retro (https://clang-retro.github.io/): +# the Windows app for Windows 95 and later, built on Linux or Windows. +# +# cmake -S . -B build/retro -DCLANG_DOS=/opt/clang-dos \ +# -DCMAKE_TOOLCHAIN_FILE=cmake/clang-retro.cmake +# +# CLANG_DOS is the unpacked clang-dos toolchain package (the environment +# variable CLANG_DOS also sets it). CLANG_RETRO_CONFIG is the --config +# file of the target (default win32-picolibc: Windows 95, 98, ME, NT 4.0 +# and later, with no C runtime DLL). +set(CMAKE_SYSTEM_NAME Windows) +set(CMAKE_SYSTEM_VERSION 4.0) +set(CMAKE_SYSTEM_PROCESSOR i386) + +if(NOT CLANG_DOS AND DEFINED ENV{CLANG_DOS}) + set(CLANG_DOS "$ENV{CLANG_DOS}") +endif() +if(NOT CLANG_DOS) + message(FATAL_ERROR "Set CLANG_DOS to the clang-dos toolchain package") +endif() +set(CLANG_DOS "${CLANG_DOS}" CACHE PATH "The clang-dos toolchain package") +set(CLANG_RETRO_CONFIG win32-picolibc CACHE STRING "The clang-retro --config file (without .cfg)") +# (try_compile projects see these two) +list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CLANG_DOS CLANG_RETRO_CONFIG) + +if(CMAKE_HOST_WIN32) + set(_exe .exe) +else() + set(_exe "") +endif() +# (the --config file is a mandatory argument of the compilers, not a flag, +# so that a -DCMAKE_C_FLAGS of a project, or of an ExternalProject, keeps it) +set(_cfg "--config=${CLANG_DOS}/bin/${CLANG_RETRO_CONFIG}.cfg") +set(CMAKE_C_COMPILER "${CLANG_DOS}/bin/clang${_exe}" "${_cfg}") +set(CMAKE_CXX_COMPILER "${CLANG_DOS}/bin/clang++${_exe}" "${_cfg}") +set(CMAKE_RC_COMPILER "${CLANG_DOS}/bin/llvm-windres${_exe}") +set(CMAKE_AR "${CLANG_DOS}/bin/llvm-ar${_exe}") +set(CMAKE_RANLIB "${CLANG_DOS}/bin/llvm-ranlib${_exe}") +# windres runs the preprocessor of clang for the target +set(CMAKE_RC_FLAGS_INIT "--target=pe-i386 --preprocessor-arg=${_cfg}") + +list(APPEND CMAKE_FIND_ROOT_PATH "${CLANG_DOS}") +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) diff --git a/core/src/session.c b/core/src/session.c index fc0b4ce..ebb5a1b 100644 --- a/core/src/session.c +++ b/core/src/session.c @@ -43,6 +43,8 @@ /* a line longer than this keeps only its end (a configurator's screens come with no line ends, and its OK after the last one) */ #define LINE_MAX 4096 +/* the most pages of one response that the session pages on */ +#define PAGES_MAX 8 /* voice: how far ahead of the line our samples go (60 ms), how many of the far end's are kept (1 s), how many of ours may wait (a third of @@ -120,6 +122,10 @@ struct dmc_session { struct command *queue, *active; int64_t active_until; int echo_seen; + /* the pages of its response that the session paged on (a key sent + to "Press any key") */ + int pages; + int prompt; /* the rest of the prompt's line: dropped */ dmc_buf response; int next_tag; /* the events, and the one dmc_next_event() last gave */ @@ -378,6 +384,8 @@ static void pump(dmc_session *s) s->active = c; s->active_until = s->now + c->timeout_ms; s->echo_seen = 0; + s->pages = 0; + s->prompt = 0; buf_clear(&s->response); buf_adds(&s->out, c->cmd); buf_addc(&s->out, '\r'); @@ -770,6 +778,17 @@ static void line_in(dmc_session *s, const char *l) static void voice_byte(dmc_session *s, unsigned char c); +/* whether l is a pager's prompt: a modem that shows a long response in + pages (ATI11 on the Agere modems, the MultiTech MT9234 among them) + stops after each page at "Press any key to continue; ESC to quit" */ +static int pager_prompt(const char *l) +{ + for (; *l; l++) + if (starts_ci(l, "any key")) + return 1; + return 0; +} + void dmc_feed(dmc_session *s, const char *data, int n) { if (s->state == DMC_CLOSED) @@ -783,16 +802,35 @@ void dmc_feed(dmc_session *s, const char *data, int n) int quiet = s->active && (s->active->flags & DMC_QUIET); if (!quiet) buf_addc(&s->term, c); + if (c == '\n' && s->prompt) { + s->prompt = 0; + continue; + } if (c == '\n') { line_in(s, buf_str(&s->line)); buf_clear(&s->line); continue; } - if (c == '\r') + if (c == '\r') { + s->prompt = 0; + continue; + } + if (s->prompt) continue; if (s->line.n >= LINE_MAX) buf_drop(&s->line, s->line.n - LINE_MAX / 2); buf_addc(&s->line, c); + /* a command's response in pages: the next page asked for + (a space), the prompt kept out of the response */ + if (s->active && (s->state == DMC_IDLE || + s->state == DMC_ONLINE_COMMAND) && + s->pages < PAGES_MAX && pager_prompt(buf_str(&s->line))) { + buf_addc(&s->out, ' '); + buf_clear(&s->line); + s->prompt = 1; + s->pages++; + s->active_until = s->now + s->active->timeout_ms; + } } } diff --git a/core/src/vt_profiles.c b/core/src/vt_profiles.c index 591b737..d48c904 100644 --- a/core/src/vt_profiles.c +++ b/core/src/vt_profiles.c @@ -88,8 +88,8 @@ static const uint8_t cbm_cbm[8] = { }; /* ------------------------------------------------------------------ */ -/* the profiles (in the struct's order: no designated initialisers for - Open Watcom) */ +/* the profiles (in the struct's order: no designated initialisers, for + older compilers) */ /* a DEC terminal */ #define DEC(id, label, term, telnet, level, features, da1, da2, home) \ diff --git a/core/src/vtint.h b/core/src/vtint.h index 1390bd9..581c376 100644 --- a/core/src/vtint.h +++ b/core/src/vtint.h @@ -12,8 +12,8 @@ * A C port of the D-Modem app's shared Kotlin emulator * (D-Modem/app: shared/src/commonMain/kotlin/org/dmodem/app/terminal), * kept close to it so that a change there can be carried here: the same - * parts, the same names where C allows, the same behaviour. C99 as - * Open Watcom takes it (no designated initialisers, no VLAs). + * parts, the same names where C allows, the same behaviour. C99 with + * no designated initialisers and no VLAs, for older compilers too. */ #ifndef DMC_VTINT_H #define DMC_VTINT_H diff --git a/core/test/dmodemctl_test.c b/core/test/dmodemctl_test.c index d9f2b0e..0001080 100644 --- a/core/test/dmodemctl_test.c +++ b/core/test/dmodemctl_test.c @@ -140,6 +140,32 @@ static void test_command(void) dmc_session_free(s); } +/* a response in pages (ATI11 on an Agere modem, a MultiTech MT9234): + a space for each "Press any key", the prompt kept out of the response */ +static void test_pages(void) +{ + dmc_session *s = dmc_session_new(); + dmc_event ev; + dmc_open(s, 0); + int tag = dmc_command(s, "ATI11", DMC_QUIET, 0); + CHECK_STR(out(s), "ATI11\r"); + feed(s, "ATI11\r\r\nLast Connection V.92\r\n" + "Press any key to continue; ESC to quit"); + CHECK_STR(out(s), " "); + CHECK(!next_of(s, DMC_EV_RESPONSE, &ev)); + feed(s, "\r\nNear Echo Level NA\r\n\r\nOK\r\n"); + CHECK_STR(out(s), ""); + CHECK(next_of(s, DMC_EV_RESPONSE, &ev)); + CHECK(ev.tag == tag && ev.ok); + CHECK_STR(ev.text, "Last Connection V.92\n\nNear Echo Level NA"); + /* text typed in the terminal is the user's own: no key sent */ + dmc_type(s, "ATI11\r", 6); + out(s); + feed(s, "ATI11\r\r\nPress any key to continue"); + CHECK_STR(out(s), ""); + dmc_session_free(s); +} + /* a call: dial, connect, online data, hang up through the escape */ static void test_call(void) { @@ -1236,6 +1262,7 @@ int main(int argc, char **argv) const char *dir = argc > 1 ? argv[1] : "."; CHECK(dmc_version() == DMC_VERSION); test_command(); + test_pages(); test_call(); test_unsolicited(); test_typed(); diff --git a/docs/STYLE.md b/docs/STYLE.md new file mode 100644 index 0000000..2e7fd3e --- /dev/null +++ b/docs/STYLE.md @@ -0,0 +1,142 @@ +# Documentation style: ASD-STE100 Simplified Technical English + +All technical documentation in the D-Modem project uses ASD-STE100 +Simplified Technical English (STE). This guide gives the rules that we use. +It applies to READMEs, the `docs/` folders, wikis, specifications, design +documents, protocol write-ups, CONTRIBUTING files (except legal text) and +technical notes in the project files. + +The official source is the ASD-STE100 specification (Issue 9) and its +dictionary. If this guide and the specification are different, use the +specification. You can get the specification free of charge from +. + +## 1. What STE does not change + +Do not change these items. Copy them exactly: + +- Code, commands, file names, paths, URLs, identifiers and configuration keys. +- AT commands, S-registers, result codes and protocol message names. +- Numbers, units, addresses, offsets and register values. +- Titles of standards (for example, ITU-T V.92) and quotations from them. +- Product names, company names and the names of people. +- Legal text: licenses, the contributor agreement, copyright and trademark + notices. Legal text keeps its legal wording. +- Text that we copied from a third party (for example, `ORIGINAL-readme.txt` + files, firmware release notes, test fixtures). + +## 2. Words + +1. Use approved words from the STE dictionary, with their approved meaning + only. For example, "close" means "to move to the closed position". It + does not mean "near". +2. Use technical names (Category: technical names). For example: modem, + handshake, carrier, codec, constellation, packet, socket, thread, + buffer, firmware, sample rate, call, line, PBX, trunk, server, client. +3. Use technical verbs (Category: technical verbs) for processes that STE + does not cover. This project uses these technical verbs: build, compile, + link, configure, install, uninstall, boot, flash, download, upload, dial, + log in, log out, debug, decode, encode, modulate, demodulate, train, + retrain, negotiate, sign, encrypt, decrypt, compress, decompress, parse, + render, cache, merge, commit, push, clone, emulate, probe. +4. Use one word for one thing. Do not change between synonyms. For example, + if you write "softmodem", do not write "software modem" in the next + paragraph. +5. Use these verb forms only: infinitive, imperative, simple present, simple + past, simple future, and the past participle as an adjective. +6. Do not use "-ing" forms of verbs, except in technical names (for example, + "ring signal", "echo canceller"). Write "the modem starts to train", not + "the modem is training". +7. Do not use phrasal verbs. Write "start", not "start up". Write "find", + not "find out". +8. Do not make noun clusters of more than three words. Use prepositions to + break up longer clusters. Write "the receive buffer of the V.34 data + pump", not "the V.34 data pump receive buffer". +9. Use articles ("the", "a") and demonstrative adjectives ("this", "these") + before nouns where possible. +10. Do not use slang, idioms, contractions ("can't", "it's") or Latin + abbreviations ("e.g.", "i.e.", "etc."). Write "for example", "that is", + "and other items". + +### Common replacements + +| Do not write | Write | +|---|---| +| utilize, make use of | use | +| ensure, make certain | make sure | +| require, need to | is necessary, must | +| should | must (a rule) or write what occurs (a fact) | +| allow, enable (a person) | let, make it possible | +| approximately, roughly | about | +| perform, carry out | do | +| obtain, fetch, grab | get | +| prior to | before | +| in order to | to | +| via | through | +| currently | now | +| additional | more | +| e.g., i.e., etc. | for example, that is, and other items | +| turn on / turn off (a setting) | enable / disable (technical verbs for software settings) | +| set up (verb) | configure, install | +| figure out, find out | find, calculate | +| it's, can't, don't | it is, cannot, do not | + +## 3. Sentences + +1. Write one topic in one sentence. +2. Procedural sentences (instructions): 20 words or fewer. +3. Descriptive sentences: 25 words or fewer. +4. Use the active voice. In descriptive text, you can use the passive voice + only when you do not know who or what does the action. +5. Do not use semicolons to join sentences. Write two sentences. +6. Use a colon before a list. Use a vertical list when there are more than + two items. +7. Use connecting words ("then", "but", "if", "because") to show how two + sentences are related. + +## 4. Procedures + +1. Write instructions in the imperative ("Install the package"). +2. Write one instruction in one sentence. You can write two actions in one + sentence only when the reader does them at the same time. +3. Write each step as a numbered item. +4. If a condition applies, write the condition first: "If the build fails, + delete the `build/` folder." +5. Put a warning or a caution before the step that it applies to. Do not put + it at the end of the procedure. +6. Write the result of a step in a separate sentence after the step, if the + reader must know it. + +## 5. Descriptive writing + +1. Give the most important information first. +2. Write one topic in one paragraph. +3. Do not write more than six sentences in a paragraph. +4. Use headings to divide long text into short sections. +5. Use tables for data that has rows and columns. + +## 6. Warnings and cautions + +Use a warning for a risk to persons. Use a caution for a risk to equipment, +data or the telephone line. Start with a short title, then the instruction, +then the risk: + +> **CAUTION: DO NOT CONNECT THE BOARD TO A LIVE LINE WITHOUT THE ISOLATION +> TRANSFORMER.** The line voltage can cause damage to the codec. + +## 7. Examples + +| Before | After (STE) | +|---|---| +| You'll need to make sure the PBX is set up before you dial out. | Configure the PBX before you dial. | +| The handshake is performed by the answering modem, which then starts sending ANSam. | The answering modem starts the handshake. Then it sends ANSam. | +| Turn it off if it's causing trouble. | If this feature causes problems, disable it. | +| `crypto/tls` can't take such a hello, and it can't be rewritten for it. | `crypto/tls` cannot accept this type of hello. Also, you cannot change `crypto/tls` to accept it. | + +## 8. Check before you commit + +- Are all sentences short (20 words for instructions, 25 for descriptions)? +- Is each instruction in the imperative, with one action? +- Is there a word with "-ing", a phrasal verb or a contraction? +- Are code, commands and identifiers exactly the same as before? +- Did you keep legal text and third-party text unchanged? diff --git a/docs/design.md b/docs/design.md index 7d91c1a..c79bd48 100644 --- a/docs/design.md +++ b/docs/design.md @@ -2,36 +2,38 @@ ## One library, three native shells -The apps share everything that is not drawing. `core/` is libdmodemctl, a -small C library with no I/O and no threads ("sans-I/O"): each app opens the -modem in its own way, hands the bytes it reads to `dmc_feed()`, writes what -`dmc_output()` gives it, and calls `dmc_poll()` from a 50 ms timer. That -keeps it easy to call from C (GTK), C++ (Win32) and Swift, and easy to test -(`core/test`, run by CI with ASan and UBSan). +The apps share all the code that does not draw. `core/` is libdmodemctl, a +small C library with no I/O and no threads ("sans-I/O"). Each app opens the +modem in its own way. Then it gives the bytes that it reads to `dmc_feed()`, +writes the data that `dmc_output()` gives it, and calls `dmc_poll()` from a +50 ms timer. Thus the library is easy to call from C (GTK), C++ (Win32) and +Swift. It is also easy to test (`core/test`, which CI runs with ASan and +UBSan). | Part | What it does | | --- | --- | -| `dmc_session` | The AT conversation: a queue of commands and their responses, the call's state from the result codes (RING, CONNECT, NO CARRIER), caller ID, the escape (`+++` with its guard times) and hanging up, and the byte stream for the terminal | -| `dmc_model` | The modem's settings from AT!M, with each setting's check and the command that sets it | -| `dmc_path` | The connection path at the top of the Settings page: the terminal, the modem, the line and what it reaches, each step's role, name, state and what it is set to, from the line settings and the session's state | -| `dmc_diag` | The last call's statistics from AT#UD, as labelled rows (the V.58 code tables decoded) | -| `dmc_vt` | The terminal emulator of the D-Modem app (D-Modem/app's `shared/.../terminal`), ported to C: every kind of terminal it is (see below), drawn by each app from its cells | -| `dmc_net` | Telnet (option negotiation, terminal type, window size) and rlogin (the handshake, window size on the server's urgent request), for the Remote page | -| `dmc_daemon_*` | Reading what dmodemd prints when it starts: the device it made, or its error | +| `dmc_session` | The AT conversation: a queue of commands and their responses, the state of the call from the result codes (RING, CONNECT, NO CARRIER), caller ID, the escape (`+++` with its guard times) and the hang-up, and the byte stream for the terminal | +| `dmc_model` | The settings of the modem from AT!M, with the check of each setting and the command that sets it | +| `dmc_path` | The connection path at the top of the Settings page: the terminal, the modem, the line and what the line reaches. For each step, its role, name, state and setting, from the line settings and the state of the session | +| `dmc_diag` | The statistics of the last call from AT#UD, as labelled rows (with the V.58 code tables decoded) | +| `dmc_vt` | The terminal emulator of the D-Modem app (`shared/.../terminal` of D-Modem/app), ported to C: each type of terminal that it emulates (see below). Each app draws it from its cells | +| `dmc_net` | Telnet (option negotiation, terminal type, window size) and rlogin (the handshake, and the window size on the urgent request of the server), for the Remote page | +| `dmc_daemon_*` | It reads the text that dmodemd prints when it starts: the device that it made, or its error | ## Where the settings come from -dmodemd's core has one settings model (`Config::model`), which already -drives its configurators (AT!CF, AT!CT, AT!C). AT!M prints that model as -tab-separated lines: each setting's key, kind (pick, number or text), -value, default, range, AT form, group, label and help, then each choice. -The Settings page builds its controls from it, so a setting added to the -modem shows in every app with no change here. A change is checked by the -library, sent as its AT command, and kept once the modem says OK. +The core of dmodemd has one settings model (`Config::model`). This model +also controls its configurators (AT!CF, AT!CT, AT!C). AT!M prints that model +as tab-separated lines. Each line has the key of a setting, its kind (pick, +number or text), value, default, range, AT form, group, label and help, and +then each choice. The Settings page builds its controls from this output. +Thus, if a setting is added to the modem, it shows in each app without a +change here. The library checks a change and sends it as its AT command. The +app keeps the change when the modem says OK. -The modem keeps no stored profile, so the page shows AT!R's init string -and its **Keep** button saves it in the app's line settings, to be sent -each time the modem opens. +The modem keeps no stored profile. Thus the page shows the init string of +AT!R. Its **Keep** button saves the string in the line settings of the app. +The app sends the string each time that the modem opens. ## The same screens everywhere @@ -40,76 +42,84 @@ Each app has the same seven pages, with the same words: | Page | Contents | | --- | --- | | Modem | The state ("Idle", "Dialling", "Online") and its detail (the CONNECT line, the caller), Dial, Answer, Hang Up, the line and the device, Start or Stop | -| Phone | A voice call's state, Call and Answer, the keypad (DTMF), Mute and Listen; the answering machine (on or off, rings, the greeting) and its messages | -| Terminal | The AT console; the buttons **Full-screen setup** (AT!CF) and **Command-line setup** (AT!CT); the kind of terminal | -| Remote | SSH, Telnet or rlogin; the server, its port (empty: the protocol's) and the user; how SSH logs in (keys and the agent, the agent alone, a key file; a PuTTY key's import); Connect; a terminal of its own, whose size goes to the server as it changes, and its kind | -| Settings | The connection path; groups of settings as native controls, changed ones marked; Defaults (ATZ), the init string and Keep | -| Call Stats | AT#UD's rows and ATI11's report, refreshed after each call | -| Log | What dmodemd printed, and the command line it was started with | +| Phone | The state of a voice call, Call and Answer, the keypad (DTMF), Mute and Listen. The answering machine (on or off, rings, the greeting) and its messages | +| Terminal | The AT console. The buttons **Full-screen setup** (AT!CF) and **Command-line setup** (AT!CT). The type of terminal | +| Remote | SSH, Telnet or rlogin. The server, its port (empty: the port of the protocol) and the user. The login method of SSH (keys and the agent, the agent only, a key file, the import of a PuTTY key). Connect. A separate terminal, with its type. The terminal sends its size to the server when the size changes | +| Settings | The connection path. Groups of settings as native controls, with the changed settings marked. Defaults (ATZ), the init string and Keep | +| Call Stats | The rows of AT#UD and the report of ATI11, refreshed after each call | +| Log | The text that dmodemd printed, and the command line that started it | -The terminal sends Backspace as BS (0x08), the modem's S5: it does not take -DEL. Colours are the brand's: background `#0a0f1c`, text `#e8f0ff`. +The terminal sends Backspace as BS (0x08), the S5 of the modem, because the +modem does not accept DEL. The colours are the colours of the brand: +background `#0a0f1c`, text `#e8f0ff`. ## The connection path -The top of the Settings page shows how a call is made, as PCOMM's -"Connection Overview" draws its link: four steps joined by one line, each -with its role above its icon and what it is below. +The top of the Settings page shows how a call is made, as the "Connection +Overview" of PCOMM draws its link: four steps joined by one line. Each step +has its role above its icon and its setting below. | Line | Program | Modem (or Port) | Line (or Modem) | Reaches (or Line) | | --- | --- | --- | --- | --- | -| SIP account | Terminal | D-Modem | SIP: the account, registered when taking calls | The phone network, through the server | +| SIP account | Terminal | D-Modem | SIP: the account, registered when the modem takes calls | The phone network, through the server | | SIP, anonymous | Terminal | D-Modem | SIP: nothing registered | SIP addresses, dialled directly | | USB modem | Terminal | D-Modem | The USB modem | Its phone line | | Codec (Linux) | Terminal | D-Modem | The ALSA device | Its phone line | | A modem that already runs | Terminal | Its device, TCP address or COM port | The modem | Its phone line | -Idle, each step is as the line settings set it up: ready in the accent -colour, or still to set (no SIP account, no device) in red with its line -dashed, and the line below says what. Starting, dialling and online, the -steps light as the call goes (green), the line below saying the CONNECT. -libdmodemctl's `dmc_path` has the words, so the three apps say the same; -each draws them (`pathview.c`, `pathview.cpp` in GDI with Windows 95's -Wingdings, `PathView.swift`). The D-Modem app has the same picture at the -top of its Settings, with its own lines (Wi-Fi and Bluetooth to another -phone, the phone's mobile calls, external modems). +When idle, each step shows the line settings. A step that is ready is in the +accent colour. A step that you must still set (no SIP account, no device) is +red and its line is dashed, and the text below says what to set. When the +modem starts, dials and is online, the steps light green as the call goes, +and the text below shows the CONNECT line. `dmc_path` of libdmodemctl has the +words, so the three apps show the same text. Each app draws them: +`pathview.c`, `pathview.cpp` (GDI, with the Wingdings of Windows 95) and +`PathView.swift`. The D-Modem app has the same picture at the top of its +Settings, with its own lines (Wi-Fi and Bluetooth to another phone, the +mobile calls of the phone, external modems). ## The terminals -Both terminals (the modem's console and the Remote page's) are -libdmodemctl's `dmc_vt`: the app's emulator in C, with the app's 29 kinds -of terminal (profiles), picked beside each terminal and kept with the -page's settings: +The two terminals (the console of the modem and the terminal of the Remote +page) use `dmc_vt` of libdmodemctl. This is the emulator of the app in C, +with the 29 types of terminal (profiles) of the app. You select the type +next to each terminal, and the app keeps it with the settings of the page: | Kind | What it is | | --- | --- | | xterm (the default) | A VT220 with colours (8, 16, 256, 24-bit), sixel, the mouse, bracketed paste, the alternate screen, titles, OSC 8 links and Tek mode | -| DEC VT52 to VT525 | Each model's answers and sequences: the VT52's own, VT100 to VT320's levels, the VT340's sixel, ReGIS and Tek mode, the VT420's rectangles, margins and pages, the VT525's colours; soft fonts (DECDLD), user-defined keys, the printer port, the status line | -| ANSI-BBS, Avatar, RIPscrip, Amiga ANSI | A PC's BBS terminal in code page 437 and the VGA's font (SyncTERM's font switching, CSI SP D, among the machines' fonts), ANSI music, iCE colours, doorway mode; Avatar's codes; RIPscrip's graphics and mouse buttons on 80x43; the Amiga's Topaz and palette | -| Commodore 64, 128 (40 and 80 col.), Plus/4, VIC-20, PET (40 and 80) | PETSCII and each machine's screen, colours and ROM font | -| Atari 8-bit (and international), Atari ST (80 and 40 col.) | ATASCII; the ST's TOS VT52 with its pens | -| Viewdata, Minitel | Prestel's 40x24 with its mosaics; the Minitel's videotex and its Téléinformatique (a VT100) | -| Tektronix 4014 | The storage tube, on its own | +| DEC VT52 to VT525 | The answers and sequences of each model: the sequences of the VT52, the levels of the VT100 to VT320, the sixel, ReGIS and Tek mode of the VT340, the rectangles, margins and pages of the VT420, the colours of the VT525. Soft fonts (DECDLD), user-defined keys, the printer port, the status line | +| ANSI-BBS, Avatar, RIPscrip, Amiga ANSI | The BBS terminal of a PC in code page 437 and the font of the VGA (the SyncTERM font switch, CSI SP D, with the fonts of the machines), ANSI music, iCE colours, doorway mode. The codes of Avatar. The graphics and mouse buttons of RIPscrip on 80x43. The Topaz and palette of the Amiga | +| Commodore 64, 128 (40 and 80 col.), Plus/4, VIC-20, PET (40 and 80) | PETSCII, and the screen, colours and ROM font of each machine | +| Atari 8-bit (and international), Atari ST (80 and 40 col.) | ATASCII. The TOS VT52 of the ST with its pens | +| Viewdata, Minitel | The 40x24 of Prestel with its mosaics. The videotex of the Minitel and its Téléinformatique (a VT100) | +| Tektronix 4014 | The storage tube, as a separate type | -The library is sans-I/O as the rest: bytes in (`dmc_vt_feed`), answers -out (`dmc_vt_reply`), and each key or character typed turned into what -the kind of terminal sends (`dmc_vt_key_mods`, `dmc_vt_char_bytes`: a -Commodore's PETSCII, an Atari's ATASCII). A view draws each cell -(`dmc_vt_cell`): its character and resolved colours, its attributes, the -bitmap of a machine's font (`dmc_vt_glyph_row`: SyncTERM's copies of the -ROMs, generated into `core/src/vt_data.c` by `tools/gen_vt_data.py`) and -a picture's tile (`dmc_vt_cell_image`: sixel, ReGIS, RIPscrip, the -Tektronix). A machine whose screen has its own size (a C64's 40x25) asks -for it (`dmc_vt_requested_cols`), and the view stretches its cells to -fill the window, by whole pixels where they fit. +The library is sans-I/O, as the remaining parts are. Bytes go in +(`dmc_vt_feed`) and answers come out (`dmc_vt_reply`). The library changes +each typed key or character into the bytes that the type of terminal sends +(`dmc_vt_key_mods`, `dmc_vt_char_bytes`: the PETSCII of a Commodore, the +ATASCII of an Atari). A view draws each cell (`dmc_vt_cell`) with these +items: + +- Its character and resolved colours, and its attributes. +- The bitmap of the font of a machine (`dmc_vt_glyph_row`). These are the + SyncTERM copies of the ROMs, generated into `core/src/vt_data.c` by + `tools/gen_vt_data.py`. +- The tile of a picture (`dmc_vt_cell_image`: sixel, ReGIS, RIPscrip, the + Tektronix). + +If the screen of a machine has its own size (40x25 for a C64), the library +requests that size (`dmc_vt_requested_cols`). The view stretches its cells +to fill the window, by whole pixels where they fit. | | The view | | --- | --- | -| Windows | `termview.cpp`: GDI, a row at a time into a DIB section (text by `ExtTextOutW`, glyphs and pictures by pixel), copied (or stretched, for DEC's double width and height) to the window | -| Linux | `termview.c`: a GtkDrawingArea drawn with Cairo and Pango (VTE is no longer used) | +| Windows | `termview.cpp`: GDI, one row at a time into a DIB section (text by `ExtTextOutW`, glyphs and pictures by pixel). The view copies the section to the window (or stretches it, for the double width and height of DEC) | +| Linux | `termview.c`: a GtkDrawingArea drawn with Cairo and Pango (the app does not use VTE now) | | macOS | `TerminalView.swift`: an NSView drawn with Core Graphics | -## Starting dmodemd +## How the apps start dmodemd | | Linux | macOS | Windows | | --- | --- | --- | --- | @@ -117,117 +127,186 @@ fill the window, by whole pixels where they fit. | Its DTE | a pty (it prints "Use `/dev/pts/N' as modem device") | a pty | `--tcp 127.0.0.1:port` | | Settings kept in | `~/.config/dmodem-gui/settings.ini` (mode 0600) | user defaults, the SIP password in the keychain | `%APPDATA%\D-Modem\dmodem.ini` | -The SIP account goes to dmodemd in its environment (`SIP_LOGIN`, -`SIP_T38`, `SIP_V152`, `SIP_V150`, `SIP_SRTP`); the country, USB modem and -debug level as flags. On Linux and macOS the pty is made in the user's -own group (`-g`), so that dmodemd needs no root. +The app gives the SIP account to dmodemd in its environment (`SIP_LOGIN`, +`SIP_T38`, `SIP_V152`, `SIP_V150`, `SIP_SRTP`). It gives the country, the +USB modem and the debug level as flags. On Linux and macOS, the app makes +the pty in the group of the user (`-g`). Thus dmodemd does not need root. -Each app can instead use a modem that already runs: a device path on -Linux and macOS; a TCP address or a COM port on Windows. +Each app can also use a modem that already runs: a device path on Linux and +macOS, or a TCP address or a COM port on Windows. + +## Hardware modems: the MultiTech MT9234MU + +The "device" line can also open a hardware modem. The apps send AT commands +to it and read its result codes, as they do with dmodemd. The Settings page +needs `AT!M`, thus it operates only with dmodemd. + +The MultiTech MultiMobile MT9234MU (USB 06E0:F114) and the MT9234ZBA-USB +(06E0:F115, 06E0:0319) are V.92 data and fax modems. They have a TI TUSB3410 +USB UART. The TUSB3410 has no firmware of its own. The host downloads the +firmware into the chip each time you connect the modem. + +| | Linux | macOS | Windows | +| --- | --- | --- | --- | +| Driver | `ti_usb_3410_5052` (in the kernel) | we do not know a driver for the MT9234MU. The CDC-ACM models (MT9234MU-CDC) use the driver of the system | the driver of MultiTech | +| Firmware | `mts_mt9234mu.fw` in `/lib/firmware` | not applicable | the driver of MultiTech has it | +| The port | `/dev/ttyUSB0` | `/dev/cu.usbmodem*` (CDC-ACM models) | a COM port | + +Linux does not include `mts_mt9234mu.fw` after June 2026. MultiTech gave no +license that lets other persons distribute it, thus linux-firmware removed +it. This repository includes the file, with a notice +(`linux/firmware/README.md`). The AGPL-3.0 license does not apply to it. +`cmake --install` puts it in `share/dmodem-gui/firmware`, and +`-DDMODEM_GUI_INSTALL_FIRMWARE=ON` also puts it in `/lib/firmware`. Else, +copy it to `/lib/firmware` (for the MT9234ZBA-USB, as `mts_mt9234zba.fw`), +then disconnect the modem and connect it again. + +On Linux, the app finds the modem in sysfs (`linux/src/usbmodem.c`). The +line settings show where the modem is, with a "Use" button. If the modem +has no firmware, they show the command that copies the file. When the app opens the port of the +modem, it sets RTS/CTS flow control (`CRTSCTS`). The modem uses `&K3` from +the factory. + +Set the country of the line with `AT%T19,0,` and `AT&F&W` in the +"Commands when the modem opens" field one time, or in the Terminal page. +`AT%T19,0,34` is the default (North America and Europe). + +`ATI11` on these modems (and on other Agere modems) shows its report on two +pages. After each page, the modem waits for a key ("Press any key"). The +library sends a space when a command of the app gets this prompt, thus the +Call Stats page gets the full report. It does this for 8 pages at most. In +the Terminal page, you push the key. + +We did not test this yet with a real MT9234MU. ## Remote logins -The Remote page logs in to a server, beside the modem, in a terminal of -its own. Telnet and rlogin are a TCP connection each app makes in its own -way, with libdmodemctl's `dmc_net` for the protocol (sans-I/O, as the -session). SSH is libdmodemssh (`ssh/`), D-Modem's own client on libssh -0.11, the same engine the Android and iOS apps use, so that SSH is the -same everywhere and needs nothing installed: +The Remote page logs in to a server, next to the modem, in a separate +terminal. Telnet and rlogin are a TCP connection that each app makes in its +own way. The app uses `dmc_net` of libdmodemctl for the protocol (sans-I/O, +as the session). SSH is libdmodemssh (`ssh/`), the client of D-Modem on +libssh 0.11. The Android and iOS apps use the same engine. Thus SSH is the +same on all platforms, and you do not need to install anything: -- one thread per connection calls `dmc_ssh_poll()` and hands each event - to the UI's thread; what is typed, a window's size and the answers go - straight to the connection from the UI (it locks); -- the host's key is checked against OpenSSH's `known_hosts`: a known key - goes on, a new one is shown (its SHA256 fingerprint) and added if the - user accepts it, a changed one is refused with a warning; -- the login is OpenSSH's order: the agent and `~/.ssh`'s keys first, - then keyboard-interactive or a password (three tries), in the app's own - dialogs; `~/.ssh/config` is read (host aliases, users, ports); -- or, as chosen beside the server (Linux's key menu, Windows' Login..., - macOS's key popover): the agent's keys alone, or a key file, OpenSSH's, - PEM or PuTTY's `.ppk` (versions 2 and 3: `ssh/src/ppk.c` reads them, - Argon2 and all, the same whatever libssh was built on), its passphrase - asked for in the app's dialog. A `.ppk` can also be imported: written - to `.ssh` in OpenSSH's form with the same passphrase, and chosen; -- the agent is an ssh-agent's socket on Linux and macOS (`SSH_AUTH_SOCK`, - or one given, as `IdentityAgent`), and on Windows PuTTY's Pageant - (asked by WM_COPYDATA, as PuTTY's own tools ask it), else OpenSSH's - agent (`\\.\pipe\openssh-ssh-agent`), or a named pipe given; - `ssh/src/agent.c` stands between libssh and those two with a pair of - loopback sockets and a thread; -- Ed25519, ECDSA and RSA keys; a shell on a pty with TERM - `xterm-256color`, its size sent as it changes. The engine also has +- One thread for each connection calls `dmc_ssh_poll()` and gives each event + to the thread of the UI. The UI sends typed text, the window size and the + answers directly to the connection (it locks). +- The app checks the key of the host against `known_hosts` of OpenSSH. If + the key is known, the login continues. If the key is new, the app shows it + (its SHA256 fingerprint) and adds it if the user accepts it. If the key + changed, the app refuses it with a warning. +- The login uses the order of OpenSSH: first the agent and the keys of + `~/.ssh`, then keyboard-interactive or a password (three tries), in the + dialogs of the app. The app reads `~/.ssh/config` (host aliases, users, + ports). +- Alternatively, you can select next to the server (the key menu on Linux, + Login... on Windows, the key popover on macOS) one of these: the keys of + the agent only, or a key file. The key file can be in the format of + OpenSSH, PEM or the `.ppk` of PuTTY (versions 2 and 3). `ssh/src/ppk.c` + reads `.ppk` files, with Argon2, the same with each libssh build. The app + asks for the passphrase in its dialog. You can also import a `.ppk`. The + app writes it to `.ssh` in the OpenSSH format with the same passphrase, + and selects it. +- On Linux and macOS, the agent is the socket of an ssh-agent + (`SSH_AUTH_SOCK`, or a socket that you give, as `IdentityAgent`). On + Windows, it is the Pageant of PuTTY (the app asks it by WM_COPYDATA, as the + tools of PuTTY do). If Pageant is not available, it is the agent of OpenSSH + (`\\.\pipe\openssh-ssh-agent`), or a named pipe that you give. + `ssh/src/agent.c` connects libssh to those two agents with a pair of + loopback sockets and a thread. +- Ed25519, ECDSA and RSA keys. A shell on a pty with TERM `xterm-256color`. + The app sends the size of the pty when it changes. The engine also has commands, direct channels (`-L`, `-D`), remote listens (`-R`), agent - channels (`-A`) and keys made or re-encrypted, which the mobile apps use. + channels (`-A`), and it can make keys or encrypt them again. The mobile + apps use these functions. -libssh and mbedTLS come from the system when it has libssh 0.11 or later -(Linux), else they are built from their release tarballs, checked by -hash (`ssh/cmake/BundledLibssh.cmake`): always on Windows and macOS. The -Windows 95 build (Open Watcom) has no libssh: it runs Windows' own -`ssh.exe` in a pseudo console when it finds one (Windows 10 1809 and -later). +If the system has libssh 0.11 or later (Linux), libssh and mbedTLS come from +the system. If not, the build makes them from their release tarballs, and +checks them by hash (`ssh/cmake/BundledLibssh.cmake`). This always occurs on +Windows and macOS. The Windows 95 build has no libssh, because mbedTLS and +libssh need Windows Vista or later (`BCryptGenRandom`). If it finds the `ssh.exe` of Windows (Windows 10 1809 and later), it runs it in a +pseudo console. | | Telnet and rlogin | SSH | Kept in | | --- | --- | --- | --- | -| Linux | GSocketClient, its socket on the main loop (G_IO_PRI for rlogin's urgent byte) | libdmodemssh on a GThread, events by `g_main_context_invoke`, AdwAlertDialogs | `settings.ini`, `[remote]` | -| Windows | Winsock 1.1, `WSAAsyncSelect` (FD_OOB for rlogin), on every Windows from 95 | libdmodemssh on a thread, events posted (`WM_APP_SSH`), the profile's `.ssh` | `dmodem.ini`, `[remote]` | +| Linux | GSocketClient, its socket on the main loop (G_IO_PRI for the urgent byte of rlogin) | libdmodemssh on a GThread, events by `g_main_context_invoke`, AdwAlertDialogs | `settings.ini`, `[remote]` | +| Windows | Winsock 1.1, `WSAAsyncSelect` (FD_OOB for rlogin), on all Windows versions from 95 | libdmodemssh on a thread, posted events (`WM_APP_SSH`), the `.ssh` of the profile | `dmodem.ini`, `[remote]` | | macOS | a BSD socket on a dispatch source | libdmodemssh (`SSHConnection.swift`) on a thread, events on the main queue, SwiftUI alerts | UserDefaults | -SSH's TERM and rlogin's terminal are the kind of terminal's (`xterm-256color`, -`vt220`, `ansi`, `petscii` ...), and Telnet's TERMINAL-TYPE its own +The TERM of SSH and the terminal of rlogin come from the type of terminal +(`xterm-256color`, `vt220`, `ansi`, `petscii` ...). The TERMINAL-TYPE of +Telnet is a separate value (`XTERM-256COLOR`, `DEC-VT220`, `ANSI` ...: `dmc_vt_profile_term`, `dmc_vt_profile_telnet`). -Telnet tells the server the terminal type and the window's size (NAWS), -and sends a typed CR as CR NUL. rlogin sends the user as both the local -and the remote name; a server that insists on a client port below 1024 -(classic BSD `rlogind`) won't take an unprivileged app, but BBSes and -most rlogin services do. Backspace sends DEL, as a host expects (the -modem's console sends BS). +Telnet tells the server the terminal type and the window size (NAWS). It +sends a typed CR as CR NUL. rlogin sends the user as the local name and as +the remote name. Some servers accept only a client port below 1024 (classic +BSD `rlogind`). These servers do not accept an unprivileged app, but BBSes +and most rlogin services accept it. Backspace sends DEL, as a host expects +(the console of the modem sends BS). ## Voice calls and the answering machine -Voice uses dmodemd's V.253 voice mode: `AT+FCLASS=8`, `AT+VSM=4` (G.711 +Voice uses the V.253 voice mode of dmodemd: `AT+FCLASS=8`, `AT+VSM=4` (G.711 μ-law at 8 kHz), then `ATD` or `AT+VLS=1`, and `AT+VTR` for the full-duplex -stream. libdmodemctl does all of it: the DLE framing and its events -(hangup, busy, dial tone, digits, caller ID), μ-law, the pacing of the -stream by the clock given to `dmc_poll`, DTMF, and the answering machine. -The apps only move 8 kHz 16-bit samples between it and the sound card -(`dmc_voice_read`, `dmc_voice_write`): +stream. libdmodemctl does all of this work. It does the DLE framing and its +events (hangup, busy, dial tone, digits, caller ID), μ-law, the pacing of +the stream by the clock that the app gives to `dmc_poll`, DTMF, and the +answering machine. The apps only move 8 kHz 16-bit samples between the +library and the sound card (`dmc_voice_read`, `dmc_voice_write`): | | Sound | Settings | Messages | Greeting files beyond the library's | | --- | --- | --- | --- | --- | -| Linux | PulseAudio on the GLib main loop (or PipeWire's Pulse server) | `settings.ini`, `[voice]` | `~/.local/share/dmodem-gui/voicemail` | libsndfile, when built with it: MP3, FLAC, Ogg Vorbis, Opus | -| Windows | `waveOut` and `waveIn` with window callbacks (Windows 95 has them) | `dmodem.ini`, `[voice]` | `%APPDATA%\D-Modem\Voicemail`, or beside the exe | the system's ACM codecs: MP3 and compressed WAVs (GSM 6.10 and the rest installed) | +| Linux | PulseAudio on the GLib main loop (or the Pulse server of PipeWire) | `settings.ini`, `[voice]` | `~/.local/share/dmodem-gui/voicemail` | libsndfile, if the build includes it: MP3, FLAC, Ogg Vorbis, Opus | +| Windows | `waveOut` and `waveIn` with window callbacks (Windows 95 has them) | `dmodem.ini`, `[voice]` | `%APPDATA%\D-Modem\Voicemail`, or next to the exe | the ACM codecs of the system: MP3 and compressed WAVs (GSM 6.10 and the other installed codecs) | | macOS | AVAudioEngine, converted to 8 kHz | UserDefaults | `~/Library/Application Support/D-Modem/Voicemail` | AVAudioFile: MP3, AAC/M4A, FLAC, ALAC, CAF | -The answering machine is off until it is turned on. When on, after the -chosen number of rings (4 by default) it answers, plays the greeting (or -none), beeps, and records until the caller hangs up, 7 s of silence, or -2 minutes. Each message is a WAV file named for its time and the caller's -number; one under a second is dropped. A greeting can be recorded from the -microphone or chosen from a sound file, which is converted to 8 kHz mono. -The library reads WAV (8 to 32-bit PCM, floats, A-law, μ-law, IMA and -Microsoft ADPCM), AIFF and AIFF-C, and Sun/NeXT `.au` itself -(`dmc_audio_decode`); each app hands the rest to the system's decoders, -as in the table. -Pick Up turns a message being taken into a call; Listen plays it as it is -left. Messages stay on this computer. +The answering machine is disabled until you enable it. When it is enabled, +it answers after the selected number of rings (4 by default). It plays the +greeting (or no greeting) and a beep. Then it records until one of these +conditions occurs: the caller hangs up, 7 s of silence, or 2 minutes. Each +message is a WAV file. Its name is its time and the number of the caller. +The app deletes a message that is shorter than one second. + +You can record a greeting from the microphone, or select a sound file. The +app converts the file to 8 kHz mono. The library itself reads WAV (8 to +32-bit PCM, floats, A-law, μ-law, IMA and Microsoft ADPCM), AIFF and AIFF-C, +and Sun/NeXT `.au` (`dmc_audio_decode`). Each app gives all other files to +the decoders of the system, as the table shows. Pick Up changes a message +into a call while the caller leaves it. Listen plays the message while the +caller leaves it. Messages stay on this computer. ## Windows 95 and later -The Windows app is plain Win32 in C++98, so that one binary runs from +The Windows app is plain Win32 in C++98. Thus one binary runs from Windows 95 to Windows 11: -- ANSI APIs, with UTF-8 from the library converted by hand (no `CP_UTF8` - on 9x); the terminal draws with `ExtTextOutW`, which 9x has. +- ANSI APIs. The app converts the UTF-8 from the library with its own code + (9x has no `CP_UTF8`). The terminal draws with `ExtTextOutW`, which 9x has. - The Windows 95 common controls (tabs, list views, the status bar), Winsock 1.1 (`wsock32`, `WSAAsyncSelect`) and the 4.0 `OPENFILENAME`. -- No `SetHandleInformation` (NT only): the pipe from dmodemd is made - non-inheritable with `DuplicateHandle`. -- Built by Open Watcom 2.0 (`windows/build-watcom.sh`: `runtime - windows=4.0`, the static C library), as CI does; MinGW and MSVC build the - same code with CMake. +- No `SetHandleInformation` (NT only). The app uses `DuplicateHandle` to + make the pipe from dmodemd non-inheritable. +- clang-retro builds the app (`cmake/clang-retro.cmake`, a CMake toolchain + file), as CI does. Its toolchain package comes from the + `clang-retro/dos-sdk/.github/actions/setup-toolchain` action, or from + `packaging/get-toolchain.sh` in that repository. `CLANG_DOS` is the + directory of the package. `CLANG_RETRO_CONFIG` is the `--config` file: + - `win32-picolibc` (the default): Windows 95, 98, ME, NT 4.0 and later. + picolibc is the C library, and it is linked into the app. Thus the app + needs no `msvcrt.dll`, which some installations of Windows 95 do not + have. This build has no libssh (`DMODEM_GUI_SSH` is OFF). + - `win7`: Windows 7 and later, with libssh (`-DDMODEM_GUI_SSH=ON`). This + is the minimum Windows version of dmodemd too. +- CI examines the imports of the Windows 95 build with `check-imports.py` + of clang-retro, for Windows 9x and for NT 4.0. The build fails if the app + uses a function that these versions do not have. CI also runs the tests + of the two builds in Wine. +- picolibc has no `_snprintf`, `_stricmp` or `_strnicmp`. `app.h` gives + these names to `snprintf`, `strcasecmp` and `strncasecmp`. +- MinGW and MSVC also build the same code with CMake. -dmodemd itself needs Windows 7 or later. On Windows 9x and NT 4 the app -defaults to a COM port, and can reach a dmodemd on another machine over TCP. +dmodemd itself needs Windows 7 or later. On Windows 9x and NT 4, the app +uses a COM port by default. It can also connect to a dmodemd on another +machine through TCP. diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index 3a19a55..bb04c70 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -5,6 +5,7 @@ add_executable(dmodem-gui src/window.c src/modem.c src/config.c + src/usbmodem.c src/settings.c src/pathview.c src/stats.c @@ -13,6 +14,11 @@ add_executable(dmodem-gui src/termview.c src/audio.c) target_link_libraries(dmodem-gui PRIVATE dmodemctl dmodemssh PkgConfig::GTK) +# where the MT9234MU's firmware is installed, and where it is in the source +include(GNUInstallDirs) +target_compile_definitions(dmodem-gui PRIVATE + DMODEM_FIRMWARE_DIR="${CMAKE_INSTALL_FULL_DATADIR}/dmodem-gui/firmware" + DMODEM_FIRMWARE_SRC="${CMAKE_CURRENT_SOURCE_DIR}/firmware") # the sound of voice calls: PulseAudio's client (PipeWire serves it # too); without it the app has no sound pkg_check_modules(PULSE IMPORTED_TARGET libpulse-mainloop-glib) @@ -39,6 +45,16 @@ install(FILES data/io.github.d_modem.DModem.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications) install(FILES data/io.github.d_modem.DModem.metainfo.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo) +# MultiTech's firmware for the MT9234MU (licence unknown: linux/firmware/README.md) +install(FILES firmware/mts_mt9234mu.fw firmware/README.md + DESTINATION ${CMAKE_INSTALL_DATADIR}/dmodem-gui/firmware) +option(DMODEM_GUI_INSTALL_FIRMWARE + "Also install mts_mt9234mu.fw (and mts_mt9234zba.fw) in /lib/firmware" OFF) +if(DMODEM_GUI_INSTALL_FIRMWARE) + install(FILES firmware/mts_mt9234mu.fw DESTINATION /lib/firmware) + install(FILES firmware/mts_mt9234mu.fw DESTINATION /lib/firmware + RENAME mts_mt9234zba.fw) +endif() install(FILES ${PROJECT_SOURCE_DIR}/assets/dmodem.svg DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps RENAME io.github.d_modem.DModem.svg) diff --git a/linux/firmware/README.md b/linux/firmware/README.md new file mode 100644 index 0000000..47e22db --- /dev/null +++ b/linux/firmware/README.md @@ -0,0 +1,32 @@ +# The firmware of the MultiTech modems + +| File | For | Size (octets) | SHA-1 | License | Source | +|---|---|---|---|---|---| +| mts_mt9234mu.fw | MultiTech MT9234MU and MT9234ZBA-USB (TI TUSB3410) | 13769 | `5537e93217c509129d5a870b9fe089cd58647070` | unknown | linux-firmware, before June 2026 (`WHENCE`: "Multi-Tech USB fax modems", "Licence: Unknown") | + +The TUSB3410 of these modems has no firmware of its own. The +`ti_usb_3410_5052` driver of Linux downloads this file into the chip each +time you connect the modem. The driver looks for the file in +`/lib/firmware`. The MT9234ZBA-USB uses the name `mts_mt9234zba.fw` for the +same code. + +To install it: + + sudo cp linux/firmware/mts_mt9234mu.fw /lib/firmware/ + sudo cp linux/firmware/mts_mt9234mu.fw /lib/firmware/mts_mt9234zba.fw + +Then disconnect the modem and connect it again. `cmake --install` puts the +file in `share/dmodem-gui/firmware`. With `-DDMODEM_GUI_INSTALL_FIRMWARE=ON`, +it also puts the file in `/lib/firmware`. + +Multi-Tech Systems, Inc. gave this file to the Linux kernel in 2010. The +file is TI's TUSB3410 UART firmware, compiled again by MultiTech with some +changes. The file has no copyright text and no license text. MultiTech did +not publish a license for it. In June 2026, linux-firmware removed it with +the other files that have an unknown license. + +We include the file so that the modem operates without a search for it. The +AGPL-3.0 license of D-Modem and the commercial license do not apply to this +file. Multi-Tech Systems, Inc. and Texas Instruments keep their rights in it. +If you are the holder of these rights and you do not agree, tell us and we +will remove the file. diff --git a/linux/firmware/mts_mt9234mu.fw b/linux/firmware/mts_mt9234mu.fw new file mode 100644 index 0000000..09c1361 Binary files /dev/null and b/linux/firmware/mts_mt9234mu.fw differ diff --git a/linux/src/app.h b/linux/src/app.h index a534297..a4280a1 100644 --- a/linux/src/app.h +++ b/linux/src/app.h @@ -102,6 +102,25 @@ gboolean config_sip_ready(const Config *c); /* the line settings dialog */ void prefs_show(App *a); +/* usbmodem.c: a MultiTech MT9234MU (or MT9234ZBA-USB) on USB, from + sysfs */ +typedef struct UsbModem { + char *name; /* "MultiTech MT9234MU" */ + char *tty; /* "/dev/ttyUSB0", or NULL if it has none */ + gboolean no_firmware; /* in the boot ROM: no firmware loaded */ +} UsbModem; +/* the first one plugged in, or NULL */ +UsbModem *usbmodem_find(void); +/* what it is and where, or what it needs, for the user */ +char *usbmodem_describe(const UsbModem *m); +/* whether Linux has its firmware file (mts_mt9234mu.fw) */ +gboolean usbmodem_firmware_present(void); +/* the copy of mts_mt9234mu.fw that comes with the app, or NULL */ +char *usbmodem_shipped_firmware(void); +/* whether tty path is such a modem's */ +gboolean usbmodem_is(const char *path); +void usbmodem_free(UsbModem *m); + /* modem.c */ void modem_start(App *a); void modem_stop(App *a); diff --git a/linux/src/config.c b/linux/src/config.c index e92c1bc..0638cac 100644 --- a/linux/src/config.c +++ b/linux/src/config.c @@ -305,6 +305,37 @@ static AdwPreferencesGroup *group(AdwPreferencesPage *page, const char *title, return ADW_PREFERENCES_GROUP(g); } +static void use_found(GtkButton *b, gpointer data) +{ + Prefs *p = data; + gtk_editable_set_text(GTK_EDITABLE(p->device), + g_object_get_data(G_OBJECT(b), "tty")); +} + +/* a MultiTech MT9234MU plugged in: a row that says where it is (with a + button that puts it in Device), or what it needs */ +static void device_found(Prefs *p) +{ + UsbModem *m = usbmodem_find(); + if (!m) + return; + char *d = usbmodem_describe(m); + GtkWidget *r = adw_action_row_new(); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(r), "Found"); + adw_action_row_set_subtitle(ADW_ACTION_ROW(r), d); + if (m->tty) { + GtkWidget *b = gtk_button_new_with_label("Use"); + gtk_widget_set_valign(b, GTK_ALIGN_CENTER); + g_object_set_data_full(G_OBJECT(b), "tty", g_strdup(m->tty), + g_free); + g_signal_connect(b, "clicked", G_CALLBACK(use_found), p); + adw_action_row_add_suffix(ADW_ACTION_ROW(r), b); + } + adw_preferences_group_add(p->device_g, r); + g_free(d); + usbmodem_free(m); +} + static char *text_of(AdwEntryRow *r) { return g_strstrip(g_strdup(gtk_editable_get_text(GTK_EDITABLE(r)))); @@ -388,8 +419,10 @@ void prefs_show(App *a) p->alsa = entry(p->alsa_g, "ALSA device", c->alsa); p->device_g = group(page, "A modem that already runs", "dmodemd started as a service, or any modem's " - "serial port."); + "serial port (a MultiTech MT9234MU is " + "/dev/ttyUSB0)."); p->device = entry(p->device_g, "Device", c->device); + device_found(p); AdwPreferencesGroup *adv = group(page, "Advanced", NULL); p->init = entry(adv, "Commands when the modem opens", c->init); diff --git a/linux/src/modem.c b/linux/src/modem.c index 266ad77..d05117f 100644 --- a/linux/src/modem.c +++ b/linux/src/modem.c @@ -157,6 +157,10 @@ static gboolean open_dte(App *a, const char *path) cfsetispeed(&t, B115200); cfsetospeed(&t, B115200); t.c_cflag |= CLOCAL | CREAD; + /* (a MultiTech MT9234MU: RTS/CTS, its &K3, so that the + modem's buffer does not overflow in a fast call) */ + if (usbmodem_is(path)) + t.c_cflag |= CRTSCTS; tcsetattr(fd, TCSANOW, &t); } a->fd = fd; diff --git a/linux/src/usbmodem.c b/linux/src/usbmodem.c new file mode 100644 index 0000000..1a70f98 --- /dev/null +++ b/linux/src/usbmodem.c @@ -0,0 +1,171 @@ +/* + * SPDX-License-Identifier: AGPL-3.0-only + * Copyright (C) 2026 D-Modem Authors + * + * usbmodem.c - hardware modems on USB that the "device" line can open: + * the MultiTech MT9234MU and MT9234ZBA-USB, found in sysfs + * + * These modems have a TI TUSB3410 USB UART. Linux's ti_usb_3410_5052 + * driver downloads its firmware (mts_mt9234mu.fw) into the chip; then + * the modem is a ttyUSB. Without the firmware file the modem stays in + * the chip's boot ROM (one configuration) and has no tty. + */ +#include +#include +#include + +#include "app.h" + +/* MultiTech's vendor ID and the products with a TUSB3410 */ +static const struct { + const char *product, *name; +} models[] = { + { "f114", "MultiTech MT9234MU" }, + { "f115", "MultiTech MT9234ZBA-USB" }, + { "0319", "MultiTech MT9234ZBA-USB" }, +}; + +/* the firmware file's places that Linux looks in */ +static const char *const firmware[] = { + "/lib/firmware/updates/mts_mt9234mu.fw", + "/lib/firmware/mts_mt9234mu.fw", + "/usr/lib/firmware/updates/mts_mt9234mu.fw", + "/usr/lib/firmware/mts_mt9234mu.fw", + "/lib/firmware/mts_mt9234zba.fw", + "/usr/lib/firmware/mts_mt9234zba.fw", + NULL +}; + +/* the trimmed text of sysfs file dir/name, or NULL */ +static char *attr(const char *dir, const char *name) +{ + char *path = g_build_filename(dir, name, NULL); + char *t = NULL; + if (g_file_get_contents(path, &t, NULL, NULL)) + g_strstrip(t); + g_free(path); + return t; +} + +/* the first ttyUSB under USB device dir's interfaces, as /dev/ttyUSBn, + or NULL */ +static char *tty_of(const char *dir) +{ + char *found = NULL; + GDir *d = g_dir_open(dir, 0, NULL); + if (!d) + return NULL; + const char *e; + while (!found && (e = g_dir_read_name(d))) { + /* (its interfaces: "1-2:2.0") */ + if (!strchr(e, ':')) + continue; + char *itf = g_build_filename(dir, e, NULL); + GDir *i = g_dir_open(itf, 0, NULL); + const char *t; + while (i && !found && (t = g_dir_read_name(i))) + if (g_str_has_prefix(t, "ttyUSB")) + found = g_strconcat("/dev/", t, NULL); + if (i) + g_dir_close(i); + g_free(itf); + } + g_dir_close(d); + return found; +} + +gboolean usbmodem_firmware_present(void) +{ + for (int i = 0; firmware[i]; i++) + if (g_file_test(firmware[i], G_FILE_TEST_EXISTS)) + return TRUE; + return FALSE; +} + +UsbModem *usbmodem_find(void) +{ + const char *root = "/sys/bus/usb/devices"; + GDir *d = g_dir_open(root, 0, NULL); + if (!d) + return NULL; + UsbModem *m = NULL; + const char *e; + while (!m && (e = g_dir_read_name(d))) { + char *dir = g_build_filename(root, e, NULL); + char *vid = attr(dir, "idVendor"); + char *pid = vid ? attr(dir, "idProduct") : NULL; + for (size_t k = 0; pid && !m && + k < sizeof(models) / sizeof(models[0]); k++) { + if (g_ascii_strcasecmp(vid, "06e0") || + g_ascii_strcasecmp(pid, models[k].product)) + continue; + m = g_new0(UsbModem, 1); + m->name = g_strdup(models[k].name); + m->tty = tty_of(dir); + char *nc = attr(dir, "bNumConfigurations"); + /* (one configuration: the boot ROM's) */ + m->no_firmware = !m->tty && nc && !strcmp(nc, "1"); + g_free(nc); + } + g_free(vid); + g_free(pid); + g_free(dir); + } + g_dir_close(d); + return m; +} + +char *usbmodem_shipped_firmware(void) +{ + static const char *const dirs[] = { + DMODEM_FIRMWARE_DIR, DMODEM_FIRMWARE_SRC, NULL + }; + for (int i = 0; dirs[i]; i++) { + char *p = g_build_filename(dirs[i], "mts_mt9234mu.fw", NULL); + if (g_file_test(p, G_FILE_TEST_EXISTS)) + return p; + g_free(p); + } + return NULL; +} + +char *usbmodem_describe(const UsbModem *m) +{ + if (m->tty) + return g_strdup_printf("%s at %s", m->name, m->tty); + if (m->no_firmware && !usbmodem_firmware_present()) { + char *fw = usbmodem_shipped_firmware(); + /* (the MT9234ZBA-USB's driver asks for its own name) */ + const char *to = strstr(m->name, "ZBA") ? + "/lib/firmware/mts_mt9234zba.fw" : "/lib/firmware/"; + char *d = g_strdup_printf("%s, with no firmware: copy %s to " + "%s (sudo cp), then connect the " + "modem again", m->name, + fw ? fw : "mts_mt9234mu.fw", to); + g_free(fw); + return d; + } + if (m->no_firmware) + return g_strdup_printf("%s, with no firmware: load the " + "ti_usb_3410_5052 driver, then connect " + "the modem again", m->name); + return g_strdup_printf("%s, with no serial port: load the " + "ti_usb_3410_5052 driver", m->name); +} + +gboolean usbmodem_is(const char *path) +{ + UsbModem *m = usbmodem_find(); + gboolean is = m && m->tty && path && !strcmp(m->tty, path); + usbmodem_free(m); + return is; +} + +void usbmodem_free(UsbModem *m) +{ + if (!m) + return; + g_free(m->name); + g_free(m->tty); + g_free(m); +} diff --git a/ssh/cmake/BundledLibssh.cmake b/ssh/cmake/BundledLibssh.cmake index 7984c56..9a3a936 100644 --- a/ssh/cmake/BundledLibssh.cmake +++ b/ssh/cmake/BundledLibssh.cmake @@ -14,13 +14,19 @@ set(_args -DCMAKE_INSTALL_PREFIX=${_prefix} -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_POSITION_INDEPENDENT_CODE=ON - -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY} -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}) +# (a toolchain file names the compiler itself) if(CMAKE_TOOLCHAIN_FILE) list(APPEND _args -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) +else() + list(APPEND _args -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}) +endif() +# (cmake/clang-retro.cmake) +if(CLANG_DOS) + list(APPEND _args -DCLANG_DOS=${CLANG_DOS} -DCLANG_RETRO_CONFIG=${CLANG_RETRO_CONFIG}) endif() if(CMAKE_SYSTEM_NAME STREQUAL "iOS") list(APPEND _args -DCMAKE_SYSTEM_NAME=iOS) @@ -62,6 +68,11 @@ set(_ssh_args) if(ANDROID) list(APPEND _ssh_args -DCMAKE_C_FLAGS=-DS_IWRITE=S_IWUSR) endif() +# (clang-retro's clang, newer than MinGW's GCC, makes an error of +# src/threads/mbedtls.c's casts of libssh's mutex callbacks) +if(CLANG_DOS) + list(APPEND _ssh_args -DCMAKE_C_FLAGS=-Wno-error=incompatible-function-pointer-types) +endif() # (WITH_SERVER: libssh runs a client's callbacks for the channels the # server opens, the forwarded agent's, only when it's built with it) @@ -88,8 +99,9 @@ target_compile_definitions(dmodem_libssh INTERFACE LIBSSH_STATIC=1) target_link_libraries(dmodem_libssh INTERFACE ${_prefix}/lib/${_ssh_lib} ${_mbed_paths}) if(WIN32) target_link_libraries(dmodem_libssh INTERFACE ws2_32 iphlpapi bcrypt shell32 advapi32) - # (MinGW's libssh locks with winpthreads) - if(MINGW) + # (MinGW's libssh locks with winpthreads; clang-retro's sysroots have + # none, and there libssh locks with Win32's own) + if(MINGW AND NOT CLANG_DOS) target_link_libraries(dmodem_libssh INTERFACE pthread) endif() elseif(UNIX) diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index 272c5ef..f6f3c7a 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -1,5 +1,5 @@ -# The Windows app with MinGW or MSVC (the Windows 95 build is Open -# Watcom's: build-watcom.sh). ANSI, for the same code to build with both. +# The Windows app with MinGW, MSVC or clang-retro (the Windows 95 build: +# cmake/clang-retro.cmake). ANSI, for the same code to build with all. enable_language(CXX) enable_language(RC) add_executable(dmodem WIN32 @@ -30,3 +30,7 @@ else() target_compile_options(dmodem PRIVATE -Wall -Wextra -Wno-unused-parameter) target_link_options(dmodem PRIVATE -static) endif() +# (picolibc starts main, unless the entry point is WinMain's) +if(CLANG_RETRO_CONFIG MATCHES "picolibc") + target_link_options(dmodem PRIVATE -Wl,-e,WinMainCRTStartup) +endif() diff --git a/windows/build-watcom.sh b/windows/build-watcom.sh deleted file mode 100755 index 53c7e6a..0000000 --- a/windows/build-watcom.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh -# Builds dmodem.exe with Open Watcom 2.0, for Windows 95 and later: -# ANSI Win32, the Windows 95 common controls, Winsock 1.1, the static -# Watcom C library. WATCOM must name Open Watcom's directory, and its -# binaries be on the PATH (on Linux, $WATCOM/binl64 or binl). -# -# windows/build-watcom.sh [the output directory, build/watcom] -set -eu -here=$(cd "$(dirname "$0")" && pwd) -root=$(dirname "$here") -out=${1:-$root/build/watcom} -mkdir -p "$out" -cd "$out" - -: "${WATCOM:?set WATCOM to Open Watcom's directory}" -inc="-i=$WATCOM/h -i=$WATCOM/h/nt -i=$root/core/include -i=$root/core/src" -# 386 code, the stack calling convention's names as Win32's, C99 -copts="-q -bt=nt -bm -3r -ox -w4 -zq -za99 $inc" -cppopts="-q -bt=nt -bm -3r -ox -w4 -zq -xs $inc -i=$here/src" - -# every file compiled, so that one run shows all the errors -objs="" -failed=0 -for f in "$root"/core/src/*.c; do - # (core_: the library's names apart from the app's, voice.c and voice.cpp) - o=core_$(basename "$f" .c).obj - wcc386 $copts -fo="$o" "$f" || failed=1 - objs="$objs $o" -done -for f in "$here"/src/*.cpp; do - o=$(basename "$f" .cpp).obj - wpp386 $cppopts -fo="$o" "$f" || failed=1 - objs="$objs $o" -done -[ $failed = 0 ] || exit 1 -wrc -q -r -bt=nt -i="$WATCOM/h/nt" -i="$here/src" -i="$here/res" \ - -fo=app.res "$here/res/app.rc" - -{ - echo "system nt_win" - echo "name dmodem.exe" - echo "option quiet" - echo "option stack=256k" - # Windows 95 and NT 4 take a subsystem version of 4.0 - echo "runtime windows=4.0" - for o in $objs; do echo "file $o"; done - echo "library comctl32.lib, wsock32.lib, comdlg32.lib, winmm.lib, msacm32.lib" - echo "option resource=app.res" -} > dmodem.lnk -wlink @dmodem.lnk -ls -l dmodem.exe diff --git a/windows/src/app.h b/windows/src/app.h index 332d238..068e72f 100644 --- a/windows/src/app.h +++ b/windows/src/app.h @@ -4,8 +4,8 @@ * * app.h - the Windows app: plain Win32 in C++98, ANSI, the common * controls of Windows 95, so the one .exe runs on Windows 95, - * 98 and ME and on NT 4 through Windows 11. Built with Open - * Watcom (windows/build-watcom.sh), or MinGW or MSVC (CMake). + * 98 and ME and on NT 4 through Windows 11. Built with + * clang-retro (cmake/clang-retro.cmake), or MinGW or MSVC. * * The modem is reached one of three ways (Link): * - dmodemd started by the app on this PC (Windows 7 and later, as @@ -33,6 +33,17 @@ #include "dmodemctl.h" +/* (picolibc, the C library of the clang-retro build, has the C99 and + POSIX names and not the names of Microsoft's C library) */ +#include +#include +#ifdef __PICOLIBC__ +#include +#define _snprintf snprintf +#define _stricmp strcasecmp +#define _strnicmp strncasecmp +#endif + /* (older headers, Open Watcom's among them, without the 64-bit names) */ #ifndef GWLP_USERDATA #define GWLP_USERDATA GWL_USERDATA diff --git a/windows/src/link.cpp b/windows/src/link.cpp index 1a9905e..1b3e56e 100644 --- a/windows/src/link.cpp +++ b/windows/src/link.cpp @@ -32,7 +32,6 @@ static char proc_line[1024]; static int proc_n; static char port_out[8192]; /* what the DTE has yet to take */ static int port_out_n; -static DWORD start_tick; static int connect_tries; static int64_t now_ms() @@ -322,7 +321,6 @@ static bool start_dmodemd() proc = pi.hProcess; proc_out = rd; proc_n = 0; - start_tick = GetTickCount(); connect_tries = 0; return true; } diff --git a/windows/src/main.cpp b/windows/src/main.cpp index cdbeac3..8134263 100644 --- a/windows/src/main.cpp +++ b/windows/src/main.cpp @@ -390,3 +390,12 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmd, int show) WSACleanup(); return (int)msg.wParam; } + +#ifdef __PICOLIBC__ +/* (picolibc's start-up code needs a main, also when the entry point is + WinMainCRTStartup, which calls WinMain: see windows/CMakeLists.txt) */ +int main(void) +{ + return WinMain(GetModuleHandleA(NULL), NULL, (LPSTR)"", SW_SHOWDEFAULT); +} +#endif diff --git a/windows/src/remote.cpp b/windows/src/remote.cpp index cedd224..6858904 100644 --- a/windows/src/remote.cpp +++ b/windows/src/remote.cpp @@ -13,7 +13,7 @@ * and asks Pageant (or else OpenSSH's own agent) for its keys; or logs * in by the agent alone, or by a key file: OpenSSH's, PEM or PuTTY's * .ppk, which can also be imported into .ssh in OpenSSH's form. - * The Windows 95 build (Open Watcom, no libssh) runs Windows' own + * The Windows 95 build (clang-retro, win32-picolibc: no libssh) runs Windows' own * ssh.exe in a pseudo console (ConPTY) instead, when it finds one * (Windows 10 1809 and later): the ConPTY calls are looked up at run * time and its output read from a timer.