├── .gitattributes ├── LICENSE.txt ├── README.md ├── croseci2c ├── trace.h ├── croseci2c.inf ├── mdlchain.c ├── croseci2c.h ├── driver.h ├── croseci2c.c └── croseci2c.vcxproj ├── croseci2c.sln ├── .gitignore └── croseci2c Package └── croseci2c Package.vcxproj /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2022 CoolStar 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Chrome EC I2C Tunnel Driver 2 | 3 | * NOTE: This driver requires the https://github.com/coolstar/crosecbus driver to be present, as well as the correct ACPI tables set up by coreboot 4 | 5 | Implements Windows's SPB protocol so most existing I2C drivers should attach and work as child devices off this driver 6 | 7 | Tested operations: 8 | * Connect 9 | * Read 10 | * Write 11 | 12 | Implemented but untested: 13 | * Sequence 14 | 15 | Do note that EC I2C tunnelling is going to be slower than a proper I2C bus. I2C drivers attaching off this should minimize the number of transactions if possible 16 | 17 | Requires Windows 10 1607 or higher (Uses ACPI `_DSD` method) 18 | 19 | Tested with rt5682 driver on HP Chromebook 14b (Ryzen 3 3250C) -------------------------------------------------------------------------------- /croseci2c/trace.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef _TRACE_H_ 4 | #define _TRACE_H_ 5 | 6 | extern "C" 7 | { 8 | // 9 | // Tracing Definitions: 10 | // 11 | // Control GUID: 12 | // {73e3b785-f5fb-423e-94a9-56627fea9053} 13 | // 14 | 15 | #define WPP_CONTROL_GUIDS \ 16 | WPP_DEFINE_CONTROL_GUID( \ 17 | SpbTestToolTraceGuid, \ 18 | (73e3b785,f5fb,423e,94a9,56627fea9053), \ 19 | WPP_DEFINE_BIT(TRACE_FLAG_WDFLOADING) \ 20 | WPP_DEFINE_BIT(TRACE_FLAG_SPBAPI) \ 21 | WPP_DEFINE_BIT(TRACE_FLAG_OTHER) \ 22 | ) 23 | } 24 | 25 | #define WPP_LEVEL_FLAGS_LOGGER(level,flags) WPP_LEVEL_LOGGER(flags) 26 | #define WPP_LEVEL_FLAGS_ENABLED(level, flags) (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_ ## flags).Level >= level) 27 | 28 | #define Trace CyapaPrint 29 | #define FuncEntry 30 | #define FuncExit 31 | #define WPP_INIT_TRACING 32 | #define WPP_CLEANUP 33 | #define TRACE_FLAG_SPBAPI 0 34 | #define TRACE_FLAG_WDFLOADING 0 35 | 36 | // begin_wpp config 37 | // FUNC FuncEntry{LEVEL=TRACE_LEVEL_VERBOSE}(FLAGS); 38 | // FUNC FuncExit{LEVEL=TRACE_LEVEL_VERBOSE}(FLAGS); 39 | // USEPREFIX(FuncEntry, "%!STDPREFIX! [%!FUNC!] --> entry"); 40 | // USEPREFIX(FuncExit, "%!STDPREFIX! [%!FUNC!] <--"); 41 | // end_wpp 42 | 43 | #endif _TRACE_H_ 44 | -------------------------------------------------------------------------------- /croseci2c/croseci2c.inf: -------------------------------------------------------------------------------- 1 | ;/*++ 2 | ; 3 | ;Copyright (c) CoolStar. All rights reserved. 4 | ; 5 | ;Module Name: 6 | ; croseci2c.inf 7 | ; 8 | ;Abstract: 9 | ; INF file for installing the CR50 I2C Driver 10 | ; 11 | ; 12 | ;--*/ 13 | 14 | [Version] 15 | Signature = "$WINDOWS NT$" 16 | Class = System 17 | ClassGuid = {4d36e97d-e325-11ce-bfc1-08002be10318} 18 | Provider = CoolStar 19 | DriverVer = 12/16/2021,1.0.0 20 | CatalogFile = croseci2c.cat 21 | PnpLockdown = 1 22 | 23 | [DestinationDirs] 24 | DefaultDestDir = 12 25 | 26 | ; ================= Class section ===================== 27 | 28 | [SourceDisksNames] 29 | 1 = %DiskId1%,,,"" 30 | 31 | [SourceDisksFiles] 32 | croseci2c.sys = 1,, 33 | 34 | ;***************************************** 35 | ; CrosEcI2C Install Section 36 | ;***************************************** 37 | 38 | [Manufacturer] 39 | %StdMfg%=Standard,NT$ARCH$.10.0...14393 40 | 41 | ; Decorated model section take precedence over undecorated 42 | ; ones on XP and later. 43 | [Standard.NT$ARCH$.10.0...14393] 44 | %CrosEcI2C.DeviceDesc%=CrosEcI2C_Device, ACPI\GOOG0012 45 | 46 | [CrosEcI2C_Device.NT] 47 | CopyFiles=Drivers_Dir 48 | 49 | [CrosEcI2C_Device.NT.HW] 50 | AddReg=CrosEcI2C_AddReg 51 | 52 | [Drivers_Dir] 53 | croseci2c.sys 54 | 55 | [CrosEcI2C_AddReg] 56 | ; Set to 1 to connect the first interrupt resource found, 0 to leave disconnected 57 | HKR,Settings,"ConnectInterrupt",0x00010001,0 58 | 59 | ;-------------- Service installation 60 | [CrosEcI2C_Device.NT.Services] 61 | AddService = CrosEcI2C,%SPSVCINST_ASSOCSERVICE%, CrosEcI2C_Service_Inst 62 | 63 | ; -------------- CrosEcI2C driver install sections 64 | [CrosEcI2C_Service_Inst] 65 | DisplayName = %CrosEcI2C.SVCDESC% 66 | ServiceType = 1 ; SERVICE_KERNEL_DRIVER 67 | StartType = 3 ; SERVICE_DEMAND_START 68 | ErrorControl = 1 ; SERVICE_ERROR_NORMAL 69 | ServiceBinary = %12%\croseci2c.sys 70 | LoadOrderGroup = Base 71 | 72 | [Strings] 73 | SPSVCINST_ASSOCSERVICE= 0x00000002 74 | StdMfg = "CoolStar" 75 | DiskId1 = "Chrome EC Installation Disk #1" 76 | CrosEcI2C.DeviceDesc = "Chromebook EC I2C" 77 | CrosEcI2C.SVCDESC = "Chrome EC Service" 78 | -------------------------------------------------------------------------------- /croseci2c/mdlchain.c: -------------------------------------------------------------------------------- 1 | #include "driver.h" 2 | 3 | NTSTATUS 4 | MdlChainGetByte( 5 | PMDL pMdlChain, 6 | size_t Length, 7 | size_t Index, 8 | UCHAR* pByte) 9 | { 10 | PMDL mdl = pMdlChain; 11 | size_t mdlByteCount; 12 | size_t currentOffset = Index; 13 | PUCHAR pBuffer; 14 | NTSTATUS status = STATUS_INFO_LENGTH_MISMATCH; 15 | 16 | // Check for out-of-bounds index 17 | 18 | if (Index < Length) { 19 | 20 | while (mdl != NULL) { 21 | 22 | mdlByteCount = MmGetMdlByteCount(mdl); 23 | 24 | if (currentOffset < mdlByteCount) { 25 | 26 | pBuffer = (PUCHAR)MmGetSystemAddressForMdlSafe(mdl, 27 | NormalPagePriority | 28 | MdlMappingNoExecute); 29 | 30 | if (pBuffer != NULL) { 31 | 32 | // Byte found, mark successful 33 | 34 | *pByte = pBuffer[currentOffset]; 35 | status = STATUS_SUCCESS; 36 | } 37 | 38 | break; 39 | } 40 | 41 | currentOffset -= mdlByteCount; 42 | mdl = mdl->Next; 43 | } 44 | 45 | // If after walking the MDL the byte hasn't been found, 46 | // status will still be STATUS_INFO_LENGTH_MISMATCH 47 | } 48 | 49 | return status; 50 | } 51 | 52 | NTSTATUS 53 | MdlChainSetByte( 54 | PMDL pMdlChain, 55 | size_t Length, 56 | size_t Index, 57 | UCHAR Byte 58 | ) 59 | { 60 | PMDL mdl = pMdlChain; 61 | size_t mdlByteCount; 62 | size_t currentOffset = Index; 63 | PUCHAR pBuffer; 64 | NTSTATUS status = STATUS_INFO_LENGTH_MISMATCH; 65 | 66 | // Check for out-of-bounds index 67 | 68 | if (Index < Length) { 69 | 70 | while (mdl != NULL) { 71 | 72 | mdlByteCount = MmGetMdlByteCount(mdl); 73 | 74 | if (currentOffset < mdlByteCount) { 75 | 76 | pBuffer = (PUCHAR)MmGetSystemAddressForMdlSafe(mdl, 77 | NormalPagePriority | 78 | MdlMappingNoExecute); 79 | 80 | if (pBuffer != NULL) { 81 | 82 | // Byte found, mark successful 83 | 84 | pBuffer[currentOffset] = Byte; 85 | status = STATUS_SUCCESS; 86 | } 87 | 88 | break; 89 | } 90 | 91 | currentOffset -= mdlByteCount; 92 | mdl = mdl->Next; 93 | } 94 | 95 | // If after walking the MDL the byte hasn't been found, 96 | // status will still be STATUS_INFO_LENGTH_MISMATCH 97 | } 98 | 99 | return status; 100 | } -------------------------------------------------------------------------------- /croseci2c/croseci2c.h: -------------------------------------------------------------------------------- 1 | #ifndef __CROS_EC_REGS_H__ 2 | #define __CROS_EC_REGS_H__ 3 | 4 | #define BIT(nr) (1UL << (nr)) 5 | 6 | typedef enum ADDRESS_MODE 7 | { 8 | AddressMode7Bit, 9 | AddressMode10Bit 10 | } 11 | ADDRESS_MODE, * PADDRESS_MODE; 12 | 13 | typedef struct PBC_TARGET_SETTINGS 14 | { 15 | // TODO: Update this structure to include other 16 | // target settings needed to configure the 17 | // controller (i.e. connection speed, phase/ 18 | // polarity for SPI). 19 | 20 | ADDRESS_MODE AddressMode; 21 | USHORT Address; 22 | ULONG ConnectionSpeed; 23 | } 24 | PBC_TARGET_SETTINGS, * PPBC_TARGET_SETTINGS; 25 | 26 | ///////////////////////////////////////////////// 27 | // 28 | // Context definitions. 29 | // 30 | ///////////////////////////////////////////////// 31 | 32 | typedef struct PBC_TARGET PBC_TARGET, * PPBC_TARGET; 33 | 34 | struct PBC_TARGET 35 | { 36 | // TODO: Update this structure with variables that 37 | // need to be stored in the target context. 38 | 39 | // Handle to the SPB target. 40 | SPBTARGET SpbTarget; 41 | 42 | // Target specific settings. 43 | PBC_TARGET_SETTINGS Settings; 44 | }; 45 | 46 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(PBC_TARGET, GetTargetContext); 47 | 48 | #define I2C_SERIAL_BUS_TYPE 0x01 49 | #define I2C_SERIAL_BUS_SPECIFIC_FLAG_10BIT_ADDRESS 0x0001 50 | 51 | /* I2C passthru command */ 52 | 53 | #define EC_CMD_I2C_PASSTHRU 0x009E 54 | 55 | /* Read data; if not present, message is a write */ 56 | #define EC_I2C_FLAG_READ BIT(15) 57 | 58 | /* Mask for address */ 59 | #define EC_I2C_ADDR_MASK 0x3ff 60 | 61 | #define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */ 62 | #define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */ 63 | 64 | /* Any error */ 65 | #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT) 66 | 67 | /** 68 | * struct cros_ec_command - Information about a ChromeOS EC command. 69 | * @version: Command version number (often 0). 70 | * @command: Command to send (EC_CMD_...). 71 | * @outsize: Outgoing length in bytes. 72 | * @insize: Max number of bytes to accept from the EC. 73 | * @result: EC's response to the command (separate from communication failure). 74 | * @data: Where to put the incoming data from EC and outgoing data to EC. 75 | */ 76 | struct cros_ec_command { 77 | UINT32 version; 78 | UINT32 command; 79 | UINT32 outsize; 80 | UINT32 insize; 81 | UINT32 result; 82 | UINT8 data[]; 83 | }; 84 | 85 | #include 86 | 87 | struct ec_params_i2c_passthru_msg { 88 | UINT16 addr_flags; /* I2C slave address (7 or 10 bits) and flags */ 89 | UINT16 len; /* Number of bytes to read or write */ 90 | }; 91 | 92 | struct ec_params_i2c_passthru { 93 | UINT8 port; /* I2C port number */ 94 | UINT8 num_msgs; /* Number of messages */ 95 | struct ec_params_i2c_passthru_msg msg[]; 96 | /* Data to write for all messages is concatenated here */ 97 | }; 98 | 99 | #include 100 | #include 101 | 102 | struct ec_response_i2c_passthru { 103 | UINT8 i2c_status; /* Status flags (EC_I2C_STATUS_...) */ 104 | UINT8 num_msgs; /* Number of messages processed */ 105 | UINT8 data[]; /* Data read by messages concatenated here */ 106 | }; 107 | 108 | #include 109 | 110 | NTSTATUS 111 | MdlChainGetByte( 112 | PMDL pMdlChain, 113 | size_t Length, 114 | size_t Index, 115 | UCHAR* pByte); 116 | 117 | NTSTATUS 118 | MdlChainSetByte( 119 | PMDL pMdlChain, 120 | size_t Length, 121 | size_t Index, 122 | UCHAR Byte 123 | ); 124 | 125 | #endif /* __CROS_EC_REGS_H__ */ -------------------------------------------------------------------------------- /croseci2c/driver.h: -------------------------------------------------------------------------------- 1 | #if !defined(_CROSECI2C_H_) 2 | #define _CROSECI2C_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 | #include 15 | #include 16 | 17 | #define RESHUB_USE_HELPER_ROUTINES 18 | #include 19 | #include 20 | 21 | typedef struct _PNP_I2C_SERIAL_BUS_DESCRIPTOR { 22 | PNP_SERIAL_BUS_DESCRIPTOR SerialBusDescriptor; 23 | ULONG ConnectionSpeed; 24 | USHORT SlaveAddress; 25 | // follwed by optional Vendor Data 26 | // followed by PNP_IO_DESCRIPTOR_RESOURCE_NAME 27 | } PNP_I2C_SERIAL_BUS_DESCRIPTOR, * PPNP_I2C_SERIAL_BUS_DESCRIPTOR; 28 | 29 | #include 30 | 31 | #include "croseci2c.h" 32 | 33 | // 34 | // String definitions 35 | // 36 | 37 | #define DRIVERNAME "croseci2c.sys: " 38 | 39 | #define CROSECI2C_POOL_TAG (ULONG) 'CRI2' 40 | #define CROSECI2C_HARDWARE_IDS L"CoolStar\\GOOG0012\0\0" 41 | #define CROSECI2C_HARDWARE_IDS_LENGTH sizeof(CROSECI2C_HARDWARE_IDS) 42 | 43 | #define NTDEVICE_NAME_STRING L"\\Device\\GOOG0012" 44 | #define SYMBOLIC_NAME_STRING L"\\DosDevices\\GOOG0012" 45 | 46 | #define true 1 47 | #define false 0 48 | 49 | typedef struct _CROSEC_COMMAND { 50 | UINT32 Version; 51 | UINT32 Command; 52 | UINT32 OutSize; 53 | UINT32 InSize; 54 | UINT32 Result; 55 | UINT8 Data[]; 56 | } CROSEC_COMMAND, *PCROSEC_COMMAND; 57 | 58 | typedef 59 | NTSTATUS 60 | (*PCROSEC_CMD_XFER_STATUS)( 61 | IN PVOID Context, 62 | OUT PCROSEC_COMMAND Msg 63 | ); 64 | 65 | typedef 66 | BOOLEAN 67 | (*PCROSEC_CHECK_FEATURES)( 68 | IN PVOID Context, 69 | IN INT Feature 70 | ); 71 | 72 | DEFINE_GUID(GUID_CROSEC_INTERFACE_STANDARD, 73 | 0xd7062676, 0xe3a4, 0x11ec, 0xa6, 0xc4, 0x24, 0x4b, 0xfe, 0x99, 0x46, 0xd0); 74 | 75 | /*DEFINE_GUID(GUID_DEVICE_PROPERTIES, 76 | 0xdaffd814, 0x6eba, 0x4d8c, 0x8a, 0x91, 0xbc, 0x9b, 0xbf, 0x4a, 0xa3, 0x01);*/ //Windows defender false positive 77 | 78 | // 79 | // Interface for getting and setting power level etc., 80 | // 81 | typedef struct _CROSEC_INTERFACE_STANDARD { 82 | INTERFACE InterfaceHeader; 83 | PCROSEC_CMD_XFER_STATUS CmdXferStatus; 84 | PCROSEC_CHECK_FEATURES CheckFeatures; 85 | } CROSEC_INTERFACE_STANDARD, * PCROSEC_INTERFACE_STANDARD; 86 | 87 | typedef struct _CROSECI2C_CONTEXT 88 | { 89 | // 90 | // Handle back to the WDFDEVICE 91 | // 92 | 93 | WDFDEVICE FxDevice; 94 | 95 | PVOID CrosEcBusContext; 96 | 97 | PCROSEC_CMD_XFER_STATUS CrosEcCmdXferStatus; 98 | 99 | WDFIOTARGET busIoTarget; 100 | 101 | UINT8 busNumber; 102 | 103 | } CROSECI2C_CONTEXT, *PCROSECI2C_CONTEXT; 104 | 105 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(CROSECI2C_CONTEXT, GetDeviceContext) 106 | 107 | // 108 | // Function definitions 109 | // 110 | 111 | DRIVER_INITIALIZE DriverEntry; 112 | 113 | EVT_WDF_DRIVER_UNLOAD CrosEcI2CDriverUnload; 114 | 115 | EVT_WDF_DRIVER_DEVICE_ADD CrosEcI2CEvtDeviceAdd; 116 | 117 | EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL CrosEcI2CEvtInternalDeviceControl; 118 | 119 | // 120 | // Helper macros 121 | // 122 | 123 | #define DEBUG_LEVEL_ERROR 1 124 | #define DEBUG_LEVEL_INFO 2 125 | #define DEBUG_LEVEL_VERBOSE 3 126 | 127 | #define DBG_INIT 1 128 | #define DBG_PNP 2 129 | #define DBG_IOCTL 4 130 | 131 | #if 0 132 | #define CrosEcI2CPrint(dbglevel, dbgcatagory, fmt, ...) { \ 133 | if (CrosEcI2CDebugLevel >= dbglevel && \ 134 | (CrosEcI2CDebugCatagories && dbgcatagory)) \ 135 | { \ 136 | DbgPrint(DRIVERNAME); \ 137 | DbgPrint(fmt, __VA_ARGS__); \ 138 | } \ 139 | } 140 | #else 141 | #define CrosEcI2CPrint(dbglevel, fmt, ...) { \ 142 | } 143 | #endif 144 | #endif -------------------------------------------------------------------------------- /croseci2c.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}") = "croseci2c", "croseci2c\croseci2c.vcxproj", "{B3E71397-9BE4-492B-AAED-4D056E59CB1F}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "croseci2c Package", "croseci2c Package\croseci2c Package.vcxproj", "{EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F} = {B3E71397-9BE4-492B-AAED-4D056E59CB1F} 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Win10 Debug|Win32 = Win10 Debug|Win32 16 | Win10 Debug|x64 = Win10 Debug|x64 17 | Win10 Release|Win32 = Win10 Release|Win32 18 | Win10 Release|x64 = Win10 Release|x64 19 | Win8.1 Debug|Win32 = Win8.1 Debug|Win32 20 | Win8.1 Debug|x64 = Win8.1 Debug|x64 21 | Win8.1 Release|Win32 = Win8.1 Release|Win32 22 | Win8.1 Release|x64 = Win8.1 Release|x64 23 | EndGlobalSection 24 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 25 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win10 Debug|Win32.ActiveCfg = Win10 Debug|Win32 26 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win10 Debug|Win32.Build.0 = Win10 Debug|Win32 27 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win10 Debug|Win32.Deploy.0 = Win10 Debug|Win32 28 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win10 Debug|x64.ActiveCfg = Win10 Debug|x64 29 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win10 Debug|x64.Build.0 = Win10 Debug|x64 30 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win10 Debug|x64.Deploy.0 = Win10 Debug|x64 31 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win10 Release|Win32.ActiveCfg = Win10 Release|Win32 32 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win10 Release|Win32.Build.0 = Win10 Release|Win32 33 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win10 Release|Win32.Deploy.0 = Win10 Release|Win32 34 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win10 Release|x64.ActiveCfg = Win10 Release|x64 35 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win10 Release|x64.Build.0 = Win10 Release|x64 36 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win10 Release|x64.Deploy.0 = Win10 Release|x64 37 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win8.1 Debug|Win32.ActiveCfg = Win8.1 Debug|Win32 38 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win8.1 Debug|Win32.Build.0 = Win8.1 Debug|Win32 39 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win8.1 Debug|Win32.Deploy.0 = Win8.1 Debug|Win32 40 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win8.1 Debug|x64.ActiveCfg = Win8 Debug|x64 41 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win8.1 Debug|x64.Build.0 = Win8 Debug|x64 42 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win8.1 Debug|x64.Deploy.0 = Win8 Debug|x64 43 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win8.1 Release|Win32.ActiveCfg = Win8.1 Release|Win32 44 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win8.1 Release|Win32.Build.0 = Win8.1 Release|Win32 45 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win8.1 Release|Win32.Deploy.0 = Win8.1 Release|Win32 46 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win8.1 Release|x64.ActiveCfg = Win8.1 Release|x64 47 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win8.1 Release|x64.Build.0 = Win8.1 Release|x64 48 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F}.Win8.1 Release|x64.Deploy.0 = Win8.1 Release|x64 49 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win10 Debug|Win32.ActiveCfg = Win10 Debug|Win32 50 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win10 Debug|Win32.Build.0 = Win10 Debug|Win32 51 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win10 Debug|Win32.Deploy.0 = Win10 Debug|Win32 52 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win10 Debug|x64.ActiveCfg = Win10 Debug|x64 53 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win10 Debug|x64.Build.0 = Win10 Debug|x64 54 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win10 Debug|x64.Deploy.0 = Win10 Debug|x64 55 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win10 Release|Win32.ActiveCfg = Win10 Release|Win32 56 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win10 Release|Win32.Build.0 = Win10 Release|Win32 57 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win10 Release|Win32.Deploy.0 = Win10 Release|Win32 58 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win10 Release|x64.ActiveCfg = Win10 Release|x64 59 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win10 Release|x64.Build.0 = Win10 Release|x64 60 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win10 Release|x64.Deploy.0 = Win10 Release|x64 61 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win8.1 Debug|Win32.ActiveCfg = Win8.1 Debug|Win32 62 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win8.1 Debug|Win32.Build.0 = Win8.1 Debug|Win32 63 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win8.1 Debug|Win32.Deploy.0 = Win8.1 Debug|Win32 64 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win8.1 Debug|x64.ActiveCfg = Win8 Debug|x64 65 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win8.1 Debug|x64.Build.0 = Win8 Debug|x64 66 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win8.1 Debug|x64.Deploy.0 = Win8 Debug|x64 67 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win8.1 Release|Win32.ActiveCfg = Win8.1 Release|Win32 68 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win8.1 Release|Win32.Build.0 = Win8.1 Release|Win32 69 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win8.1 Release|Win32.Deploy.0 = Win8.1 Release|Win32 70 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win8.1 Release|x64.ActiveCfg = Win8.1 Release|x64 71 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win8.1 Release|x64.Build.0 = Win8.1 Release|x64 72 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B}.Win8.1 Release|x64.Deploy.0 = Win8.1 Release|x64 73 | EndGlobalSection 74 | GlobalSection(SolutionProperties) = preSolution 75 | HideSolutionNode = FALSE 76 | EndGlobalSection 77 | GlobalSection(ExtensibilityGlobals) = postSolution 78 | SolutionGuid = {86D249D6-FF1E-41F4-AA9B-3813428D6C1A} 79 | EndGlobalSection 80 | EndGlobal 81 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /croseci2c Package/croseci2c Package.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Win10 Debug 6 | Win32 7 | 8 | 9 | Win10 Debug 10 | x64 11 | 12 | 13 | Win10 Release 14 | Win32 15 | 16 | 17 | Win10 Release 18 | x64 19 | 20 | 21 | Win8.1 Debug 22 | Win32 23 | 24 | 25 | Win8.1 Release 26 | Win32 27 | 28 | 29 | Win8 Debug 30 | Win32 31 | 32 | 33 | Win8 Release 34 | Win32 35 | 36 | 37 | Win8.1 Debug 38 | x64 39 | 40 | 41 | Win8.1 Release 42 | x64 43 | 44 | 45 | Win8 Debug 46 | x64 47 | 48 | 49 | Win8 Release 50 | x64 51 | 52 | 53 | 54 | {EA676041-89D8-4ACF-A48B-F11CA9F5DD8B} 55 | {4605da2c-74a5-4865-98e1-152ef136825f} 56 | v4.5 57 | 11.0 58 | Win8.1 Debug 59 | Win32 60 | croseci2c_Package 61 | 10.0.22000.0 62 | croseci2c Package 63 | 64 | 65 | 66 | WindowsV6.3 67 | true 68 | WindowsKernelModeDriver10.0 69 | Utility 70 | Package 71 | true 72 | 73 | 74 | WindowsV6.3 75 | false 76 | WindowsKernelModeDriver10.0 77 | Utility 78 | Package 79 | true 80 | 81 | 82 | WindowsV6.3 83 | false 84 | WindowsKernelModeDriver10.0 85 | Utility 86 | Package 87 | true 88 | 89 | 90 | Windows8 91 | true 92 | WindowsKernelModeDriver10.0 93 | Utility 94 | Package 95 | true 96 | 97 | 98 | Windows8 99 | true 100 | WindowsKernelModeDriver10.0 101 | Utility 102 | Package 103 | true 104 | 105 | 106 | Windows8 107 | false 108 | WindowsKernelModeDriver10.0 109 | Utility 110 | Package 111 | true 112 | 113 | 114 | WindowsV6.3 115 | true 116 | WindowsKernelModeDriver10.0 117 | Utility 118 | Package 119 | true 120 | 121 | 122 | WindowsV6.3 123 | false 124 | WindowsKernelModeDriver10.0 125 | Utility 126 | Package 127 | true 128 | 129 | 130 | WindowsV6.3 131 | false 132 | WindowsKernelModeDriver10.0 133 | Utility 134 | Package 135 | true 136 | 137 | 138 | Windows8 139 | true 140 | WindowsKernelModeDriver10.0 141 | Utility 142 | Package 143 | true 144 | 145 | 146 | Windows8 147 | true 148 | WindowsKernelModeDriver10.0 149 | Utility 150 | Package 151 | true 152 | 153 | 154 | Windows8 155 | false 156 | WindowsKernelModeDriver10.0 157 | Utility 158 | Package 159 | true 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | DbgengKernelDebugger 171 | False 172 | True 173 | 174 | 175 | 176 | False 177 | False 178 | True 179 | 180 | 133563 181 | 182 | 183 | DbgengKernelDebugger 184 | False 185 | True 186 | 187 | 188 | 189 | False 190 | False 191 | True 192 | 193 | 133563 194 | 195 | 196 | DbgengKernelDebugger 197 | False 198 | True 199 | 200 | 201 | 202 | False 203 | False 204 | True 205 | 206 | 133563 207 | 208 | 209 | DbgengKernelDebugger 210 | False 211 | True 212 | 213 | 214 | 215 | False 216 | False 217 | True 218 | 219 | 133563 220 | 221 | 222 | DbgengKernelDebugger 223 | False 224 | True 225 | 226 | 227 | 228 | False 229 | False 230 | True 231 | 232 | 133563 233 | 234 | 235 | DbgengKernelDebugger 236 | False 237 | True 238 | 239 | 240 | 241 | False 242 | False 243 | True 244 | 245 | 133563 246 | 247 | 248 | DbgengKernelDebugger 249 | False 250 | True 251 | 252 | 253 | 254 | False 255 | False 256 | True 257 | 258 | 133563 259 | 260 | 261 | DbgengKernelDebugger 262 | False 263 | True 264 | 265 | 266 | 267 | False 268 | False 269 | True 270 | 271 | 133563 272 | 273 | 274 | DbgengKernelDebugger 275 | False 276 | True 277 | 278 | 279 | 280 | False 281 | False 282 | True 283 | 284 | 133563 285 | 286 | 287 | DbgengKernelDebugger 288 | False 289 | True 290 | 291 | 292 | 293 | False 294 | False 295 | True 296 | 297 | 133563 298 | 299 | 300 | DbgengKernelDebugger 301 | False 302 | True 303 | 304 | 305 | 306 | False 307 | False 308 | True 309 | 310 | 133563 311 | 312 | 313 | DbgengKernelDebugger 314 | False 315 | True 316 | 317 | 318 | 319 | False 320 | False 321 | True 322 | 323 | 133563 324 | 325 | 326 | 327 | SHA256 328 | 329 | 330 | 331 | 332 | SHA256 333 | 334 | 335 | 336 | 337 | SHA256 338 | 339 | 340 | 341 | 342 | SHA256 343 | 344 | 345 | 346 | 347 | SHA256 348 | 349 | 350 | 351 | 352 | SHA256 353 | 354 | 355 | 356 | 357 | SHA256 358 | 359 | 360 | 361 | 362 | SHA256 363 | 364 | 365 | 366 | 367 | SHA256 368 | 369 | 370 | 371 | 372 | SHA256 373 | 374 | 375 | 376 | 377 | SHA256 378 | 379 | 380 | 381 | 382 | SHA256 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | {b3e71397-9be4-492b-aaed-4d056e59cb1f} 391 | 392 | 393 | 394 | 395 | 396 | -------------------------------------------------------------------------------- /croseci2c/croseci2c.c: -------------------------------------------------------------------------------- 1 | #define DESCRIPTOR_DEF 2 | #include "driver.h" 3 | #include "stdint.h" 4 | 5 | #define bool int 6 | #define MS_IN_US 1000 7 | 8 | static ULONG CrosEcI2CDebugLevel = 100; 9 | static ULONG CrosEcI2CDebugCatagories = DBG_INIT || DBG_PNP || DBG_IOCTL; 10 | 11 | NTSTATUS 12 | DriverEntry( 13 | __in PDRIVER_OBJECT DriverObject, 14 | __in PUNICODE_STRING RegistryPath 15 | ) 16 | { 17 | NTSTATUS status = STATUS_SUCCESS; 18 | WDF_DRIVER_CONFIG config; 19 | WDF_OBJECT_ATTRIBUTES attributes; 20 | 21 | CrosEcI2CPrint(DEBUG_LEVEL_INFO, DBG_INIT, 22 | "Driver Entry\n"); 23 | 24 | WDF_DRIVER_CONFIG_INIT(&config, CrosEcI2CEvtDeviceAdd); 25 | 26 | WDF_OBJECT_ATTRIBUTES_INIT(&attributes); 27 | 28 | // 29 | // Create a framework driver object to represent our driver. 30 | // 31 | 32 | status = WdfDriverCreate(DriverObject, 33 | RegistryPath, 34 | &attributes, 35 | &config, 36 | WDF_NO_HANDLE 37 | ); 38 | 39 | if (!NT_SUCCESS(status)) 40 | { 41 | CrosEcI2CPrint(DEBUG_LEVEL_ERROR, DBG_INIT, 42 | "WdfDriverCreate failed with status 0x%x\n", status); 43 | } 44 | 45 | return status; 46 | } 47 | 48 | static NTSTATUS GetBusInformation( 49 | _In_ WDFDEVICE FxDevice 50 | ) { 51 | PCROSECI2C_CONTEXT pDevice = GetDeviceContext(FxDevice); 52 | WDFMEMORY outputMemory = WDF_NO_HANDLE; 53 | 54 | NTSTATUS status = STATUS_ACPI_NOT_INITIALIZED; 55 | char* propertyStr = "google,remote-bus"; 56 | 57 | size_t inputBufferLen = sizeof(ACPI_GET_DEVICE_SPECIFIC_DATA) + strlen(propertyStr) + 1; 58 | ACPI_GET_DEVICE_SPECIFIC_DATA* inputBuffer = ExAllocatePoolWithTag(NonPagedPool, inputBufferLen, CROSECI2C_POOL_TAG); 59 | if (!inputBuffer) { 60 | goto Exit; 61 | } 62 | RtlZeroMemory(inputBuffer, inputBufferLen); 63 | 64 | inputBuffer->Signature = IOCTL_ACPI_GET_DEVICE_SPECIFIC_DATA_SIGNATURE; 65 | 66 | unsigned char uuidend[] = { 0x8a, 0x91, 0xbc, 0x9b, 0xbf, 0x4a, 0xa3, 0x01 }; 67 | 68 | inputBuffer->Section.Data1 = 0xdaffd814; 69 | inputBuffer->Section.Data2 = 0x6eba; 70 | inputBuffer->Section.Data3 = 0x4d8c; 71 | memcpy(inputBuffer->Section.Data4, uuidend, sizeof(uuidend)); //Avoid Windows defender false positive 72 | 73 | strcpy(inputBuffer->PropertyName, propertyStr); 74 | inputBuffer->PropertyNameLength = strlen(propertyStr) + 1; 75 | 76 | PACPI_EVAL_OUTPUT_BUFFER outputBuffer; 77 | size_t outputArgumentBufferSize = 8; 78 | size_t outputBufferSize = FIELD_OFFSET(ACPI_EVAL_OUTPUT_BUFFER, Argument) + sizeof(ACPI_METHOD_ARGUMENT_V1) + outputArgumentBufferSize; 79 | 80 | WDF_OBJECT_ATTRIBUTES attributes; 81 | WDF_OBJECT_ATTRIBUTES_INIT(&attributes); 82 | attributes.ParentObject = FxDevice; 83 | status = WdfMemoryCreate(&attributes, 84 | NonPagedPoolNx, 85 | 0, 86 | outputBufferSize, 87 | &outputMemory, 88 | &outputBuffer); 89 | if (!NT_SUCCESS(status)) { 90 | goto Exit; 91 | } 92 | 93 | WDF_MEMORY_DESCRIPTOR inputMemDesc; 94 | WDF_MEMORY_DESCRIPTOR outputMemDesc; 95 | WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&inputMemDesc, inputBuffer, (ULONG)inputBufferLen); 96 | WDF_MEMORY_DESCRIPTOR_INIT_HANDLE(&outputMemDesc, outputMemory, NULL); 97 | 98 | status = WdfIoTargetSendInternalIoctlSynchronously( 99 | WdfDeviceGetIoTarget(FxDevice), 100 | NULL, 101 | IOCTL_ACPI_GET_DEVICE_SPECIFIC_DATA, 102 | &inputMemDesc, 103 | &outputMemDesc, 104 | NULL, 105 | NULL 106 | ); 107 | if (!NT_SUCCESS(status)) { 108 | CrosEcI2CPrint( 109 | DEBUG_LEVEL_ERROR, 110 | DBG_IOCTL, 111 | "Error getting device data - 0x%x\n", 112 | status); 113 | goto Exit; 114 | } 115 | 116 | if (outputBuffer->Signature != ACPI_EVAL_OUTPUT_BUFFER_SIGNATURE_V1 && 117 | outputBuffer->Count < 1 && 118 | outputBuffer->Argument->Type != ACPI_METHOD_ARGUMENT_INTEGER && 119 | outputBuffer->Argument->DataLength < 1) { 120 | status = STATUS_ACPI_INVALID_ARGUMENT; 121 | goto Exit; 122 | } 123 | 124 | pDevice->busNumber = outputBuffer->Argument->Data[0]; 125 | 126 | Exit: 127 | if (inputBuffer) { 128 | ExFreePoolWithTag(inputBuffer, CROSECI2C_POOL_TAG); 129 | } 130 | if (outputMemory != WDF_NO_HANDLE) { 131 | WdfObjectDelete(outputMemory); 132 | } 133 | return status; 134 | } 135 | 136 | NTSTATUS ConnectToEc( 137 | _In_ WDFDEVICE FxDevice 138 | ) { 139 | PCROSECI2C_CONTEXT pDevice = GetDeviceContext(FxDevice); 140 | WDF_OBJECT_ATTRIBUTES objectAttributes; 141 | 142 | WDF_OBJECT_ATTRIBUTES_INIT(&objectAttributes); 143 | objectAttributes.ParentObject = FxDevice; 144 | 145 | NTSTATUS status = WdfIoTargetCreate(FxDevice, 146 | &objectAttributes, 147 | &pDevice->busIoTarget 148 | ); 149 | if (!NT_SUCCESS(status)) 150 | { 151 | CrosEcI2CPrint( 152 | DEBUG_LEVEL_ERROR, 153 | DBG_IOCTL, 154 | "Error creating IoTarget object - 0x%x\n", 155 | status); 156 | if (pDevice->busIoTarget) 157 | WdfObjectDelete(pDevice->busIoTarget); 158 | return status; 159 | } 160 | 161 | DECLARE_CONST_UNICODE_STRING(busDosDeviceName, L"\\DosDevices\\GOOG0004"); 162 | 163 | WDF_IO_TARGET_OPEN_PARAMS openParams; 164 | WDF_IO_TARGET_OPEN_PARAMS_INIT_OPEN_BY_NAME( 165 | &openParams, 166 | &busDosDeviceName, 167 | (GENERIC_READ | GENERIC_WRITE)); 168 | 169 | openParams.ShareAccess = FILE_SHARE_READ | FILE_SHARE_WRITE; 170 | openParams.CreateDisposition = FILE_OPEN; 171 | openParams.FileAttributes = FILE_ATTRIBUTE_NORMAL; 172 | 173 | CROSEC_INTERFACE_STANDARD CrosEcInterface; 174 | RtlZeroMemory(&CrosEcInterface, sizeof(CrosEcInterface)); 175 | 176 | status = WdfIoTargetOpen(pDevice->busIoTarget, &openParams); 177 | if (!NT_SUCCESS(status)) 178 | { 179 | CrosEcI2CPrint( 180 | DEBUG_LEVEL_ERROR, 181 | DBG_IOCTL, 182 | "Error opening IoTarget object - 0x%x\n", 183 | status); 184 | WdfObjectDelete(pDevice->busIoTarget); 185 | return status; 186 | } 187 | 188 | status = WdfIoTargetQueryForInterface(pDevice->busIoTarget, 189 | &GUID_CROSEC_INTERFACE_STANDARD, 190 | (PINTERFACE)&CrosEcInterface, 191 | sizeof(CrosEcInterface), 192 | 1, 193 | NULL); 194 | WdfIoTargetClose(pDevice->busIoTarget); 195 | pDevice->busIoTarget = NULL; 196 | if (!NT_SUCCESS(status)) { 197 | CrosEcI2CPrint(DEBUG_LEVEL_ERROR, DBG_PNP, 198 | "WdfFdoQueryForInterface failed 0x%x\n", status); 199 | return status; 200 | } 201 | 202 | pDevice->CrosEcBusContext = CrosEcInterface.InterfaceHeader.Context; 203 | pDevice->CrosEcCmdXferStatus = CrosEcInterface.CmdXferStatus; 204 | return status; 205 | } 206 | 207 | NTSTATUS 208 | OnPrepareHardware( 209 | _In_ WDFDEVICE FxDevice, 210 | _In_ WDFCMRESLIST FxResourcesRaw, 211 | _In_ WDFCMRESLIST FxResourcesTranslated 212 | ) 213 | /*++ 214 | 215 | Routine Description: 216 | 217 | This routine caches the SPB resource connection ID. 218 | 219 | Arguments: 220 | 221 | FxDevice - a handle to the framework device object 222 | FxResourcesRaw - list of translated hardware resources that 223 | the PnP manager has assigned to the device 224 | FxResourcesTranslated - list of raw hardware resources that 225 | the PnP manager has assigned to the device 226 | 227 | Return Value: 228 | 229 | Status 230 | 231 | --*/ 232 | { 233 | PCROSECI2C_CONTEXT pDevice = GetDeviceContext(FxDevice); 234 | NTSTATUS status = STATUS_INSUFFICIENT_RESOURCES; 235 | 236 | UNREFERENCED_PARAMETER(FxResourcesRaw); 237 | UNREFERENCED_PARAMETER(FxResourcesTranslated); 238 | 239 | status = GetBusInformation(FxDevice); 240 | if (!NT_SUCCESS(status)) 241 | { 242 | return status; 243 | } 244 | 245 | status = ConnectToEc(FxDevice); 246 | if (!NT_SUCCESS(status)) { 247 | return status; 248 | } 249 | 250 | 251 | (*pDevice->CrosEcCmdXferStatus)(pDevice->CrosEcBusContext, NULL); 252 | 253 | return status; 254 | } 255 | 256 | NTSTATUS 257 | OnReleaseHardware( 258 | _In_ WDFDEVICE FxDevice, 259 | _In_ WDFCMRESLIST FxResourcesTranslated 260 | ) 261 | /*++ 262 | 263 | Routine Description: 264 | 265 | Arguments: 266 | 267 | FxDevice - a handle to the framework device object 268 | FxResourcesTranslated - list of raw hardware resources that 269 | the PnP manager has assigned to the device 270 | 271 | Return Value: 272 | 273 | Status 274 | 275 | --*/ 276 | { 277 | NTSTATUS status = STATUS_SUCCESS; 278 | 279 | UNREFERENCED_PARAMETER(FxResourcesTranslated); 280 | 281 | return status; 282 | } 283 | 284 | NTSTATUS 285 | OnD0Entry( 286 | _In_ WDFDEVICE FxDevice, 287 | _In_ WDF_POWER_DEVICE_STATE FxPreviousState 288 | ) 289 | /*++ 290 | 291 | Routine Description: 292 | 293 | This routine allocates objects needed by the driver. 294 | 295 | Arguments: 296 | 297 | FxDevice - a handle to the framework device object 298 | FxPreviousState - previous power state 299 | 300 | Return Value: 301 | 302 | Status 303 | 304 | --*/ 305 | { 306 | UNREFERENCED_PARAMETER(FxPreviousState); 307 | NTSTATUS status = STATUS_SUCCESS; 308 | 309 | return status; 310 | } 311 | 312 | NTSTATUS 313 | OnD0Exit( 314 | _In_ WDFDEVICE FxDevice, 315 | _In_ WDF_POWER_DEVICE_STATE FxTargetState 316 | ) 317 | /*++ 318 | 319 | Routine Description: 320 | 321 | This routine destroys objects needed by the driver. 322 | 323 | Arguments: 324 | 325 | FxDevice - a handle to the framework device object 326 | FxTargetState - target power state 327 | 328 | Return Value: 329 | 330 | Status 331 | 332 | --*/ 333 | { 334 | UNREFERENCED_PARAMETER(FxTargetState); 335 | 336 | NTSTATUS status = STATUS_SUCCESS; 337 | 338 | return status; 339 | } 340 | 341 | static int ec_i2c_count_message(SPBREQUEST SpbRequest, int Count) { 342 | int i; 343 | int size; 344 | 345 | size = sizeof(struct ec_params_i2c_passthru); 346 | size += Count * sizeof(struct ec_params_i2c_passthru_msg); 347 | 348 | SPB_TRANSFER_DESCRIPTOR descriptor; 349 | for (i = 0; i < Count; i++) { 350 | SPB_TRANSFER_DESCRIPTOR_INIT(&descriptor); 351 | SpbRequestGetTransferParameters(SpbRequest, 352 | i, 353 | &descriptor, 354 | NULL); 355 | 356 | if (descriptor.Direction == SpbTransferDirectionToDevice) 357 | size += descriptor.TransferLength; 358 | } 359 | return size; 360 | } 361 | 362 | static NTSTATUS ec_i2c_construct_message( 363 | UINT8* buf, 364 | SPBTARGET SpbTarget, 365 | SPBREQUEST SpbRequest, 366 | int Count, 367 | UINT8 busNum, 368 | int *BytesTransferred) { 369 | PPBC_TARGET pTarget = GetTargetContext(SpbTarget); 370 | 371 | if (pTarget->Settings.AddressMode != AddressMode7Bit) { 372 | return STATUS_INVALID_ADDRESS; 373 | } 374 | 375 | struct ec_params_i2c_passthru* params; 376 | 377 | uint8_t *out_data = buf + sizeof(struct ec_params_i2c_passthru) + 378 | Count * sizeof(struct ec_params_i2c_passthru_msg); 379 | 380 | params = (struct ec_params_i2c_passthru*)buf; 381 | params->port = busNum; 382 | params->num_msgs = Count; 383 | 384 | SPB_TRANSFER_DESCRIPTOR descriptor; 385 | for (int i = 0; i < Count; i++) { 386 | PMDL mdlChain; 387 | 388 | SPB_TRANSFER_DESCRIPTOR_INIT(&descriptor); 389 | SpbRequestGetTransferParameters(SpbRequest, 390 | i, 391 | &descriptor, 392 | &mdlChain); 393 | 394 | struct ec_params_i2c_passthru_msg* msg = ¶ms->msg[i]; 395 | msg->len = descriptor.TransferLength; 396 | msg->addr_flags = pTarget->Settings.Address; 397 | 398 | if (descriptor.Direction == SpbTransferDirectionFromDevice) { 399 | msg->addr_flags |= EC_I2C_FLAG_READ; 400 | } 401 | else { 402 | for (int j = 0; j < msg->len; j++) { 403 | if (!NT_SUCCESS(MdlChainGetByte(mdlChain, msg->len, j, out_data))) { 404 | CrosEcI2CPrint(DEBUG_LEVEL_INFO, DBG_PNP, 405 | "Failed to copy send byte %d of %d\n", 406 | j, msg->len); 407 | return STATUS_DATA_ERROR; 408 | } 409 | out_data++; 410 | } 411 | *BytesTransferred += msg->len; 412 | } 413 | } 414 | return STATUS_SUCCESS; 415 | } 416 | 417 | static int ec_i2c_count_response(SPBREQUEST SpbRequest, int Count) 418 | { 419 | int size = sizeof(struct ec_response_i2c_passthru); 420 | 421 | SPB_TRANSFER_DESCRIPTOR descriptor; 422 | for (int i = 0; i < Count; i++) { 423 | SPB_TRANSFER_DESCRIPTOR_INIT(&descriptor); 424 | SpbRequestGetTransferParameters(SpbRequest, 425 | i, 426 | &descriptor, 427 | NULL); 428 | 429 | if (descriptor.Direction == SpbTransferDirectionFromDevice) 430 | size += descriptor.TransferLength; 431 | } 432 | 433 | return size; 434 | } 435 | 436 | static NTSTATUS ec_i2c_parse_response(const UINT8* buf, 437 | SPBREQUEST SpbRequest, 438 | int* Count, 439 | int *BytesTransferred) 440 | { 441 | const struct ec_response_i2c_passthru* resp; 442 | const UINT8* in_data = buf + sizeof(struct ec_response_i2c_passthru); 443 | 444 | resp = (const struct ec_response_i2c_passthru*)buf; 445 | if (resp->i2c_status & EC_I2C_STATUS_TIMEOUT) 446 | return STATUS_IO_TIMEOUT; 447 | else if (resp->i2c_status & EC_I2C_STATUS_NAK) 448 | return STATUS_DEVICE_DOES_NOT_EXIST; 449 | else if (resp->i2c_status & EC_I2C_STATUS_ERROR) 450 | return STATUS_IO_DEVICE_ERROR; 451 | 452 | /* Other side could send us back fewer messages, but not more */ 453 | if (resp->num_msgs > *Count) 454 | return STATUS_PROTOCOL_NOT_SUPPORTED; 455 | *Count = resp->num_msgs; 456 | 457 | SPB_TRANSFER_DESCRIPTOR descriptor; 458 | for (int i = 0; i < *Count; i++) { 459 | PMDL mdlChain; 460 | 461 | SPB_TRANSFER_DESCRIPTOR_INIT(&descriptor); 462 | SpbRequestGetTransferParameters(SpbRequest, 463 | i, 464 | &descriptor, 465 | &mdlChain); 466 | 467 | if (descriptor.Direction == SpbTransferDirectionFromDevice) { 468 | size_t len = descriptor.TransferLength; 469 | 470 | for (int j = 0; j < len; j++) { 471 | if (!NT_SUCCESS(MdlChainSetByte(mdlChain, len, j, *in_data))) { 472 | CrosEcI2CPrint(DEBUG_LEVEL_INFO, DBG_PNP, 473 | "Failed to copy recv byte %d of %d\n", 474 | j, len); 475 | return STATUS_DATA_ERROR; 476 | } 477 | in_data++; 478 | } 479 | *BytesTransferred += len; 480 | } 481 | } 482 | return STATUS_SUCCESS; 483 | } 484 | 485 | static NTSTATUS ec_i2c_xfer( 486 | _In_ PCROSECI2C_CONTEXT pDevice, 487 | _In_ SPBTARGET SpbTarget, 488 | _In_ SPBREQUEST SpbRequest, 489 | _In_ ULONG TransferCount 490 | ) { 491 | int request_len; 492 | int response_len; 493 | int alloc_size; 494 | NTSTATUS result; 495 | struct cros_ec_command* msg; 496 | int bytes_transferred = 0; 497 | 498 | request_len = ec_i2c_count_message(SpbRequest, TransferCount); 499 | if (request_len < 0) { 500 | CrosEcI2CPrint(DEBUG_LEVEL_INFO, DBG_PNP, 501 | "Error constructing message %d\n", 502 | request_len); 503 | return STATUS_INTERNAL_ERROR; 504 | } 505 | 506 | response_len = ec_i2c_count_response(SpbRequest, TransferCount); 507 | if (response_len < 0) { 508 | /* Unexpected; no errors should come when NULL response */ 509 | CrosEcI2CPrint(DEBUG_LEVEL_INFO, DBG_PNP, 510 | "Error preparing response %d\n", response_len); 511 | return STATUS_INTERNAL_ERROR; 512 | } 513 | 514 | alloc_size = max(request_len, response_len); 515 | msg = ExAllocatePoolWithTag(NonPagedPool ,sizeof(struct cros_ec_command) + alloc_size, CROSECI2C_POOL_TAG); 516 | if (!msg) { 517 | return STATUS_MEMORY_NOT_ALLOCATED; 518 | } 519 | 520 | result = ec_i2c_construct_message(msg->data, SpbTarget, SpbRequest, TransferCount, pDevice->busNumber, &bytes_transferred); 521 | if (!NT_SUCCESS(result)) { 522 | CrosEcI2CPrint(DEBUG_LEVEL_INFO, DBG_PNP, 523 | "Error constructing EC i2c message 0x%x\n", result); 524 | goto exit; 525 | } 526 | 527 | msg->version = 0; 528 | msg->command = EC_CMD_I2C_PASSTHRU; 529 | msg->outsize = request_len; 530 | msg->insize = response_len; 531 | 532 | result = (*pDevice->CrosEcCmdXferStatus)(pDevice->CrosEcBusContext, msg); 533 | if (!NT_SUCCESS(result)) { 534 | CrosEcI2CPrint(DEBUG_LEVEL_INFO, DBG_PNP, 535 | "Error transferring EC I2C Message 0x%x\n", result); 536 | goto exit; 537 | } 538 | 539 | int TransferredCount = TransferCount; 540 | result = ec_i2c_parse_response(msg->data, SpbRequest, &TransferredCount, &bytes_transferred); 541 | if (!NT_SUCCESS(result)) { 542 | goto exit; 543 | } 544 | 545 | WdfRequestSetInformation(SpbRequest, bytes_transferred); 546 | 547 | exit: 548 | ExFreePoolWithTag(msg, CROSECI2C_POOL_TAG); 549 | return result; 550 | } 551 | 552 | NTSTATUS OnTargetConnect( 553 | _In_ WDFDEVICE SpbController, 554 | _In_ SPBTARGET SpbTarget 555 | ) { 556 | UNREFERENCED_PARAMETER(SpbController); 557 | 558 | PPBC_TARGET pTarget = GetTargetContext(SpbTarget); 559 | 560 | // 561 | // Get target connection parameters. 562 | // 563 | 564 | SPB_CONNECTION_PARAMETERS params; 565 | SPB_CONNECTION_PARAMETERS_INIT(¶ms); 566 | 567 | SpbTargetGetConnectionParameters(SpbTarget, ¶ms); 568 | PRH_QUERY_CONNECTION_PROPERTIES_OUTPUT_BUFFER connection = (PRH_QUERY_CONNECTION_PROPERTIES_OUTPUT_BUFFER)params.ConnectionParameters; 569 | 570 | if (connection->PropertiesLength < sizeof(PNP_SERIAL_BUS_DESCRIPTOR)) { 571 | CrosEcI2CPrint(DEBUG_LEVEL_INFO, DBG_PNP, 572 | "Invalid connection properties (length = %lu, " 573 | "expected = %Iu)\n", 574 | connection->PropertiesLength, 575 | sizeof(PNP_SERIAL_BUS_DESCRIPTOR)); 576 | return STATUS_INVALID_PARAMETER; 577 | } 578 | 579 | PPNP_SERIAL_BUS_DESCRIPTOR descriptor = (PPNP_SERIAL_BUS_DESCRIPTOR)connection->ConnectionProperties; 580 | if (descriptor->SerialBusType != I2C_SERIAL_BUS_TYPE) { 581 | CrosEcI2CPrint(DEBUG_LEVEL_INFO, DBG_PNP, 582 | "Bus type %c not supported, only I2C\n", 583 | descriptor->SerialBusType); 584 | return STATUS_INVALID_PARAMETER; 585 | } 586 | 587 | PPNP_I2C_SERIAL_BUS_DESCRIPTOR i2cDescriptor = (PPNP_I2C_SERIAL_BUS_DESCRIPTOR)connection->ConnectionProperties; 588 | pTarget->Settings.Address = (ULONG)i2cDescriptor->SlaveAddress; 589 | 590 | USHORT I2CFlags = i2cDescriptor->SerialBusDescriptor.TypeSpecificFlags; 591 | 592 | pTarget->Settings.AddressMode = ((I2CFlags & I2C_SERIAL_BUS_SPECIFIC_FLAG_10BIT_ADDRESS) == 0) ? AddressMode7Bit : AddressMode10Bit; 593 | pTarget->Settings.ConnectionSpeed = i2cDescriptor->ConnectionSpeed; 594 | 595 | return STATUS_SUCCESS; 596 | } 597 | 598 | VOID OnSpbIoRead( 599 | _In_ WDFDEVICE SpbController, 600 | _In_ SPBTARGET SpbTarget, 601 | _In_ SPBREQUEST SpbRequest, 602 | _In_ size_t Length 603 | ) 604 | { 605 | PCROSECI2C_CONTEXT pDevice = GetDeviceContext(SpbController); 606 | 607 | NTSTATUS status = ec_i2c_xfer(pDevice, SpbTarget, SpbRequest, 1); 608 | SpbRequestComplete(SpbRequest, status); 609 | } 610 | 611 | VOID OnSpbIoWrite( 612 | _In_ WDFDEVICE SpbController, 613 | _In_ SPBTARGET SpbTarget, 614 | _In_ SPBREQUEST SpbRequest, 615 | _In_ size_t Length 616 | ) 617 | { 618 | PCROSECI2C_CONTEXT pDevice = GetDeviceContext(SpbController); 619 | 620 | NTSTATUS status = ec_i2c_xfer(pDevice, SpbTarget, SpbRequest, 1); 621 | SpbRequestComplete(SpbRequest, status); 622 | } 623 | 624 | VOID OnSpbIoSequence( 625 | _In_ WDFDEVICE SpbController, 626 | _In_ SPBTARGET SpbTarget, 627 | _In_ SPBREQUEST SpbRequest, 628 | _In_ ULONG TransferCount 629 | ) 630 | { 631 | 632 | PCROSECI2C_CONTEXT pDevice = GetDeviceContext(SpbController); 633 | 634 | NTSTATUS status = ec_i2c_xfer(pDevice, SpbTarget, SpbRequest, TransferCount); 635 | SpbRequestComplete(SpbRequest, status); 636 | } 637 | 638 | NTSTATUS 639 | CrosEcI2CEvtDeviceAdd( 640 | IN WDFDRIVER Driver, 641 | IN PWDFDEVICE_INIT DeviceInit 642 | ) 643 | { 644 | NTSTATUS status = STATUS_SUCCESS; 645 | WDF_OBJECT_ATTRIBUTES attributes; 646 | WDFDEVICE device; 647 | PCROSECI2C_CONTEXT devContext; 648 | 649 | UNREFERENCED_PARAMETER(Driver); 650 | 651 | PAGED_CODE(); 652 | 653 | CrosEcI2CPrint(DEBUG_LEVEL_INFO, DBG_PNP, 654 | "CrosEcI2CEvtDeviceAdd called\n"); 655 | 656 | status = SpbDeviceInitConfig(DeviceInit); 657 | if (!NT_SUCCESS(status)) { 658 | CrosEcI2CPrint(DEBUG_LEVEL_ERROR, DBG_PNP, 659 | "SpbDeviceInitConfig failed with status code 0x%x\n", status); 660 | return status; 661 | } 662 | 663 | { 664 | WDF_PNPPOWER_EVENT_CALLBACKS pnpCallbacks; 665 | WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpCallbacks); 666 | 667 | pnpCallbacks.EvtDevicePrepareHardware = OnPrepareHardware; 668 | pnpCallbacks.EvtDeviceReleaseHardware = OnReleaseHardware; 669 | pnpCallbacks.EvtDeviceD0Entry = OnD0Entry; 670 | pnpCallbacks.EvtDeviceD0Exit = OnD0Exit; 671 | 672 | WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpCallbacks); 673 | } 674 | 675 | // 676 | // Setup the device context 677 | // 678 | 679 | WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, CROSECI2C_CONTEXT); 680 | 681 | // 682 | // Create a framework device object.This call will in turn create 683 | // a WDM device object, attach to the lower stack, and set the 684 | // appropriate flags and attributes. 685 | // 686 | 687 | status = WdfDeviceCreate(&DeviceInit, &attributes, &device); 688 | 689 | if (!NT_SUCCESS(status)) 690 | { 691 | CrosEcI2CPrint(DEBUG_LEVEL_ERROR, DBG_PNP, 692 | "WdfDeviceCreate failed with status code 0x%x\n", status); 693 | 694 | return status; 695 | } 696 | 697 | devContext = GetDeviceContext(device); 698 | 699 | devContext->FxDevice = device; 700 | 701 | // 702 | // Bind a SPB controller object to the device. 703 | // 704 | 705 | SPB_CONTROLLER_CONFIG spbConfig; 706 | SPB_CONTROLLER_CONFIG_INIT(&spbConfig); 707 | 708 | spbConfig.PowerManaged = WdfTrue; 709 | spbConfig.EvtSpbTargetConnect = OnTargetConnect; 710 | spbConfig.EvtSpbIoRead = OnSpbIoRead; 711 | spbConfig.EvtSpbIoWrite = OnSpbIoWrite; 712 | spbConfig.EvtSpbIoSequence = OnSpbIoSequence; 713 | 714 | status = SpbDeviceInitialize(devContext->FxDevice, &spbConfig); 715 | if (!NT_SUCCESS(status)) 716 | { 717 | CrosEcI2CPrint(DEBUG_LEVEL_ERROR, DBG_PNP, 718 | "SpbDeviceInitialize failed with status code 0x%x\n", status); 719 | 720 | return status; 721 | } 722 | 723 | WDF_OBJECT_ATTRIBUTES targetAttributes; 724 | WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&targetAttributes, PBC_TARGET); 725 | 726 | SpbControllerSetTargetAttributes(devContext->FxDevice, &targetAttributes); 727 | 728 | return status; 729 | } -------------------------------------------------------------------------------- /croseci2c/croseci2c.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Win10 Debug 6 | Win32 7 | 8 | 9 | Win10 Debug 10 | x64 11 | 12 | 13 | Win10 Release 14 | Win32 15 | 16 | 17 | Win10 Release 18 | x64 19 | 20 | 21 | Win8.1 Debug 22 | Win32 23 | 24 | 25 | Win8.1 Release 26 | Win32 27 | 28 | 29 | Win8 Debug 30 | Win32 31 | 32 | 33 | Win8 Release 34 | Win32 35 | 36 | 37 | Win8.1 Debug 38 | x64 39 | 40 | 41 | Win8.1 Release 42 | x64 43 | 44 | 45 | Win8 Debug 46 | x64 47 | 48 | 49 | Win8 Release 50 | x64 51 | 52 | 53 | 54 | {B3E71397-9BE4-492B-AAED-4D056E59CB1F} 55 | {1bc93793-694f-48fe-9372-81e2b05556fd} 56 | v4.5 57 | 11.0 58 | Win8.1 Debug 59 | Win32 60 | croseci2c 61 | 10.0.22000.0 62 | croseci2c 63 | 64 | 65 | 66 | WindowsV6.3 67 | true 68 | WindowsKernelModeDriver10.0 69 | Driver 70 | KMDF 71 | 72 | 73 | WindowsV6.3 74 | false 75 | WindowsKernelModeDriver10.0 76 | Driver 77 | KMDF 78 | 79 | 80 | Windows10 81 | false 82 | WindowsKernelModeDriver10.0 83 | Driver 84 | KMDF 85 | 86 | 87 | Windows8 88 | true 89 | WindowsKernelModeDriver10.0 90 | Driver 91 | KMDF 92 | 93 | 94 | Windows10 95 | true 96 | WindowsKernelModeDriver10.0 97 | Driver 98 | KMDF 99 | 100 | 101 | Windows8 102 | false 103 | WindowsKernelModeDriver10.0 104 | Driver 105 | KMDF 106 | 107 | 108 | WindowsV6.3 109 | true 110 | WindowsKernelModeDriver10.0 111 | Driver 112 | KMDF 113 | 114 | 115 | WindowsV6.3 116 | false 117 | WindowsKernelModeDriver10.0 118 | Driver 119 | KMDF 120 | 121 | 122 | Windows10 123 | false 124 | WindowsKernelModeDriver10.0 125 | Driver 126 | KMDF 127 | 128 | 129 | Windows8 130 | true 131 | WindowsKernelModeDriver10.0 132 | Driver 133 | KMDF 134 | 135 | 136 | Windows10 137 | true 138 | WindowsKernelModeDriver10.0 139 | Driver 140 | KMDF 141 | 142 | 143 | Windows8 144 | false 145 | WindowsKernelModeDriver10.0 146 | Driver 147 | KMDF 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | DbgengKernelDebugger 159 | 160 | 161 | DbgengKernelDebugger 162 | 163 | 164 | DbgengKernelDebugger 165 | 166 | 167 | DbgengKernelDebugger 168 | 169 | 170 | DbgengKernelDebugger 171 | 172 | 173 | DbgengKernelDebugger 174 | 175 | 176 | DbgengKernelDebugger 177 | 178 | 179 | DbgengKernelDebugger 180 | 181 | 182 | DbgengKernelDebugger 183 | 184 | 185 | DbgengKernelDebugger 186 | 187 | 188 | DbgengKernelDebugger 189 | 190 | 191 | DbgengKernelDebugger 192 | 193 | 194 | 195 | true 196 | trace.h 197 | true 198 | false 199 | $(SPB_INC_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR);%(AdditionalIncludeDirectories) 200 | 201 | 202 | 1.0.0 203 | 204 | 205 | SHA256 206 | 207 | 208 | $(SPB_LIB_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR)\SpbCxStubs.lib;%(AdditionalDependencies) 209 | 210 | 211 | 212 | 213 | true 214 | trace.h 215 | true 216 | false 217 | $(SPB_INC_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR);%(AdditionalIncludeDirectories) 218 | 219 | 220 | 1.0.0 221 | 222 | 223 | SHA256 224 | 225 | 226 | $(SPB_LIB_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR)\SpbCxStubs.lib;%(AdditionalDependencies) 227 | 228 | 229 | 230 | 231 | true 232 | trace.h 233 | true 234 | false 235 | $(SPB_INC_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR);%(AdditionalIncludeDirectories) 236 | 237 | 238 | 1.0.0 239 | 240 | 241 | SHA256 242 | 243 | 244 | $(SPB_LIB_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR)\SpbCxStubs.lib;%(AdditionalDependencies) 245 | 246 | 247 | 248 | 249 | true 250 | trace.h 251 | true 252 | false 253 | $(SPB_INC_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR);%(AdditionalIncludeDirectories) 254 | 255 | 256 | 1.0.0 257 | 258 | 259 | SHA256 260 | 261 | 262 | $(SPB_LIB_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR)\SpbCxStubs.lib;%(AdditionalDependencies) 263 | 264 | 265 | 266 | 267 | true 268 | trace.h 269 | true 270 | false 271 | $(SPB_INC_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR);%(AdditionalIncludeDirectories) 272 | 273 | 274 | 1.0.0 275 | 276 | 277 | SHA256 278 | 279 | 280 | $(SPB_LIB_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR)\SpbCxStubs.lib;%(AdditionalDependencies) 281 | 282 | 283 | 284 | 285 | true 286 | trace.h 287 | true 288 | false 289 | $(SPB_INC_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR);%(AdditionalIncludeDirectories) 290 | 291 | 292 | 1.0.0 293 | 294 | 295 | SHA256 296 | 297 | 298 | $(SPB_LIB_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR)\SpbCxStubs.lib;%(AdditionalDependencies) 299 | 300 | 301 | 302 | 303 | true 304 | trace.h 305 | true 306 | false 307 | $(SPB_INC_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR);%(AdditionalIncludeDirectories) 308 | 309 | 310 | 1.0.0 311 | 312 | 313 | SHA256 314 | 315 | 316 | $(SPB_LIB_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR)\SpbCxStubs.lib;%(AdditionalDependencies) 317 | 318 | 319 | 320 | 321 | true 322 | trace.h 323 | true 324 | false 325 | $(SPB_INC_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR);%(AdditionalIncludeDirectories) 326 | 327 | 328 | 1.0.0 329 | 330 | 331 | SHA256 332 | 333 | 334 | $(SPB_LIB_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR)\SpbCxStubs.lib;%(AdditionalDependencies) 335 | 336 | 337 | 338 | 339 | true 340 | trace.h 341 | true 342 | false 343 | $(SPB_INC_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR);%(AdditionalIncludeDirectories) 344 | 345 | 346 | 1.0.0 347 | 348 | 349 | SHA256 350 | 351 | 352 | $(SPB_LIB_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR)\SpbCxStubs.lib;%(AdditionalDependencies) 353 | 354 | 355 | 356 | 357 | true 358 | trace.h 359 | true 360 | false 361 | $(SPB_INC_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR);%(AdditionalIncludeDirectories) 362 | 363 | 364 | 1.0.0 365 | 366 | 367 | SHA256 368 | 369 | 370 | $(SPB_LIB_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR)\SpbCxStubs.lib;%(AdditionalDependencies) 371 | 372 | 373 | 374 | 375 | true 376 | trace.h 377 | true 378 | false 379 | $(SPB_INC_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR);%(AdditionalIncludeDirectories) 380 | 381 | 382 | 1.0.0 383 | 384 | 385 | SHA256 386 | 387 | 388 | $(SPB_LIB_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR)\SpbCxStubs.lib;%(AdditionalDependencies) 389 | 390 | 391 | 392 | 393 | true 394 | trace.h 395 | true 396 | false 397 | $(SPB_INC_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR);%(AdditionalIncludeDirectories) 398 | 399 | 400 | 1.0.0 401 | 402 | 403 | SHA256 404 | 405 | 406 | $(SPB_LIB_PATH)\$(SPB_VERSION_MAJOR).$(SPB_VERSION_MINOR)\SpbCxStubs.lib;%(AdditionalDependencies) 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | --------------------------------------------------------------------------------