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
This commit is contained in:
tslight
2026-03-29 16:16:57 +03:00
committed by Vladimir Kondratyev
parent 40f55eada5
commit 103325323c
3 changed files with 66 additions and 56 deletions
+9 -4
View File
@@ -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,7 +830,10 @@ 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 (hw->idVendor == USB_VENDOR_APPLE) { /* belt & braces! */
if (hidbus_locate(ptr, len,
HID_USAGE2(HUP_CONSUMER, HUG_APPLE_EJECT),
hid_input, tlc_index, 0, &sc->sc_loc_apple_eject, &flags,
@@ -839,8 +844,8 @@ hkbd_parse_hid(struct hkbd_softc *sc, const uint8_t *ptr, uint32_t len,
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.
* 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 */
@@ -851,8 +856,7 @@ hkbd_parse_hid(struct hkbd_softc *sc, const uint8_t *ptr, uint32_t len,
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,
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;
@@ -861,6 +865,7 @@ hkbd_parse_hid(struct hkbd_softc *sc, const uint8_t *ptr, uint32_t len,
break;
}
}
}
/* figure out event buffer */
if (hidbus_locate(ptr, len,
+8 -3
View File
@@ -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,6 +1094,7 @@ 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 (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,
@@ -1102,8 +1104,8 @@ ukbd_parse_hid(struct ukbd_softc *sc, const uint8_t *ptr, uint32_t len)
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.
* 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 */
@@ -1112,7 +1114,8 @@ ukbd_parse_hid(struct ukbd_softc *sc, const uint8_t *ptr, uint32_t len)
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),
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)
@@ -1122,6 +1125,7 @@ ukbd_parse_hid(struct ukbd_softc *sc, const uint8_t *ptr, uint32_t len)
break;
}
}
}
/* figure out event buffer */
if (hid_locate(ptr, len,
@@ -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;
+1 -1
View File
@@ -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>