From d3069760d70af899f6c6b213436dc9272c6af752 Mon Sep 17 00:00:00 2001 From: Jens van Almsick Date: Fri, 25 Sep 2026 20:05:33 +0200 Subject: [PATCH] [OS Detection] Don't classify MacOS sequences as Windows when cnt_02 >= 2 (#26303) fix(os_detection): don't classify macOS sequences as Windows macOS 26.x (ChibiOS) can send a late wLength=0x04 packet after the two 0xFF packets that already established OS_MACOS. The Windows check (cnt_ff >= 2 && cnt_04 >= 1) fired on this combination and overwrites the correct result. Real-world Windows sequences always start with 0xFF packets (cnt_02 = 0); macOS sequences always open with at least two 0x02 packets (cnt_02 >= 2). Adding && setups_data.cnt_02 < 2 to the Windows condition is sufficient to separate the two populations without affecting any existing detection. Adds a regression test for the affected sequence. --- quantum/os_detection.c | 2 +- quantum/os_detection/tests/os_detection.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/quantum/os_detection.c b/quantum/os_detection.c index 2a5237dfc31..8c78e4c94eb 100644 --- a/quantum/os_detection.c +++ b/quantum/os_detection.c @@ -147,7 +147,7 @@ void process_wlength(const uint16_t w_length) { // now try to make a guess os_variant_t guessed = OS_UNSURE; if (setups_data.count >= 3) { - if (setups_data.cnt_ff >= 2 && setups_data.cnt_04 >= 1) { + if (setups_data.cnt_ff >= 2 && setups_data.cnt_04 >= 1 && setups_data.cnt_02 < 2) { guessed = OS_WINDOWS; } else if (setups_data.count == setups_data.cnt_ff) { // Linux has 3 packets with 0xFF. diff --git a/quantum/os_detection/tests/os_detection.cpp b/quantum/os_detection/tests/os_detection.cpp index 21c4536243e..6a1f0b9db3e 100644 --- a/quantum/os_detection/tests/os_detection.cpp +++ b/quantum/os_detection/tests/os_detection.cpp @@ -71,6 +71,7 @@ macOS 12.5: [2, 24, 2, 28, FF] macOS 15.1.x: [ 2, 4E, 2, 1C, 2, 1A, FF, FF] macOS 15.x (another host): [ 2, 0E, 2, 1E, 2, 42, FF] macOS 15.x (periodic weirdness): [ 2, 42, 2, 1C, 2, 1A, FF, 2, 42, 2, 1C, 2, 1A, FF ] +macOS 26.x: [02, 22, 02, 0E, 02, 42, FF, FF, 4, FF] iOS/iPadOS 15.6: [2, 24, 2, 28] Linux (including Android, Raspberry Pi and WebOS TV): [FF, FF, FF] Linux (another host): [FF, FF, FF, FF, FF, FF] @@ -163,6 +164,12 @@ TEST_F(OsDetectionTest, TestChibiosMacSequoia3) { assert_not_reported(); } +TEST_F(OsDetectionTest, TestChibiosMacosWithLate04Packet) { + EXPECT_EQ(check_sequence({0x02, 0x22, 0x02, 0x0E, 0x02, 0x42, 0xFF, 0xFF, 0x04, 0xFF}), OS_MACOS); + os_detection_task(); + assert_not_reported(); +} + TEST_F(OsDetectionTest, TestLufaMacos) { EXPECT_EQ(check_sequence({0x2, 0x10, 0x2, 0xE, 0xFF}), OS_MACOS); os_detection_task();