Skip to content

Scope libgpiod/pkg-config detection to Linux in CMake - #678

Draft
wb2osz with Copilot wants to merge 71 commits into
masterfrom
copilot/fix-windows-latest-mingw-hamlib
Draft

wb2osz with Copilot wants to merge 71 commits into
masterfrom
copilot/fix-windows-latest-mingw-hamlib

Conversation

Copilot AI commented Sep 17, 2026 •

Copy link
Copy Markdown

The Windows Latest MinGW 64bit with Hamlib job was failing during CMake configure, even though Hamlib itself was found successfully. The failure came from libgpiod detection pulling in a required PkgConfig dependency on Windows for a Linux-only feature.

  • Root cause

    • find_package(gpiod) could succeed on the Windows runner environment.
    • That triggered unconditional libgpiod version probing via:
      • find_package(PkgConfig REQUIRED)
      • pkg_check_modules(LIBGPIOD REQUIRED libgpiod)
    • Windows does not use libgpiod in this codebase, so configure failed for an unsupported optional path.
  • CMake change

    • Restrict libgpiod detection and pkg-config-based version probing to LINUX.
    • Leave GPIOD_INCLUDE_DIRS and GPIOD_LIBRARIES empty on non-Linux platforms.
  • Behavioral impact

    • Preserves existing Linux libgpiod support.
    • Prevents Windows MinGW + Hamlib builds from failing on a Linux-only pkg-config requirement.
    • Keeps Hamlib detection unchanged.
if(LINUX)
  find_package(gpiod)
  if(GPIOD_FOUND)
    find_package(PkgConfig REQUIRED)
    pkg_check_modules(LIBGPIOD REQUIRED libgpiod)
    ...
  endif()
else()
  set(GPIOD_INCLUDE_DIRS "")
  set(GPIOD_LIBRARIES "")
endif()

mfncooper and others added 30 commits October 5, 2025 15:15
Dire Wolf 1.7 introduced the ability to configure multiple KISS TCP
ports, each for a single radio channel. However, DNS Service Discovery
announced only the first configured port. This set of changes expands
DNS-SD support to announce all configured KISS TCP ports, and adds
support for announcing the AGWPE port if configured. The functionality
is available on both Linux and Mac. (Dire Wolf does not currently
support DNS Service Discovery on Windows.)

Details of these changes follow.

On both Linux and Mac:

* All configured KISS TCP and AGWPE ports are announced via DNS-SD.

* Announcement messages include radio channel where appropriate.

* Cleanup code added to gracefully shut down and de-register from
  DNS-SD on exit or error.

* DNS-SD code now checks for services to publish, so that the
  caller doesn't need to do this.

* Standard Dire Wolf style comments added for all functions.

On Linux only:

* Handling of service name collisions is now iterative rather than
  recursive.

* No more gotos.

On Mac only:

* Now-complete implementation includes event loop for handling
  notifications from the DNS-SD daemon, which were previously lost.

* As a consequence of the above, successful announcement message
  now appears in the console (as it did before only for Linux).

* Text color set properly for console messages.

These changes have been tested with as many combinations of config
settings as possible, on Linux Mint 22.1 and macOS Sequoia 15.6.1.
The SCHANNEL feature is essentially the same as the existing NCHANNEL
feature but allowing for the mapping of a serial TNC to a channel, as
opposed to the network TNC supported by NCHANNEL.

Configuration uses the following form in the direwolf.conf file:

    SCHANNEL <channel> <device> [<baudrate>]

The implementation is a close parallel to that for NCHANNEL, sharing
some of the code, and makes use of existing serial port handling that
hides OS differences. This results in fewer changes than might have
been expected otherwise.
New SCHANNEL feature, like NCHANNEL but for serial TNCs
When a connection attempt via AGWPE had exhausted all retries, Direwolf
would crash (segfault) on Linux. This happened because the timer expiry
check (dl_timer_expiry) iterates over the state machine list in a way
that assumes the list is not modified during iteration. However, recent
changes to clean up AGWPE connections violated this assumption, such
that a state machine might be removed from the list during iteration.
Updating the iterations was missed in those earlier changes.

This change replaces the loop structure with one that allows for the
modification of the list during iteration. Currently t1_expiry() is
the only case in which the list may be modified; however, t3_expiry()
and tm201_expiry() loops have also been changed to insure against
possible future modifications.

