NetBSD Problem Report #56738
From www@netbsd.org Thu Mar 3 11:06:54 2022
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id C9A431A9239
for <gnats-bugs@gnats.NetBSD.org>; Thu, 3 Mar 2022 11:06:54 +0000 (UTC)
Message-Id: <20220303110653.32DC21A923A@mollari.NetBSD.org>
Date: Thu, 3 Mar 2022 11:06:53 +0000 (UTC)
From: anthony.mallet@laas.fr
Reply-To: anthony.mallet@laas.fr
To: gnats-bugs@NetBSD.org
Subject: ukbd(4): PMFE_AUDIO_VOLUME* event issue, Xorg KeyPress events ...
X-Send-Pr-Version: www-1.0
>Number: 56738
>Category: kern
>Synopsis: ukbd(4): PMFE_AUDIO_VOLUME* event issue, Xorg KeyPress events ...
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: kern-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Mar 03 11:10:00 +0000 2022
>Last-Modified: Fri Mar 04 17:45:01 +0000 2022
>Originator: Anthony Mallet
>Release: 9.99.91
>Organization:
>Environment:
NetBSD cactus 9.99.91 NetBSD 9.99.91 (CACTUS) #7: Sun Oct 17 18:33:59 CEST 2021 troot@cactus:/usr/obj/sys/arch/amd64/compile/CACTUS amd64
>Description:
1/ It seems that the VOLUME_* keys on my sun type 6 USB keyboard don't generate any PMF event. Or I am not able to track them properly:
powerd -d doesn't reveal anything and remains silent, and audio volume is not changing either.
I wonder if the culprit is not here (ukbd.c rev. 1.112):
https://anonhg.netbsd.org/src/diff/86b43c598d20/sys/dev/usb/ukbd.c#l1.61
As I understand pmf_event_inject(9), the 'dev' argument should be NULL so that audio(4) can receive the event?
2/ Maybe this should be a separate PR, but with the related commit of ukbd.c rev. 1.120 that actually uses the PMF framework introduced in 1.112 for those VOLUME_* keys:
https://anonhg.netbsd.org/src/diff/c1fc7c88275a/sys/dev/usb/ukbd.c
I don't receive any Xorg KeyPress event anymore for those keys (as expected). I've the feeling that removing the 'else' branch in
https://anonhg.netbsd.org/src/diff/86b43c598d20/sys/dev/usb/ukbd.c#l1.65
i.e. generating the PMF event and still registering the key event should allow both PMF and Xorg KeyPress to work.
3/ Is there a way to make this PMF event conditional? I want to avoid controlling my local audio with those keys and rather bind some custom script to the Xorg KeyPress event (or a powerd(8) hotkey event for that matter) to control my remote, connected HiFi power amp :)
PS: right now http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/dev/usb/ukbd.c is telling me "Error parsing RCS output: kassert that we aren't overflowing the array.". Should I PR this?
>How-To-Repeat:
1/ Plug a sun type 6/7 USB keyboard and try to mute audio.
2/ Try to catch and Xorg KeyPress event with e.g audio mute key.
3/ Try to write some custom script for powerd(8) bound to the audio mute key, and do not mess with local audio at all.
>Fix:
>Audit-Trail:
From: Anthony Mallet <anthony.mallet@laas.fr>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/56738: ukbd(4): PMFE_AUDIO_VOLUME* event issue, Xorg KeyPress events ...
Date: Thu, 3 Mar 2022 23:53:58 +0100
--Qa0zlsVIL6
Content-Type: text/plain; charset=us-ascii
Content-Description: message body text
Content-Transfer-Encoding: 7bit
So I tried the attached patch and this actually fixes 1/ and 2/ for me.
For 1/, I simply call pmf_event_inject() with NULL as the 'dev'
parameter, so that the event is actually dispatched to audio(4) that
has the appropriate callback registered and not to the ukbd itself
that doesn't care about it. Now audio volume is properly
muted/adjusted when I press the corresponding keys.
For 2/, I added a IS_SELF flag, that prevents
ukbd_translate_keycodes() from eating up the keypress event, so that
it still eventually generates a X KeyPress event that can be caught
independently of the PMF event.
I added the IS_SELF flag to not change the behaviour for
trtab_apple_fn[] or trtab_gdium_fn[] translation tables, for which I
don't know if the keypress event should still be generated in addition
to the PMF event or not.
Now that 1/ works, I'm still missing 3/: a way to disable this
behaviour with some user setting, so that the keys do not mess with
the local audio at all, but only perform some action of my choice.
Any hint? Adding a new sysctl?
--Qa0zlsVIL6
Content-Type: text/plain;
name="patch-ukbd.c"
Content-Disposition: inline;
filename="patch-ukbd.c"
Content-Transfer-Encoding: 7bit
Index: sys/dev/usb/ukbd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/ukbd.c,v
retrieving revision 1.153
diff -u -r1.153 ukbd.c
--- sys/dev/usb/ukbd.c 11 Oct 2021 00:00:03 -0000 1.153
+++ sys/dev/usb/ukbd.c 3 Mar 2022 22:36:31 -0000
@@ -101,6 +101,7 @@
};
#define IS_PMF 0x8000
+#define IS_SELF 0x4000
Static const struct ukbd_keycodetrans trtab_apple_fn[] = {
{ 0x0c, 0x5d }, /* i -> KP 5 */
@@ -177,9 +178,9 @@
#endif
Static const struct ukbd_keycodetrans trtab_generic[] = {
- { 0x7f, IS_PMF | PMFE_AUDIO_VOLUME_TOGGLE },
- { 0x80, IS_PMF | PMFE_AUDIO_VOLUME_UP },
- { 0x81, IS_PMF | PMFE_AUDIO_VOLUME_DOWN },
+ { 0x7f, IS_SELF | IS_PMF | PMFE_AUDIO_VOLUME_TOGGLE },
+ { 0x80, IS_SELF | IS_PMF | PMFE_AUDIO_VOLUME_UP },
+ { 0x81, IS_SELF | IS_PMF | PMFE_AUDIO_VOLUME_DOWN },
{ 0x00, 0x00 }
};
@@ -595,11 +596,12 @@
if (tp->from == i) {
if (tp->to & IS_PMF) {
pmf_event_inject(
- sc->sc_hdev.sc_dev,
+ NULL,
tp->to & 0xff);
} else
setbit(ud->keys, tp->to);
- clrbit(ud->keys, i);
+ if (!(tp->to & IS_SELF))
+ clrbit(ud->keys, i);
break;
}
}
--Qa0zlsVIL6--
From: Anthony Mallet <anthony.mallet@laas.fr>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/56738: ukbd(4): PMFE_AUDIO_VOLUME* event issue, Xorg KeyPress events ...
Date: Fri, 4 Mar 2022 18:44:38 +0100
To keep it simple, I just added a defflag
UKBD_NO_PMF_AUDIO_EVENTS. Please ignore the previous patch and
consider just this one.
. If UKBD_NO_PMF_AUDIO_EVENTS is defined, no PMF event are generated for
audio related keys: ukbd generates normal key press events. This is
limited to audio events, because there are no USB scancode defined
for other kind of events (e.g. display brightness).
. If not defined, previous behaviour is retained (with the
pmf_event_inject fix that makes it actually work for me).
While here, I simplified a bit the translations for 'apple_fn' and
'gdium_fn': the F[3-5] keys are mapped to the normal USB scancode for
audio keys. They are in turn translated to PMF event by the 'generic'
translation table, if enabled.
Index: sys/dev/usb/files.usb
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/files.usb,v
retrieving revision 1.177
diff -u -r1.177 files.usb
--- sys/dev/usb/files.usb 29 Jun 2021 10:22:37 -0000 1.177
+++ sys/dev/usb/files.usb 4 Mar 2022 17:39:38 -0000
@@ -156,6 +156,7 @@
# Keyboards
defparam UKBD_LAYOUT
+defflag opt_ukbd.h UKBD_NO_PMF_AUDIO_EVENTS
# Gdium's Fn key needs software translation
defflag opt_ukbd.h GDIUM_KEYBOARD_HACK
device ukbd: hid, wskbddev
Index: sys/dev/usb/ukbd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/ukbd.c,v
retrieving revision 1.153
diff -u -r1.153 ukbd.c
--- sys/dev/usb/ukbd.c 11 Oct 2021 00:00:03 -0000 1.153
+++ sys/dev/usb/ukbd.c 4 Mar 2022 17:39:38 -0000
@@ -124,9 +124,9 @@
{ 0x38, 0x57 }, /* / -> KP + */
{ 0x3a, IS_PMF | PMFE_DISPLAY_BRIGHTNESS_DOWN },
{ 0x3b, IS_PMF | PMFE_DISPLAY_BRIGHTNESS_UP },
- { 0x3c, IS_PMF | PMFE_AUDIO_VOLUME_TOGGLE },
- { 0x3d, IS_PMF | PMFE_AUDIO_VOLUME_DOWN },
- { 0x3e, IS_PMF | PMFE_AUDIO_VOLUME_UP },
+ { 0x3c, 0x7f }, /* F3 -> Keyboard Mute */
+ { 0x3d, 0x80 }, /* F4 -> Keyboard Volume Up */
+ { 0x3e, 0x81 }, /* F5 -> Keyboard Volume Down */
{ 0x3f, 0xd6 }, /* num lock */
{ 0x40, 0xd7 },
{ 0x41, IS_PMF | PMFE_KEYBOARD_BRIGHTNESS_TOGGLE },
@@ -154,9 +154,9 @@
{ 58, 0 }, /* F1 -> toggle camera */
{ 59, 0 }, /* F2 -> toggle wireless */
#endif
- { 60, IS_PMF | PMFE_AUDIO_VOLUME_TOGGLE },
- { 61, IS_PMF | PMFE_AUDIO_VOLUME_UP },
- { 62, IS_PMF | PMFE_AUDIO_VOLUME_DOWN },
+ { 60, 0x7f }, /* F3 -> Keyboard Mute */
+ { 61, 0x80 }, /* F4 -> Keyboard Volume Up */
+ { 62, 0x81 }, /* F5 -> Keyboard Volume Down */
#ifdef notyet
{ 63, 0 }, /* F6 -> toggle ext. video */
{ 64, 0 }, /* F7 -> toggle mouse */
@@ -177,9 +177,11 @@
#endif
Static const struct ukbd_keycodetrans trtab_generic[] = {
+#ifndef UKBD_NO_PMF_AUDIO_EVENTS
{ 0x7f, IS_PMF | PMFE_AUDIO_VOLUME_TOGGLE },
{ 0x80, IS_PMF | PMFE_AUDIO_VOLUME_UP },
{ 0x81, IS_PMF | PMFE_AUDIO_VOLUME_DOWN },
+#endif
{ 0x00, 0x00 }
};
@@ -595,7 +597,7 @@
if (tp->from == i) {
if (tp->to & IS_PMF) {
pmf_event_inject(
- sc->sc_hdev.sc_dev,
+ NULL,
tp->to & 0xff);
} else
setbit(ud->keys, tp->to);
Index: share/man/man4/ukbd.4
===================================================================
RCS file: /cvsroot/src/share/man/man4/ukbd.4,v
retrieving revision 1.11
diff -u -r1.11 ukbd.4
--- share/man/man4/ukbd.4 30 Apr 2008 13:10:54 -0000 1.11
+++ share/man/man4/ukbd.4 4 Mar 2022 17:39:38 -0000
@@ -36,6 +36,8 @@
.Sh SYNOPSIS
.Cd "ukbd* at uhidev? reportid ?"
.Cd "wskbd* at ukbd? console ?"
+.Pp
+.Cd "options UKBD_NO_PMF_AUDIO_EVENTS"
.Sh DESCRIPTION
The
.Nm
(Contact us)
$NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.