From 9261f6f2020b73cdcace4a73f9ba3e84d530acdc Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Wed, 11 Dec 2024 08:27:15 -0800 Subject: [PATCH 1/4] [OS Detection] Improve MacOS detection --- quantum/os_detection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/os_detection.c b/quantum/os_detection.c index 0dd048a8c472..84bbeeed5448 100644 --- a/quantum/os_detection.c +++ b/quantum/os_detection.c @@ -133,7 +133,7 @@ void process_wlength(const uint16_t w_length) { } else if (setups_data.count == setups_data.cnt_ff) { // Linux has 3 packets with 0xFF. guessed = OS_LINUX; - } else if (setups_data.count == 5 && setups_data.last_wlength == 0xFF && setups_data.cnt_ff == 1 && setups_data.cnt_02 == 2) { + } else if (setups_data.count >= 5 && setups_data.last_wlength == 0xFF && setups_data.cnt_ff >= 1 && setups_data.cnt_02 >= 2) { guessed = OS_MACOS; } else if (setups_data.count == 4 && setups_data.cnt_ff == 0 && setups_data.cnt_02 == 2) { // iOS and iPadOS don't have the last 0xFF packet. From de87483f5ab8a5e542eeebea446c14ab6bfe81c0 Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Wed, 11 Dec 2024 21:20:09 -0800 Subject: [PATCH 2/4] Add more data and tests --- quantum/os_detection/tests/os_detection.cpp | 47 ++++++++++++++++++--- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/quantum/os_detection/tests/os_detection.cpp b/quantum/os_detection/tests/os_detection.cpp index ea43de144c3a..b1271174fdf9 100644 --- a/quantum/os_detection/tests/os_detection.cpp +++ b/quantum/os_detection/tests/os_detection.cpp @@ -68,6 +68,8 @@ void assert_reported(os_variant_t os) { Windows 10: [FF, FF, 4, 24, 4, 24, 4, FF, 24, FF, 4, FF, 24, 4, 24, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A] Windows 10 (another host): [FF, FF, 4, 24, 4, 24, 4, 24, 4, 24, 4, 24] macOS 12.5: [2, 24, 2, 28, FF] +macOS 15.1.x: [ 2, 4E, 2, 1C, 2, 1A, FF, FF] +macOS 15.x (periodic weirdness): [ 2, 42, 2, 1C, 2, 1A, FF, 2, 42, 2, 1C, 2, 1A, FF ] iOS/iPadOS 15.6: [2, 24, 2, 28] Linux (including Android, Raspberry Pi and WebOS TV): [FF, FF, FF] PS5: [2, 4, 2, 28, 2, 24] @@ -79,6 +81,7 @@ Windows 10 (first connect): [12, FF, FF, 4, 10, FF, FF, FF, 4, 10, 20A, 20A, 20A Windows 10 (subsequent connect): [FF, FF, 4, 10, FF, 4, FF, 10, FF, 20A, 20A, 20A, 20A, 20A, 20A] Windows 10 (another host): [FF, FF, 4, 10, 4, 10] macOS: [2, 10, 2, E, FF] +macOS 15.x: [ 2, 64, 2, 28, FF, FF] iOS/iPadOS: [2, 10, 2, E] Linux: [FF, FF, FF] PS5: [2, 4, 2, E, 2, 10] @@ -115,12 +118,49 @@ TEST_F(OsDetectionTest, TestChibiosMacos) { assert_not_reported(); } +TEST_F(OsDetectionTest, TestChibiosMacos2) { + EXPECT_EQ(check_sequence({0x2, 0x42, 0x2, 0x1C, 0x2, 0x1A, 0xFF}), OS_MACOS); + os_detection_task(); + assert_not_reported(); +} + +TEST_F(OsDetectionTest, TestChibiosMacos3) { + EXPECT_EQ(check_sequence({ 0x2, 0x42, 0x2, 0x1C, 0x2, 0x1A, 0xFF, 0x2, 0x42, 0x2, 0x1C, 0x2, 0x1A, 0xFF}), OS_MACOS); + os_detection_task(); + assert_not_reported(); +} + +// Regression reported in https://github.com/qmk/qmk_firmware/pull/21777#issuecomment-1922815841 +TEST_F(OsDetectionTest, TestChibiosMacM1) { + EXPECT_EQ(check_sequence({0x02, 0x32, 0x02, 0x24, 0x101, 0xFF}), OS_MACOS); + os_detection_task(); + assert_not_reported(); +} + +TEST_F(OsDetectionTest, TestChibiosMacSequoia) { + EXPECT_EQ(check_sequence({0x02, 0x4E, 0x02, 0x1C, 0x02, 0x1A, 0xFF, 0xFF}), OS_MACOS); + os_detection_task(); + assert_not_reported(); +} + +TEST_F(OsDetectionTest, TestChibiosMacSequoia2) { + EXPECT_EQ(check_sequence({0x02, 0x4E, 0x02, 0x1C, 0x02, 0x1A, 0xFF, 0x02, 0x42, 0x02, 0x1C, 0x02, 0x1A, 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(); assert_not_reported(); } +TEST_F(OsDetectionTest, TestDetectLufaMacSequoia2) { + EXPECT_EQ(check_sequence({0x02, 0x64, 0x02, 0x28, 0xFF, 0xFF}), OS_MACOS); + os_detection_task(); + assert_not_reported(); +} + TEST_F(OsDetectionTest, TestVusbMacos) { EXPECT_EQ(check_sequence({0x2, 0xE, 0x2, 0xE, 0xFF}), OS_MACOS); os_detection_task(); @@ -235,13 +275,6 @@ TEST_F(OsDetectionTest, TestVusbQuest2) { assert_not_reported(); } -// Regression reported in https://github.com/qmk/qmk_firmware/pull/21777#issuecomment-1922815841 -TEST_F(OsDetectionTest, TestDetectMacM1AsIOS) { - EXPECT_EQ(check_sequence({0x02, 0x32, 0x02, 0x24, 0x101, 0xFF}), OS_IOS); - os_detection_task(); - assert_not_reported(); -} - TEST_F(OsDetectionTest, TestDoNotReportIfUsbUnstable) { EXPECT_EQ(check_sequence({0xFF, 0xFF, 0xFF, 0xFE}), OS_LINUX); os_detection_task(); From 68f89142f6dec3993be6782e025daebbf36a5ef8 Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Wed, 11 Dec 2024 21:22:09 -0800 Subject: [PATCH 3/4] Appease the lint gods --- quantum/os_detection/tests/os_detection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/os_detection/tests/os_detection.cpp b/quantum/os_detection/tests/os_detection.cpp index b1271174fdf9..648028cecf7c 100644 --- a/quantum/os_detection/tests/os_detection.cpp +++ b/quantum/os_detection/tests/os_detection.cpp @@ -125,7 +125,7 @@ TEST_F(OsDetectionTest, TestChibiosMacos2) { } TEST_F(OsDetectionTest, TestChibiosMacos3) { - EXPECT_EQ(check_sequence({ 0x2, 0x42, 0x2, 0x1C, 0x2, 0x1A, 0xFF, 0x2, 0x42, 0x2, 0x1C, 0x2, 0x1A, 0xFF}), OS_MACOS); + EXPECT_EQ(check_sequence({0x2, 0x42, 0x2, 0x1C, 0x2, 0x1A, 0xFF, 0x2, 0x42, 0x2, 0x1C, 0x2, 0x1A, 0xFF}), OS_MACOS); os_detection_task(); assert_not_reported(); } From d81ef55e1610fcd150b350ce10b423eb08cbb59e Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Fri, 13 Dec 2024 18:17:50 -0800 Subject: [PATCH 4/4] Add additional tests --- quantum/os_detection/tests/os_detection.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/quantum/os_detection/tests/os_detection.cpp b/quantum/os_detection/tests/os_detection.cpp index 648028cecf7c..21c4536243e6 100644 --- a/quantum/os_detection/tests/os_detection.cpp +++ b/quantum/os_detection/tests/os_detection.cpp @@ -69,9 +69,11 @@ Windows 10: [FF, FF, 4, 24, 4, 24, 4, FF, 24, FF, 4, FF, 24, 4, 24, 20A, 20A, 20 Windows 10 (another host): [FF, FF, 4, 24, 4, 24, 4, 24, 4, 24, 4, 24] 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 ] 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] PS5: [2, 4, 2, 28, 2, 24] Nintendo Switch: [82, FF, 40, 40, FF, 40, 40, FF, 40, 40, FF, 40, 40, FF, 40, 40] Quest 2: [FF, FF, FF, FE, FF, FE, FF, FE, FF, FE, FF] @@ -112,6 +114,12 @@ TEST_F(OsDetectionTest, TestLinux) { assert_not_reported(); } +TEST_F(OsDetectionTest, TestChibiosLinux) { + EXPECT_EQ(check_sequence({0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}), OS_LINUX); + os_detection_task(); + assert_not_reported(); +} + TEST_F(OsDetectionTest, TestChibiosMacos) { EXPECT_EQ(check_sequence({0x2, 0x24, 0x2, 0x28, 0xFF}), OS_MACOS); os_detection_task(); @@ -149,6 +157,12 @@ TEST_F(OsDetectionTest, TestChibiosMacSequoia2) { assert_not_reported(); } +TEST_F(OsDetectionTest, TestChibiosMacSequoia3) { + EXPECT_EQ(check_sequence({0x02, 0x0E, 0x02, 0x1E, 0x02, 0x42, 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();