Fixes #621
Fix crash when AGWPE connection attempt times out
* Add new build config for Direwolf with Hamlib on Windows

In parallel with the existing 64-bit Windows build, these changes add
a new matrix config for the same build but including Hamlib as part of
the build and package distribution. The resultant package zip file has
"-hamlib" appended to the name to distinguish it from the standard
Windows build.

Installing Hamlib as a build dependency using a package manager isn't
a viable option on Windows. Instead, we interrogate the GitHub release
assets to find the latest 4.x release of Hamlib, download and expand
the zip file for that release, and provide the path to the directory
for CMake configuration.

* Fix WIndows build errors

* Include Hamlib license-related files in Windows Hamlib zip
An AGWPE client request for Heard Stations ('H' frame) requires that
data for the most recent 20 heard callsigns be returned. Much of the
data for this was already being collected, and displayed with the
'-d m' command line option, but was not available via AGWPE.

The following changes have been made to support requests for Heard
Stations:

* Last heard times are now saved on a per-channel basis, since the
  AGWPE request specifies the channel for which data is being
  requested. The most recently heard time on any channel is still
  available using the 'chan' value, reflecting the channel on which
  the callsign was most recently heard.

* First heard times are saved in addition to last heard times.

* Two new functions, mheard_latest_for_channel and mheard_latest_for_is,
  are exposed from the mheard code, for use by the AGWPE server code.
  These two functions parallel the separation between the existing
  mheard_save_rf and mheard_save_is functions.

* The AGWPE server responds to 'H' frame requests by constructing and
  returning 20 'H' frame responses (including blank responses if fewer
  stations have been heard). The responses include both the text and
  binary forms of the first and last heard times, as described in the
  AGWPE spec.

* Macros are used to wrap the platform differences for qsort_r /
  qsort_s, needed to sort heard times on a per-channel basis.

Tested on Linux Mint 22.1, macOS Sequoia 15.6.1, and Windows 10.
wb2osz and others added 18 commits August 10, 2026 14:50
The Morse table contains two conflicting definitions for '-':

1. "-...-" on L101 (henceforth "3dit")
2. "-....-" on L108 ("4dit")

The order of the list meant that 3dit was used as it came first.
However it also used 3dit for `=` (L107).

Multiple sources, most notably the International Telecommunication Union
Recommendation for Morse code (ITU-R;
https://www.itu.int/dms_pubrec/itu-r/rec/m/R-REC-M.1677-1-200910-I!!PDF-E.pdf),
use 4dit for `-`, and I found nobody else using 3dit.

As such, especially given the conflicting definitions, I think 3dit is
an error, and this commit removes it.
)

Direwolf measures a per-frame signal metric — audio level rec(mark/space)
plus the retry/FEC decode level — but only emits it to stdout and the
APRS-only CSV log, never over the AGWPE monitor API. This adds an opt-in,
backwards-compatible way for an AGWPE client to receive it in-band.

A client enables the feature with a new 'q' command; the server replies
with a 'q' frame carrying "ExtSig=1". For clients that opted in, the
per-frame metrics are packed into the four otherwise-zero user_reserved
header bytes of 'U'/'S'/'I' monitor frames:

    user_reserved[0] = rec      (0..255)
    user_reserved[1] = mark     (0..255; 0xFF = N/A for non-AFSK)
    user_reserved[2] = space    (0..255; 0xFF = N/A)
    user_reserved[3] = retries  (0 = clean copy)

Backwards compatibility is structural: the bytes are written only in the
copy sent to a client that sent 'q', after the header is zeroed, so any
client that does not opt in — every stock AGWPE client — receives
byte-identical frames. A stock Direwolf ignores the unknown 'q' command,
so a client requesting the extension against stock never sees the ACK and
leaves the feature off.

alevel and the retry count are threaded from app_process_rec_packet
through server_send_rec_packet into server_send_monitored. Own
transmitted ('T') frames and synthetic packets (AIS objects, APRStt) pass
a rec = -1 sentinel, which suppresses the reserved-byte write.
…671)

* server: don't let a stalled AGWPE client block the rest of Dire Wolf

Every AGWPE client write went through a plain blocking send() on the
caller's thread.  If a client stopped reading, that send() blocked, and
whichever thread was in it stopped doing its real job.

