Skip to content

[OS Detection] Don't classify MacOS sequences as Windows when cnt_02 >= 2#26303

Open
bin101 wants to merge 1 commit into
qmk:developfrom
bin101:fix/os-detection-macos-windows-misidentification
Open

[OS Detection] Don't classify MacOS sequences as Windows when cnt_02 >= 2#26303
bin101 wants to merge 1 commit into
qmk:developfrom
bin101:fix/os-detection-macos-windows-misidentification

Conversation

@bin101

@bin101 bin101 commented Jun 30, 2026

Copy link
Copy Markdown

Fixes macOS 26.x being misidentified as Windows on ChibiOS keyboards

Description

On macOS 26.x with ChibiOS-based keyboards, the USB enumeration sends a late wLength=0x04 packet after the two 0xFF packets that already correctly established OS_MACOS. The existing Windows detection condition (cnt_ff >= 2 && cnt_04 >= 1) fires on this combination and permanently overwrites the correct result, causing the keyboard to report OS_WINDOWS on macOS for the remainder of the session.

Observed sequence (ChibiOS, macOS 15.x):
[0x02, 0x22, 0x02, 0x0E, 0x02, 0x42, 0xFF, 0xFF, 0x04, 0xFF]

After packet #6 (0xFF), detected_os is correctly set to OS_MACOS (cnt_02=3, cnt_ff=1). At packet #8 (0x04), cnt_ff=2 and cnt_04=1 satisfy the Windows condition, overwriting OS_MACOS with OS_WINDOWS. The final 0xFF at packet #9 re-evaluates to OS_WINDOWS again. The debounced callback delivers the incorrect result.

Fix: Add setups_data.cnt_02 < 2 as a conjunct to the Windows detection condition. This is sufficient because:

  • Every documented real-world Windows sequence starts with 0xFF packets and has cnt_02 = 0 at the point the Windows condition first triggers.
  • Every macOS sequence begins with at least two wLength=0x02 packets (cnt_02 >= 2).

These populations do not overlap. All existing Windows sequences in the test suite pass the new condition unchanged (cnt_02 = 0 in all cases).

A test case for the affected sequence has been added to quantum/os_detection/tests/os_detection.cpp

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

  • N/A

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

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.
@github-actions github-actions Bot added the core label Jun 30, 2026
@bin101 bin101 changed the title Don't classify MacOS sequences as Windows when cnt_02 >= 2 [OS Detection] Don't classify MacOS sequences as Windows when cnt_02 >= 2 Jun 30, 2026
@bin101

bin101 commented Jul 8, 2026

Copy link
Copy Markdown
Author

@drashna How many reviews are required for a merge?

@drashna

drashna commented Jul 9, 2026

Copy link
Copy Markdown
Member

@drashna How many reviews are required for a merge?

Usually 2 approvals before a merge.

Also, this should probably target the develop branch, rather than master.

@bin101 bin101 marked this pull request as draft July 9, 2026 08:09
@bin101 bin101 marked this pull request as ready for review July 9, 2026 08:10
@bin101 bin101 changed the base branch from master to develop July 9, 2026 08:10
@drashna drashna requested a review from a team July 9, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants