├── croskblightclient ├── croskblightclient │ ├── icon.ico │ ├── resource.h │ ├── croskblightclient.h │ ├── croskblightcommon.h │ ├── croskblightclient.vcxproj.filters │ ├── Resource.rc │ ├── croskblightclient.c │ ├── croskblightclient.vcxproj │ └── client.c └── croskblightclient.sln ├── croskblight ├── resource.h ├── croskblight.rc ├── hidcommon.h ├── Trace.h ├── croskblight.inf ├── eccmds.h ├── croskblight.h ├── croskblight.vcxproj └── croskblight.cpp ├── croskblight.sln ├── croskblight Package └── croskblight Package.vcxproj └── .gitignore /croskblightclient/croskblightclient/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chrultrabook/croskblight/main/croskblightclient/croskblightclient/icon.ico -------------------------------------------------------------------------------- /croskblight/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by croskblight.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /croskblightclient/croskblightclient/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Resource.rc 4 | // 5 | #define IDI_ICON1 103 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 104 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /croskblightclient/croskblightclient/croskblightclient.h: -------------------------------------------------------------------------------- 1 | #if !defined(_CROSTP_CLIENT_H_) 2 | #define _CROSTP_CLIENT_H_ 3 | 4 | #include 5 | #include "croskblightcommon.h" 6 | 7 | typedef struct _croskblight_client_t* pcroskblight_client; 8 | 9 | USHORT getVendorID(); 10 | 11 | pcroskblight_client croskblight_alloc(void); 12 | 13 | void croskblight_free(pcroskblight_client vmulti); 14 | 15 | BOOL croskblight_connect(pcroskblight_client vmulti); 16 | 17 | void croskblight_disconnect(pcroskblight_client vmulti); 18 | 19 | BOOL croskblight_read_message(pcroskblight_client vmulti, CrosKBLightGetLightReport* pReport); 20 | 21 | BOOL croskblight_write_message(pcroskblight_client vmulti, CrosKBLightSettingsReport* pReport); 22 | 23 | #endif -------------------------------------------------------------------------------- /croskblightclient/croskblightclient/croskblightcommon.h: -------------------------------------------------------------------------------- 1 | #if !defined(_CROSKBLIGHT_COMMON_H_) 2 | #define _CROSKBLIGHT_COMMON_H_ 3 | 4 | // 5 | //These are the device attributes returned by vmulti in response 6 | // to IOCTL_HID_GET_DEVICE_ATTRIBUTES. 7 | // 8 | 9 | #define CROSKBLIGHT_PID 0x0002 10 | #define CROSKBLIGHT_VID 0x18D1 11 | #define CROSKBLIGHT_VERSION 0x0001 12 | 13 | // 14 | // These are the report ids 15 | // 16 | 17 | #define REPORTID_KBLIGHT 0x01 18 | 19 | // 20 | // Feature report infomation 21 | // 22 | 23 | #define DEVICE_MODE_MOUSE 0x00 24 | #define DEVICE_MODE_SINGLE_INPUT 0x01 25 | #define DEVICE_MODE_MULTI_INPUT 0x02 26 | 27 | #pragma pack(1) 28 | typedef struct _CROSKBLIGHT_GETLIGHT_REPORT 29 | { 30 | 31 | BYTE ReportID; 32 | 33 | BYTE Brightness; 34 | 35 | } CrosKBLightGetLightReport; 36 | #pragma pack() 37 | 38 | #pragma pack(1) 39 | typedef struct _CROSKBLIGHT_SETTINGS_REPORT 40 | { 41 | 42 | BYTE ReportID; 43 | 44 | BYTE SetBrightness; 45 | 46 | BYTE Brightness; 47 | 48 | } CrosKBLightSettingsReport; 49 | #pragma pack() 50 | 51 | #endif 52 | #pragma once 53 | -------------------------------------------------------------------------------- /croskblight/croskblight.rc: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation All Rights Reserved 4 | 5 | Module Name: 6 | 7 | croskblight.rc 8 | 9 | Abstract: 10 | 11 | --*/ 12 | 13 | #include 14 | 15 | #define VER_FILETYPE VFT_DRV 16 | #define VER_FILESUBTYPE VFT2_DRV_KEYBOARD 17 | #define VER_FILEDESCRIPTION_STR "Chromebook Keyboard Backlight" 18 | #define VER_INTERNALNAME_STR "croskblight.sys" 19 | #define VER_ORIGINALFILENAME_STR "croskblight.sys" 20 | 21 | #define VER_LEGALCOPYRIGHT_YEARS "2023" 22 | #define VER_LEGALCOPYRIGHT_STR "Copyright (C) " VER_LEGALCOPYRIGHT_YEARS " CoolStar." 23 | 24 | #define VER_FILEVERSION 2,0,1,0 25 | #define VER_PRODUCTVERSION_STR "2.0.1.0" 26 | #define VER_PRODUCTVERSION 2,0,1,0 27 | #define LVER_PRODUCTVERSION_STR L"2.0.1.0" 28 | 29 | #define VER_FILEFLAGSMASK (VS_FF_DEBUG | VS_FF_PRERELEASE) 30 | #ifdef DEBUG 31 | #define VER_FILEFLAGS (VS_FF_DEBUG) 32 | #else 33 | #define VER_FILEFLAGS (0) 34 | #endif 35 | 36 | #define VER_FILEOS VOS_NT_WINDOWS32 37 | 38 | #define VER_COMPANYNAME_STR "CoolStar" 39 | #define VER_PRODUCTNAME_STR "Chromebook Keyboard Backlight" 40 | 41 | #include "common.ver" -------------------------------------------------------------------------------- /croskblight/hidcommon.h: -------------------------------------------------------------------------------- 1 | #if !defined(_CROSKBLIGHT_COMMON_H_) 2 | #define _CROSKBLIGHT_COMMON_H_ 3 | 4 | // 5 | //These are the device attributes returned by vmulti in response 6 | // to IOCTL_HID_GET_DEVICE_ATTRIBUTES. 7 | // 8 | 9 | #define CROSKBLIGHT_PID 0x0002 10 | #define CROSKBLIGHT_VID 0x18D1 11 | #define CROSKBLIGHT_VERSION 0x0001 12 | 13 | // 14 | // These are the report ids 15 | // 16 | 17 | #define REPORTID_KBLIGHT 0x01 18 | 19 | // 20 | // Feature report infomation 21 | // 22 | 23 | #define DEVICE_MODE_MOUSE 0x00 24 | #define DEVICE_MODE_SINGLE_INPUT 0x01 25 | #define DEVICE_MODE_MULTI_INPUT 0x02 26 | 27 | #pragma pack(1) 28 | typedef struct _CROSKBLIGHT_FEATURE_REPORT 29 | { 30 | 31 | BYTE ReportID; 32 | 33 | BYTE DeviceMode; 34 | 35 | BYTE DeviceIdentifier; 36 | 37 | } CrosKBLightFeatureReport; 38 | 39 | typedef struct _CROSKBLIGHT_MAXCOUNT_REPORT 40 | { 41 | 42 | BYTE ReportID; 43 | 44 | BYTE MaximumCount; 45 | 46 | } CrosKBLightMaxCountReport; 47 | #pragma pack() 48 | 49 | #pragma pack(1) 50 | typedef struct _CROSKBLIGHT_GETLIGHT_REPORT 51 | { 52 | 53 | BYTE ReportID; 54 | 55 | BYTE Brightness; 56 | 57 | } CrosKBLightGetLightReport; 58 | #pragma pack() 59 | 60 | #pragma pack(1) 61 | typedef struct _CROSKBLIGHT_SETTINGS_REPORT 62 | { 63 | 64 | BYTE ReportID; 65 | 66 | BYTE SetBrightness; 67 | 68 | BYTE Brightness; 69 | 70 | } CrosKBLightSettingsReport; 71 | #pragma pack() 72 | 73 | #endif 74 | #pragma once 75 | -------------------------------------------------------------------------------- /croskblightclient/croskblightclient.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31829.152 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "croskblightclient", "croskblightclient\croskblightclient.vcxproj", "{D359354A-6448-463A-9F18-9516D89400F0}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {D359354A-6448-463A-9F18-9516D89400F0}.Debug|x64.ActiveCfg = Debug|x64 17 | {D359354A-6448-463A-9F18-9516D89400F0}.Debug|x64.Build.0 = Debug|x64 18 | {D359354A-6448-463A-9F18-9516D89400F0}.Debug|x86.ActiveCfg = Debug|Win32 19 | {D359354A-6448-463A-9F18-9516D89400F0}.Debug|x86.Build.0 = Debug|Win32 20 | {D359354A-6448-463A-9F18-9516D89400F0}.Release|x64.ActiveCfg = Release|x64 21 | {D359354A-6448-463A-9F18-9516D89400F0}.Release|x64.Build.0 = Release|x64 22 | {D359354A-6448-463A-9F18-9516D89400F0}.Release|x86.ActiveCfg = Release|Win32 23 | {D359354A-6448-463A-9F18-9516D89400F0}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {B0F98ABB-8AF0-4F81-99C4-168A9CB49B01} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /croskblightclient/croskblightclient/croskblightclient.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | Source Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | 37 | 38 | Resource Files 39 | 40 | 41 | 42 | 43 | Resource Files 44 | 45 | 46 | -------------------------------------------------------------------------------- /croskblight/Trace.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Module Name: 4 | 5 | Trace.h 6 | 7 | Abstract: 8 | 9 | Header file for the debug tracing related function defintions and macros. 10 | 11 | Environment: 12 | 13 | Kernel mode 14 | 15 | --*/ 16 | 17 | // 18 | // Define the tracing flags. 19 | // 20 | // Tracing GUID - 79182672-fe97-45b4-bd65-fe00a2fb2477 21 | // 22 | 23 | #define WPP_CONTROL_GUIDS \ 24 | WPP_DEFINE_CONTROL_GUID( \ 25 | croskeyboard3TraceGuid, (79182672,fe97,45b4,bd65,fe00a2fb2477), \ 26 | \ 27 | WPP_DEFINE_BIT(MYDRIVER_ALL_INFO) \ 28 | WPP_DEFINE_BIT(TRACE_DRIVER) \ 29 | WPP_DEFINE_BIT(TRACE_DEVICE) \ 30 | WPP_DEFINE_BIT(TRACE_QUEUE) \ 31 | ) 32 | 33 | #define WPP_FLAG_LEVEL_LOGGER(flag, level) \ 34 | WPP_LEVEL_LOGGER(flag) 35 | 36 | #define WPP_FLAG_LEVEL_ENABLED(flag, level) \ 37 | (WPP_LEVEL_ENABLED(flag) && \ 38 | WPP_CONTROL(WPP_BIT_ ## flag).Level >= level) 39 | 40 | #define WPP_LEVEL_FLAGS_LOGGER(lvl,flags) \ 41 | WPP_LEVEL_LOGGER(flags) 42 | 43 | #define WPP_LEVEL_FLAGS_ENABLED(lvl, flags) \ 44 | (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_ ## flags).Level >= lvl) 45 | 46 | // 47 | // This comment block is scanned by the trace preprocessor to define our 48 | // Trace function. 49 | // 50 | // begin_wpp config 51 | // FUNC Trace{FLAG=MYDRIVER_ALL_INFO}(LEVEL, MSG, ...); 52 | // FUNC TraceEvents(LEVEL, FLAGS, MSG, ...); 53 | // end_wpp 54 | // 55 | -------------------------------------------------------------------------------- /croskblightclient/croskblightclient/Resource.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "winres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United States) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 20 | #pragma code_page(1252) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_ICON1 ICON "icon.ico" 56 | 57 | #endif // English (United States) resources 58 | ///////////////////////////////////////////////////////////////////////////// 59 | 60 | 61 | 62 | #ifndef APSTUDIO_INVOKED 63 | ///////////////////////////////////////////////////////////////////////////// 64 | // 65 | // Generated from the TEXTINCLUDE 3 resource. 66 | // 67 | 68 | 69 | ///////////////////////////////////////////////////////////////////////////// 70 | #endif // not APSTUDIO_INVOKED 71 | 72 | -------------------------------------------------------------------------------- /croskblightclient/croskblightclient/croskblightclient.c: -------------------------------------------------------------------------------- 1 | // croskblightclient.cpp : This file contains the 'main' function. Program execution begins and ends there. 2 | // 3 | 4 | #include "croskblightclient.h" 5 | #include 6 | 7 | int main(int argc, char** argv) 8 | { 9 | if (argc < 2) { 10 | return -1; 11 | } 12 | 13 | pcroskblight_client client = croskblight_alloc(); 14 | if (!croskblight_connect(client)) { 15 | printf("Failed to connect to croskbclient\n"); 16 | return -1; 17 | } 18 | 19 | CrosKBLightSettingsReport writeReport; 20 | writeReport.ReportID = REPORTID_KBLIGHT; 21 | writeReport.SetBrightness = 0; 22 | writeReport.Brightness = 0; 23 | 24 | if (!croskblight_write_message(client, &writeReport)) { 25 | printf("Failed to send query msg to croskblight\n"); 26 | return -1; 27 | } 28 | CrosKBLightGetLightReport readReport; 29 | if (!croskblight_read_message(client, &readReport)) { 30 | printf("Failed to read msg from croskblight\n"); 31 | return -1; 32 | } 33 | 34 | int brightness = readReport.Brightness; 35 | if (strcmp(argv[1], "r") == 0) { 36 | return brightness; 37 | } 38 | 39 | long argInt = strtol(argv[2], NULL, 10); 40 | 41 | if (strcmp(argv[1], "=") == 0) { 42 | brightness = argInt; 43 | } else if (strcmp(argv[1], "+") == 0) { 44 | brightness += argInt; 45 | } else if (strcmp(argv[1], "-") == 0) { 46 | brightness -= argInt; 47 | } else { 48 | printf("Arg2 must be =, +, -, or r\n"); 49 | return -1; 50 | } 51 | 52 | if (argc < 3) { 53 | return -1; 54 | } 55 | 56 | if (brightness < 0) { 57 | brightness = 0; 58 | } 59 | else if (brightness > 100) { 60 | brightness = 100; 61 | } 62 | 63 | writeReport.SetBrightness = 1; 64 | writeReport.Brightness = brightness; 65 | 66 | if (!croskblight_write_message(client, &writeReport)) { 67 | printf("Failed to send set msg to croskblight\n"); 68 | return -1; 69 | } 70 | return 0; 71 | } 72 | 73 | int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char* lpCmdLine, int nShowCmd) 74 | { 75 | return main(__argc, __argv); 76 | } -------------------------------------------------------------------------------- /croskblight/croskblight.inf: -------------------------------------------------------------------------------- 1 | ;/*++ 2 | ; 3 | ;Copyright (c) CoolStar. All rights reserved. 4 | ; 5 | ;Module Name: 6 | ; coolstar.inf 7 | ; 8 | ;Abstract: 9 | ; INF file for installing the CrosKeyboard Backlight Driver 10 | ; 11 | ; 12 | ;--*/ 13 | 14 | [Version] 15 | Signature = "$WINDOWS NT$" 16 | Class = HIDClass 17 | ClassGuid = {745a17a0-74d3-11d0-b6fe-00a0c90f57da} 18 | Provider = CoolStar 19 | DriverVer = 06/21/2006,6.1.7779.2 20 | CatalogFile = croskblight.cat 21 | PnpLockdown=1 22 | 23 | [DestinationDirs] 24 | DefaultDestDir = 12 25 | 26 | ; ================= Class section ===================== 27 | 28 | [SourceDisksNames] 29 | 1 = %DiskId1%,,,"" 30 | 31 | [SourceDisksFiles] 32 | croskblight.sys = 1,, 33 | 34 | ;***************************************** 35 | ; CrosKbLight Install Section 36 | ;***************************************** 37 | 38 | [Manufacturer] 39 | %StdMfg%=Standard,NT$ARCH$ 40 | 41 | ; Decorated model section take precedence over undecorated 42 | ; ones on XP and later. 43 | [Standard.NT$ARCH$] 44 | %CrosKBLight.DeviceDesc%=CrosKBLight_Device, ACPI\GOOG0002 45 | 46 | [CrosKBLight_Device.NT] 47 | CopyFiles=Drivers_Dir 48 | 49 | [CrosKBLight_Device.NT.HW] 50 | AddReg=CrosKBLight_AddReg 51 | 52 | [Drivers_Dir] 53 | croskblight.sys 54 | 55 | [CrosKBLight_AddReg] 56 | ; Set to 1 to connect the first interrupt resource found, 0 to leave disconnected 57 | HKR,Settings,"ConnectInterrupt",0x00010001,0 58 | HKR,,"UpperFilters",0x00010000,"mshidkmdf" 59 | 60 | ;-------------- Service installation 61 | [CrosKBLight_Device.NT.Services] 62 | AddService = CrosKBLight,%SPSVCINST_ASSOCSERVICE%, CrosKBLight_Service_Inst 63 | 64 | ; -------------- CrosKBLight driver install sections 65 | [CrosKBLight_Service_Inst] 66 | DisplayName = %CrosKBLight.SVCDESC% 67 | ServiceType = 1 ; SERVICE_KERNEL_DRIVER 68 | StartType = 3 ; SERVICE_DEMAND_START 69 | ErrorControl = 1 ; SERVICE_ERROR_NORMAL 70 | ServiceBinary = %12%\croskblight.sys 71 | LoadOrderGroup = Base 72 | 73 | [Strings] 74 | SPSVCINST_ASSOCSERVICE= 0x00000002 75 | StdMfg = "CoolStar" 76 | DiskId1 = "CrosKBLight Installation Disk #1" 77 | CrosKBLight.DeviceDesc = "Chromebook Keyboard Backlight" 78 | CrosKBLight.SVCDESC = "CrosKBLight Service" 79 | -------------------------------------------------------------------------------- /croskblight.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "croskblight", "croskblight\croskblight.vcxproj", "{E0C3F023-6A54-419C-9C6E-E0638B55D99F}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "croskblight Package", "croskblight Package\croskblight Package.vcxproj", "{D47D5E26-2CB1-4445-8B46-6D1AC3E0694F}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|x64 = Debug|x64 13 | Debug|x86 = Debug|x86 14 | Release|x64 = Release|x64 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {E0C3F023-6A54-419C-9C6E-E0638B55D99F}.Debug|x64.ActiveCfg = Debug|x64 19 | {E0C3F023-6A54-419C-9C6E-E0638B55D99F}.Debug|x64.Build.0 = Debug|x64 20 | {E0C3F023-6A54-419C-9C6E-E0638B55D99F}.Debug|x86.ActiveCfg = Debug|Win32 21 | {E0C3F023-6A54-419C-9C6E-E0638B55D99F}.Debug|x86.Build.0 = Debug|Win32 22 | {E0C3F023-6A54-419C-9C6E-E0638B55D99F}.Release|x64.ActiveCfg = Release|x64 23 | {E0C3F023-6A54-419C-9C6E-E0638B55D99F}.Release|x64.Build.0 = Release|x64 24 | {E0C3F023-6A54-419C-9C6E-E0638B55D99F}.Release|x86.ActiveCfg = Release|Win32 25 | {E0C3F023-6A54-419C-9C6E-E0638B55D99F}.Release|x86.Build.0 = Release|Win32 26 | {D47D5E26-2CB1-4445-8B46-6D1AC3E0694F}.Debug|x64.ActiveCfg = Debug|x64 27 | {D47D5E26-2CB1-4445-8B46-6D1AC3E0694F}.Debug|x64.Build.0 = Debug|x64 28 | {D47D5E26-2CB1-4445-8B46-6D1AC3E0694F}.Debug|x64.Deploy.0 = Debug|x64 29 | {D47D5E26-2CB1-4445-8B46-6D1AC3E0694F}.Debug|x86.ActiveCfg = Debug|Win32 30 | {D47D5E26-2CB1-4445-8B46-6D1AC3E0694F}.Debug|x86.Build.0 = Debug|Win32 31 | {D47D5E26-2CB1-4445-8B46-6D1AC3E0694F}.Debug|x86.Deploy.0 = Debug|Win32 32 | {D47D5E26-2CB1-4445-8B46-6D1AC3E0694F}.Release|x64.ActiveCfg = Release|x64 33 | {D47D5E26-2CB1-4445-8B46-6D1AC3E0694F}.Release|x64.Build.0 = Release|x64 34 | {D47D5E26-2CB1-4445-8B46-6D1AC3E0694F}.Release|x64.Deploy.0 = Release|x64 35 | {D47D5E26-2CB1-4445-8B46-6D1AC3E0694F}.Release|x86.ActiveCfg = Release|Win32 36 | {D47D5E26-2CB1-4445-8B46-6D1AC3E0694F}.Release|x86.Build.0 = Release|Win32 37 | {D47D5E26-2CB1-4445-8B46-6D1AC3E0694F}.Release|x86.Deploy.0 = Release|Win32 38 | EndGlobalSection 39 | GlobalSection(SolutionProperties) = preSolution 40 | HideSolutionNode = FALSE 41 | EndGlobalSection 42 | EndGlobal 43 | -------------------------------------------------------------------------------- /croskblight/eccmds.h: -------------------------------------------------------------------------------- 1 | #ifndef __CROS_EC_REGS_H__ 2 | #define __CROS_EC_REGS_H__ 3 | 4 | #define BIT(nr) (1UL << (nr)) 5 | 6 | /* Command version mask */ 7 | #define EC_VER_MASK(version) (1UL << (version)) 8 | 9 | /* Get keyboard backlight */ 10 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ 11 | #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022 12 | 13 | #include 14 | 15 | struct ec_response_pwm_get_keyboard_backlight { 16 | UINT8 percent; 17 | UINT8 enabled; 18 | }; 19 | 20 | #include 21 | 22 | /* Set keyboard backlight */ 23 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ 24 | #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023 25 | 26 | #include 27 | 28 | struct ec_params_pwm_set_keyboard_backlight { 29 | UINT8 percent; 30 | }; 31 | 32 | #include 33 | 34 | /* Set target fan PWM duty cycle */ 35 | #define EC_CMD_PWM_SET_FAN_DUTY 0x0024 36 | 37 | /* Version 0 of input params */ 38 | #include 39 | 40 | struct ec_params_pwm_set_fan_duty_v0 { 41 | UINT32 percent; 42 | }; 43 | 44 | #include 45 | 46 | /* Version 1 of input params */ 47 | #include 48 | 49 | struct ec_params_pwm_set_fan_duty_v1 { 50 | UINT32 percent; 51 | UINT8 fan_idx; 52 | }; 53 | 54 | #include 55 | 56 | #define EC_CMD_PWM_SET_DUTY 0x0025 57 | /* 16 bit duty cycle, 0xffff = 100% */ 58 | #define EC_PWM_MAX_DUTY 0xffff 59 | 60 | enum ec_pwm_type { 61 | /* All types, indexed by board-specific enum pwm_channel */ 62 | EC_PWM_TYPE_GENERIC = 0, 63 | /* Keyboard backlight */ 64 | EC_PWM_TYPE_KB_LIGHT, 65 | /* Display backlight */ 66 | EC_PWM_TYPE_DISPLAY_LIGHT, 67 | EC_PWM_TYPE_COUNT, 68 | }; 69 | 70 | #include 71 | 72 | struct ec_params_pwm_set_duty { 73 | UINT16 duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ 74 | UINT8 pwm_type; /* ec_pwm_type */ 75 | UINT8 index; /* Type-specific index, or 0 if unique */ 76 | }; 77 | 78 | #include 79 | 80 | #define EC_CMD_PWM_GET_DUTY 0x0026 81 | 82 | #include 83 | 84 | struct ec_params_pwm_get_duty { 85 | UINT8 pwm_type; /* ec_pwm_type */ 86 | UINT8 index; /* Type-specific index, or 0 if unique */ 87 | }; 88 | 89 | #include 90 | 91 | #include 92 | 93 | struct ec_response_pwm_get_duty { 94 | UINT16 duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ 95 | }; 96 | 97 | #include 98 | 99 | /* Read versions supported for a command */ 100 | #define EC_CMD_GET_CMD_VERSIONS 0x0008 101 | 102 | /** 103 | * struct ec_params_get_cmd_versions - Parameters for the get command versions. 104 | * @cmd: Command to check. 105 | */ 106 | #include 107 | struct ec_params_get_cmd_versions { 108 | UINT8 cmd; 109 | }; 110 | #include 111 | 112 | /** 113 | * struct ec_params_get_cmd_versions_v1 - Parameters for the get command 114 | * versions (v1) 115 | * @cmd: Command to check. 116 | */ 117 | #include 118 | struct ec_params_get_cmd_versions_v1 { 119 | UINT16 cmd; 120 | }; 121 | #include 122 | 123 | /** 124 | * struct ec_response_get_cmd_version - Response to the get command versions. 125 | * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with 126 | * a desired version. 127 | */ 128 | #include 129 | struct ec_response_get_cmd_versions { 130 | UINT32 version_mask; 131 | }; 132 | #include 133 | 134 | 135 | /* Get protocol information */ 136 | #define EC_CMD_GET_PROTOCOL_INFO 0x0b 137 | 138 | /* Flags for ec_response_get_protocol_info.flags */ 139 | /* EC_RES_IN_PROGRESS may be returned if a command is slow */ 140 | #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0) 141 | 142 | #include 143 | 144 | struct ec_response_get_protocol_info { 145 | /* Fields which exist if at least protocol version 3 supported */ 146 | 147 | /* Bitmask of protocol versions supported (1 << n means version n)*/ 148 | UINT32 protocol_versions; 149 | 150 | /* Maximum request packet size, in bytes */ 151 | UINT16 max_request_packet_size; 152 | 153 | /* Maximum response packet size, in bytes */ 154 | UINT16 max_response_packet_size; 155 | 156 | /* Flags; see EC_PROTOCOL_INFO_* */ 157 | UINT32 flags; 158 | }; 159 | 160 | #include 161 | 162 | #endif /* __CROS_EC_REGS_H__ */ -------------------------------------------------------------------------------- /croskblight Package/croskblight Package.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | {e0c3f023-6a54-419c-9c6e-e0638b55d99f} 24 | 25 | 26 | 27 | {D47D5E26-2CB1-4445-8B46-6D1AC3E0694F} 28 | {4605da2c-74a5-4865-98e1-152ef136825f} 29 | v4.5 30 | 12.0 31 | Debug 32 | Win32 33 | croskblight_Package 34 | 10.0.22000.0 35 | croskblight Package 36 | 37 | 38 | 39 | Windows8 40 | true 41 | WindowsKernelModeDriver10.0 42 | Utility 43 | Package 44 | true 45 | 46 | 47 | Windows8 48 | false 49 | WindowsKernelModeDriver10.0 50 | Utility 51 | Package 52 | true 53 | 54 | 55 | Windows8 56 | true 57 | WindowsKernelModeDriver10.0 58 | Utility 59 | Package 60 | true 61 | 62 | 63 | WindowsV6.3 64 | false 65 | WindowsKernelModeDriver10.0 66 | Utility 67 | Package 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | DbgengKernelDebugger 80 | 81 | 82 | 83 | False 84 | False 85 | True 86 | 87 | 133563 88 | 89 | 90 | DbgengKernelDebugger 91 | 92 | 93 | 94 | False 95 | False 96 | True 97 | 98 | 133563 99 | 100 | 101 | DbgengKernelDebugger 102 | 103 | 104 | 105 | False 106 | False 107 | True 108 | 109 | 133563 110 | 111 | 112 | DbgengKernelDebugger 113 | 114 | 115 | 116 | False 117 | False 118 | True 119 | 120 | 133563 121 | 122 | 123 | 124 | SHA256 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | bld/ 24 | [Bb]in/ 25 | [Oo]bj/ 26 | [Ll]og/ 27 | 28 | # Visual Studio 2015/2017 cache/options directory 29 | .vs/ 30 | # Uncomment if you have tasks that create the project's static files in wwwroot 31 | #wwwroot/ 32 | 33 | # Visual Studio 2017 auto generated files 34 | Generated\ Files/ 35 | 36 | # MSTest test Results 37 | [Tt]est[Rr]esult*/ 38 | [Bb]uild[Ll]og.* 39 | 40 | # NUNIT 41 | *.VisualState.xml 42 | TestResult.xml 43 | 44 | # Build Results of an ATL Project 45 | [Dd]ebugPS/ 46 | [Rr]eleasePS/ 47 | dlldata.c 48 | 49 | # Benchmark Results 50 | BenchmarkDotNet.Artifacts/ 51 | 52 | # .NET Core 53 | project.lock.json 54 | project.fragment.lock.json 55 | artifacts/ 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_h.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *_wpftmp.csproj 81 | *.log 82 | *.vspscc 83 | *.vssscc 84 | .builds 85 | *.pidb 86 | *.svclog 87 | *.scc 88 | 89 | # Chutzpah Test files 90 | _Chutzpah* 91 | 92 | # Visual C++ cache files 93 | ipch/ 94 | *.aps 95 | *.ncb 96 | *.opendb 97 | *.opensdf 98 | *.sdf 99 | *.cachefile 100 | *.VC.db 101 | *.VC.VC.opendb 102 | 103 | # Visual Studio profiler 104 | *.psess 105 | *.vsp 106 | *.vspx 107 | *.sap 108 | 109 | # Visual Studio Trace Files 110 | *.e2e 111 | 112 | # TFS 2012 Local Workspace 113 | $tf/ 114 | 115 | # Guidance Automation Toolkit 116 | *.gpState 117 | 118 | # ReSharper is a .NET coding add-in 119 | _ReSharper*/ 120 | *.[Rr]e[Ss]harper 121 | *.DotSettings.user 122 | 123 | # JustCode is a .NET coding add-in 124 | .JustCode 125 | 126 | # TeamCity is a build add-in 127 | _TeamCity* 128 | 129 | # DotCover is a Code Coverage Tool 130 | *.dotCover 131 | 132 | # AxoCover is a Code Coverage Tool 133 | .axoCover/* 134 | !.axoCover/settings.json 135 | 136 | # Visual Studio code coverage results 137 | *.coverage 138 | *.coveragexml 139 | 140 | # NCrunch 141 | _NCrunch_* 142 | .*crunch*.local.xml 143 | nCrunchTemp_* 144 | 145 | # MightyMoose 146 | *.mm.* 147 | AutoTest.Net/ 148 | 149 | # Web workbench (sass) 150 | .sass-cache/ 151 | 152 | # Installshield output folder 153 | [Ee]xpress/ 154 | 155 | # DocProject is a documentation generator add-in 156 | DocProject/buildhelp/ 157 | DocProject/Help/*.HxT 158 | DocProject/Help/*.HxC 159 | DocProject/Help/*.hhc 160 | DocProject/Help/*.hhk 161 | DocProject/Help/*.hhp 162 | DocProject/Help/Html2 163 | DocProject/Help/html 164 | 165 | # Click-Once directory 166 | publish/ 167 | 168 | # Publish Web Output 169 | *.[Pp]ublish.xml 170 | *.azurePubxml 171 | # Note: Comment the next line if you want to checkin your web deploy settings, 172 | # but database connection strings (with potential passwords) will be unencrypted 173 | *.pubxml 174 | *.publishproj 175 | 176 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 177 | # checkin your Azure Web App publish settings, but sensitive information contained 178 | # in these scripts will be unencrypted 179 | PublishScripts/ 180 | 181 | # NuGet Packages 182 | *.nupkg 183 | # The packages folder can be ignored because of Package Restore 184 | **/[Pp]ackages/* 185 | # except build/, which is used as an MSBuild target. 186 | !**/[Pp]ackages/build/ 187 | # Uncomment if necessary however generally it will be regenerated when needed 188 | #!**/[Pp]ackages/repositories.config 189 | # NuGet v3's project.json files produces more ignorable files 190 | *.nuget.props 191 | *.nuget.targets 192 | 193 | # Microsoft Azure Build Output 194 | csx/ 195 | *.build.csdef 196 | 197 | # Microsoft Azure Emulator 198 | ecf/ 199 | rcf/ 200 | 201 | # Windows Store app package directories and files 202 | AppPackages/ 203 | BundleArtifacts/ 204 | Package.StoreAssociation.xml 205 | _pkginfo.txt 206 | *.appx 207 | 208 | # Visual Studio cache files 209 | # files ending in .cache can be ignored 210 | *.[Cc]ache 211 | # but keep track of directories ending in .cache 212 | !*.[Cc]ache/ 213 | 214 | # Others 215 | ClientBin/ 216 | ~$* 217 | *~ 218 | *.dbmdl 219 | *.dbproj.schemaview 220 | *.jfm 221 | *.pfx 222 | *.publishsettings 223 | orleans.codegen.cs 224 | 225 | # Including strong name files can present a security risk 226 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 227 | #*.snk 228 | 229 | # Since there are multiple workflows, uncomment next line to ignore bower_components 230 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 231 | #bower_components/ 232 | 233 | # RIA/Silverlight projects 234 | Generated_Code/ 235 | 236 | # Backup & report files from converting an old project file 237 | # to a newer Visual Studio version. Backup files are not needed, 238 | # because we have git ;-) 239 | _UpgradeReport_Files/ 240 | Backup*/ 241 | UpgradeLog*.XML 242 | UpgradeLog*.htm 243 | ServiceFabricBackup/ 244 | *.rptproj.bak 245 | 246 | # SQL Server files 247 | *.mdf 248 | *.ldf 249 | *.ndf 250 | 251 | # Business Intelligence projects 252 | *.rdl.data 253 | *.bim.layout 254 | *.bim_*.settings 255 | *.rptproj.rsuser 256 | 257 | # Microsoft Fakes 258 | FakesAssemblies/ 259 | 260 | # GhostDoc plugin setting file 261 | *.GhostDoc.xml 262 | 263 | # Node.js Tools for Visual Studio 264 | .ntvs_analysis.dat 265 | node_modules/ 266 | 267 | # Visual Studio 6 build log 268 | *.plg 269 | 270 | # Visual Studio 6 workspace options file 271 | *.opt 272 | 273 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 274 | *.vbw 275 | 276 | # Visual Studio LightSwitch build output 277 | **/*.HTMLClient/GeneratedArtifacts 278 | **/*.DesktopClient/GeneratedArtifacts 279 | **/*.DesktopClient/ModelManifest.xml 280 | **/*.Server/GeneratedArtifacts 281 | **/*.Server/ModelManifest.xml 282 | _Pvt_Extensions 283 | 284 | # Paket dependency manager 285 | .paket/paket.exe 286 | paket-files/ 287 | 288 | # FAKE - F# Make 289 | .fake/ 290 | 291 | # JetBrains Rider 292 | .idea/ 293 | *.sln.iml 294 | 295 | # CodeRush personal settings 296 | .cr/personal 297 | 298 | # Python Tools for Visual Studio (PTVS) 299 | __pycache__/ 300 | *.pyc 301 | 302 | # Cake - Uncomment if you are using it 303 | # tools/** 304 | # !tools/packages.config 305 | 306 | # Tabs Studio 307 | *.tss 308 | 309 | # Telerik's JustMock configuration file 310 | *.jmconfig 311 | 312 | # BizTalk build output 313 | *.btp.cs 314 | *.btm.cs 315 | *.odx.cs 316 | *.xsd.cs 317 | 318 | # OpenCover UI analysis results 319 | OpenCover/ 320 | 321 | # Azure Stream Analytics local run output 322 | ASALocalRun/ 323 | 324 | # MSBuild Binary and Structured Log 325 | *.binlog 326 | 327 | # NVidia Nsight GPU debugger configuration file 328 | *.nvuser 329 | 330 | # MFractors (Xamarin productivity tool) working folder 331 | .mfractor/ 332 | 333 | # Local History for Visual Studio 334 | .localhistory/ 335 | -------------------------------------------------------------------------------- /croskblight/croskblight.h: -------------------------------------------------------------------------------- 1 | #if !defined(_CROSKEYBOARD_H_) 2 | #define _CROSKEYBOARD_H_ 3 | 4 | #pragma warning(disable:4200) // suppress nameless struct/union warning 5 | #pragma warning(disable:4201) // suppress nameless struct/union warning 6 | #pragma warning(disable:4214) // suppress bit field types other than int warning 7 | #include 8 | #include 9 | 10 | #pragma warning(default:4200) 11 | #pragma warning(default:4201) 12 | #pragma warning(default:4214) 13 | #include 14 | 15 | #include 16 | 17 | #pragma warning(disable:4201) // suppress nameless struct/union warning 18 | #pragma warning(disable:4214) // suppress bit field types other than int warning 19 | #include 20 | 21 | #include "hidcommon.h" 22 | #include "eccmds.h" 23 | 24 | extern "C" 25 | 26 | NTSTATUS 27 | DriverEntry( 28 | _In_ PDRIVER_OBJECT pDriverObject, 29 | _In_ PUNICODE_STRING pRegistryPath 30 | ); 31 | 32 | EVT_WDF_DRIVER_DEVICE_ADD OnDeviceAdd; 33 | EVT_WDF_OBJECT_CONTEXT_CLEANUP OnDriverCleanup; 34 | 35 | // 36 | // String definitions 37 | // 38 | 39 | #define DRIVERNAME "croskblight.sys: " 40 | 41 | #define CROSKBLIGHT_POOL_TAG (ULONG) 'lbkC' 42 | #define CROSKBLIGHT_HARDWARE_IDS L"CoolStar\\CrosKBLight\0\0" 43 | #define CROSKBLIGHT_HARDWARE_IDS_LENGTH sizeof(CROSKBLIGHT_HARDWARE_IDS) 44 | 45 | #define NTDEVICE_NAME_STRING L"\\Device\\CrosKBLight" 46 | #define SYMBOLIC_NAME_STRING L"\\DosDevices\\CrosKBLight" 47 | // 48 | // This is the default report descriptor for the Hid device provided 49 | // by the mini driver in response to IOCTL_HID_GET_REPORT_DESCRIPTOR. 50 | // 51 | 52 | typedef UCHAR HID_REPORT_DESCRIPTOR, *PHID_REPORT_DESCRIPTOR; 53 | 54 | #ifdef DESCRIPTOR_DEF 55 | HID_REPORT_DESCRIPTOR DefaultReportDescriptor[] = { 56 | 0x06, 0x00, 0xff, // USAGE_PAGE (Vendor Defined Page 1) 57 | 0x09, 0x01, // USAGE (Vendor Usage 1) 58 | 0xa1, 0x01, // COLLECTION (Application) 59 | 0x85, REPORTID_KBLIGHT, // REPORT_ID (Keyboard Backlight) 60 | 0x15, 0x00, // LOGICAL_MINIMUM (0) 61 | 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (256) 62 | 0x75, 0x08, // REPORT_SIZE (8) - bits 63 | 0x95, 0x01, // REPORT_COUNT (1) - Bytes 64 | 0x09, 0x02, // USAGE (Vendor Usage 1) 65 | 0x91, 0x02, // OUTPUT (Data,Var,Abs) 66 | 0x09, 0x03, // USAGE (Vendor Usage 2) 67 | 0x91, 0x02, // OUTPUT (Data,Var,Abs) 68 | 0x09, 0x02, // USAGE (Vendor Usage 1) 69 | 0x81, 0x02, // INPUT (Data,Var,Abs) 70 | 0xc0, // END_COLLECTION 71 | }; 72 | 73 | 74 | // 75 | // This is the default HID descriptor returned by the mini driver 76 | // in response to IOCTL_HID_GET_DEVICE_DESCRIPTOR. The size 77 | // of report descriptor is currently the size of DefaultReportDescriptor. 78 | // 79 | 80 | CONST HID_DESCRIPTOR DefaultHidDescriptor = { 81 | 0x09, // length of HID descriptor 82 | 0x21, // descriptor type == HID 0x21 83 | 0x0100, // hid spec release 84 | 0x00, // country code == Not Specified 85 | 0x01, // number of HID class descriptors 86 | { 0x22, // descriptor type 87 | sizeof(DefaultReportDescriptor) } // total length of report descriptor 88 | }; 89 | #endif 90 | 91 | #define true 1 92 | #define false 0 93 | 94 | typedef struct _CROSEC_COMMAND { 95 | UINT32 Version; 96 | UINT32 Command; 97 | UINT32 OutSize; 98 | UINT32 InSize; 99 | UINT32 Result; 100 | UINT8 Data[]; 101 | } CROSEC_COMMAND, * PCROSEC_COMMAND; 102 | 103 | typedef 104 | NTSTATUS 105 | (*PCROSEC_CMD_XFER_STATUS)( 106 | IN PVOID Context, 107 | OUT PCROSEC_COMMAND Msg 108 | ); 109 | 110 | typedef 111 | BOOLEAN 112 | (*PCROSEC_CHECK_FEATURES)( 113 | IN PVOID Context, 114 | IN INT Feature 115 | ); 116 | 117 | DEFINE_GUID(GUID_CROSEC_INTERFACE_STANDARD, 118 | 0xd7062676, 0xe3a4, 0x11ec, 0xa6, 0xc4, 0x24, 0x4b, 0xfe, 0x99, 0x46, 0xd0); 119 | 120 | /*DEFINE_GUID(GUID_DEVICE_PROPERTIES, 121 | 0xdaffd814, 0x6eba, 0x4d8c, 0x8a, 0x91, 0xbc, 0x9b, 0xbf, 0x4a, 0xa3, 0x01);*/ //Windows defender false positive 122 | 123 | // 124 | // Interface for getting and setting power level etc., 125 | // 126 | typedef struct _CROSEC_INTERFACE_STANDARD { 127 | INTERFACE InterfaceHeader; 128 | PCROSEC_CMD_XFER_STATUS CmdXferStatus; 129 | PCROSEC_CHECK_FEATURES CheckFeatures; 130 | } CROSEC_INTERFACE_STANDARD, * PCROSEC_INTERFACE_STANDARD; 131 | 132 | typedef struct _CROSKBLIGHT_CONTEXT 133 | { 134 | WDFDEVICE FxDevice; 135 | 136 | WDFQUEUE ReportQueue; 137 | 138 | BYTE DeviceMode; 139 | 140 | UINT8 currentBrightness; 141 | 142 | PVOID CrosEcBusContext; 143 | 144 | //S0IX Notify 145 | ACPI_INTERFACE_STANDARD2 S0ixNotifyAcpiInterface; 146 | 147 | PCROSEC_CMD_XFER_STATUS CrosEcCmdXferStatus; 148 | 149 | WDFIOTARGET busIoTarget; 150 | 151 | } CROSKBLIGHT_CONTEXT, *PCROSKBLIGHT_CONTEXT; 152 | 153 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(CROSKBLIGHT_CONTEXT, GetDeviceContext) 154 | 155 | // 156 | // Function definitions 157 | // 158 | 159 | DRIVER_INITIALIZE DriverEntry; 160 | 161 | EVT_WDF_DRIVER_UNLOAD CrosKBLightDriverUnload; 162 | 163 | EVT_WDF_DRIVER_DEVICE_ADD CrosKBLightEvtDeviceAdd; 164 | 165 | EVT_WDFDEVICE_WDM_IRP_PREPROCESS CrosKBLightEvtWdmPreprocessMnQueryId; 166 | 167 | EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL CrosKBLightEvtInternalDeviceControl; 168 | 169 | NTSTATUS 170 | CrosKBLightGetHidDescriptor( 171 | IN WDFDEVICE Device, 172 | IN WDFREQUEST Request 173 | ); 174 | 175 | NTSTATUS 176 | CrosKBLightGetReportDescriptor( 177 | IN WDFDEVICE Device, 178 | IN WDFREQUEST Request 179 | ); 180 | 181 | NTSTATUS 182 | CrosKBLightGetDeviceAttributes( 183 | IN WDFREQUEST Request 184 | ); 185 | 186 | NTSTATUS 187 | CrosKBLightGetString( 188 | IN WDFREQUEST Request 189 | ); 190 | 191 | NTSTATUS 192 | CrosKBLightWriteReport( 193 | IN PCROSKBLIGHT_CONTEXT DevContext, 194 | IN WDFREQUEST Request 195 | ); 196 | 197 | NTSTATUS 198 | CrosKBLightProcessVendorReport( 199 | IN PCROSKBLIGHT_CONTEXT DevContext, 200 | IN PVOID ReportBuffer, 201 | IN ULONG ReportBufferLen, 202 | OUT size_t* BytesWritten 203 | ); 204 | 205 | NTSTATUS 206 | CrosKBLightReadReport( 207 | IN PCROSKBLIGHT_CONTEXT DevContext, 208 | IN WDFREQUEST Request, 209 | OUT BOOLEAN* CompleteRequest 210 | ); 211 | 212 | NTSTATUS 213 | CrosKBLightSetFeature( 214 | IN PCROSKBLIGHT_CONTEXT DevContext, 215 | IN WDFREQUEST Request, 216 | OUT BOOLEAN* CompleteRequest 217 | ); 218 | 219 | NTSTATUS 220 | CrosKBLightGetFeature( 221 | IN PCROSKBLIGHT_CONTEXT DevContext, 222 | IN WDFREQUEST Request, 223 | OUT BOOLEAN* CompleteRequest 224 | ); 225 | 226 | PCHAR 227 | DbgHidInternalIoctlString( 228 | IN ULONG IoControlCode 229 | ); 230 | 231 | // 232 | // Helper macros 233 | // 234 | 235 | #define DEBUG_LEVEL_ERROR 1 236 | #define DEBUG_LEVEL_INFO 2 237 | #define DEBUG_LEVEL_VERBOSE 3 238 | 239 | #define DBG_INIT 1 240 | #define DBG_PNP 2 241 | #define DBG_IOCTL 4 242 | 243 | #if DBG 244 | #define CrosKBLightPrint(dbglevel, dbgcatagory, fmt, ...) { \ 245 | if (CrosKBLightDebugLevel >= dbglevel && \ 246 | (CrosKBLightDebugCatagories && dbgcatagory)) \ 247 | { \ 248 | DbgPrint(DRIVERNAME); \ 249 | DbgPrint(fmt, __VA_ARGS__); \ 250 | } \ 251 | } 252 | #else 253 | #define CrosKBLightPrint(dbglevel, fmt, ...) { \ 254 | } 255 | #endif 256 | 257 | #endif 258 | #pragma once 259 | -------------------------------------------------------------------------------- /croskblight/croskblight.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | {E0C3F023-6A54-419C-9C6E-E0638B55D99F} 39 | {497e31cb-056b-4f31-abb8-447fd55ee5a5} 40 | v4.5 41 | 12.0 42 | Debug 43 | Win32 44 | croskeyboard3 45 | 10.0.22000.0 46 | croskblight 47 | 48 | 49 | 50 | 51 | 52 | true 53 | WindowsKernelModeDriver10.0 54 | Driver 55 | KMDF 56 | 57 | 58 | 59 | 60 | 61 | 62 | false 63 | WindowsKernelModeDriver10.0 64 | Driver 65 | KMDF 66 | 67 | 68 | 69 | 70 | 71 | 72 | true 73 | WindowsKernelModeDriver10.0 74 | Driver 75 | KMDF 76 | 77 | 78 | 79 | 80 | 81 | 82 | false 83 | WindowsKernelModeDriver10.0 84 | Driver 85 | KMDF 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | DbgengKernelDebugger 99 | 100 | 101 | DbgengKernelDebugger 102 | 103 | 104 | DbgengKernelDebugger 105 | 106 | 107 | DbgengKernelDebugger 108 | 109 | 110 | 111 | true 112 | true 113 | trace.h 114 | true 115 | 116 | 117 | SHA256 118 | 119 | 120 | 2.0.1 121 | 122 | 123 | 124 | 125 | true 126 | true 127 | trace.h 128 | true 129 | 130 | 131 | SHA256 132 | 133 | 134 | 2.0.1 135 | 136 | 137 | 138 | 139 | true 140 | true 141 | trace.h 142 | true 143 | false 144 | 145 | 146 | SHA256 147 | 148 | 149 | 2.0.1 150 | 151 | 152 | 153 | 154 | true 155 | true 156 | trace.h 157 | true 158 | false 159 | Level4 160 | 161 | 162 | 2.0.1 163 | 164 | 165 | SHA256 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /croskblightclient/croskblightclient/croskblightclient.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {d359354a-6448-463a-9f18-9516d89400f0} 25 | croskblightclient 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v142 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Windows 94 | true 95 | 96 | 97 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;setupapi.lib;hid.lib;%(AdditionalDependencies) 98 | 99 | 100 | 101 | 102 | Level3 103 | true 104 | true 105 | true 106 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 107 | true 108 | 109 | 110 | Windows 111 | true 112 | true 113 | true 114 | 115 | 116 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;setupapi.lib;hid.lib;%(AdditionalDependencies) 117 | 118 | 119 | 120 | 121 | Level3 122 | true 123 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 124 | true 125 | 126 | 127 | Windows 128 | true 129 | 130 | 131 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;setupapi.lib;hid.lib;%(AdditionalDependencies) 132 | 133 | 134 | 135 | 136 | Level3 137 | true 138 | true 139 | true 140 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 141 | true 142 | 143 | 144 | Windows 145 | true 146 | true 147 | true 148 | 149 | 150 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;setupapi.lib;hid.lib;%(AdditionalDependencies) 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /croskblightclient/croskblightclient/client.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "croskblightclient.h" 8 | 9 | #if __GNUC__ 10 | #define __in 11 | #define __in_ecount(x) 12 | typedef void* PVOID; 13 | typedef PVOID HDEVINFO; 14 | WINHIDSDI BOOL WINAPI HidD_SetOutputReport(HANDLE, PVOID, ULONG); 15 | #endif 16 | 17 | typedef struct _croskblight_client_t 18 | { 19 | HANDLE hSettings; 20 | } croskblight_client_t; 21 | 22 | // 23 | // Function prototypes 24 | // 25 | 26 | HANDLE 27 | SearchMatchingHwID( 28 | USAGE myUsagePage, 29 | USAGE myUsage 30 | ); 31 | 32 | HANDLE 33 | OpenDeviceInterface( 34 | HDEVINFO HardwareDeviceInfo, 35 | PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, 36 | USAGE myUsagePage, 37 | USAGE myUsage 38 | ); 39 | 40 | BOOLEAN 41 | CheckIfOurDevice( 42 | HANDLE file, 43 | USAGE myUsagePage, 44 | USAGE myUsage 45 | ); 46 | 47 | BOOL 48 | HidOutput( 49 | BOOL useSetOutputReport, 50 | HANDLE file, 51 | PCHAR buffer, 52 | ULONG bufferSize 53 | ); 54 | 55 | // 56 | // Copied this structure from hidport.h 57 | // 58 | 59 | typedef struct _HID_DEVICE_ATTRIBUTES { 60 | 61 | ULONG Size; 62 | // 63 | // sizeof (struct _HID_DEVICE_ATTRIBUTES) 64 | // 65 | // 66 | // Vendor ids of this hid device 67 | // 68 | USHORT VendorID; 69 | USHORT ProductID; 70 | USHORT VersionNumber; 71 | USHORT Reserved[11]; 72 | 73 | } HID_DEVICE_ATTRIBUTES, *PHID_DEVICE_ATTRIBUTES; 74 | 75 | static USHORT TpVendorID = 0; 76 | 77 | USHORT getVendorID() { 78 | return TpVendorID; 79 | } 80 | 81 | // 82 | // Implementation 83 | // 84 | 85 | pcroskblight_client croskblight_alloc(void) 86 | { 87 | return (pcroskblight_client)malloc(sizeof(croskblight_client_t)); 88 | } 89 | 90 | void croskblight_free(pcroskblight_client croskblight) 91 | { 92 | free(croskblight); 93 | } 94 | 95 | BOOL croskblight_connect(pcroskblight_client croskblight) 96 | { 97 | // 98 | // Find the HID devices 99 | // 100 | 101 | croskblight->hSettings = SearchMatchingHwID(0xff00, 0x0001); 102 | if (croskblight->hSettings == INVALID_HANDLE_VALUE || croskblight->hSettings == NULL) 103 | { 104 | croskblight_disconnect(croskblight); 105 | return FALSE; 106 | } 107 | 108 | // 109 | // Set the buffer count to 10 on the setting HID 110 | // 111 | 112 | if (!HidD_SetNumInputBuffers(croskblight->hSettings, 10)) 113 | { 114 | printf("failed HidD_SetNumInputBuffers %d\n", GetLastError()); 115 | croskblight_disconnect(croskblight); 116 | return FALSE; 117 | } 118 | 119 | return TRUE; 120 | } 121 | 122 | void croskblight_disconnect(pcroskblight_client croskblight) 123 | { 124 | if (croskblight->hSettings != NULL) 125 | CloseHandle(croskblight->hSettings); 126 | croskblight->hSettings = NULL; 127 | } 128 | 129 | BOOL croskblight_read_message(pcroskblight_client vmulti, CrosKBLightGetLightReport* pReport) 130 | { 131 | ULONG bytesRead; 132 | 133 | // 134 | // Read the report 135 | // 136 | 137 | if (!ReadFile(vmulti->hSettings, pReport, sizeof(CrosKBLightGetLightReport), &bytesRead, NULL)) 138 | { 139 | printf("failed ReadFile %d\n", GetLastError()); 140 | return FALSE; 141 | } 142 | 143 | return TRUE; 144 | } 145 | 146 | BOOL croskblight_write_message(pcroskblight_client croskblight, CrosKBLightSettingsReport* pReport) 147 | { 148 | ULONG bytesWritten; 149 | 150 | // 151 | // Write the report 152 | // 153 | 154 | if (!WriteFile(croskblight->hSettings, pReport, sizeof(CrosKBLightSettingsReport), &bytesWritten, NULL)) 155 | { 156 | printf("failed WriteFile %d\n", GetLastError()); 157 | return FALSE; 158 | } 159 | 160 | return TRUE; 161 | } 162 | 163 | HANDLE 164 | SearchMatchingHwID( 165 | USAGE myUsagePage, 166 | USAGE myUsage 167 | ) 168 | { 169 | HDEVINFO hardwareDeviceInfo; 170 | SP_DEVICE_INTERFACE_DATA deviceInterfaceData; 171 | SP_DEVINFO_DATA devInfoData; 172 | GUID hidguid; 173 | int i; 174 | 175 | HidD_GetHidGuid(&hidguid); 176 | 177 | hardwareDeviceInfo = 178 | SetupDiGetClassDevs((LPGUID)&hidguid, 179 | NULL, 180 | NULL, // Define no 181 | (DIGCF_PRESENT | 182 | DIGCF_INTERFACEDEVICE)); 183 | 184 | if (INVALID_HANDLE_VALUE == hardwareDeviceInfo) 185 | { 186 | printf("SetupDiGetClassDevs failed: %x\n", GetLastError()); 187 | return INVALID_HANDLE_VALUE; 188 | } 189 | 190 | deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); 191 | 192 | devInfoData.cbSize = sizeof(SP_DEVINFO_DATA); 193 | 194 | // 195 | // Enumerate devices of this interface class 196 | // 197 | 198 | printf("\n....looking for our HID device (with UP=0x%x " 199 | "and Usage=0x%x)\n", myUsagePage, myUsage); 200 | 201 | for (i = 0; SetupDiEnumDeviceInterfaces(hardwareDeviceInfo, 202 | 0, // No care about specific PDOs 203 | (LPGUID)&hidguid, 204 | i, // 205 | &deviceInterfaceData); 206 | i++) 207 | { 208 | 209 | // 210 | // Open the device interface and Check if it is our device 211 | // by matching the Usage page and Usage from Hid_Caps. 212 | // If this is our device then send the hid request. 213 | // 214 | 215 | HANDLE file = OpenDeviceInterface(hardwareDeviceInfo, &deviceInterfaceData, myUsagePage, myUsage); 216 | 217 | if (file != INVALID_HANDLE_VALUE) 218 | { 219 | SetupDiDestroyDeviceInfoList(hardwareDeviceInfo); 220 | return file; 221 | } 222 | 223 | // 224 | //device was not found so loop around. 225 | // 226 | 227 | } 228 | 229 | printf("Failure: Could not find our HID device \n"); 230 | 231 | SetupDiDestroyDeviceInfoList(hardwareDeviceInfo); 232 | 233 | return INVALID_HANDLE_VALUE; 234 | } 235 | 236 | HANDLE 237 | OpenDeviceInterface( 238 | HDEVINFO hardwareDeviceInfo, 239 | PSP_DEVICE_INTERFACE_DATA deviceInterfaceData, 240 | USAGE myUsagePage, 241 | USAGE myUsage 242 | ) 243 | { 244 | PSP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData = NULL; 245 | 246 | DWORD predictedLength = 0; 247 | DWORD requiredLength = 0; 248 | HANDLE file = INVALID_HANDLE_VALUE; 249 | 250 | SetupDiGetDeviceInterfaceDetail( 251 | hardwareDeviceInfo, 252 | deviceInterfaceData, 253 | NULL, // probing so no output buffer yet 254 | 0, // probing so output buffer length of zero 255 | &requiredLength, 256 | NULL 257 | ); // not interested in the specific dev-node 258 | 259 | predictedLength = requiredLength; 260 | 261 | deviceInterfaceDetailData = 262 | (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(predictedLength); 263 | 264 | if (!deviceInterfaceDetailData) 265 | { 266 | printf("Error: OpenDeviceInterface: malloc failed\n"); 267 | goto cleanup; 268 | } 269 | 270 | deviceInterfaceDetailData->cbSize = 271 | sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); 272 | 273 | if (!SetupDiGetDeviceInterfaceDetail( 274 | hardwareDeviceInfo, 275 | deviceInterfaceData, 276 | deviceInterfaceDetailData, 277 | predictedLength, 278 | &requiredLength, 279 | NULL)) 280 | { 281 | printf("Error: SetupDiGetInterfaceDeviceDetail failed\n"); 282 | free(deviceInterfaceDetailData); 283 | goto cleanup; 284 | } 285 | 286 | file = CreateFile(deviceInterfaceDetailData->DevicePath, 287 | GENERIC_READ | GENERIC_WRITE, 288 | FILE_SHARE_READ | FILE_SHARE_WRITE, 289 | NULL, // no SECURITY_ATTRIBUTES structure 290 | OPEN_EXISTING, // No special create flags 291 | 0, // No special attributes 292 | NULL); // No template file 293 | 294 | if (INVALID_HANDLE_VALUE == file) { 295 | printf("Error: CreateFile failed: %d\n", GetLastError()); 296 | goto cleanup; 297 | } 298 | 299 | if (CheckIfOurDevice(file, myUsagePage, myUsage)) { 300 | 301 | goto cleanup; 302 | 303 | } 304 | 305 | CloseHandle(file); 306 | 307 | file = INVALID_HANDLE_VALUE; 308 | 309 | cleanup: 310 | 311 | free(deviceInterfaceDetailData); 312 | 313 | return file; 314 | 315 | } 316 | 317 | 318 | BOOLEAN 319 | CheckIfOurDevice( 320 | HANDLE file, 321 | USAGE myUsagePage, 322 | USAGE myUsage) 323 | { 324 | PHIDP_PREPARSED_DATA Ppd = NULL; // The opaque parser info describing this device 325 | HIDD_ATTRIBUTES Attributes; // The Attributes of this hid device. 326 | HIDP_CAPS Caps; // The Capabilities of this hid device. 327 | BOOLEAN result = FALSE; 328 | 329 | if (!HidD_GetPreparsedData(file, &Ppd)) 330 | { 331 | printf("Error: HidD_GetPreparsedData failed \n"); 332 | goto cleanup; 333 | } 334 | 335 | if (!HidD_GetAttributes(file, &Attributes)) 336 | { 337 | printf("Error: HidD_GetAttributes failed \n"); 338 | goto cleanup; 339 | } 340 | 341 | if (Attributes.VendorID == CROSKBLIGHT_VID && Attributes.ProductID == CROSKBLIGHT_PID) 342 | { 343 | TpVendorID = Attributes.VendorID; 344 | 345 | if (!HidP_GetCaps(Ppd, &Caps)) 346 | { 347 | printf("Error: HidP_GetCaps failed \n"); 348 | goto cleanup; 349 | } 350 | 351 | if ((Caps.UsagePage == myUsagePage) && (Caps.Usage == myUsage)) 352 | { 353 | printf("Success: Found my device.. \n"); 354 | result = TRUE; 355 | } 356 | } 357 | 358 | cleanup: 359 | 360 | if (Ppd != NULL) 361 | { 362 | HidD_FreePreparsedData(Ppd); 363 | } 364 | 365 | return result; 366 | } 367 | 368 | BOOL 369 | HidOutput( 370 | BOOL useSetOutputReport, 371 | HANDLE file, 372 | PCHAR buffer, 373 | ULONG bufferSize 374 | ) 375 | { 376 | ULONG bytesWritten; 377 | if (useSetOutputReport) 378 | { 379 | // 380 | // Send Hid report thru HidD_SetOutputReport API 381 | // 382 | 383 | if (!HidD_SetOutputReport(file, buffer, bufferSize)) 384 | { 385 | printf("failed HidD_SetOutputReport %d\n", GetLastError()); 386 | return FALSE; 387 | } 388 | } 389 | else 390 | { 391 | if (!WriteFile(file, buffer, bufferSize, &bytesWritten, NULL)) 392 | { 393 | printf("failed WriteFile %d\n", GetLastError()); 394 | return FALSE; 395 | } 396 | } 397 | 398 | return TRUE; 399 | } -------------------------------------------------------------------------------- /croskblight/croskblight.cpp: -------------------------------------------------------------------------------- 1 | #define DESCRIPTOR_DEF 2 | #include "croskblight.h" 3 | #include 4 | #include 5 | 6 | VOID 7 | CrosKBLightS0ixNotifyCallback( 8 | PCROSKBLIGHT_CONTEXT pDevice, 9 | ULONG NotifyCode); 10 | 11 | static ULONG CrosKBLightDebugLevel = 100; 12 | static ULONG CrosKBLightDebugCatagories = DBG_INIT || DBG_PNP || DBG_IOCTL; 13 | 14 | NTSTATUS 15 | DriverEntry( 16 | __in PDRIVER_OBJECT DriverObject, 17 | __in PUNICODE_STRING RegistryPath 18 | ) 19 | { 20 | NTSTATUS status = STATUS_SUCCESS; 21 | WDF_DRIVER_CONFIG config; 22 | WDF_OBJECT_ATTRIBUTES attributes; 23 | 24 | CrosKBLightPrint(DEBUG_LEVEL_INFO, DBG_INIT, 25 | "Driver Entry"); 26 | 27 | WDF_DRIVER_CONFIG_INIT(&config, CrosKBLightEvtDeviceAdd); 28 | 29 | WDF_OBJECT_ATTRIBUTES_INIT(&attributes); 30 | 31 | // 32 | // Create a framework driver object to represent our driver. 33 | // 34 | 35 | status = WdfDriverCreate(DriverObject, 36 | RegistryPath, 37 | &attributes, 38 | &config, 39 | WDF_NO_HANDLE 40 | ); 41 | 42 | if (!NT_SUCCESS(status)) 43 | { 44 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_INIT, 45 | "WdfDriverCreate failed with status 0x%x\n", status); 46 | } 47 | 48 | return status; 49 | } 50 | 51 | NTSTATUS ConnectToEc( 52 | _In_ WDFDEVICE FxDevice 53 | ) { 54 | PCROSKBLIGHT_CONTEXT pDevice = GetDeviceContext(FxDevice); 55 | WDF_OBJECT_ATTRIBUTES objectAttributes; 56 | 57 | WDF_OBJECT_ATTRIBUTES_INIT(&objectAttributes); 58 | objectAttributes.ParentObject = FxDevice; 59 | 60 | NTSTATUS status = WdfIoTargetCreate(FxDevice, 61 | &objectAttributes, 62 | &pDevice->busIoTarget 63 | ); 64 | if (!NT_SUCCESS(status)) 65 | { 66 | CrosKBLightPrint( 67 | DEBUG_LEVEL_ERROR, 68 | DBG_IOCTL, 69 | "Error creating IoTarget object - 0x%x\n", 70 | status); 71 | if (pDevice->busIoTarget) 72 | WdfObjectDelete(pDevice->busIoTarget); 73 | return status; 74 | } 75 | 76 | DECLARE_CONST_UNICODE_STRING(busDosDeviceName, L"\\DosDevices\\GOOG0004"); 77 | 78 | WDF_IO_TARGET_OPEN_PARAMS openParams; 79 | WDF_IO_TARGET_OPEN_PARAMS_INIT_OPEN_BY_NAME( 80 | &openParams, 81 | &busDosDeviceName, 82 | (GENERIC_READ | GENERIC_WRITE)); 83 | 84 | openParams.ShareAccess = FILE_SHARE_READ | FILE_SHARE_WRITE; 85 | openParams.CreateDisposition = FILE_OPEN; 86 | openParams.FileAttributes = FILE_ATTRIBUTE_NORMAL; 87 | 88 | CROSEC_INTERFACE_STANDARD CrosEcInterface; 89 | RtlZeroMemory(&CrosEcInterface, sizeof(CrosEcInterface)); 90 | 91 | status = WdfIoTargetOpen(pDevice->busIoTarget, &openParams); 92 | if (!NT_SUCCESS(status)) 93 | { 94 | CrosKBLightPrint( 95 | DEBUG_LEVEL_ERROR, 96 | DBG_IOCTL, 97 | "Error opening IoTarget object - 0x%x\n", 98 | status); 99 | WdfObjectDelete(pDevice->busIoTarget); 100 | return status; 101 | } 102 | 103 | status = WdfIoTargetQueryForInterface(pDevice->busIoTarget, 104 | &GUID_CROSEC_INTERFACE_STANDARD, 105 | (PINTERFACE)&CrosEcInterface, 106 | sizeof(CrosEcInterface), 107 | 1, 108 | NULL); 109 | WdfIoTargetClose(pDevice->busIoTarget); 110 | pDevice->busIoTarget = NULL; 111 | if (!NT_SUCCESS(status)) { 112 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_PNP, 113 | "WdfFdoQueryForInterface failed 0x%x\n", status); 114 | return status; 115 | } 116 | 117 | pDevice->CrosEcBusContext = CrosEcInterface.InterfaceHeader.Context; 118 | pDevice->CrosEcCmdXferStatus = CrosEcInterface.CmdXferStatus; 119 | return status; 120 | } 121 | 122 | static NTSTATUS send_ec_command( 123 | _In_ PCROSKBLIGHT_CONTEXT pDevice, 124 | UINT32 cmd, 125 | UINT32 version, 126 | UINT8* out, 127 | size_t outSize, 128 | UINT8* in, 129 | size_t inSize) 130 | { 131 | PCROSEC_COMMAND msg = (PCROSEC_COMMAND)ExAllocatePoolWithTag(NonPagedPool, sizeof(CROSEC_COMMAND) + max(outSize, inSize), CROSKBLIGHT_POOL_TAG); 132 | if (!msg) { 133 | return STATUS_NO_MEMORY; 134 | } 135 | msg->Version = version; 136 | msg->Command = cmd; 137 | msg->OutSize = outSize; 138 | msg->InSize = inSize; 139 | 140 | if (outSize) 141 | memcpy(msg->Data, out, outSize); 142 | 143 | NTSTATUS status = (*pDevice->CrosEcCmdXferStatus)(pDevice->CrosEcBusContext, msg); 144 | if (!NT_SUCCESS(status)) { 145 | goto exit; 146 | } 147 | 148 | if (in && inSize) { 149 | memcpy(in, msg->Data, inSize); 150 | } 151 | 152 | exit: 153 | ExFreePoolWithTag(msg, CROSKBLIGHT_POOL_TAG); 154 | return status; 155 | } 156 | 157 | /** 158 | * Get the versions of the command supported by the EC. 159 | * 160 | * @param cmd Command 161 | * @param pmask Destination for version mask; will be set to 0 on 162 | * error. 163 | */ 164 | static NTSTATUS cros_ec_get_cmd_versions(PCROSKBLIGHT_CONTEXT pDevice, int cmd, UINT32* pmask) { 165 | struct ec_params_get_cmd_versions_v1 pver_v1; 166 | struct ec_params_get_cmd_versions pver; 167 | struct ec_response_get_cmd_versions rver; 168 | NTSTATUS status; 169 | 170 | *pmask = 0; 171 | 172 | pver_v1.cmd = cmd; 173 | status = send_ec_command(pDevice, EC_CMD_GET_CMD_VERSIONS, 1, (UINT8*)&pver_v1, sizeof(pver_v1), 174 | (UINT8*)&rver, sizeof(rver)); 175 | 176 | if (!NT_SUCCESS(status)) { 177 | pver.cmd = cmd; 178 | status = send_ec_command(pDevice, EC_CMD_GET_CMD_VERSIONS, 0, (UINT8*)&pver, sizeof(pver), 179 | (UINT8*)&rver, sizeof(rver)); 180 | } 181 | 182 | *pmask = rver.version_mask; 183 | return status; 184 | } 185 | 186 | /** 187 | * Return non-zero if the EC supports the command and version 188 | * 189 | * @param cmd Command to check 190 | * @param ver Version to check 191 | * @return non-zero if command version supported; 0 if not. 192 | */ 193 | BOOLEAN cros_ec_cmd_version_supported(PCROSKBLIGHT_CONTEXT pDevice, int cmd, int ver) 194 | { 195 | UINT32 mask = 0; 196 | 197 | if (NT_SUCCESS(cros_ec_get_cmd_versions(pDevice, cmd, &mask))) 198 | return false; 199 | 200 | return (mask & EC_VER_MASK(ver)) ? true : false; 201 | } 202 | 203 | NTSTATUS 204 | CrosKBLightGetBacklight( 205 | _In_ PCROSKBLIGHT_CONTEXT pDevice, 206 | UINT8* PBacklight 207 | ) 208 | { 209 | struct ec_response_pwm_get_keyboard_backlight backlightParams; 210 | NTSTATUS status = send_ec_command(pDevice, EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT, 0, NULL, 0, (UINT8*)&backlightParams, sizeof(struct ec_response_pwm_get_keyboard_backlight)); 211 | if (!NT_SUCCESS(status)) 212 | return status; 213 | if (PBacklight) { 214 | if (backlightParams.enabled) { 215 | *PBacklight = backlightParams.percent; 216 | } 217 | else { 218 | *PBacklight = 0; 219 | } 220 | } 221 | return status; 222 | } 223 | 224 | NTSTATUS 225 | CrosKBLightSetBacklight( 226 | _In_ PCROSKBLIGHT_CONTEXT pDevice, 227 | UINT8 Backlight 228 | ) 229 | { 230 | struct ec_params_pwm_set_keyboard_backlight backlightParams; 231 | backlightParams.percent = Backlight; 232 | return send_ec_command(pDevice, EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT, 0, (UINT8*)&backlightParams, sizeof(struct ec_params_pwm_set_keyboard_backlight), NULL, 0); 233 | } 234 | 235 | NTSTATUS 236 | OnPrepareHardware( 237 | _In_ WDFDEVICE FxDevice, 238 | _In_ WDFCMRESLIST FxResourcesRaw, 239 | _In_ WDFCMRESLIST FxResourcesTranslated 240 | ) 241 | /*++ 242 | 243 | Routine Description: 244 | 245 | This routine caches the SPB resource connection ID. 246 | 247 | Arguments: 248 | 249 | FxDevice - a handle to the framework device object 250 | FxResourcesRaw - list of translated hardware resources that 251 | the PnP manager has assigned to the device 252 | FxResourcesTranslated - list of raw hardware resources that 253 | the PnP manager has assigned to the device 254 | 255 | Return Value: 256 | 257 | Status 258 | 259 | --*/ 260 | { 261 | PCROSKBLIGHT_CONTEXT pDevice = GetDeviceContext(FxDevice); 262 | NTSTATUS status = STATUS_SUCCESS; 263 | 264 | UNREFERENCED_PARAMETER(FxResourcesRaw); 265 | UNREFERENCED_PARAMETER(FxResourcesTranslated); 266 | 267 | status = ConnectToEc(FxDevice); 268 | if (!NT_SUCCESS(status)) { 269 | return status; 270 | } 271 | 272 | (*pDevice->CrosEcCmdXferStatus)(pDevice->CrosEcBusContext, NULL); 273 | 274 | CrosKBLightGetBacklight(pDevice, &pDevice->currentBrightness); 275 | 276 | status = WdfFdoQueryForInterface(FxDevice, 277 | &GUID_ACPI_INTERFACE_STANDARD2, 278 | (PINTERFACE)&pDevice->S0ixNotifyAcpiInterface, 279 | sizeof(ACPI_INTERFACE_STANDARD2), 280 | 1, 281 | NULL); 282 | 283 | if (!NT_SUCCESS(status)) { 284 | return status; 285 | } 286 | 287 | status = pDevice->S0ixNotifyAcpiInterface.RegisterForDeviceNotifications( 288 | pDevice->S0ixNotifyAcpiInterface.Context, 289 | (PDEVICE_NOTIFY_CALLBACK2)CrosKBLightS0ixNotifyCallback, 290 | pDevice); 291 | if (!NT_SUCCESS(status)) { 292 | return status; 293 | } 294 | 295 | return status; 296 | } 297 | 298 | NTSTATUS 299 | OnReleaseHardware( 300 | _In_ WDFDEVICE FxDevice, 301 | _In_ WDFCMRESLIST FxResourcesTranslated 302 | ) 303 | /*++ 304 | 305 | Routine Description: 306 | 307 | Arguments: 308 | 309 | FxDevice - a handle to the framework device object 310 | FxResourcesTranslated - list of raw hardware resources that 311 | the PnP manager has assigned to the device 312 | 313 | Return Value: 314 | 315 | Status 316 | 317 | --*/ 318 | { 319 | PCROSKBLIGHT_CONTEXT pDevice = GetDeviceContext(FxDevice); 320 | NTSTATUS status = STATUS_SUCCESS; 321 | 322 | UNREFERENCED_PARAMETER(FxResourcesTranslated); 323 | 324 | if (pDevice->S0ixNotifyAcpiInterface.Context) { //Used for S0ix notifications 325 | pDevice->S0ixNotifyAcpiInterface.UnregisterForDeviceNotifications(pDevice->S0ixNotifyAcpiInterface.Context); 326 | } 327 | 328 | return status; 329 | } 330 | 331 | NTSTATUS 332 | OnD0Entry( 333 | _In_ WDFDEVICE FxDevice, 334 | _In_ WDF_POWER_DEVICE_STATE FxPreviousState 335 | ) 336 | /*++ 337 | 338 | Routine Description: 339 | 340 | This routine allocates objects needed by the driver. 341 | 342 | Arguments: 343 | 344 | FxDevice - a handle to the framework device object 345 | FxPreviousState - previous power state 346 | 347 | Return Value: 348 | 349 | Status 350 | 351 | --*/ 352 | { 353 | UNREFERENCED_PARAMETER(FxPreviousState); 354 | 355 | PCROSKBLIGHT_CONTEXT pDevice = GetDeviceContext(FxDevice); 356 | NTSTATUS status = STATUS_SUCCESS; 357 | 358 | CrosKBLightSetBacklight(pDevice, pDevice->currentBrightness); 359 | 360 | return status; 361 | } 362 | 363 | NTSTATUS 364 | OnD0Exit( 365 | _In_ WDFDEVICE FxDevice, 366 | _In_ WDF_POWER_DEVICE_STATE FxTargetState 367 | ) 368 | /*++ 369 | 370 | Routine Description: 371 | 372 | This routine destroys objects needed by the driver. 373 | 374 | Arguments: 375 | 376 | FxDevice - a handle to the framework device object 377 | FxTargetState - target power state 378 | 379 | Return Value: 380 | 381 | Status 382 | 383 | --*/ 384 | { 385 | PCROSKBLIGHT_CONTEXT pDevice = GetDeviceContext(FxDevice); 386 | 387 | if (FxTargetState != WdfPowerDeviceD3Final && 388 | FxTargetState != WdfPowerDevicePrepareForHibernation) { 389 | CrosKBLightSetBacklight(pDevice, 0); 390 | } 391 | 392 | return STATUS_SUCCESS; 393 | } 394 | 395 | VOID 396 | CrosKBLightS0ixNotifyCallback( 397 | PCROSKBLIGHT_CONTEXT pDevice, 398 | ULONG NotifyCode) { 399 | if (NotifyCode) { 400 | OnD0Exit(pDevice->FxDevice, WdfPowerDeviceD3); 401 | } 402 | else { 403 | OnD0Entry(pDevice->FxDevice, WdfPowerDeviceD3); 404 | } 405 | } 406 | 407 | static void update_brightness(PCROSKBLIGHT_CONTEXT pDevice, BYTE brightness) { 408 | _CROSKBLIGHT_GETLIGHT_REPORT report; 409 | report.ReportID = REPORTID_KBLIGHT; 410 | report.Brightness = brightness; 411 | 412 | size_t bytesWritten; 413 | CrosKBLightProcessVendorReport(pDevice, &report, sizeof(report), &bytesWritten); 414 | } 415 | 416 | NTSTATUS 417 | CrosKBLightEvtDeviceAdd( 418 | IN WDFDRIVER Driver, 419 | IN PWDFDEVICE_INIT DeviceInit 420 | ) 421 | { 422 | NTSTATUS status = STATUS_SUCCESS; 423 | WDF_IO_QUEUE_CONFIG queueConfig; 424 | WDF_OBJECT_ATTRIBUTES attributes; 425 | WDFDEVICE device; 426 | WDF_INTERRUPT_CONFIG interruptConfig; 427 | WDFQUEUE queue; 428 | UCHAR minorFunction; 429 | PCROSKBLIGHT_CONTEXT devContext; 430 | 431 | UNREFERENCED_PARAMETER(Driver); 432 | 433 | PAGED_CODE(); 434 | 435 | CrosKBLightPrint(DEBUG_LEVEL_INFO, DBG_PNP, 436 | "CrosKBLightEvtDeviceAdd called\n"); 437 | 438 | // 439 | // Tell framework this is a filter driver. Filter drivers by default are 440 | // not power policy owners. This works well for this driver because 441 | // HIDclass driver is the power policy owner for HID minidrivers. 442 | // 443 | 444 | WdfFdoInitSetFilter(DeviceInit); 445 | 446 | { 447 | WDF_PNPPOWER_EVENT_CALLBACKS pnpCallbacks; 448 | WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpCallbacks); 449 | 450 | pnpCallbacks.EvtDevicePrepareHardware = OnPrepareHardware; 451 | pnpCallbacks.EvtDeviceReleaseHardware = OnReleaseHardware; 452 | pnpCallbacks.EvtDeviceD0Entry = OnD0Entry; 453 | pnpCallbacks.EvtDeviceD0Exit = OnD0Exit; 454 | 455 | WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpCallbacks); 456 | } 457 | 458 | // 459 | // Setup the device context 460 | // 461 | 462 | WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, CROSKBLIGHT_CONTEXT); 463 | 464 | // 465 | // Create a framework device object.This call will in turn create 466 | // a WDM device object, attach to the lower stack, and set the 467 | // appropriate flags and attributes. 468 | // 469 | 470 | status = WdfDeviceCreate(&DeviceInit, &attributes, &device); 471 | 472 | if (!NT_SUCCESS(status)) 473 | { 474 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_PNP, 475 | "WdfDeviceCreate failed with status code 0x%x\n", status); 476 | 477 | return status; 478 | } 479 | 480 | { 481 | WDF_DEVICE_STATE deviceState; 482 | WDF_DEVICE_STATE_INIT(&deviceState); 483 | 484 | deviceState.NotDisableable = WdfFalse; 485 | WdfDeviceSetDeviceState(device, &deviceState); 486 | } 487 | 488 | WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queueConfig, WdfIoQueueDispatchParallel); 489 | 490 | queueConfig.EvtIoInternalDeviceControl = CrosKBLightEvtInternalDeviceControl; 491 | 492 | status = WdfIoQueueCreate(device, 493 | &queueConfig, 494 | WDF_NO_OBJECT_ATTRIBUTES, 495 | &queue 496 | ); 497 | 498 | if (!NT_SUCCESS(status)) 499 | { 500 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_PNP, 501 | "WdfIoQueueCreate failed 0x%x\n", status); 502 | 503 | return status; 504 | } 505 | 506 | // 507 | // Create manual I/O queue to take care of hid report read requests 508 | // 509 | 510 | devContext = GetDeviceContext(device); 511 | devContext->FxDevice = device; 512 | 513 | WDF_IO_QUEUE_CONFIG_INIT(&queueConfig, WdfIoQueueDispatchManual); 514 | 515 | queueConfig.PowerManaged = WdfTrue; 516 | 517 | status = WdfIoQueueCreate(device, 518 | &queueConfig, 519 | WDF_NO_OBJECT_ATTRIBUTES, 520 | &devContext->ReportQueue 521 | ); 522 | 523 | if (!NT_SUCCESS(status)) 524 | { 525 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_PNP, 526 | "WdfIoQueueCreate failed 0x%x\n", status); 527 | 528 | return status; 529 | } 530 | 531 | // 532 | // Initialize DeviceMode 533 | // 534 | 535 | devContext->DeviceMode = DEVICE_MODE_MOUSE; 536 | 537 | return status; 538 | } 539 | 540 | VOID 541 | CrosKBLightEvtInternalDeviceControl( 542 | IN WDFQUEUE Queue, 543 | IN WDFREQUEST Request, 544 | IN size_t OutputBufferLength, 545 | IN size_t InputBufferLength, 546 | IN ULONG IoControlCode 547 | ) 548 | { 549 | NTSTATUS status = STATUS_SUCCESS; 550 | WDFDEVICE device; 551 | PCROSKBLIGHT_CONTEXT devContext; 552 | BOOLEAN completeRequest = TRUE; 553 | 554 | UNREFERENCED_PARAMETER(OutputBufferLength); 555 | UNREFERENCED_PARAMETER(InputBufferLength); 556 | 557 | device = WdfIoQueueGetDevice(Queue); 558 | devContext = GetDeviceContext(device); 559 | 560 | CrosKBLightPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, 561 | "%s, Queue:0x%p, Request:0x%p\n", 562 | DbgHidInternalIoctlString(IoControlCode), 563 | Queue, 564 | Request 565 | ); 566 | 567 | // 568 | // Please note that HIDCLASS provides the buffer in the Irp->UserBuffer 569 | // field irrespective of the ioctl buffer type. However, framework is very 570 | // strict about type checking. You cannot get Irp->UserBuffer by using 571 | // WdfRequestRetrieveOutputMemory if the ioctl is not a METHOD_NEITHER 572 | // internal ioctl. So depending on the ioctl code, we will either 573 | // use retreive function or escape to WDM to get the UserBuffer. 574 | // 575 | 576 | switch (IoControlCode) 577 | { 578 | 579 | case IOCTL_HID_GET_DEVICE_DESCRIPTOR: 580 | // 581 | // Retrieves the device's HID descriptor. 582 | // 583 | status = CrosKBLightGetHidDescriptor(device, Request); 584 | break; 585 | 586 | case IOCTL_HID_GET_DEVICE_ATTRIBUTES: 587 | // 588 | //Retrieves a device's attributes in a HID_DEVICE_ATTRIBUTES structure. 589 | // 590 | status = CrosKBLightGetDeviceAttributes(Request); 591 | break; 592 | 593 | case IOCTL_HID_GET_REPORT_DESCRIPTOR: 594 | // 595 | //Obtains the report descriptor for the HID device. 596 | // 597 | status = CrosKBLightGetReportDescriptor(device, Request); 598 | break; 599 | 600 | case IOCTL_HID_GET_STRING: 601 | // 602 | // Requests that the HID minidriver retrieve a human-readable string 603 | // for either the manufacturer ID, the product ID, or the serial number 604 | // from the string descriptor of the device. The minidriver must send 605 | // a Get String Descriptor request to the device, in order to retrieve 606 | // the string descriptor, then it must extract the string at the 607 | // appropriate index from the string descriptor and return it in the 608 | // output buffer indicated by the IRP. Before sending the Get String 609 | // Descriptor request, the minidriver must retrieve the appropriate 610 | // index for the manufacturer ID, the product ID or the serial number 611 | // from the device extension of a top level collection associated with 612 | // the device. 613 | // 614 | status = CrosKBLightGetString(Request); 615 | break; 616 | 617 | case IOCTL_HID_WRITE_REPORT: 618 | case IOCTL_HID_SET_OUTPUT_REPORT: 619 | // 620 | //Transmits a class driver-supplied report to the device. 621 | // 622 | status = CrosKBLightWriteReport(devContext, Request); 623 | break; 624 | 625 | case IOCTL_HID_READ_REPORT: 626 | case IOCTL_HID_GET_INPUT_REPORT: 627 | // 628 | // Returns a report from the device into a class driver-supplied buffer. 629 | // 630 | status = CrosKBLightReadReport(devContext, Request, &completeRequest); 631 | break; 632 | 633 | case IOCTL_HID_SET_FEATURE: 634 | // 635 | // This sends a HID class feature report to a top-level collection of 636 | // a HID class device. 637 | // 638 | status = CrosKBLightSetFeature(devContext, Request, &completeRequest); 639 | break; 640 | 641 | case IOCTL_HID_GET_FEATURE: 642 | // 643 | // returns a feature report associated with a top-level collection 644 | // 645 | status = CrosKBLightGetFeature(devContext, Request, &completeRequest); 646 | break; 647 | 648 | case IOCTL_HID_ACTIVATE_DEVICE: 649 | // 650 | // Makes the device ready for I/O operations. 651 | // 652 | case IOCTL_HID_DEACTIVATE_DEVICE: 653 | // 654 | // Causes the device to cease operations and terminate all outstanding 655 | // I/O requests. 656 | // 657 | default: 658 | status = STATUS_NOT_SUPPORTED; 659 | break; 660 | } 661 | 662 | if (completeRequest) 663 | { 664 | WdfRequestComplete(Request, status); 665 | 666 | CrosKBLightPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, 667 | "%s completed, Queue:0x%p, Request:0x%p\n", 668 | DbgHidInternalIoctlString(IoControlCode), 669 | Queue, 670 | Request 671 | ); 672 | } 673 | else 674 | { 675 | CrosKBLightPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, 676 | "%s deferred, Queue:0x%p, Request:0x%p\n", 677 | DbgHidInternalIoctlString(IoControlCode), 678 | Queue, 679 | Request 680 | ); 681 | } 682 | 683 | return; 684 | } 685 | 686 | NTSTATUS 687 | CrosKBLightGetHidDescriptor( 688 | IN WDFDEVICE Device, 689 | IN WDFREQUEST Request 690 | ) 691 | { 692 | NTSTATUS status = STATUS_SUCCESS; 693 | size_t bytesToCopy = 0; 694 | WDFMEMORY memory; 695 | 696 | UNREFERENCED_PARAMETER(Device); 697 | 698 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 699 | "CrosKBLightGetHidDescriptor Entry\n"); 700 | 701 | // 702 | // This IOCTL is METHOD_NEITHER so WdfRequestRetrieveOutputMemory 703 | // will correctly retrieve buffer from Irp->UserBuffer. 704 | // Remember that HIDCLASS provides the buffer in the Irp->UserBuffer 705 | // field irrespective of the ioctl buffer type. However, framework is very 706 | // strict about type checking. You cannot get Irp->UserBuffer by using 707 | // WdfRequestRetrieveOutputMemory if the ioctl is not a METHOD_NEITHER 708 | // internal ioctl. 709 | // 710 | status = WdfRequestRetrieveOutputMemory(Request, &memory); 711 | 712 | if (!NT_SUCCESS(status)) 713 | { 714 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 715 | "WdfRequestRetrieveOutputMemory failed 0x%x\n", status); 716 | 717 | return status; 718 | } 719 | 720 | // 721 | // Use hardcoded "HID Descriptor" 722 | // 723 | bytesToCopy = DefaultHidDescriptor.bLength; 724 | 725 | if (bytesToCopy == 0) 726 | { 727 | status = STATUS_INVALID_DEVICE_STATE; 728 | 729 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 730 | "DefaultHidDescriptor is zero, 0x%x\n", status); 731 | 732 | return status; 733 | } 734 | 735 | status = WdfMemoryCopyFromBuffer(memory, 736 | 0, // Offset 737 | (PVOID)&DefaultHidDescriptor, 738 | bytesToCopy); 739 | 740 | if (!NT_SUCCESS(status)) 741 | { 742 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 743 | "WdfMemoryCopyFromBuffer failed 0x%x\n", status); 744 | 745 | return status; 746 | } 747 | 748 | // 749 | // Report how many bytes were copied 750 | // 751 | WdfRequestSetInformation(Request, bytesToCopy); 752 | 753 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 754 | "CrosKBLightGetHidDescriptor Exit = 0x%x\n", status); 755 | 756 | return status; 757 | } 758 | 759 | NTSTATUS 760 | CrosKBLightGetReportDescriptor( 761 | IN WDFDEVICE Device, 762 | IN WDFREQUEST Request 763 | ) 764 | { 765 | NTSTATUS status = STATUS_SUCCESS; 766 | ULONG_PTR bytesToCopy; 767 | WDFMEMORY memory; 768 | 769 | UNREFERENCED_PARAMETER(Device); 770 | 771 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 772 | "CrosKBLightGetReportDescriptor Entry\n"); 773 | 774 | // 775 | // This IOCTL is METHOD_NEITHER so WdfRequestRetrieveOutputMemory 776 | // will correctly retrieve buffer from Irp->UserBuffer. 777 | // Remember that HIDCLASS provides the buffer in the Irp->UserBuffer 778 | // field irrespective of the ioctl buffer type. However, framework is very 779 | // strict about type checking. You cannot get Irp->UserBuffer by using 780 | // WdfRequestRetrieveOutputMemory if the ioctl is not a METHOD_NEITHER 781 | // internal ioctl. 782 | // 783 | status = WdfRequestRetrieveOutputMemory(Request, &memory); 784 | if (!NT_SUCCESS(status)) 785 | { 786 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 787 | "WdfRequestRetrieveOutputMemory failed 0x%x\n", status); 788 | 789 | return status; 790 | } 791 | 792 | // 793 | // Use hardcoded Report descriptor 794 | // 795 | bytesToCopy = DefaultHidDescriptor.DescriptorList[0].wReportLength; 796 | 797 | if (bytesToCopy == 0) 798 | { 799 | status = STATUS_INVALID_DEVICE_STATE; 800 | 801 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 802 | "DefaultHidDescriptor's reportLength is zero, 0x%x\n", status); 803 | 804 | return status; 805 | } 806 | 807 | status = WdfMemoryCopyFromBuffer(memory, 808 | 0, 809 | (PVOID)DefaultReportDescriptor, 810 | bytesToCopy); 811 | if (!NT_SUCCESS(status)) 812 | { 813 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 814 | "WdfMemoryCopyFromBuffer failed 0x%x\n", status); 815 | 816 | return status; 817 | } 818 | 819 | // 820 | // Report how many bytes were copied 821 | // 822 | WdfRequestSetInformation(Request, bytesToCopy); 823 | 824 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 825 | "CrosKBLightGetReportDescriptor Exit = 0x%x\n", status); 826 | 827 | return status; 828 | } 829 | 830 | 831 | NTSTATUS 832 | CrosKBLightGetDeviceAttributes( 833 | IN WDFREQUEST Request 834 | ) 835 | { 836 | NTSTATUS status = STATUS_SUCCESS; 837 | PHID_DEVICE_ATTRIBUTES deviceAttributes = NULL; 838 | 839 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 840 | "CrosKBLightGetDeviceAttributes Entry\n"); 841 | 842 | // 843 | // This IOCTL is METHOD_NEITHER so WdfRequestRetrieveOutputMemory 844 | // will correctly retrieve buffer from Irp->UserBuffer. 845 | // Remember that HIDCLASS provides the buffer in the Irp->UserBuffer 846 | // field irrespective of the ioctl buffer type. However, framework is very 847 | // strict about type checking. You cannot get Irp->UserBuffer by using 848 | // WdfRequestRetrieveOutputMemory if the ioctl is not a METHOD_NEITHER 849 | // internal ioctl. 850 | // 851 | status = WdfRequestRetrieveOutputBuffer(Request, 852 | sizeof(HID_DEVICE_ATTRIBUTES), 853 | (PVOID *)&deviceAttributes, 854 | NULL); 855 | if (!NT_SUCCESS(status)) 856 | { 857 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 858 | "WdfRequestRetrieveOutputBuffer failed 0x%x\n", status); 859 | 860 | return status; 861 | } 862 | 863 | // 864 | // Set USB device descriptor 865 | // 866 | 867 | deviceAttributes->Size = sizeof(HID_DEVICE_ATTRIBUTES); 868 | deviceAttributes->VendorID = CROSKBLIGHT_VID; 869 | deviceAttributes->ProductID = CROSKBLIGHT_PID; 870 | deviceAttributes->VersionNumber = CROSKBLIGHT_VERSION; 871 | 872 | // 873 | // Report how many bytes were copied 874 | // 875 | WdfRequestSetInformation(Request, sizeof(HID_DEVICE_ATTRIBUTES)); 876 | 877 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 878 | "CrosKBLightGetDeviceAttributes Exit = 0x%x\n", status); 879 | 880 | return status; 881 | } 882 | 883 | NTSTATUS 884 | CrosKBLightGetString( 885 | IN WDFREQUEST Request 886 | ) 887 | { 888 | 889 | NTSTATUS status = STATUS_SUCCESS; 890 | PWSTR pwstrID; 891 | size_t lenID; 892 | WDF_REQUEST_PARAMETERS params; 893 | void *pStringBuffer = NULL; 894 | 895 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 896 | "CrosKBLightGetString Entry\n"); 897 | 898 | WDF_REQUEST_PARAMETERS_INIT(¶ms); 899 | WdfRequestGetParameters(Request, ¶ms); 900 | 901 | switch ((ULONG_PTR)params.Parameters.DeviceIoControl.Type3InputBuffer & 0xFFFF) 902 | { 903 | case HID_STRING_ID_IMANUFACTURER: 904 | pwstrID = L"CrosKBLight.\0"; 905 | break; 906 | 907 | case HID_STRING_ID_IPRODUCT: 908 | pwstrID = L"MaxTouch Touch Screen\0"; 909 | break; 910 | 911 | case HID_STRING_ID_ISERIALNUMBER: 912 | pwstrID = L"123123123\0"; 913 | break; 914 | 915 | default: 916 | pwstrID = NULL; 917 | break; 918 | } 919 | 920 | lenID = pwstrID ? wcslen(pwstrID)*sizeof(WCHAR) + sizeof(UNICODE_NULL) : 0; 921 | 922 | if (pwstrID == NULL) 923 | { 924 | 925 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 926 | "CrosKBLightGetString Invalid request type\n"); 927 | 928 | status = STATUS_INVALID_PARAMETER; 929 | 930 | return status; 931 | } 932 | 933 | status = WdfRequestRetrieveOutputBuffer(Request, 934 | lenID, 935 | &pStringBuffer, 936 | &lenID); 937 | 938 | if (!NT_SUCCESS(status)) 939 | { 940 | 941 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 942 | "CrosKBLightGetString WdfRequestRetrieveOutputBuffer failed Status 0x%x\n", status); 943 | 944 | return status; 945 | } 946 | 947 | RtlCopyMemory(pStringBuffer, pwstrID, lenID); 948 | 949 | WdfRequestSetInformation(Request, lenID); 950 | 951 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 952 | "CrosKBLightGetString Exit = 0x%x\n", status); 953 | 954 | return status; 955 | } 956 | 957 | NTSTATUS 958 | CrosKBLightWriteReport( 959 | IN PCROSKBLIGHT_CONTEXT DevContext, 960 | IN WDFREQUEST Request 961 | ) 962 | { 963 | NTSTATUS status = STATUS_SUCCESS; 964 | WDF_REQUEST_PARAMETERS params; 965 | PHID_XFER_PACKET transferPacket = NULL; 966 | size_t bytesWritten = 0; 967 | 968 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 969 | "CrosKBLightWriteReport Entry\n"); 970 | 971 | WDF_REQUEST_PARAMETERS_INIT(¶ms); 972 | WdfRequestGetParameters(Request, ¶ms); 973 | 974 | if (params.Parameters.DeviceIoControl.InputBufferLength < sizeof(HID_XFER_PACKET)) 975 | { 976 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 977 | "CrosKBLightWriteReport Xfer packet too small\n"); 978 | 979 | status = STATUS_BUFFER_TOO_SMALL; 980 | } 981 | else 982 | { 983 | 984 | transferPacket = (PHID_XFER_PACKET)WdfRequestWdmGetIrp(Request)->UserBuffer; 985 | 986 | if (transferPacket == NULL) 987 | { 988 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 989 | "CrosKBLightWriteReport No xfer packet\n"); 990 | 991 | status = STATUS_INVALID_DEVICE_REQUEST; 992 | } 993 | else 994 | { 995 | // 996 | // switch on the report id 997 | // 998 | 999 | switch (transferPacket->reportId) 1000 | { 1001 | case REPORTID_KBLIGHT: { 1002 | CrosKBLightSettingsReport *pReport = (CrosKBLightSettingsReport *)transferPacket->reportBuffer; 1003 | 1004 | int reg = pReport->SetBrightness; 1005 | int val = pReport->Brightness; 1006 | 1007 | if (reg == 0) { 1008 | int brightness = DevContext->currentBrightness; 1009 | update_brightness(DevContext, brightness); 1010 | } 1011 | else if (reg == 1) { 1012 | DevContext->currentBrightness = val; 1013 | CrosKBLightSetBacklight(DevContext, DevContext->currentBrightness); 1014 | } 1015 | break; 1016 | } 1017 | default: 1018 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 1019 | "CrosKBLightWriteReport Unhandled report type %d\n", transferPacket->reportId); 1020 | 1021 | status = STATUS_INVALID_PARAMETER; 1022 | 1023 | break; 1024 | } 1025 | } 1026 | } 1027 | 1028 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 1029 | "CrosKBLightWriteReport Exit = 0x%x\n", status); 1030 | 1031 | return status; 1032 | 1033 | } 1034 | 1035 | NTSTATUS 1036 | CrosKBLightProcessVendorReport( 1037 | IN PCROSKBLIGHT_CONTEXT DevContext, 1038 | IN PVOID ReportBuffer, 1039 | IN ULONG ReportBufferLen, 1040 | OUT size_t* BytesWritten 1041 | ) 1042 | { 1043 | NTSTATUS status = STATUS_SUCCESS; 1044 | WDFREQUEST reqRead; 1045 | PVOID pReadReport = NULL; 1046 | size_t bytesReturned = 0; 1047 | 1048 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 1049 | "CrosKBLightProcessVendorReport Entry\n"); 1050 | 1051 | status = WdfIoQueueRetrieveNextRequest(DevContext->ReportQueue, 1052 | &reqRead); 1053 | 1054 | if (NT_SUCCESS(status)) 1055 | { 1056 | status = WdfRequestRetrieveOutputBuffer(reqRead, 1057 | ReportBufferLen, 1058 | &pReadReport, 1059 | &bytesReturned); 1060 | 1061 | if (NT_SUCCESS(status)) 1062 | { 1063 | // 1064 | // Copy ReportBuffer into read request 1065 | // 1066 | 1067 | if (bytesReturned > ReportBufferLen) 1068 | { 1069 | bytesReturned = ReportBufferLen; 1070 | } 1071 | 1072 | RtlCopyMemory(pReadReport, 1073 | ReportBuffer, 1074 | bytesReturned); 1075 | 1076 | // 1077 | // Complete read with the number of bytes returned as info 1078 | // 1079 | 1080 | WdfRequestCompleteWithInformation(reqRead, 1081 | status, 1082 | bytesReturned); 1083 | 1084 | CrosKBLightPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, 1085 | "CrosKBLightProcessVendorReport %d bytes returned\n", bytesReturned); 1086 | 1087 | // 1088 | // Return the number of bytes written for the write request completion 1089 | // 1090 | 1091 | *BytesWritten = bytesReturned; 1092 | 1093 | CrosKBLightPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, 1094 | "%s completed, Queue:0x%p, Request:0x%p\n", 1095 | DbgHidInternalIoctlString(IOCTL_HID_READ_REPORT), 1096 | DevContext->ReportQueue, 1097 | reqRead); 1098 | } 1099 | else 1100 | { 1101 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 1102 | "WdfRequestRetrieveOutputBuffer failed Status 0x%x\n", status); 1103 | } 1104 | } 1105 | else 1106 | { 1107 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 1108 | "WdfIoQueueRetrieveNextRequest failed Status 0x%x\n", status); 1109 | } 1110 | 1111 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 1112 | "CrosKBLightProcessVendorReport Exit = 0x%x\n", status); 1113 | 1114 | return status; 1115 | } 1116 | 1117 | NTSTATUS 1118 | CrosKBLightReadReport( 1119 | IN PCROSKBLIGHT_CONTEXT DevContext, 1120 | IN WDFREQUEST Request, 1121 | OUT BOOLEAN* CompleteRequest 1122 | ) 1123 | { 1124 | NTSTATUS status = STATUS_SUCCESS; 1125 | 1126 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 1127 | "CrosKBLightReadReport Entry\n"); 1128 | 1129 | // 1130 | // Forward this read request to our manual queue 1131 | // (in other words, we are going to defer this request 1132 | // until we have a corresponding write request to 1133 | // match it with) 1134 | // 1135 | 1136 | status = WdfRequestForwardToIoQueue(Request, DevContext->ReportQueue); 1137 | 1138 | if (!NT_SUCCESS(status)) 1139 | { 1140 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 1141 | "WdfRequestForwardToIoQueue failed Status 0x%x\n", status); 1142 | } 1143 | else 1144 | { 1145 | *CompleteRequest = FALSE; 1146 | } 1147 | 1148 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 1149 | "CrosKBLightReadReport Exit = 0x%x\n", status); 1150 | 1151 | return status; 1152 | } 1153 | 1154 | NTSTATUS 1155 | CrosKBLightSetFeature( 1156 | IN PCROSKBLIGHT_CONTEXT DevContext, 1157 | IN WDFREQUEST Request, 1158 | OUT BOOLEAN* CompleteRequest 1159 | ) 1160 | { 1161 | NTSTATUS status = STATUS_SUCCESS; 1162 | WDF_REQUEST_PARAMETERS params; 1163 | PHID_XFER_PACKET transferPacket = NULL; 1164 | CrosKBLightFeatureReport* pReport = NULL; 1165 | 1166 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 1167 | "CrosKBLightSetFeature Entry\n"); 1168 | 1169 | WDF_REQUEST_PARAMETERS_INIT(¶ms); 1170 | WdfRequestGetParameters(Request, ¶ms); 1171 | 1172 | if (params.Parameters.DeviceIoControl.InputBufferLength < sizeof(HID_XFER_PACKET)) 1173 | { 1174 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 1175 | "CrosKBLightSetFeature Xfer packet too small\n"); 1176 | 1177 | status = STATUS_BUFFER_TOO_SMALL; 1178 | } 1179 | else 1180 | { 1181 | 1182 | transferPacket = (PHID_XFER_PACKET)WdfRequestWdmGetIrp(Request)->UserBuffer; 1183 | 1184 | if (transferPacket == NULL) 1185 | { 1186 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 1187 | "CrosKBLightWriteReport No xfer packet\n"); 1188 | 1189 | status = STATUS_INVALID_DEVICE_REQUEST; 1190 | } 1191 | else 1192 | { 1193 | // 1194 | // switch on the report id 1195 | // 1196 | 1197 | switch (transferPacket->reportId) 1198 | { 1199 | default: 1200 | 1201 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 1202 | "CrosKBLightSetFeature Unhandled report type %d\n", transferPacket->reportId); 1203 | 1204 | status = STATUS_INVALID_PARAMETER; 1205 | 1206 | break; 1207 | } 1208 | } 1209 | } 1210 | 1211 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 1212 | "CrosKBLightSetFeature Exit = 0x%x\n", status); 1213 | 1214 | return status; 1215 | } 1216 | 1217 | NTSTATUS 1218 | CrosKBLightGetFeature( 1219 | IN PCROSKBLIGHT_CONTEXT DevContext, 1220 | IN WDFREQUEST Request, 1221 | OUT BOOLEAN* CompleteRequest 1222 | ) 1223 | { 1224 | NTSTATUS status = STATUS_SUCCESS; 1225 | WDF_REQUEST_PARAMETERS params; 1226 | PHID_XFER_PACKET transferPacket = NULL; 1227 | 1228 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 1229 | "CrosKBLightGetFeature Entry\n"); 1230 | 1231 | WDF_REQUEST_PARAMETERS_INIT(¶ms); 1232 | WdfRequestGetParameters(Request, ¶ms); 1233 | 1234 | if (params.Parameters.DeviceIoControl.OutputBufferLength < sizeof(HID_XFER_PACKET)) 1235 | { 1236 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 1237 | "CrosKBLightGetFeature Xfer packet too small\n"); 1238 | 1239 | status = STATUS_BUFFER_TOO_SMALL; 1240 | } 1241 | else 1242 | { 1243 | 1244 | transferPacket = (PHID_XFER_PACKET)WdfRequestWdmGetIrp(Request)->UserBuffer; 1245 | 1246 | if (transferPacket == NULL) 1247 | { 1248 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 1249 | "CrosKBLightGetFeature No xfer packet\n"); 1250 | 1251 | status = STATUS_INVALID_DEVICE_REQUEST; 1252 | } 1253 | else 1254 | { 1255 | // 1256 | // switch on the report id 1257 | // 1258 | 1259 | switch (transferPacket->reportId) 1260 | { 1261 | default: 1262 | 1263 | CrosKBLightPrint(DEBUG_LEVEL_ERROR, DBG_IOCTL, 1264 | "CrosKBLightGetFeature Unhandled report type %d\n", transferPacket->reportId); 1265 | 1266 | status = STATUS_INVALID_PARAMETER; 1267 | 1268 | break; 1269 | } 1270 | } 1271 | } 1272 | 1273 | CrosKBLightPrint(DEBUG_LEVEL_VERBOSE, DBG_IOCTL, 1274 | "CrosKBLightGetFeature Exit = 0x%x\n", status); 1275 | 1276 | return status; 1277 | } 1278 | 1279 | PCHAR 1280 | DbgHidInternalIoctlString( 1281 | IN ULONG IoControlCode 1282 | ) 1283 | { 1284 | switch (IoControlCode) 1285 | { 1286 | case IOCTL_HID_GET_DEVICE_DESCRIPTOR: 1287 | return "IOCTL_HID_GET_DEVICE_DESCRIPTOR"; 1288 | case IOCTL_HID_GET_REPORT_DESCRIPTOR: 1289 | return "IOCTL_HID_GET_REPORT_DESCRIPTOR"; 1290 | case IOCTL_HID_READ_REPORT: 1291 | return "IOCTL_HID_READ_REPORT"; 1292 | case IOCTL_HID_GET_DEVICE_ATTRIBUTES: 1293 | return "IOCTL_HID_GET_DEVICE_ATTRIBUTES"; 1294 | case IOCTL_HID_WRITE_REPORT: 1295 | return "IOCTL_HID_WRITE_REPORT"; 1296 | case IOCTL_HID_SET_FEATURE: 1297 | return "IOCTL_HID_SET_FEATURE"; 1298 | case IOCTL_HID_GET_FEATURE: 1299 | return "IOCTL_HID_GET_FEATURE"; 1300 | case IOCTL_HID_GET_STRING: 1301 | return "IOCTL_HID_GET_STRING"; 1302 | case IOCTL_HID_ACTIVATE_DEVICE: 1303 | return "IOCTL_HID_ACTIVATE_DEVICE"; 1304 | case IOCTL_HID_DEACTIVATE_DEVICE: 1305 | return "IOCTL_HID_DEACTIVATE_DEVICE"; 1306 | case IOCTL_HID_SEND_IDLE_NOTIFICATION_REQUEST: 1307 | return "IOCTL_HID_SEND_IDLE_NOTIFICATION_REQUEST"; 1308 | case IOCTL_HID_SET_OUTPUT_REPORT: 1309 | return "IOCTL_HID_SET_OUTPUT_REPORT"; 1310 | case IOCTL_HID_GET_INPUT_REPORT: 1311 | return "IOCTL_HID_GET_INPUT_REPORT"; 1312 | default: 1313 | return "Unknown IOCTL"; 1314 | } 1315 | } 1316 | --------------------------------------------------------------------------------