# Design ## One library, three native shells 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 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 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. 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 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 | 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 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 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 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 | 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 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 | 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 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, 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 | ## How the apps start dmodemd | | Linux | macOS | Windows | | --- | --- | --- | --- | | Started with | GSubprocess | Process | CreateProcess | | 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 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 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, 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 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 it can make keys or encrypt them again. The mobile apps use these functions. 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. A build with no libssh (`-DDMODEM_GUI_SSH=OFF`) runs the `ssh.exe` of Windows (Windows 10 1809 and later) in a pseudo console, if it finds it. The Windows 95 build also has libssh. libssh and mbedTLS use some functions that Windows 95 does not have. Thus the build changes them as follows (`ssh/cmake/PatchMbedtls.cmake` and `PatchLibssh.cmake`, only for targets before Windows Vista): | Function | Windows that have it | In the Windows 95 build | | --- | --- | --- | | `BCryptGenRandom` (mbedTLS, the random numbers) | Vista and later | `CryptGenRandom` of CryptoAPI, found at run time. CryptoAPI is in Windows 95 OSR2, 98, NT 4.0 and later, and Internet Explorer 3 and later installs it. If CryptoAPI is not there, SSH cannot connect. The other pages operate | | `SHGetSpecialFolderPathA` (libssh, the home folder) | 98, 2000, and 95 and NT 4.0 with the shell of Internet Explorer 4 | found at run time, else `USERPROFILE` | | `if_nametoindex` (libssh, IPv6 link-local addresses) | Vista and later | found at run time, else no interface names | | `WSAStringToAddressA` (libssh, the address check) | 98, and 95 with Winsock 2 | found at run time, else IPv4 with `inet_addr` of Winsock 1.1 | | `gai_strerrorA` of mingw-w64 (it calls `FormatMessageW`) | NT | `ssh/src/gai_strerror.c`, with `FormatMessageA` | Thus the app imports only DLLs that each Windows 95 has, as before. libssh uses Winsock 1.1 (`wsock32`) for its sockets. `getaddrinfo` is the `WspiapiGetAddrInfo` of mingw-w64, which uses `gethostbyname` if Winsock 2 is not there. | | Telnet and rlogin | SSH | Kept in | | --- | --- | --- | --- | | 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 | 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 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 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 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 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 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. Thus one binary runs from Windows 95 to Windows 11: - 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 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 libssh too (see "Remote logins", above). - `win7`: Windows 7 and later. 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 uses a COM port by default. It can also connect to a dmodemd on another machine through TCP. ## The Windows app on Linux and macOS The Windows app also builds for Linux and macOS. This is a first pass. clang-retro MFC has a portable Win32 layer (`port/`, `libwinport.a`). The layer supplies the Win32 API on X11, Wayland and Cocoa. The app links with this layer and not with Windows. Its source code is the same as on Windows. - Use `-DDMODEM_GUI_WINPORT=ON` and set `CLANG_RETRO_MFC` to a checkout of clang-retro MFC. Use clang. `winport/CMakeLists.txt` builds `libwinport.a` with the Makefile of MFC. It converts `app.rc` to C++ with `port/tools/res2cpp.py` (this needs `llvm-rc`). The app is `winport/dmodem-win32` in the build directory. - `DMODEM_WINPORT` is defined for this build. The app uses it in these locations only: - The settings file is `~/.config/D-Modem/dmodem.ini`. - The line is TCP by default (`127.0.0.1:2323`, a dmodemd that runs). The app does not start dmodemd on these systems yet. - SSH uses `~/.ssh` and `/` in paths. - The path view on the Settings page draws its pictures from Unicode (DejaVu Sans), because these systems do not have Wingdings. - The group boxes go under the other controls. The hit test of the layer stops at a window that answers `HTTRANSPARENT`, and does not try the windows under it. Windows tries them. Thus without this change, a click on a control in a group box goes to the page. - The layer does not have these functions yet. `winport/include` and `winport/src/stubs.cpp` supply stand-ins for them: | Function | The stand-in | | --- | --- | | `waveOut*`, `waveIn*` (`mmsystem.h`), `acm*` (`msacm.h`) | Returns `MMSYSERR_NODRIVER`. The Phone page cannot play or record. | | `GetCommState`, `SetCommState`, `SetCommTimeouts` (COM ports) | Returns `FALSE` (`ERROR_NOT_SUPPORTED`). Do not use a COM port. | | `CreatePipe`, `PeekNamedPipe` | Returns `FALSE`. The app cannot start dmodemd. | | `GetEnvironmentStrings`, `GetUserName`, `Beep` | Uses `environ`, `$USER` and `MessageBeep`. | | `ListView_*`, `TabCtrl_*` (`commctrl.h`), `winsock.h` | Macros and an include of `winsock2.h`. | When the layer gets these functions, remove the stand-ins (and the group box change). Each stand-in is in `winport/` only, or in a `DMODEM_WINPORT` block. - CI builds the app on Linux and macOS. On Linux, it starts the app in Xvfb with `winport/test/smoke.sh`. The test makes sure that the app stays up and sends AT commands to a test modem through TCP.