Two callers make this serious:

* recv_process() is the single DLQ consumer thread.  It does not only
  feed AGWPE clients -- the same loop drives dl_timer_expiry(),
  lm_data_indication(), dl_connect_request(), lm_channel_busy() and the
  rest of the connected mode state machine.  Blocking there stops all
  AX.25 link layer timers, so established connections time out and drop,
  and the DLQ grows without bound.  That produces the familiar cascade:

      Received frame queue is out of control. Length=...
      INTERNAL ERROR:  DLQ memory leak, new=..., delete=...
      Report to WB2OSZ - Memory leak for packet objects.

* server_send_monitored() is also called from send_one_frame() on the
  xmit thread, between ptt_set(OCTYPE_PTT, chan, 1) and the matching
  ptt_set(..., 0).  A stalled client with monitoring enabled could
  therefore block the transmit thread with PTT still asserted, holding
  the transmitter keyed.

The worst case is a client whose TCP connection is black holed rather
than closed -- an AGWPE terminal over ssh when the link drops, a laptop
that sleeps, a NAT entry that gets evicted.  No FIN or RST ever arrives,
keepalive is off by default, so send() waits on the retransmission
timeout: about 15 minutes on Linux with the default tcp_retries2.  A
client that merely crashes sends a RST and fails fast, which is why this
only ever showed up on flaky links.

Fix: decouple frame generation from socket I/O.

* Per-client output queue drained by a dedicated client_send_thread(),
  so no caller ever blocks on a client socket.  Bounded at 512 items
  (~150 KB); beyond that frames are dropped for that client only.
* SO_SNDTIMEO of 10 seconds on each accepted socket, so a black holed
  connection is detected in 10 seconds instead of ~15 minutes.
* Because SO_SNDTIMEO makes a short send() count possible, a partial
  write is now treated as an error.  AGWPE is a length prefixed stream
  with no resync, so a truncated frame would desynchronize the client
  for the rest of the session; dropping the connection is the only safe
  response.
* The "send queue full" warning uses hysteresis: it re-arms only once
  the queue has drained to half the limit.  Resetting it on every
  successful enqueue would re-arm it each time a single frame drained,
  so a client parked at the limit would flood the console with the very
  warning meant to be occasional.
* client_disconnect() replaces five scattered inline disconnect blocks.
  It swaps out client_sock under the lock, so it is idempotent and
  dlq_client_cleanup() runs exactly once no matter which thread notices
  the failure first.  It also drains the queue, so a new client can
  never inherit frames left over from the previous occupant of the slot.

This also removes two WSACleanup() calls that were in the per-client
send error paths.  WSACleanup() deinitializes Winsock for the whole
process, so on Windows a single failed write to one AGWPE client tore
down every socket in Dire Wolf -- AGWPE, KISS over TCP and IGate alike.
The four legitimate calls in connect_listen_thread are left alone.

Measured with a 9600 baud feed and a client that enables 'k' and 'm',
reads for 3 seconds, then stops reading for 40:

  before:  decoding stops completely after ~15 s and has not resumed
           7 s after the client finally closes the socket.  12598
           packets decoded, and 188536 lines of the cascade above.
  after:   decode rate is flat across the entire stall.  58318 packets
           decoded, 2 "send queue full" warnings, client disconnected.

* Add test harness to PR to reproduce the initial problem
and test that the commit solves it.

We can move this to a better location before merge if needed.
…ll occurrences of the CodeQL Action in your workflow files to v4.
Co-authored-by: wb2osz <6499991+wb2osz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix failing GitHub Actions job for Hamlib Scope libgpiod/pkg-config detection to Linux in CMake Sep 17, 2026
Copilot AI requested a review from wb2osz September 17, 2026 15:50
Copilot AI and others added 2 commits September 17, 2026 16:08
Co-authored-by: wb2osz <6499991+wb2osz@users.noreply.github.com>
Co-authored-by: wb2osz <6499991+wb2osz@users.noreply.github.com>
@wb2osz

wb2osz commented Sep 17, 2026

Copy link
Copy Markdown
Owner

NO! This is not what I wanted. I don't want to update 82 files in master branch.
I just want the dev branch to build cleanly. Linux and MacOS are OK.
The problem is the Windows build with hamlib.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants