Reverse Engineering the ITE8291 USB HID RGB Protocol: Inside mrSpyCC
Most Tongfang, AiStone, and Game Garaj barebone laptops rely on the ITE8291 USB HID controller for per-key RGB keyboard lighting. OEM control centers are typically tied to heavy background services and limited static presets, yet the underlying silicon can stream live pixel buffers above 30 FPS when driven with the right HID packets.
mrSpyCC is a single-EXE portable control center built with C# and .NET 10 WPF that drives the ITE8291 directly over Win32 P/Invoke (hid.dll, setupapi.dll, kernel32.dll, winmm.dll) with zero third-party HID wrapper dependencies. This post breaks down the HID discovery flow, the 512-byte frame protocol, the 96-key matrix table, safe GCUBridge lock handoff, and the 31.25 FPS render loop.
1. Pure Win32 P/Invoke HID Enumeration
Composite USB HID devices expose multiple logical interfaces (MI_00, MI_01, etc.). Standard keystrokes travel over the keyboard interface, while RGB control lives on a vendor-defined Usage Page.
In NativeHid.cs and Ite8291Device.cs, device selection filters interfaces in four steps:
- Enumerate active HID device interfaces via
SetupDiGetClassDevs. - Resolve each
DevicePathwithSetupDiEnumDeviceInterfacesandSetupDiGetDeviceInterfaceDetail. - Verify hardware identity from
HIDD_ATTRIBUTES:VendorID == 0x048DandProductID == 0x600B(VID_048D&PID_600B&MI_01). - Inspect
HIDP_CAPS.UsagePageviaHidD_GetPreparsedDataandHidP_GetCapsto match0xFF03(VENDOR_USAGE_PAGE).
2. EC Handshake and 512-Byte Frame Protocol
Before accepting raw pixel frames, the ITE8291 controller must be switched into per-key custom mode through EnterCustomMode() in Ite8291Device.cs:
| Step | Win32 Call | Size | Payload / Purpose |
|---|---|---|---|
| 1. EC Prep 1 (Buffer Reset) | HidD_SetFeature | 9 bytes | [0x00, 0x12, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00] |
| 2. Clear Hardware Matrix | WriteFile | 65 bytes | Zero-filled frame to clear stale LED state |
3. EC Prep 2 (Custom Mode 0x33) | HidD_SetFeature | 9 bytes | [0x00, 0x08, 0x02, 0x33, 0x00, 0x32, 0x00, 0x00, 0x00] |
Byte 0x33 enables per-key custom mode and 0x32 (50 decimal) sets maximum hardware brightness.
Frame Transmission (SendFrame)
Each 512-byte frame is transmitted in two stages:
- Feature Header (
_featureHeader): A 9-byteHidD_SetFeaturecall[0x00, 0x12, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00]signals command0x12followed by 8 chunks. - Chunked
WriteFile: 8 sequential 65-byte writes (0x00Report ID + 64 payload bytes = 512 bytes total per frame).
Preallocated class-level buffers (_featureHeader, _chunkBuffer[65], and _scaledBuffer[512]) keep the hot render loop completely allocation-free.
3. 96-Key Matrix Mapping (KeyMapTable.cs)
The 512-byte payload maps directly to the EC scan matrix rather than a linear RGB array. KeyMapTable.cs maps 96 physical keys across 6 rows × 21 columns into exact byte offsets (for example: Esc at 21, F1 at 45, Sc at 333, IsoEnterPrimary at 349, and IsoEnterSecondary at 321).
4. GCUBridge Lock Handoff (VendorLockManager.cs)
The stock GCUBridge Windows service holds an open handle to the HID interface, causing ERROR_SHARING_VIOLATION (32) when another process opens it. Permanently killing GCUBridge is unsafe because it also manages laptop fan curves and thermal profiles.
Instead, AcquireLock opens the device with dwShareMode = 0 (exclusive). When GCUBridge is running and the app is elevated, it temporarily stops GCUBridge, acquires the exclusive HID handle with progressive retries (250ms * attempt), and immediately restarts GCUBridge in finally so thermal management stays active.
5. 31.25 FPS Timing, WASAPI FFT, and 45+ Effects
AnimationEngine.cs runs on a dedicated AboveNormal thread (mrSpyCC_RenderThread) using winmm.dll timeBeginPeriod(1) locked to 32.0 ms per frame (31.25 FPS), the hardware-safe ceiling for ITE8291. On top of this pipeline, WasapiAudioCapture.cs and FastFourierTransform.cs drive low-latency audio-reactive visualizers alongside 45+ effects including keyboard mini-games (Snake, Dino, Space Invaders, Flappy Bird) and cyber entities (Living Eyes, Tamagotchi, Ant Colony).
Source code: MrSpy00/mrSpyCC on GitHub.