diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6f4aceb..65286e3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,6 @@ # Builds and tests the app (windows/) and the library that it uses -# (core/, ssh/): on Windows 95 to Windows 11, and on Linux and macOS over -# clang-retro MFC's portable Win32 layer (winport/) +# (core/, ssh/): on Windows 95 to Windows 11, and on Linux, macOS and +# Haiku over clang-retro MFC's portable Win32 layer (winport/) name: Build # The nightly release (nightly.yml) takes its files from this @@ -250,6 +250,51 @@ jobs: name: ${{ matrix.artifact }} path: dmodem-win32-macos-${{ matrix.arch }}.tar.gz + # The app for Haiku (x86_64), cross-built on Linux with the runner's + # clang against a sysroot of Haiku's own packages (D-Modem's + # platforms/haiku/haiku_sysroot.py, which checks them against the + # repositories' SHA-256). Nothing here runs the app: that needs a + # Haiku guest. Refer to docs/haiku.md. + winport-haiku: + name: Windows app on Haiku, the modem built in (clang-retro MFC's Win32 layer) + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - uses: actions/checkout@v4 + with: + repository: clang-retro/mfc + path: mfc + submodules: recursive + - name: Packages + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + cmake ninja-build clang lld llvm libzstd1 python3 + - name: Haiku packages cache + uses: actions/cache@v4 + with: + path: haiku-packages + key: haiku-packages-${{ hashFiles('external/D-Modem/platforms/haiku/haiku_sysroot.py') }} + - name: Sysroot + run: python3 external/D-Modem/platforms/haiku/haiku_sysroot.py haiku-sysroot --cache haiku-packages + - name: Build + run: | + cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_TOOLCHAIN_FILE="$PWD/cmake/haiku.cmake" \ + -DHAIKU_SYSROOT="$PWD/haiku-sysroot" \ + -DDMODEM_GUI_WINPORT=ON -DCLANG_RETRO_MFC="$PWD/mfc" + cmake --build build --target dmodem-win32 + - name: The built-in modem is in the app + run: llvm-nm build/winport/dmodem-win32 | grep -q dmodem_embed_start + - name: Package + run: tar -C build/winport -czf dmodem-win32-haiku-x86_64.tar.gz dmodem-win32 + - uses: actions/upload-artifact@v4 + with: + name: dmodem-win32-haiku + path: dmodem-win32-haiku-x86_64.tar.gz + # The app for Mac OS X 10.4 (Tiger) and later, PowerPC and Intel # (i386), as one fat program, over the Mac OS X 10.0-10.5 port of # clang-retro MFC (cmake/macosx-legacy.cmake). All of it builds on diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 412696d..fc951e0 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -76,6 +76,7 @@ jobs: take dmodem-win32-macos dmodem-win32-macos-arm64.tar.gz take dmodem-win32-macos-x86_64 dmodem-win32-macos-x86_64.tar.gz take dmodem-win32-macosx-legacy dmodem-win32-macosx10.4.tar.gz + take dmodem-win32-haiku dmodem-win32-haiku-x86_64.tar.gz (cd out && sha256sum * > SHA256SUMS) ls -l out { @@ -91,6 +92,7 @@ jobs: echo "| \`dmodem-win32-macos-arm64.tar.gz\` | The app on macOS with the modem built in, arm64 (Apple silicon) |" echo "| \`dmodem-win32-macos-x86_64.tar.gz\` | The app on macOS with the modem built in, x86_64 (Intel Mac) |" echo "| \`dmodem-win32-macosx10.4.tar.gz\` | The app on Mac OS X 10.4 (Tiger) and later with the modem built in, one program for PowerPC and Intel (i386). Not tested on a Mac yet |" + echo "| \`dmodem-win32-haiku-x86_64.tar.gz\` | The app on Haiku R1/beta6 and later with the modem built in, x86_64. Needs \`pkgman install libusb\` |" echo "| \`SHA256SUMS\` | The SHA-256 of each file |" if [ -f missing ]; then echo diff --git a/README.md b/README.md index ce36bf0..3e5402a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ # D-Modem desktop app -The D-Modem desktop app is one Win32 app for Windows, macOS and Linux. The +The D-Modem desktop app is one Win32 app for Windows, macOS, Linux and +Haiku. The site of the app is . The app has the modem built in, so it needs no dmodemd (refer to @@ -22,11 +23,11 @@ thin Win32 shell over one small C library, libdmodemctl. - **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). **Look for a modem** finds the modem and its port -| | Windows | macOS | Linux | -| --- | --- | --- | --- | -| Toolkit | Win32, C++ | Win32, over the Cocoa layer of [clang-retro MFC](https://github.com/clang-retro/mfc) | Win32, over the X11 and Wayland layer of clang-retro MFC | -| Built with | [clang-retro](https://clang-retro.github.io/), MinGW or MSVC | clang | clang | -| Runs on | Windows 95 and later | arm64 (Apple silicon) and x86_64 (Intel Mac). Also Mac OS X 10.4 and later on PowerPC and i386 | x86_64 | +| | Windows | macOS | Linux | Haiku | +| --- | --- | --- | --- | --- | +| Toolkit | Win32, C++ | Win32, over the Cocoa layer of [clang-retro MFC](https://github.com/clang-retro/mfc) | Win32, over the X11 and Wayland layer of clang-retro MFC | Win32, over the Interface Kit layer of clang-retro MFC | +| Built with | [clang-retro](https://clang-retro.github.io/), MinGW or MSVC | clang | clang | clang (cross-built on Linux) | +| Runs on | Windows 95 and later | arm64 (Apple silicon) and x86_64 (Intel Mac). Also Mac OS X 10.4 and later on PowerPC and i386 | x86_64 | R1/beta6 and later, x86_64 | The source code of the app is the same on each system. Refer to "The Windows app on Linux and macOS" in [Design](docs/design.md). @@ -39,7 +40,7 @@ Windows app on Linux and macOS" in [Design](docs/design.md). The [nightly release](https://github.com/D-Modem/gui/releases/tag/nightly) has the app from the newest build of `main`: for Windows 95 and later, for -Windows 7 and later, for Linux, and for macOS. A workflow +Windows 7 and later, for Linux, for macOS, and for Haiku. A workflow (`.github/workflows/nightly.yml`) replaces the release one time each day. When `main` has no new commits, the release does not change. When the main branch of D-Modem changes, a workflow moves the built-in modem to it @@ -67,6 +68,7 @@ For Windows (with clang-retro) and macOS, refer to - [The site](https://d-modem.github.io/gui/): the home page, the downloads and all the pages below - [Features](docs/features.md): each page and menu of the app - [Building](docs/building.md): Windows with clang-retro, and the app on Linux and macOS +- [The app on Haiku](docs/haiku.md): install, build, serial ports and limits - [The built-in modem](docs/embedded-modem.md): the modem inside the app, with no dmodemd - [Design](docs/design.md): how the app is built, hardware modems (the MultiTech MT9234MU), the Windows 9x notes, and the app on Linux and macOS - [libdmodemctl](core/include/dmodemctl.h): the API of the library diff --git a/cmake/haiku.cmake b/cmake/haiku.cmake new file mode 100644 index 0000000..23b1824 --- /dev/null +++ b/cmake/haiku.cmake @@ -0,0 +1,20 @@ +# haiku.cmake - the toolchain file for the app on Haiku (x86_64), built +# on Linux with Clang and lld. It is the toolchain file of D-Modem +# (external/D-Modem/platforms/haiku/haiku.cmake), which the modem in the +# app uses too. +# +# python3 external/D-Modem/platforms/haiku/haiku_sysroot.py haiku-sysroot +# cmake -S . -B build/haiku -G Ninja -DCMAKE_BUILD_TYPE=Release \ +# -DCMAKE_TOOLCHAIN_FILE=cmake/haiku.cmake -DHAIKU_SYSROOT=$PWD/haiku-sysroot \ +# -DDMODEM_GUI_WINPORT=ON -DCLANG_RETRO_MFC=/path/to/mfc +# +# Refer to docs/haiku.md. +if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/../external/D-Modem/platforms/haiku/haiku.cmake") + message(FATAL_ERROR "cmake/haiku.cmake: no external/D-Modem (git submodule update --init)") +endif() +# (the roots that a project gives, as libssh's build gets the prefix of +# mbedTLS, stay with the sysroot, which D-Modem's file sets) +set(_dmodem_find_roots ${CMAKE_FIND_ROOT_PATH}) +include("${CMAKE_CURRENT_LIST_DIR}/../external/D-Modem/platforms/haiku/haiku.cmake") +list(APPEND CMAKE_FIND_ROOT_PATH ${_dmodem_find_roots}) +list(REMOVE_DUPLICATES CMAKE_FIND_ROOT_PATH) diff --git a/docs/building.md b/docs/building.md index 7f59cba..c7feec7 100644 --- a/docs/building.md +++ b/docs/building.md @@ -52,6 +52,11 @@ for an Intel Mac on a Mac with Apple silicon, add `-DCMAKE_OSX_ARCHITECTURES=x86_64` to the first command. Set one architecture only. The app cannot be a universal binary. +## Haiku + +You build the app for Haiku (x86_64) on Linux, with clang and a sysroot +of Haiku's packages. Refer to [The app on Haiku](haiku.md#build). + ## Mac OS X 10.4 and later (PowerPC and Intel) The app for Mac OS X 10.4 (Tiger) and later builds on Linux. It uses the diff --git a/docs/download.md b/docs/download.md index 009a9ea..6a2df26 100644 --- a/docs/download.md +++ b/docs/download.md @@ -20,6 +20,7 @@ When `main` has no new commits, the release does not change. | macOS, arm64 (Apple silicon) | [`dmodem-win32-macos-arm64.tar.gz`](https://github.com/D-Modem/gui/releases/download/nightly/dmodem-win32-macos-arm64.tar.gz) | The app on macOS, with the built-in modem. | | macOS, x86_64 (Intel Mac) | [`dmodem-win32-macos-x86_64.tar.gz`](https://github.com/D-Modem/gui/releases/download/nightly/dmodem-win32-macos-x86_64.tar.gz) | The app on macOS, with the built-in modem. | | Mac OS X 10.4 and later, PowerPC and Intel | [`dmodem-win32-macosx10.4.tar.gz`](https://github.com/D-Modem/gui/releases/download/nightly/dmodem-win32-macosx10.4.tar.gz) | The app with the built-in modem. One program for PowerPC (G3, G4, G5) and Intel (i386). It is not tested on a Mac yet. | +| Haiku R1/beta6 and later, x86_64 | [`dmodem-win32-haiku-x86_64.tar.gz`](https://github.com/D-Modem/gui/releases/download/nightly/dmodem-win32-haiku-x86_64.tar.gz) | The app on Haiku, with the built-in modem. It needs libusb. | | All | [`SHA256SUMS`](https://github.com/D-Modem/gui/releases/download/nightly/SHA256SUMS) | The SHA-256 of each file. | If a file is not in the release, the newest build did not make it. The @@ -67,6 +68,15 @@ The result for the file must be `OK`. 3. Extract the file. Type `tar -xzf dmodem-win32-linux-x86_64.tar.gz`. 4. Start the app. Type `./dmodem-win32`. +## Install on Haiku + +1. Install libusb. In a Terminal, type `pkgman install libusb`. +2. Download `dmodem-win32-haiku-x86_64.tar.gz`. +3. Extract the file. Type `tar -xzf dmodem-win32-haiku-x86_64.tar.gz`. +4. Start the app. Type `./dmodem-win32`. + +For more information, refer to [The app on Haiku](haiku.md). + ## Build the app To build the app from the source code, refer to [Building](building.md). diff --git a/docs/haiku.md b/docs/haiku.md new file mode 100644 index 0000000..6675d8f --- /dev/null +++ b/docs/haiku.md @@ -0,0 +1,98 @@ +# The app on Haiku + +The Windows app also runs on Haiku (x86_64). The app is the same Win32 +source code. It runs over the portable Win32 layer of +[clang-retro MFC](https://github.com/clang-retro/mfc), which shows the +windows with Haiku's Interface Kit. The built-in modem is in the app, as +on the other systems. + +The Modem page of the app on Haiku The Line Settings dialog of the app on Haiku + +## Requirements + +- Haiku R1/beta6 or later, x86_64. The app was tested on R1/beta6. +- libusb. In a Terminal, type `pkgman install libusb`. + +## Install + +1. Download `dmodem-win32-haiku-x86_64.tar.gz` from the + [nightly release](https://github.com/D-Modem/gui/releases/tag/nightly). +2. Open a Terminal in the download folder. +3. Extract the file. Type `tar -xzf dmodem-win32-haiku-x86_64.tar.gz`. +4. Start the app. Type `./dmodem-win32`. + +The app keeps its settings in `~/config/settings/libmfc`. + +## Build + +You build the app on Linux. The build uses the system's clang and a +sysroot that has Haiku's own packages. + +1. Install the tools. On Ubuntu 24.04, type + `sudo apt install cmake ninja-build clang lld llvm libzstd1 python3`. +2. Get [clang-retro MFC](https://github.com/clang-retro/mfc) and the + D-Modem submodule (`git submodule update --init`). +3. Make the sysroot. The script downloads Haiku's packages and examines + them against the SHA-256 of their repositories: + + python3 external/D-Modem/platforms/haiku/haiku_sysroot.py haiku-sysroot + +4. Build the app: + + cmake -S . -B build/haiku -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_TOOLCHAIN_FILE=$PWD/cmake/haiku.cmake \ + -DHAIKU_SYSROOT=$PWD/haiku-sysroot \ + -DDMODEM_GUI_WINPORT=ON -DCLANG_RETRO_MFC=/path/to/mfc + cmake --build build/haiku --target dmodem-win32 + +The app is `build/haiku/winport/dmodem-win32`. Copy it to the Haiku +computer. + +`cmake/haiku.cmake` includes the toolchain file of D-Modem +(`external/D-Modem/platforms/haiku/haiku.cmake`). The CI job +`winport-haiku` (`.github/workflows/build.yml`) does these steps. It does +not start the app. + +## Serial ports and modems + +Haiku keeps the serial ports in `/dev/ports`: + +- `pc_serial0`, `pc_serial1` and on are the serial ports of the computer. +- `usb0`, `usb1` and on are the USB serial adapters and the CDC-ACM USB + modems. Haiku's `usb_serial` driver makes these ports. + +In **Line settings**, the **Port** list shows the ports of `/dev/ports`, +for example `/dev/ports/usb0`. You can also type `COM1` (the first port +by name), `COM2` (the second port), and so on. + +**Look for a modem** does these steps: + +1. It finds the ports in `/dev/ports`. +2. It finds the USB devices with Haiku's USB Kit. It gives each `usbN` + port the name of its device (the maker and the product). +3. If a CDC-ACM device tells that it takes AT commands, the app selects + its port as the modem. + +Haiku has no driver for the MultiTech MT9234MU. If you connect this +modem, **Look for a modem** tells you that Haiku cannot use it. Use a +modem with a serial port, or a CDC-ACM USB modem. + +## Keys + +The keys are those of a PC keyboard: + +| Key on the keyboard | Key in the app | +| --- | --- | +| Control | Control. For example, Control+C copies. | +| Alt (Haiku's Command key, by default) | Alt. For example, Alt+M opens the **Modem** menu. | +| Windows (Haiku's Option key) | Windows | + +## Limits + +- The app has no sound on Haiku. The **Phone** page cannot play or + record the call. +- The app cannot print. Only "Save as PDF" is available. +- The Deskbar shows a generic icon for the app. +- The USB modems were not tested on Haiku yet. QEMU's USB serial adapter + does not operate with Haiku, so the tests used the serial port of the + computer only. diff --git a/docs/images/haiku-line-settings.png b/docs/images/haiku-line-settings.png new file mode 100644 index 0000000..da242c3 Binary files /dev/null and b/docs/images/haiku-line-settings.png differ diff --git a/docs/images/haiku-modem.png b/docs/images/haiku-modem.png new file mode 100644 index 0000000..ab9ac48 Binary files /dev/null and b/docs/images/haiku-modem.png differ diff --git a/mkdocs.yml b/mkdocs.yml index 829bf38..9f06475 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -17,6 +17,7 @@ nav: - Features: features.md - The built-in modem: embedded-modem.md - Building: building.md + - The app on Haiku: haiku.md - Design: design.md - "libdmodemctl API": https://github.com/D-Modem/gui/blob/main/core/include/dmodemctl.h - Documentation style: STYLE.md diff --git a/ssh/CMakeLists.txt b/ssh/CMakeLists.txt index 756b765..b28d593 100644 --- a/ssh/CMakeLists.txt +++ b/ssh/CMakeLists.txt @@ -38,6 +38,11 @@ if(WIN32) elseif(UNIX) find_package(Threads REQUIRED) target_link_libraries(dmodemssh PUBLIC Threads::Threads) + # Haiku has the sockets in libnetwork and strsep (for libssh) in + # libbsd, not in libroot + if(HAIKU) + target_link_libraries(dmodemssh PUBLIC network bsd) + endif() endif() if(MSVC) target_compile_options(dmodemssh PRIVATE /W4 /wd4996) diff --git a/ssh/cmake/BundledLibssh.cmake b/ssh/cmake/BundledLibssh.cmake index 3f1e97d..920fba6 100644 --- a/ssh/cmake/BundledLibssh.cmake +++ b/ssh/cmake/BundledLibssh.cmake @@ -35,6 +35,10 @@ if(MACOSX_LEGACY_TARGET) list(APPEND _args -D${_v}=${${_v}}) endforeach() endif() +# (cmake/haiku.cmake: D-Modem's Haiku toolchain file) +if(HAIKU_SYSROOT) + list(APPEND _args -DHAIKU_SYSROOT=${HAIKU_SYSROOT} -DHAIKU_TRIPLE=${HAIKU_TRIPLE}) +endif() if(CMAKE_SYSTEM_NAME STREQUAL "iOS") list(APPEND _args -DCMAKE_SYSTEM_NAME=iOS) endif() @@ -93,6 +97,11 @@ if(CLANG_DOS) list(APPEND _ssh_args -DHAVE_ARPA_INET_H= -DHAVE_IO_H= -DHAVE_TERMIOS_H=) endif() endif() +# (Haiku: getaddrinfo is in libnetwork, which libssh's check does not +# link with) +if(HAIKU) + list(APPEND _ssh_args -DHAVE_GETADDRINFO=1) +endif() list(APPEND _ssh_args "-DCMAKE_C_FLAGS=${_ssh_cflags}") # (WITH_SERVER: libssh runs a client's callbacks for the channels the diff --git a/ssh/cmake/PatchLibssh.cmake b/ssh/cmake/PatchLibssh.cmake index b429f9b..c2fcea8 100644 --- a/ssh/cmake/PatchLibssh.cmake +++ b/ssh/cmake/PatchLibssh.cmake @@ -150,3 +150,31 @@ dmodem_patch(src/misc.c #define dmodem_if_nametoindex if_nametoindex /* D-Modem */ ") + +# The terminal modes that Haiku's termios.h does not have (IMAXBEL, +# VREPRINT, VWERASE, VLNEXT, VDISCARD): sent only where they are. +dmodem_patch(src/ttyopts.c + " SSH_ENCODE_INPUT_OPT(IMAXBEL) +" + "#ifdef IMAXBEL /* D-Modem: not on Haiku */ + SSH_ENCODE_INPUT_OPT(IMAXBEL) +#endif +") +dmodem_patch(src/ttyopts.c + " SSH_ENCODE_CC_OPT(VREPRINT) + SSH_ENCODE_CC_OPT(VWERASE) + SSH_ENCODE_CC_OPT(VLNEXT) +" + "#ifdef VREPRINT /* D-Modem: not on Haiku */ + SSH_ENCODE_CC_OPT(VREPRINT) + SSH_ENCODE_CC_OPT(VWERASE) + SSH_ENCODE_CC_OPT(VLNEXT) +#endif +") +dmodem_patch(src/ttyopts.c + " SSH_ENCODE_CC_OPT(VDISCARD) +" + "#ifdef VDISCARD /* D-Modem: not on Haiku */ + SSH_ENCODE_CC_OPT(VDISCARD) +#endif +") diff --git a/windows/src/ports.cpp b/windows/src/ports.cpp index 1b46f58..633db26 100644 --- a/windows/src/ports.cpp +++ b/windows/src/ports.cpp @@ -13,6 +13,12 @@ * USB maker and product of each port. A MultiTech MT9234MU with no * firmware has no port: ports_problem() tells you what to do. * - macOS (winport/): the /dev/cu.* devices. + * - Haiku (winport/): the devices in /dev/ports: pc_serial0 and the + * other ports of the computer, and usb0 and the other USB serial + * ports and USB modems (CDC-ACM) of the usb_serial driver, with the + * USB maker and product of each one from the USB Kit + * (ports_haiku.cpp). A CDC-ACM device that takes AT commands is a + * modem. */ #include "app.h" @@ -282,6 +288,118 @@ void ports_problem(char *out, int n) out[0] = '\0'; } +#elif defined(__HAIKU__) + +#include "ports_haiku.h" + +/* the directory of the serial ports (a test can give another one) */ +#ifndef PORTS_DEVDIR +#define PORTS_DEVDIR "/dev/ports" +#endif + +/* Compares two port names for qsort: in the order of their names. */ +static int by_name(const void *a, const void *b) +{ + return strcmp(((const PortInfo *)a)->name, ((const PortInfo *)b)->name); +} + +/* Gives the ports of /dev/ports in the order of their names, with the + names of their USB devices and the CDC-ACM modems from the USB Kit. */ +int ports_list(PortInfo *out, int max) +{ + int count = 0; + DIR *d = opendir(PORTS_DEVDIR); + if (!d) + return 0; + struct dirent *e; + while ((e = readdir(d)) != NULL) { + const char *n = e->d_name; + if (n[0] == '.') + continue; + char path[64]; + _snprintf(path, sizeof(path), PORTS_DEVDIR "/%s", n); + path[sizeof(path) - 1] = '\0'; + /* (usb_serial names each USB port usbN: a serial adapter + or a CDC-ACM modem; the ports of the computer are + pc_serialN) */ + count = add(out, count, max, path, + !strncmp(n, "usb", 3) ? "USB serial port or modem" : + !strncmp(n, "pc_serial", 9) ? "Serial port" : NULL, + 0); + } + closedir(d); + /* (the order of COM1, COM2 and on in clang-retro MFC) */ + qsort(out, (size_t)count, sizeof(out[0]), by_name); + + /* The USB devices with a usbN port, in the order of their places + on the buses, which is the order that usb_serial numbers them + in when the computer starts. When there are as many devices as + usbN ports, each port gets the maker, the product and the modem + flag of its device. */ + HaikuUsbSerial usb[32]; + int n_usb = haiku_usb_serial(usb, 32), n_serial = 0; + for (int i = 0; i < n_usb; i++) + if (usb[i].has_port) + usb[n_serial++] = usb[i]; + int n_ports = 0; + for (int i = 0; i < count; i++) + if (!strncmp(out[i].name, PORTS_DEVDIR "/usb", sizeof(PORTS_DEVDIR "/usb") - 1)) + n_ports++; + if (n_serial > 0 && n_serial == n_ports) { + int k = 0; + for (int i = 0; i < count; i++) { + if (strncmp(out[i].name, PORTS_DEVDIR "/usb", sizeof(PORTS_DEVDIR "/usb") - 1)) + continue; + if (usb[k].desc[0]) + copy(out[i].desc, usb[k].desc, sizeof(out[i].desc)); + const char *mt = NULL; + for (int m = 0; m < N_MULTITECH; m++) { + char pid[8]; + _snprintf(pid, sizeof(pid), "%04x", usb[k].product); + pid[sizeof(pid) - 1] = '\0'; + if (usb[k].vendor == 0x06e0 && !_stricmp(pid, multitech[m].product)) + mt = multitech[m].name; + } + if (mt) + copy(out[i].desc, mt, sizeof(out[i].desc)); + out[i].modem = usb[k].modem || mt; + k++; + } + } + modems_first(out, count); + return count; +} + +/* Tells why a modem that is connected has no port on Haiku (the + MultiTech MT9234MU has no driver), or gives an empty string. */ +void ports_problem(char *out, int n) +{ + if (n <= 0) + return; + out[0] = '\0'; + /* A MultiTech modem with no usbN port: usb_serial has no driver + for its USB UART (a TI TUSB3410). */ + HaikuUsbSerial usb[32]; + int n_usb = haiku_usb_serial(usb, 32); + for (int i = 0; i < n_usb; i++) { + if (usb[i].vendor != 0x06e0 || usb[i].has_port) + continue; + for (int m = 0; m < N_MULTITECH; m++) { + char pid[8]; + _snprintf(pid, sizeof(pid), "%04x", usb[i].product); + pid[sizeof(pid) - 1] = '\0'; + if (_stricmp(pid, multitech[m].product)) + continue; + _snprintf(out, (size_t)n, + "%s: Haiku has no serial port driver for " + "this modem. Use a modem with a serial port, " + "or a CDC-ACM USB modem.", multitech[m].name); + out[n - 1] = '\0'; + return; + } + } +} + #else /* Linux */ /* the root of sysfs (a test can give another one) */ diff --git a/windows/src/ports_haiku.cpp b/windows/src/ports_haiku.cpp new file mode 100644 index 0000000..732dff3 --- /dev/null +++ b/windows/src/ports_haiku.cpp @@ -0,0 +1,115 @@ +/* + * SPDX-License-Identifier: AGPL-3.0-only + * Copyright (C) 2026 D-Modem Authors + * + * ports_haiku.cpp - the USB serial devices of a Haiku computer, from + * the USB Kit, for ports.cpp ("Look for a modem"). + * + * This file uses Haiku's headers and none of the Windows headers (their + * types clash). ports.cpp calls haiku_usb_serial() and matches the + * devices to the usbN ports of the usb_serial driver. + */ +#if defined(__HAIKU__) + +#include "ports_haiku.h" + +#include + +#include +#include +#include +#include + +#include +#include +#include + +/* The vendors of the USB serial adapters that usb_serial knows: FTDI, + KLSI, Prolific, Silicon Labs and WinChipHead */ +static const uint16 serial_vendors[] = { 0x0403, 0x05e9, 0x067b, 0x10c4, 0x1a86 }; + +/* Gives the paths of the USB devices under dir (/dev/bus/usb), in the + order of their names, each hub with the devices on it after it. */ +static void walk(const std::string &dir, std::vector *out) +{ + DIR *d = opendir(dir.c_str()); + if (!d) + return; + std::vector names; + struct dirent *e; + while ((e = readdir(d)) != NULL) + if (e->d_name[0] != '.') + names.push_back(e->d_name); + closedir(d); + std::sort(names.begin(), names.end()); + for (const std::string &n : names) { + std::string p = dir + "/" + n; + struct stat st; + if (stat(p.c_str(), &st) != 0) + continue; + if (S_ISDIR(st.st_mode)) + walk(p, out); + else if (n != "hub") + out->push_back(p); + } +} + +/* Tells if a device has a CDC-ACM interface (class 2, subclass 2), and + if that interface takes AT commands (protocol 1, V.250): a modem. */ +static bool acm(const BUSBDevice &dev, bool *at) +{ + *at = false; + bool found = dev.Class() == 2 && dev.Subclass() == 2; + if (found && dev.Protocol() == 1) + *at = true; + const BUSBConfiguration *c = dev.ActiveConfiguration(); + if (!c && dev.CountConfigurations() > 0) + c = dev.ConfigurationAt(0); + for (uint32 i = 0; c && i < c->CountInterfaces(); i++) { + const BUSBInterface *itf = c->InterfaceAt(i); + if (!itf || itf->Class() != 2 || itf->Subclass() != 2) + continue; + found = true; + if (itf->Protocol() == 1) + *at = true; + } + return found; +} + +/* Gives the USB devices (at most max, hubs not included) in the order + of their places on the USB buses, with the vendors and products, if + usb_serial makes a port for each, and if each is a modem. */ +int haiku_usb_serial(HaikuUsbSerial *out, int max) +{ + std::vector paths; + walk("/dev/bus/usb", &paths); + int n = 0; + for (const std::string &p : paths) { + if (n >= max) + break; + BUSBDevice dev(p.c_str()); + if (dev.InitCheck() != B_OK || dev.IsHub()) + continue; + bool at = false; + bool is_acm = acm(dev, &at); + bool serial = is_acm; + for (uint16 v : serial_vendors) + if (dev.VendorID() == v) + serial = true; + HaikuUsbSerial *s = &out[n]; + memset(s, 0, sizeof(*s)); + s->vendor = dev.VendorID(); + s->product = dev.ProductID(); + s->has_port = serial; + s->modem = at; + const char *maker = dev.ManufacturerString(); + const char *product = dev.ProductString(); + snprintf(s->desc, sizeof(s->desc), "%s%s%s", maker ? maker : "", + maker && *maker && product && *product ? " " : "", + product ? product : ""); + n++; + } + return n; +} + +#endif diff --git a/windows/src/ports_haiku.h b/windows/src/ports_haiku.h new file mode 100644 index 0000000..828290d --- /dev/null +++ b/windows/src/ports_haiku.h @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: AGPL-3.0-only + * Copyright (C) 2026 D-Modem Authors + * + * ports_haiku.h - the USB devices of a Haiku computer (ports_haiku.cpp), + * for ports.cpp. It uses neither the Windows headers + * nor Haiku's, so that both files can include it. + */ +#ifndef DMODEM_PORTS_HAIKU_H +#define DMODEM_PORTS_HAIKU_H + +/* A USB device, as the USB Kit tells it */ +typedef struct HaikuUsbSerial { + unsigned short vendor, product; + int has_port; /* usb_serial makes a usbN port for it */ + int modem; /* a CDC-ACM interface that takes AT commands */ + char desc[128]; /* its maker and product, from the device */ +} HaikuUsbSerial; + +/* Gives the USB devices (at most max, hubs not included), in the order + of their places on the USB buses. */ +int haiku_usb_serial(HaikuUsbSerial *out, int max); + +#endif diff --git a/winport/CMakeLists.txt b/winport/CMakeLists.txt index ea2613b..9cd118b 100644 --- a/winport/CMakeLists.txt +++ b/winport/CMakeLists.txt @@ -1,8 +1,14 @@ -# The Windows app (windows/) for Linux and macOS, over the portable Win32 -# layer of clang-retro MFC (libwinport, in port/ of that project). +# The Windows app (windows/) for Linux, macOS and Haiku, over the +# portable Win32 layer of clang-retro MFC (libwinport, in port/ of that +# project). # # cmake -B build -DDMODEM_GUI_WINPORT=ON -DCLANG_RETRO_MFC=/path/to/mfc \ # -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ +# +# Haiku, from Linux (cmake/haiku.cmake and docs/haiku.md): +# +# cmake -B build -DDMODEM_GUI_WINPORT=ON -DCLANG_RETRO_MFC=/path/to/mfc \ +# -DCMAKE_TOOLCHAIN_FILE=cmake/haiku.cmake -DHAIKU_SYSROOT=/path/to/sysroot enable_language(CXX) if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") @@ -45,6 +51,9 @@ if(MACOSX_LEGACY_TARGET) set(WINPORT_TARGET "${MACOSX_LEGACY_TARGET}") elseif(APPLE) set(WINPORT_TARGET "${_arch_apple}-apple-macos11") +elseif(HAIKU) + # (the Haiku toolchain file gives the triple and the sysroot) + set(WINPORT_TARGET "${HAIKU_TRIPLE}") else() set(WINPORT_TARGET "${_arch_linux}-linux-gnu") endif() @@ -67,6 +76,10 @@ if(MACOSX_LEGACY_TARGET) SDK=${MACOSX_LEGACY_SDK} LIBCXX=${MACOSX_LEGACY_SYSROOT} CCTOOLS=${MACOSX_LEGACY_CCTOOLS}/bin/powerpc-apple-darwin8- "CXXFLAGS=-O2 -include cstdlib") +elseif(HAIKU) + # (Haiku's C++ library is libstdc++, which the sysroot has) + set(_winport_make_args STDLIB= CXX=${_winport_cxx} AR=${CMAKE_AR} + SYSROOT=${HAIKU_SYSROOT}) else() set(_winport_make_args STDLIB= CXX=${_winport_cxx} AR=${CMAKE_AR}) endif() @@ -120,6 +133,14 @@ if(MACOSX_LEGACY_TARGET) target_link_libraries(dmodem-win32 PRIVATE "-framework Cocoa" "-framework OpenGL" pthread) elseif(APPLE) target_link_libraries(dmodem-win32 PRIVATE "-framework Cocoa" pthread) +elseif(HAIKU) + # (the USB devices for Look for a modem, from the USB Kit: + # windows/src/ports_haiku.cpp, with Haiku's headers only) + target_sources(dmodem-win32 PRIVATE "${_win}/src/ports_haiku.cpp") + # (libbe: the Interface Kit; libdevice: the USB Kit; libnetwork: the + # sockets; libbsd: dl_iterate_phdr. libroot has the rest, dlopen and + # the threads too.) + target_link_libraries(dmodem-win32 PRIVATE be device network bsd) else() target_link_libraries(dmodem-win32 PRIVATE dl pthread) endif() @@ -127,7 +148,7 @@ endif() # The install on Linux (cmake --install): the app, its desktop entry, # its AppStream data and its icon. Also the firmware of the MultiTech # MT9234MU (the licence is unknown: firmware/README.md). -if(UNIX AND NOT APPLE) +if(UNIX AND NOT APPLE AND NOT HAIKU) include(GNUInstallDirs) install(TARGETS dmodem-win32 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES data/io.github.d_modem.DModem.desktop