Saturday, October 31, 2020

Disable fingerprint scanner when laptop lid is closed

Since Fedora 32, I was able to enable login and sudo with fingerprints in Gnome settings. However, when my laptop is docked and the lid closed, sudo still prompts from my fingerprints. I have to wait for a few seconds for the fingerprint reader to time out before I can input my password.

I would like to change sudo to skip fingerprint authentication when the laptop lid is closed. I came up with two options,

  1. Enable the fingerprint reader when I open the lid and disable it when I close the lid.
  2. Change PAM config to check for lid status and skip pam_fprintd.so when the lid is closed.

For either options to work, they need to know the lid status. On my ThinkPad X1 7th gen laptop, /proc/acpi/button/lid/LID/state has the lid status. I think the second option is better. But I did not figure out how to tell PAM to skip pam_fprintd.so conditionally. So I implemented the first solution.

On Linux, you can enable/disable an USB device by setting the authorized bit in sysfs.

I also found a acpid program that monitors ACPI events and runs scripts when certain events happen. I installed it and create these two files.

/etc/acpi/events/lid

event=button/lid.*
action=/etc/acpi/actions/lid.sh 

/etc/acpi/actions/lid.sh

#!/usr/bin/sh
 
PATH=/usr/sbin:/usr/bin
 
grep -q close /proc/acpi/button/lid/LID/state
if [ $? = 0 ]; then
    echo 0 > /sys/bus/usb/devices/1-9:1.0/authorized
fi
 
grep -q open /proc/acpi/button/lid/LID/state
if [ $? = 0 ]; then
    echo 1 > /sys/bus/usb/devices/1-9:1.0/authorized
fi
 
exit 0

So every time the lid status changes, acpid will run lid.sh and it will check the lid status and the disable/enable the fingerprint reader. To prevent acpid conflicting with Gnome, I removed all other files in /etc/acpi/events.



Sunday, October 25, 2020

On Digital Terrestrial Radio Broadcast

I have been so absorbed in digital radio recently that I bought a clock radio that support HD Radio last week. I also read Wikipedia articles and technical docs on NRSC-5 (the offcial name for HD Radio) and DAB.

NRSC-5 is the digital radio broadcast standard in the US. NRSC-5 was developed by a private company, iBiquity, which gave it a trademark of HD Radio. It was selected by FCC in 2002 for digital radio broadcast. NRSC-5 supports both AM and FM bands. This article will focus on FM.

NRSC-5 has two modes, hybrid and all-digital. In hybrid mode, a station broadcasts analog audio signal plus two rectangular sub-carriers that contain digital audio and data. In all digital mode the full bandwidth is used for digital audio.

Waterfall plot of NRSC-5 hybrid mode


NRSC-5 has many advantages over analog FM,

  • NRSC-5 is more robust against multi-path and fading thanks to OFDM. NRSC-5 also supports single frequency network.
  • NRSC-5 can multiplex several audio streams encoded in modified HE-AAC on the same frequency. The first stream, HD-1, is the main program. While HD-2/3/4 are supplemental programs. NRSC-5 supports up to 4 audio streams in hybrid mode and 7 streams in all digital mode. All NRSC-5 signals I receive are in hybrid mode.
  • NRSC-5 supports text, images, and emergency alerts in additional to audio. Several stations around broadcast traffic and weather maps to be displayed on vehicle head units.

I think analog FM broadcast will still exist in the next ten years for these reasons,

  • Lack of NRSC-5 receivers. HD Radio is a trademark of a private company. A manufacture needs to pay license fees to produce HD Radio branded devices. So there are very few NRSC-5 capable tabletop/portable radios on the market. While many car radio supports NRSC-5, my car does not. In contrast, Europe's DAB is an ETSI open standard and many manufactures produce DAB capable radios.
  • There is no federal push for NRSC-5 (This is US). About half of FM stations in my city does not use NRSC-5. I read somewhere that radio stations have to pay for NRSC-5. In comparison, EU requires new cars to support DAB starting in 2021. Norway have switched off analog FM.
  • Mediocre audio quality. In hybrid mode, the digital data rate is about 100 kbps. A station needs to allocate it among all audio streams. Most stations I receive allocate 48 kbps to HD-1 and 32 kbps to HD-2/3 each. HE-AAC at 48 kbps does not outperform analog audio. In comparison, a DAB station have about 1 Mbps data rate. Each audio stream gets ~100 kbps.
  • NRSC-5 signal uses more bandwidth than analog FM. Adjacent stations could interfere. So FCC initially limited the power of digital signal to 1% of the analog signal. Later in 2010 FCC relaxed the limit to 10%. Still the coverage of digital broadcast is less than that of analog.
  • The rise of 4G and Internet streaming services. Many people (including me) listen to music/podcasts on their phone during commute.

References