summaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
authorRuslan Sayfutdinov <ruslan@sayfutdinov.com>2022-12-08 16:45:30 +0000
committerGitHub <noreply@github.com>2022-12-09 03:45:30 +1100
commit85ee55ff3becd29e1590376c3462c6a99c976fa0 (patch)
tree36ab093ee44919070ac260f8aaf2770871d14910 /tmk_core
parente06f50c489e02068465dfb3e5b3c7473006e6273 (diff)
Detect host OS based on USB fingerprint (#18463)
Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/protocol/chibios/usb_main.c10
-rw-r--r--tmk_core/protocol/lufa/lufa.c2
-rw-r--r--tmk_core/protocol/usb_descriptor.c9
-rw-r--r--tmk_core/protocol/usb_descriptor.h2
-rw-r--r--tmk_core/protocol/vusb/vusb.c7
5 files changed, 23 insertions, 7 deletions
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index 094c14d1b3..5d36900bdd 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -111,9 +111,10 @@ uint8_t extra_report_blank[3] = {0};
static const USBDescriptor *usb_get_descriptor_cb(USBDriver *usbp, uint8_t dtype, uint8_t dindex, uint16_t wIndex) {
(void)usbp;
static USBDescriptor desc;
- uint16_t wValue = ((uint16_t)dtype << 8) | dindex;
- desc.ud_string = NULL;
- desc.ud_size = get_usb_descriptor(wValue, wIndex, (const void **const) & desc.ud_string);
+ uint16_t wValue = ((uint16_t)dtype << 8) | dindex;
+ uint16_t wLength = ((uint16_t)usbp->setup[7] << 8) | usbp->setup[6];
+ desc.ud_string = NULL;
+ desc.ud_size = get_usb_descriptor(wValue, wIndex, wLength, (const void **const) & desc.ud_string);
if (desc.ud_string == NULL)
return NULL;
else
@@ -585,7 +586,8 @@ static uint16_t get_hword(uint8_t *p) {
*/
static uint8_t set_report_buf[2] __attribute__((aligned(4)));
-static void set_led_transfer_cb(USBDriver *usbp) {
+
+static void set_led_transfer_cb(USBDriver *usbp) {
if (usbp->setup[6] == 2) { /* LSB(wLength) */
uint8_t report_id = set_report_buf[0];
if ((report_id == REPORT_ID_KEYBOARD) || (report_id == REPORT_ID_NKRO)) {
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 8f36e02b9a..99f7d31287 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -901,5 +901,5 @@ void protocol_post_task(void) {
}
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint16_t wIndex, const void **const DescriptorAddress) {
- return get_usb_descriptor(wValue, wIndex, DescriptorAddress);
+ return get_usb_descriptor(wValue, wIndex, USB_ControlRequest.wLength, DescriptorAddress);
}
diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c
index c7d78be856..5ab9e3ff4f 100644
--- a/tmk_core/protocol/usb_descriptor.c
+++ b/tmk_core/protocol/usb_descriptor.c
@@ -45,6 +45,10 @@
# include "joystick.h"
#endif
+#ifdef OS_DETECTION_ENABLE
+# include "os_detection.h"
+#endif
+
// clang-format off
/*
@@ -1092,7 +1096,7 @@ const USB_Descriptor_String_t PROGMEM SerialNumberString = {
* is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
* USB host.
*/
-uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const void** const DescriptorAddress) {
+uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const uint16_t wLength, const void** const DescriptorAddress) {
const uint8_t DescriptorType = (wValue >> 8);
const uint8_t DescriptorIndex = (wValue & 0xFF);
const void* Address = NULL;
@@ -1134,6 +1138,9 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
break;
#endif
}
+#ifdef OS_DETECTION_ENABLE
+ process_wlength(wLength);
+#endif
break;
case HID_DTYPE_HID:
diff --git a/tmk_core/protocol/usb_descriptor.h b/tmk_core/protocol/usb_descriptor.h
index bc5e84e586..ed84f4c9ab 100644
--- a/tmk_core/protocol/usb_descriptor.h
+++ b/tmk_core/protocol/usb_descriptor.h
@@ -308,4 +308,4 @@ enum usb_endpoints {
#define JOYSTICK_EPSIZE 8
#define DIGITIZER_EPSIZE 8
-uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const void** const DescriptorAddress);
+uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const uint16_t wLength, const void** const DescriptorAddress);
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index 2d17761978..b3eeff9e01 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -44,6 +44,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "ring_buffer.h"
#endif
+#ifdef OS_DETECTION_ENABLE
+# include "os_detection.h"
+#endif
+
#define NEXT_INTERFACE __COUNTER__
/*
@@ -1013,6 +1017,9 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
break;
#endif
}
+#ifdef OS_DETECTION_ENABLE
+ process_wlength(rq->wLength.word);
+#endif
break;
case USBDESCR_HID:
switch (rq->wValue.bytes[0]) {