[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.
This commit is contained in:
Jens van Almsick
2026-09-25 19:05:33 +01:00
committed by GitHub
parent cb5590fa6b
commit d3069760d7
2 changed files with 8 additions and 1 deletions
+1 -1
View File
@@ -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.
@@ -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();