diff --git a/PLAN.md b/PLAN.md index 1e9ec63..d29ef93 100644 --- a/PLAN.md +++ b/PLAN.md @@ -15,9 +15,10 @@ control a radio, with rigctld started when the radio is plugged in. - [ ] Tell Elecraft's radios apart. The K3, KX3, KX2 and K4 all answer `ID017;`, so `radio` lists all four. Find an Elecraft command whose reply names the model -- [ ] PTT through a CM108 sound card (Digirig, AIOC, SignaLink-style - interfaces): a udev rule so you can open its `hidraw` device, for - Dire Wolf and others +- [ ] Use PTT through a CM108 sound card in `radio configure` for an + interface whose radio has no CAT (a Digirig or AIOC on a handheld): + Dire Wolf's `PTT CM108`, Graywolf's cm108 method. HamPack's udev rule + already lets you open the card's `hidraw` device - [ ] Check that the WSJT-X and QLog Flatpaks can open serial ports (`--device=all`), in `hampackcheck` or the smoketest - [ ] List USB sound cards with no serial port (SignaLink USB, VOX-keyed diff --git a/README.md b/README.md index ffac7ec..1177350 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Graywolf's web UI is at http://localhost:8080 and, by default, can only be reach `radio` lists the radios plugged into USB: each one's serial port, the sound card that came with it, and its model and Hamlib model number when it recognises it. Most Icoms are recognised from their USB serial number alone. For other radios, run `radio detect --probe`. This asks each one what it is (the CAT `ID;` command, or Icom's CI-V equivalent) over every serial port no other program is using. `radio probe /dev/ttyUSB0` asks a single port. -Controlling a radio means opening its serial port, and on Arch only members of the `uucp` group can. HamPack adds you to it when it installs. Log out and back in once afterwards for it to take effect. `hampackremove` takes you out of the group again, unless you were already in it before HamPack. +Controlling a radio means opening its serial port, and on Arch only members of the `uucp` group can. Keying a radio through the PTT line on a CM108-family sound card (a Digirig, an AIOC) means opening the card's `hidraw` device, which normally only root can; HamPack installs a udev rule, `/etc/udev/rules.d/70-hampack-cm108.rules`, that lets whoever is logged in at the desktop use it, as they can the sound card. HamPack adds you to it when it installs. Log out and back in once afterwards for it to take effect. `hampackremove` takes you out of the group again, unless you were already in it before HamPack. Probing opens the port, which raises its DTR and RTS lines for a moment before `radio` drops them. Interfaces that key the transmitter with DTR or RTS may key it briefly, so probe with the radio on a dummy load or an antenna. diff --git a/TEST.md b/TEST.md index 7affefe..7fb41a3 100644 --- a/TEST.md +++ b/TEST.md @@ -132,6 +132,23 @@ Dire Wolf, not1mm, QLog and POTACAT quit: |------|--------|-------|---------|--------|---------|-----|--------|-----------|--------|------|---------|----------|-------|-------| | | | | | | | | | | | | | | | | +## PTT through a CM108 sound card + +With a Digirig, an AIOC or another CM108-family interface plugged in, after +`update` has installed `/etc/udev/rules.d/70-hampack-cm108.rules`: + +1. `ls /dev/hidraw*` and `udevadm info /dev/hidrawN` find the interface's + hidraw device (its idVendor is 0d8c, 0c76 or 1209). +2. `getfacl /dev/hidrawN` gives you rw, through an ACL ("user:YOU:rw-"), + without being in the audio group. +3. Dire Wolf's `cm108` tool lists the device with "**" and you can run it + without sudo. With `PTT CM108` in direwolf.conf, a beacon keys the radio. +4. A C-Media USB headset that isn't CM108-compatible gets no ACL. + +| Date | Commit | Interface | ACL | Keys the radio | Notes | +|------|--------|-----------|-----|----------------|-------| +| | | | | | | + ## Pairing radios with sound cards - Two radios plugged in at once: each gets its own sound card. diff --git a/hampackremove b/hampackremove index f7a441c..76cc4ec 100755 --- a/hampackremove +++ b/hampackremove @@ -266,6 +266,13 @@ if [ -f "$RIGCTLD_UNIT" ]; then systemctl --user daemon-reload 2> /dev/null fi +# The udev rules update.sh installed +UDEV_RULES="${HAMPACK_UDEV_RULES_DIR:-/etc/udev/rules.d}/70-hampack-cm108.rules" +if [ -e "$UDEV_RULES" ]; then + echo "Removing HamPack's udev rules..." + sudo rm -f "$UDEV_RULES" && sudo udevadm control --reload-rules +fi + # The flrig autostart entry `radio configure --flrig` added, marked as HamPack's FLRIG_AUTOSTART="${XDG_CONFIG_HOME:-$HOME/.config}/autostart/hampack-flrig.desktop" if grep -qx 'X-HamPack=radio configure --flrig' "$FLRIG_AUTOSTART" 2> /dev/null; then diff --git a/tests/conf.bats b/tests/conf.bats index 919e807..cca2051 100644 --- a/tests/conf.bats +++ b/tests/conf.bats @@ -156,3 +156,23 @@ check_radio() { done no_problems } + +@test "udev rules: udevadm accepts HamPack's, if it's there to ask" { + [ -x /usr/bin/udevadm ] || skip "no udevadm" + /usr/bin/udevadm verify --no-summary "$REPO"/udev/*.rules +} + +@test "udev rules: the CM108 rule matches each device Dire Wolf treats as CM108-compatible" { + local rules="$REPO/udev/70-hampack-cm108.rules" device vid pid + for device in 0d8c:0008 0d8c:000f 0d8c:0012 0d8c:0013 0d8c:0139 0d8c:013a 0d8c:013c 0c76:1605 0c76:1607 0c76:160b 1209:7388; do + vid="${device%:*}" pid="${device#*:}" + grep "ATTRS{idVendor}==\"$vid\"" "$rules" | grep -oE 'idProduct}=="[^"]+"' | cut -d'"' -f2 | tr '|' '\n' | + while read -r pattern; do [[ "$pid" == $pattern ]] && echo match; done | grep -q match || + PROBLEMS+=("$device isn't matched") + done + # and not other C-Media devices, such as headsets + grep "0d8c" "$rules" | grep -oE 'idProduct}=="[^"]+"' | cut -d'"' -f2 | tr '|' '\n' | + while read -r pattern; do [[ 0014 == $pattern || 0001 == $pattern ]] && echo "matches 0014 or 0001"; done | grep -q . && + PROBLEMS+=("matches C-Media devices that aren't CM108-compatible") + no_problems +} diff --git a/tests/hampackremove.bats b/tests/hampackremove.bats index f7db11f..c1f252a 100644 --- a/tests/hampackremove.bats +++ b/tests/hampackremove.bats @@ -130,6 +130,14 @@ remove() { [ -e "$HOME/.config/autostart/my-flrig.desktop" ] } +@test "removes HamPack's udev rule" { + mkdir -p "$HAMPACK_UDEV_RULES_DIR" + echo rule > "$HAMPACK_UDEV_RULES_DIR/70-hampack-cm108.rules" + remove + [ "$status" -eq 0 ] + grep -qx "sudo rm -f $HAMPACK_UDEV_RULES_DIR/70-hampack-cm108.rules" "$STUB_LOG" +} + @test "does nothing unless confirmed" { mark_installed fldigi mkdir -p "$HAMPACK_STATE" diff --git a/tests/helpers.bash b/tests/helpers.bash index 63a8f8a..d27b3b3 100644 --- a/tests/helpers.bash +++ b/tests/helpers.bash @@ -16,6 +16,8 @@ setup_fake_home() { # "dep" means it was installed as a dependency export FAKE_PACMAN_DB="$BATS_TEST_TMPDIR/pacman-db" export FAKE_FLATPAKS="$BATS_TEST_TMPDIR/flatpaks" + # Where update.sh installs udev rules + export HAMPACK_UDEV_RULES_DIR="$BATS_TEST_TMPDIR/udev-rules" unset DISPLAY WAYLAND_DISPLAY WINEPREFIX HAMPACK_SKIP_WINDOWS_APPS mkdir -p "$HOME/.local/bin" "$TMPDIR" "$STUB_DIR" "$FAKE_PACMAN_DB" "$FAKE_FLATPAKS" : > "$STUB_LOG" diff --git a/tests/update.bats b/tests/update.bats index c485b45..2853183 100644 --- a/tests/update.bats +++ b/tests/update.bats @@ -65,6 +65,25 @@ setup() { [ ! -e "$HAMPACK_STATE/added-groups" ] } +@test "installs the CM108 udev rule once, and again when it changes" { + run bash "$REPO/update.sh" + [ "$status" -eq 0 ] + grep -qx "sudo install -m 644 $REPO/udev/70-hampack-cm108.rules $HAMPACK_UDEV_RULES_DIR/70-hampack-cm108.rules" "$STUB_LOG" + grep -qx "udevadm control --reload-rules" "$STUB_LOG" + grep -qx "udevadm trigger --subsystem-match=hidraw --action=change" "$STUB_LOG" + + # Installed as it is now: nothing to do + mkdir -p "$HAMPACK_UDEV_RULES_DIR" + cp "$REPO/udev/70-hampack-cm108.rules" "$HAMPACK_UDEV_RULES_DIR/" + : > "$STUB_LOG" + run bash "$REPO/update.sh" + ! grep -q "70-hampack-cm108" "$STUB_LOG" + + echo "# older" >> "$HAMPACK_UDEV_RULES_DIR/70-hampack-cm108.rules" + run bash "$REPO/update.sh" + grep -q "^sudo install -m 644 .*70-hampack-cm108.rules" "$STUB_LOG" +} + @test "update leaves alone a radio command that isn't HamPack's" { echo "theirs" > "$HOME/.local/bin/radio" run bash "$REPO/update.sh" diff --git a/udev/70-hampack-cm108.rules b/udev/70-hampack-cm108.rules new file mode 100644 index 0000000..4a73a55 --- /dev/null +++ b/udev/70-hampack-cm108.rules @@ -0,0 +1,21 @@ +# Lets you key a radio through the PTT line on a CM108-family USB sound card +# (a Digirig, an AIOC, many homemade interfaces), from Dire Wolf, Graywolf +# and other programs. They set a GPIO pin on the sound card through its +# hidraw device, which only root can open otherwise. "uaccess" gives the +# person logged in at the desktop access to it, as they have to the sound +# card itself, without joining the audio group. +# +# The devices are those Dire Wolf 1.8 treats as CM108-compatible (its +# cm108.c GOOD_DEVICE). Installed by HamPack's update.sh, removed by +# hampackremove. Numbered below 73 so uaccess is set before +# 73-seat-late.rules applies it. + +# C-Media CM108, CM109, CM119 (0008-000f), CM108B (0012), CM119B (0013), +# CM108AH (0139), CM119A (013a), CM108AH and HS100 (013c) +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="0d8c", ATTRS{idProduct}=="000[89a-f]|0012|0013|0139|013a|013c", TAG+="uaccess" + +# SSS1621 and SSS1623 +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="0c76", ATTRS{idProduct}=="1605|1607|160b", TAG+="uaccess" + +# AIOC (All-In-One Cable) +SUBSYSTEM=="hidraw", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="7388", TAG+="uaccess" diff --git a/update.sh b/update.sh index 6c9a88b..b9f976e 100644 --- a/update.sh +++ b/update.sh @@ -90,6 +90,18 @@ join_serial_group() { echo " Added you to the uucp group, so programs can control your radio. Log out and back in for it to take effect." } +# Let you key a radio through a CM108-family sound card's PTT pin (Digirig, +# AIOC), which programs reach through its hidraw device. Reinstalled when +# udev/70-hampack-cm108.rules changes +install_udev_rules() { + local rules="${HAMPACK_UDEV_RULES_DIR:-/etc/udev/rules.d}/70-hampack-cm108.rules" + cmp -s "$SELF/udev/70-hampack-cm108.rules" "$rules" && return 0 + echo "Installing $rules..." + sudo install -m 644 "$SELF/udev/70-hampack-cm108.rules" "$rules" && + sudo udevadm control --reload-rules && + sudo udevadm trigger --subsystem-match=hidraw --action=change +} + # Install the packages in packages.conf, and record the ones that weren't # already installed, so hampackremove removes those and nothing the user had before install_hampack_packages() { @@ -164,6 +176,7 @@ fi step "Removing stale HamPack files" remove_stale_files step "Installing HamPack tools" install_tools step "Adding you to the uucp group, for radios' serial ports" join_serial_group +step "Installing udev rules, for PTT through a CM108 sound card" install_udev_rules step "Installing HamPack packages" install_hampack_packages step "Installing Flatpak applications" bash "$SELF/install-flatpaks.sh" step "Installing pre-built binaries" bash "$SELF/install-binaries.sh"