Software Disconnection of Xbox Series Controllers via GIP: Technical Deep Dive
Steam Big Picture is convenient for couch gaming but has shortcomings: it doesn't switch audio output, doesn't deactivate Night Light, and doesn't disconnect Xbox Series controllers when exiting the mode. A developer created Big Picture Manager in C# for automation. The app monitors the launch of the Steam Big Picture window, switches audio devices, manages the Windows registry for Night Light, and solves the controller issue.
For audio, a target device is set upon entry, with a return to the original upon exit. Night Light is disabled via direct registry writing, with restoration happening automatically.
Xbox Series: Connection and Fault Tolerance
The Xbox Series controller connects via Bluetooth, Xbox Wireless Adapter (2.4 GHz), or USB. The disconnection problem is solved by disabling Bluetooth entirely, but this isn't ideal. The goal is selective disconnection via GIP (Game Input Protocol).
Microsoft published documentation on GameInput in 2024, unifying XInput, DirectInput, Raw Input, HID, and WinRT. GIP is a transport protocol for gaming devices. The Set Device State (0x04) command transitions a device to GIP Off State.
Implementing XboxGIP Access in C#
Access to the interface is opened via \\.\XboxGIP with read/write permissions. The code uses P/Invoke for kernel32.dll: CreateFileW, DeviceIoControl, ReadFile, WriteFile.
Example code for reinitialization and sending the disconnect command:
using System.ComponentModel;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
public class XboxGipController
{
private const uint GENERIC_READ = 0x80000000;
private const uint GENERIC_WRITE = 0x40000000;
private const uint FILE_SHARE_READ = 0x00000001;
private const uint FILE_SHARE_WRITE = 0x00000002;
private const uint OPEN_EXISTING = 3;
private const uint FILE_ATTRIBUTE_NORMAL = 0x00000080;
private const uint GIP_ADD_REENUMERATE_CALLER_CONTEXT = 0x40001CD0;
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern SafeFileHandle CreateFileW(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
IntPtr lpSecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
IntPtr hTemplateFile
);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool DeviceIoControl(
SafeFileHandle hDevice,
uint dwIoControlCode,
IntPtr lpInBuffer,
uint nInBufferSize,
IntPtr lpOutBuffer,
uint nOutBufferSize,
out uint lpBytesReturned,
IntPtr lpOverlapped
);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool ReadFile(
SafeFileHandle hFile,
byte[] lpBuffer,
uint nNumberOfBytesToRead,
out uint lpNumberOfBytesRead,
IntPtr lpOverlapped
);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool WriteFile(
SafeFileHandle hFile,
byte[] lpBuffer,
uint nNumberOfBytesToWrite,
out uint lpNumberOfBytesWritten,
IntPtr lpOverlapped
);
// ... (rest of ProcessGipMessage and ReenumerateGipControllers code)
}
Operation Sequence
- Opening a handle to
\\.\XboxGIP. - Calling DeviceIoControl with GIP_ADD_REENUMERATE_CALLER_CONTEXT for reinitialization.
- Forming the disconnect packet:
- Bytes 0-7: Xbox controller identifier (0x7E 0xED 0x82 0xC6 0x8B 0xDA 0x00 0x00).
- Byte 8: Command ID (0x05).
- Byte 9: Flags (0x20).
- Byte 10: Sequence (0x01).
- Byte 11: Payload length (0x01).
- Byte 12: Payload (0x04 for Off).
- Sending via WriteFile.
- Reading the response in a loop via ReadFile until ERROR_NO_MORE_DATA (code 259).
Debugging and Limitations
The code works when connected via Xbox Wireless Adapter. WriteFile may fail if the device isn't ready. ReadFile processes incoming GIP messages for analysis. For complete disconnection, precise byte tuning and state handling are required.
- Advantages of the approach: Low-level control without system hacks.
- Disadvantages: Dependency on GIP documentation, potential changes in driver updates.
- Recommendations: Test on Windows 10/11, monitor Win32Exception.
Key Takeaways
- GameInput and GIP provide unified access to Xbox Series controllers.
- Command 0x04 in Set Device State transitions a device to Off State.
- P/Invoke in C# allows sending raw packets via
\\.\XboxGIP. - Reinitialization via GIP_ADD_REENUMERATE_CALLER_CONTEXT is mandatory before commands.
- The approach is only applicable for wireless adapters, not Bluetooth/USB.
— Editorial Team
No comments yet.