Date: Sun, 29 Mar 2026 13:17:43 +0000 From: Vladimir Kondratyev <wulf@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: tslight <tslight@pm.com> Subject: git: 103325323c7d - main - hkbd(4): be more cautious & explicit about Apple vendor checking Message-ID: <69c92677.1e161.65df2900@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=103325323c7daf9fe6c9a6c71aa5c90974c9dff4 commit 103325323c7daf9fe6c9a6c71aa5c90974c9dff4 Author: tslight <tslight@pm.com> AuthorDate: 2026-03-29 13:16:57 +0000 Commit: Vladimir Kondratyev <wulf@FreeBSD.org> CommitDate: 2026-03-29 13:16:57 +0000 hkbd(4): be more cautious & explicit about Apple vendor checking Apply the changes to ukbd(4) as well. Signed-off-by: tslight <tslight@pm.com> Reviewed by: wulf MFC after: 1 month Pull Request: https://github.com/freebsd/freebsd-src/pull/1998 --- sys/dev/hid/hkbd.c | 63 +++++++++++++++++++++++-------------------- sys/dev/usb/input/ukbd.c | 57 +++++++++++++++++++++------------------ sys/modules/hid/hkbd/Makefile | 2 +- 3 files changed, 66 insertions(+), 56 deletions(-) diff --git a/sys/dev/hid/hkbd.c b/sys/dev/hid/hkbd.c index a91a01a385e3..9ab02e940089 100644 --- a/sys/dev/hid/hkbd.c +++ b/sys/dev/hid/hkbd.c @@ -73,6 +73,8 @@ #include <dev/hid/hidquirk.h> #include <dev/hid/hidrdesc.h> +#include "usbdevs.h" + #ifdef EVDEV_SUPPORT #include <dev/evdev/input.h> #include <dev/evdev/evdev.h> @@ -828,40 +830,43 @@ hkbd_parse_hid(struct hkbd_softc *sc, const uint8_t *ptr, uint32_t len, sc->sc_kbd_size = hid_report_size_max(ptr, len, hid_input, &sc->sc_kbd_id); + const struct hid_device_info *hw = hid_get_device_info(sc->sc_dev); + /* investigate if this is an Apple Keyboard */ - if (hidbus_locate(ptr, len, - HID_USAGE2(HUP_CONSUMER, HUG_APPLE_EJECT), - hid_input, tlc_index, 0, &sc->sc_loc_apple_eject, &flags, - &sc->sc_id_apple_eject, NULL)) { - if (flags & HIO_VARIABLE) - sc->sc_flags |= HKBD_FLAG_APPLE_EJECT | - HKBD_FLAG_APPLE_SWAP; - DPRINTFN(1, "Found Apple eject-key\n"); - } - /* - * check the same vendor pages that linux does to find the one apple - * uses for the function key. - */ - static const uint16_t apple_pages[] = { - HUP_APPLE, /* HID_UP_CUSTOM in linux */ - HUP_MICROSOFT, /* HID_UP_MSVENDOR in linux */ - HUP_HP, /* HID_UP_HPVENDOR2 in linux */ - 0xFFFF /* Original FreeBSD check (Remove?) */ - }; - for (int i = 0; i < (int)nitems(apple_pages); i++) { + if (hw->idVendor == USB_VENDOR_APPLE) { /* belt & braces! */ if (hidbus_locate(ptr, len, - HID_USAGE2(apple_pages[i], 0x0003), - hid_input, tlc_index, 0, - &sc->sc_loc_apple_fn, &flags, - &sc->sc_id_apple_fn, NULL)) { + HID_USAGE2(HUP_CONSUMER, HUG_APPLE_EJECT), + hid_input, tlc_index, 0, &sc->sc_loc_apple_eject, &flags, + &sc->sc_id_apple_eject, NULL)) { if (flags & HIO_VARIABLE) - sc->sc_flags |= HKBD_FLAG_APPLE_FN; - DPRINTFN(1, "Found Apple FN-key on page 0x%04x\n", - apple_pages[i]); - break; + sc->sc_flags |= HKBD_FLAG_APPLE_EJECT | + HKBD_FLAG_APPLE_SWAP; + DPRINTFN(1, "Found Apple eject-key\n"); + } + /* + * check the same vendor pages that linux does to find the one + * apple uses for the function key. + */ + static const uint16_t apple_pages[] = { + HUP_APPLE, /* HID_UP_CUSTOM in linux */ + HUP_MICROSOFT, /* HID_UP_MSVENDOR in linux */ + HUP_HP, /* HID_UP_HPVENDOR2 in linux */ + 0xFFFF /* Original FreeBSD check (Remove?) */ + }; + for (int i = 0; i < (int)nitems(apple_pages); i++) { + if (hidbus_locate(ptr, len, + HID_USAGE2(apple_pages[i], 0x0003), + hid_input, tlc_index, 0, &sc->sc_loc_apple_fn, &flags, + &sc->sc_id_apple_fn, NULL)) { + if (flags & HIO_VARIABLE) + sc->sc_flags |= HKBD_FLAG_APPLE_FN; + DPRINTFN(1, "Found Apple FN-key on page 0x%04x\n", + apple_pages[i]); + break; + } } } - + /* figure out event buffer */ if (hidbus_locate(ptr, len, HID_USAGE2(HUP_KEYBOARD, 0x00), diff --git a/sys/dev/usb/input/ukbd.c b/sys/dev/usb/input/ukbd.c index c15528553086..3ebdf1e9747d 100644 --- a/sys/dev/usb/input/ukbd.c +++ b/sys/dev/usb/input/ukbd.c @@ -205,6 +205,7 @@ struct ukbd_softc { uint16_t sc_inputs; uint16_t sc_inputhead; uint16_t sc_inputtail; + uint16_t sc_vendor_id; uint8_t sc_leds; /* store for async led requests */ uint8_t sc_iface_index; @@ -1093,33 +1094,36 @@ ukbd_parse_hid(struct ukbd_softc *sc, const uint8_t *ptr, uint32_t len) hid_input, &sc->sc_kbd_id); /* investigate if this is an Apple Keyboard */ - if (hid_locate(ptr, len, - HID_USAGE2(HUP_CONSUMER, HUG_APPLE_EJECT), - hid_input, 0, &sc->sc_loc_apple_eject, &flags, - &sc->sc_id_apple_eject)) { - if (flags & HIO_VARIABLE) - sc->sc_flags |= UKBD_FLAG_APPLE_EJECT; - DPRINTFN(1, "Found Apple eject-key\n"); - } - /* - * check the same vendor pages that linux does to find the one apple - * uses for the function key. - */ - static const uint16_t apple_pages[] = { - HUP_APPLE, /* HID_UP_CUSTOM in linux */ - HUP_MICROSOFT, /* HID_UP_MSVENDOR in linux */ - HUP_HP, /* HID_UP_HPVENDOR2 in linux */ - 0xFFFF /* Original FreeBSD check (Remove?) */ - }; - for (int i = 0; i < (int)nitems(apple_pages); i++) { - if (hid_locate(ptr, len, HID_USAGE2(apple_pages[i], 0x0003), - hid_input, 0, &sc->sc_loc_apple_fn, &flags, - &sc->sc_id_apple_fn)) { + if (sc->sc_vendor_id == USB_VENDOR_APPLE) { + if (hid_locate(ptr, len, + HID_USAGE2(HUP_CONSUMER, HUG_APPLE_EJECT), + hid_input, 0, &sc->sc_loc_apple_eject, &flags, + &sc->sc_id_apple_eject)) { if (flags & HIO_VARIABLE) - sc->sc_flags |= UKBD_FLAG_APPLE_FN; - DPRINTFN(1, "Found Apple FN-key on page 0x%04x\n", - apple_pages[i]); - break; + sc->sc_flags |= UKBD_FLAG_APPLE_EJECT; + DPRINTFN(1, "Found Apple eject-key\n"); + } + /* + * check the same vendor pages that linux does to find the one + * apple uses for the function key. + */ + static const uint16_t apple_pages[] = { + HUP_APPLE, /* HID_UP_CUSTOM in linux */ + HUP_MICROSOFT, /* HID_UP_MSVENDOR in linux */ + HUP_HP, /* HID_UP_HPVENDOR2 in linux */ + 0xFFFF /* Original FreeBSD check (Remove?) */ + }; + for (int i = 0; i < (int)nitems(apple_pages); i++) { + if (hid_locate(ptr, len, + HID_USAGE2(apple_pages[i], 0x0003), + hid_input, 0, &sc->sc_loc_apple_fn, &flags, + &sc->sc_id_apple_fn)) { + if (flags & HIO_VARIABLE) + sc->sc_flags |= UKBD_FLAG_APPLE_FN; + DPRINTFN(1, "Found Apple FN-key on page 0x%04x\n", + apple_pages[i]); + break; + } } } @@ -1208,6 +1212,7 @@ ukbd_attach(device_t dev) sc->sc_udev = uaa->device; sc->sc_iface = uaa->iface; + sc->sc_vendor_id = uaa->info.idVendor; sc->sc_iface_index = uaa->info.bIfaceIndex; sc->sc_iface_no = uaa->info.bIfaceNum; sc->sc_mode = K_XLATE; diff --git a/sys/modules/hid/hkbd/Makefile b/sys/modules/hid/hkbd/Makefile index 42b5d69dda9e..82f6599cca1d 100644 --- a/sys/modules/hid/hkbd/Makefile +++ b/sys/modules/hid/hkbd/Makefile @@ -3,6 +3,6 @@ KMOD= hkbd SRCS= hkbd.c SRCS+= opt_hid.h opt_evdev.h opt_kbd.h opt_hkbd.h -SRCS+= bus_if.h device_if.h +SRCS+= bus_if.h device_if.h usbdevs.h .include <bsd.kmod.mk>home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69c92677.1e161.65df2900>
