Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/usb/input/ukbd.c
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | |||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/sx.h> | #include <sys/sx.h> | ||||
#include <sys/unistd.h> | #include <sys/unistd.h> | ||||
#include <sys/callout.h> | #include <sys/callout.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/priv.h> | #include <sys/priv.h> | ||||
#include <sys/proc.h> | #include <sys/proc.h> | ||||
#include <dev/hid/hid.h> | |||||
#include <dev/usb/usb.h> | #include <dev/usb/usb.h> | ||||
#include <dev/usb/usbdi.h> | #include <dev/usb/usbdi.h> | ||||
#include <dev/usb/usbdi_util.h> | #include <dev/usb/usbdi_util.h> | ||||
#include <dev/usb/usbhid.h> | #include <dev/usb/usbhid.h> | ||||
#define USB_DEBUG_VAR ukbd_debug | #define USB_DEBUG_VAR ukbd_debug | ||||
#include <dev/usb/usb_debug.h> | #include <dev/usb/usb_debug.h> | ||||
▲ Show 20 Lines • Show All 639 Lines • ▼ Show 20 Lines | for (i = 0; i != UKBD_NKEYCODE; i++) { | ||||
continue; /* invalid HID ID */ | continue; /* invalid HID ID */ | ||||
} else if (i == 0) { | } else if (i == 0) { | ||||
struct hid_location tmp_loc = sc->sc_loc_key[0]; | struct hid_location tmp_loc = sc->sc_loc_key[0]; | ||||
/* range check array size */ | /* range check array size */ | ||||
if (tmp_loc.count > UKBD_NKEYCODE) | if (tmp_loc.count > UKBD_NKEYCODE) | ||||
tmp_loc.count = UKBD_NKEYCODE; | tmp_loc.count = UKBD_NKEYCODE; | ||||
while (tmp_loc.count--) { | while (tmp_loc.count--) { | ||||
uint32_t key = | uint32_t key = | ||||
hid_get_data_unsigned(sc->sc_buffer, len, &tmp_loc); | hid_get_udata(sc->sc_buffer, len, &tmp_loc); | ||||
/* advance to next location */ | /* advance to next location */ | ||||
tmp_loc.pos += tmp_loc.size; | tmp_loc.pos += tmp_loc.size; | ||||
if (modifiers & MOD_FN) | if (modifiers & MOD_FN) | ||||
key = ukbd_apple_fn(key); | key = ukbd_apple_fn(key); | ||||
if (sc->sc_flags & UKBD_FLAG_APPLE_SWAP) | if (sc->sc_flags & UKBD_FLAG_APPLE_SWAP) | ||||
key = ukbd_apple_swap(key); | key = ukbd_apple_swap(key); | ||||
if (key == KEY_NONE || key == KEY_ERROR || key >= UKBD_NKEYCODE) | if (key == KEY_NONE || key == KEY_ERROR || key >= UKBD_NKEYCODE) | ||||
continue; | continue; | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | case USB_ST_SETUP: | ||||
id = 0; | id = 0; | ||||
any = 0; | any = 0; | ||||
/* Assumption: All led bits must be in the same ID. */ | /* Assumption: All led bits must be in the same ID. */ | ||||
if (sc->sc_flags & UKBD_FLAG_NUMLOCK) { | if (sc->sc_flags & UKBD_FLAG_NUMLOCK) { | ||||
if (sc->sc_leds & NLKED) { | if (sc->sc_leds & NLKED) { | ||||
hid_put_data_unsigned(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1, | hid_put_udata(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1, | ||||
&sc->sc_loc_numlock, 1); | &sc->sc_loc_numlock, 1); | ||||
} | } | ||||
id = sc->sc_id_numlock; | id = sc->sc_id_numlock; | ||||
any = 1; | any = 1; | ||||
} | } | ||||
if (sc->sc_flags & UKBD_FLAG_SCROLLLOCK) { | if (sc->sc_flags & UKBD_FLAG_SCROLLLOCK) { | ||||
if (sc->sc_leds & SLKED) { | if (sc->sc_leds & SLKED) { | ||||
hid_put_data_unsigned(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1, | hid_put_udata(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1, | ||||
&sc->sc_loc_scrolllock, 1); | &sc->sc_loc_scrolllock, 1); | ||||
} | } | ||||
id = sc->sc_id_scrolllock; | id = sc->sc_id_scrolllock; | ||||
any = 1; | any = 1; | ||||
} | } | ||||
if (sc->sc_flags & UKBD_FLAG_CAPSLOCK) { | if (sc->sc_flags & UKBD_FLAG_CAPSLOCK) { | ||||
if (sc->sc_leds & CLKED) { | if (sc->sc_leds & CLKED) { | ||||
hid_put_data_unsigned(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1, | hid_put_udata(sc->sc_buffer + 1, UKBD_BUFFER_SIZE - 1, | ||||
&sc->sc_loc_capslock, 1); | &sc->sc_loc_capslock, 1); | ||||
} | } | ||||
id = sc->sc_id_capslock; | id = sc->sc_id_capslock; | ||||
any = 1; | any = 1; | ||||
} | } | ||||
/* if no leds, nothing to do */ | /* if no leds, nothing to do */ | ||||
if (!any) | if (!any) | ||||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | ukbd_parse_hid(struct ukbd_softc *sc, const uint8_t *ptr, uint32_t len) | ||||
/* reset detected bits */ | /* reset detected bits */ | ||||
sc->sc_flags &= ~UKBD_FLAG_HID_MASK; | sc->sc_flags &= ~UKBD_FLAG_HID_MASK; | ||||
/* reset detected keys */ | /* reset detected keys */ | ||||
memset(sc->sc_loc_key_valid, 0, sizeof(sc->sc_loc_key_valid)); | memset(sc->sc_loc_key_valid, 0, sizeof(sc->sc_loc_key_valid)); | ||||
/* check if there is an ID byte */ | /* check if there is an ID byte */ | ||||
sc->sc_kbd_size = hid_report_size(ptr, len, | sc->sc_kbd_size = hid_report_size_max(ptr, len, | ||||
hid_input, &sc->sc_kbd_id); | hid_input, &sc->sc_kbd_id); | ||||
/* investigate if this is an Apple Keyboard */ | /* investigate if this is an Apple Keyboard */ | ||||
if (hid_locate(ptr, len, | if (hid_locate(ptr, len, | ||||
HID_USAGE2(HUP_CONSUMER, HUG_APPLE_EJECT), | HID_USAGE2(HUP_CONSUMER, HUG_APPLE_EJECT), | ||||
hid_input, 0, &sc->sc_loc_apple_eject, &flags, | hid_input, 0, &sc->sc_loc_apple_eject, &flags, | ||||
&sc->sc_id_apple_eject)) { | &sc->sc_id_apple_eject)) { | ||||
if (flags & HIO_VARIABLE) | if (flags & HIO_VARIABLE) | ||||
Show All 33 Lines | if (hid_locate(ptr, len, | ||||
sc->sc_loc_key_valid[key / 64] |= | sc->sc_loc_key_valid[key / 64] |= | ||||
1ULL << (key % 64); | 1ULL << (key % 64); | ||||
DPRINTFN(1, "Found key 0x%02x\n", key); | DPRINTFN(1, "Found key 0x%02x\n", key); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/* figure out leds on keyboard */ | /* figure out leds on keyboard */ | ||||
sc->sc_led_size = hid_report_size(ptr, len, | sc->sc_led_size = hid_report_size_max(ptr, len, | ||||
hid_output, NULL); | hid_output, NULL); | ||||
if (hid_locate(ptr, len, | if (hid_locate(ptr, len, | ||||
HID_USAGE2(HUP_LEDS, 0x01), | HID_USAGE2(HUP_LEDS, 0x01), | ||||
hid_output, 0, &sc->sc_loc_numlock, &flags, | hid_output, 0, &sc->sc_loc_numlock, &flags, | ||||
&sc->sc_id_numlock)) { | &sc->sc_id_numlock)) { | ||||
if (flags & HIO_VARIABLE) | if (flags & HIO_VARIABLE) | ||||
sc->sc_flags |= UKBD_FLAG_NUMLOCK; | sc->sc_flags |= UKBD_FLAG_NUMLOCK; | ||||
▲ Show 20 Lines • Show All 1,149 Lines • Show Last 20 Lines |