Skip to content

Commit

Permalink
HID: update device ID to prevent some ID collision
Browse files Browse the repository at this point in the history
  • Loading branch information
imbushuo committed Jun 2, 2021
1 parent 4cdc3eb commit dd364d6
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/AmtPtpDeviceSpiKm/AppleDefinition.h
@@ -1,6 +1,7 @@
#pragma once

#define SPI_TRACKPAD_MAX_FINGERS 10
#define DEVICE_VID 0x8910

typedef struct _SPI_TRACKPAD_FINGER
{
Expand Down
4 changes: 3 additions & 1 deletion src/AmtPtpDeviceSpiKm/Hid.c
Expand Up @@ -340,7 +340,9 @@ AmtPtpGetDeviceAttribs(
}

pDeviceAttributes->Size = sizeof(HID_DEVICE_ATTRIBUTES);
pDeviceAttributes->VendorID = pDeviceContext->HidVendorID;
// Okay here's one thing: we cannot report the real ID here, otherwise there's will be some great conflict with the USB/BT driver.
// Therefore Vendor ID is changed to a hardcoded number
pDeviceAttributes->VendorID = DEVICE_VID;
pDeviceAttributes->ProductID = pDeviceContext->HidProductID;
pDeviceAttributes->VersionNumber = pDeviceContext->HidVersionNumber;

Expand Down
93 changes: 69 additions & 24 deletions src/AmtPtpDeviceUniversalPkg/AmtPtpDevice.inf
Expand Up @@ -22,11 +22,13 @@ PtpUmDrivers_Dir = 13
AmtPtpDeviceUsbKm.sys = 1,,
AmtPtpDeviceUsbUm.dll = 1,,
AmtPtpDeviceSpiKm.sys = 1,,
AmtPtpHidFilter.sys = 1,,

[Manufacturer]
%ManufacturerName%=Standard,NT$ARCH$

[Standard.NT$ARCH$]
; Apple T2
%AmtPtpDeviceUsbKm.DeviceDesc%=AmtPtpDeviceUsbKm_Device, USB\Vid_05ac&Pid_0273&MI_02
%AmtPtpDeviceUsbKm.DeviceDesc%=AmtPtpDeviceUsbKm_Device, USB\Vid_05ac&Pid_0274&MI_02
%AmtPtpDeviceUsbKm.DeviceDesc%=AmtPtpDeviceUsbKm_Device, USB\Vid_05ac&Pid_0277&MI_02
Expand All @@ -41,6 +43,7 @@ AmtPtpDeviceSpiKm.sys = 1,,
%AmtPtpDeviceUsbKm.DeviceDesc%=AmtPtpDeviceUsbKm_Device, USB\Vid_05ac&Pid_0291&MI_02
%AmtPtpDeviceUsbKm.DeviceDesc%=AmtPtpDeviceUsbKm_Device, USB\Vid_05ac&Pid_0340&MI_02

; Traditional Mac trackpad
%AmtPtpDeviceUsbUm.DeviceDesc%=AmtPtpDeviceUsbUm_Install, USB\Vid_05ac&Pid_0236&MI_01
%AmtPtpDeviceUsbUm.DeviceDesc%=AmtPtpDeviceUsbUm_Install, USB\Vid_05ac&Pid_0237&MI_01
%AmtPtpDeviceUsbUm.DeviceDesc%=AmtPtpDeviceUsbUm_Install, USB\Vid_05ac&Pid_0238&MI_01
Expand All @@ -67,8 +70,8 @@ AmtPtpDeviceSpiKm.sys = 1,,
%AmtPtpDeviceUsbUm.DeviceDesc%=AmtPtpDeviceUsbUm_Install, USB\Vid_05ac&Pid_0274&MI_02
%AmtPtpDeviceUsbUm.DeviceDesc%=AmtPtpDeviceUsbUm_Install, USB\Vid_05ac&Pid_0290&MI_02
%AmtPtpDeviceUsbUm.DeviceDesc%=AmtPtpDeviceUsbUm_Install, USB\Vid_05ac&Pid_0291&MI_02
%AmtPtpDeviceUsbUm.DeviceDesc%=AmtPtpDeviceUsbUm_Install, USB\Vid_05ac&Pid_0265&MI_01

; SPI
%AmtPtpDeviceSpiKm.DeviceDesc%=AmtPtpDeviceSpiKm_Device, SPI\VID_05ac&PID_0272&MI_02
%AmtPtpDeviceSpiKm.DeviceDesc%=AmtPtpDeviceSpiKm_Device, SPI\VID_05ac&PID_0273&MI_02
%AmtPtpDeviceSpiKm.DeviceDesc%=AmtPtpDeviceSpiKm_Device, SPI\VID_05ac&PID_0275&MI_02
Expand All @@ -80,14 +83,72 @@ AmtPtpDeviceSpiKm.sys = 1,,
%AmtPtpDeviceSpiKm.DeviceDesc%=AmtPtpDeviceSpiKm_Device, SPI\VID_05ac&PID_0290&MI_02
%AmtPtpDeviceSpiKm.DeviceDesc%=AmtPtpDeviceSpiKm_Device, SPI\VID_05ac&PID_0291&MI_02

; USB KM
; Magic Trackpad 2 USB
; Note: this will be a last few versions where Magic Trackpad 2 uses this old implementation
%AmtPtpDeviceUsbUm.DeviceDesc%=AmtPtpDeviceUsbUm_Install, USB\Vid_05ac&Pid_0265&MI_01
; Magic Trackpad 2 Bluetooth
%AmtPtpHidFilter.DeviceDesc%=AmtPtpHidFilter_MiniPortDevice, HID\{00001124-0000-1000-8000-00805f9b34fb}_VID&0001004c_PID&0265&Col01
%AmtPtpHidFilter.NullDeviceDesc%=AmtPtpHidFilter_NullDevice, HID\{00001124-0000-1000-8000-00805f9b34fb}_VID&0001004c_PID&0265&Col02

[AmtPtpDeviceUsbKm_Device.NT]
CopyFiles=PtpKmDrivers_Dir
; Null Device
[AmtPtpHidFilter_NullDevice]
; Nothing!

[AmtPtpHidFilter_NullDevice.Services]
AddService = ,2 ; no value for the service name

; File paylods for each set of driver
[FilterDriver_Payload]
AmtPtpHidFilter.sys

[PtpKmDrivers_Dir]
AmtPtpDeviceUsbKm.sys

[PtpUmDrivers_Dir]
AmtPtpDeviceUsbUm.dll

[SpiKmDrivers_Dir]
AmtPtpDeviceSpiKm.sys

; Microsoft HID KMDF driver install sections
[mshidkmdf_Service_Inst]
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 3 ; SERVICE_DEMAND_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %10%\System32\Drivers\mshidkmdf.sys

; PTP filter
[AmtPtpHidFilter_MiniPortDevice.NT]
CopyFiles=FilterDriver_Payload

[AmtPtpHidFilter_MiniPortDevice.NT.Services]
AddService = AmtPtpHidFilter,, AmtPtpHidFilter_Service_Inst
AddService = mshidkmdf, %SPSVCINST_ASSOCSERVICE%, mshidkmdf_Service_Inst

[AmtPtpHidFilter_MiniPortDevice.NT.HW]
AddReg=AmtPtpHidFilter_AddReg

[AmtPtpHidFilter_AddReg]
HKR,,FriendlyName,,%AmtPtpHidFilter.DeviceDesc%
HKR,,"LowerFilters",0x00010008,"AmtPtpHidFilter"

[AmtPtpHidFilter_MiniPortDevice.NT.Wdf]
KmdfService = AmtPtpHidFilter, AmtPtpHidFilter_wdfsect

[AmtPtpHidFilter_Service_Inst]
DisplayName = %AmtPtpHidFilter.SVCDESC%
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 3 ; SERVICE_DEMAND_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %13%\AmtPtpHidFilter.sys

[AmtPtpHidFilter_wdfsect]
KmdfLibraryVersion = $KMDFVERSION$

; USB KM
[AmtPtpDeviceUsbKm_Device.NT]
CopyFiles=PtpKmDrivers_Dir

[AmtPtpDeviceUsbKm_Device.NT.Services]
AddService = AmtPtpDeviceUsbKm,, AmtPtpDeviceUsbKm_Service_Inst
AddService = mshidkmdf, %SPSVCINST_ASSOCSERVICE%, mshidkmdf_Service_Inst
Expand All @@ -99,13 +160,6 @@ AddReg=AmtPtpDeviceUsbKm_AddReg
HKR,,FriendlyName,,%AmtPtpDeviceUsbKm.DeviceDesc%
HKR,,"LowerFilters",0x00010008,"AmtPtpDeviceUsbKm"

; -------------- Microsoft HID KMDF driver install sections
[mshidkmdf_Service_Inst]
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 3 ; SERVICE_DEMAND_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %10%\System32\Drivers\mshidkmdf.sys

; -------------- AmtPtpDeviceUsbKm driver install sections
[AmtPtpDeviceUsbKm_Service_Inst]
DisplayName = %AmtPtpDeviceUsbKm.SVCDESC%
Expand All @@ -131,9 +185,6 @@ AddReg=AmtPtpDeviceUsbUm_AddReg
AddService=mshidumdf, 0x000001fa, MSHIDUMDF_ServiceInstall ; flag 0x2 sets this as the service for the device
AddService=WUDFRd,0x000001f8,WUDFRD_ServiceInstall ; this service is installed because its a filter.

[AmtPtpDeviceUsbUm_Install.NT.CoInstallers]
AddReg=UsbUmCoInstallers_AddReg

[AmtPtpDeviceUsbUm_Install.NT.Wdf]
UmdfDispatcher=NativeUSB
UmdfService=AmtPtpDeviceUsbUm,AmtPtpDeviceUsbUm_Install
Expand Down Expand Up @@ -165,19 +216,10 @@ StartType = 3
ErrorControl = 1
ServiceBinary = %12%\WUDFRd.sys

[PtpUmDrivers_Dir]
AmtPtpDeviceUsbUm.dll

[UsbUmCoInstallers_AddReg]
HKR,,CoInstallers32,0x00010000,"WUDFCoinstaller.dll"

; SPI KM
[AmtPtpDeviceSpiKm_Device.NT]
CopyFiles=SpiKmDrivers_Dir

[SpiKmDrivers_Dir]
AmtPtpDeviceSpiKm.sys

[AmtPtpDeviceSpiKm_Device.NT.Services]
AddService = AmtPtpDeviceSpiKm,, AmtPtpDeviceSpiKm_Service_Inst
AddService = mshidkmdf, %SPSVCINST_ASSOCSERVICE%, mshidkmdf_Service_Inst ;flag 0x2 sets this as the service for the device
Expand All @@ -188,7 +230,6 @@ AddReg = AmtPtpDeviceSpiKm_Device.NT.AddReg
[AmtPtpDeviceSpiKm_Device.NT.AddReg]
HKR,,"LowerFilters",0x00010008,"AmtPtpDeviceSpiKm"

; -------------- AmtPtpDeviceSpiKm driver install sections
[AmtPtpDeviceSpiKm_Service_Inst]
DisplayName = %AmtPtpDeviceSpiKm.SVCDESC%
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
Expand All @@ -215,3 +256,7 @@ AmtPtpDeviceSpiKm.DeviceDesc = "Apple SPI Precision Touchpad Device"
AmtPtpDeviceSpiKm.SVCDESC = "Apple SPI Precision Touchpad Driver Service"
AmtPtpDeviceUsbKm.SVCDESC = "Apple USB Precision Touchpad Service"
WudfRdDisplayName = "Windows Driver Foundation - User-mode Driver Framework Reflector"
AmtPtpHidRootDevice.DeviceDesc = "Apple Multi-touch Trackpad HID Device"
AmtPtpHidFilter.DeviceDesc = "Apple Multi-touch Trackpad HID Filter"
AmtPtpHidFilter.NullDeviceDesc = "Apple Multi-touch Auxiliary Services"
AmtPtpHidFilter.SVCDESC = "Apple Multi-touch Trackpad HID Filter Service"
31 changes: 29 additions & 2 deletions src/AmtPtpDeviceUniversalPkg/AmtPtpDeviceUniversalPkg.vcxproj
Expand Up @@ -48,6 +48,9 @@
<ProjectReference Include="..\AmtPtpDeviceUsbUm\MagicTrackpad2PtpDevice.vcxproj">
<Project>{87efa31b-25eb-4944-a30a-300171bfff57}</Project>
</ProjectReference>
<ProjectReference Include="..\AmtPtpHidFilter\AmtPtpHidFilter.vcxproj">
<Project>{ee63c42b-f401-4f55-adbb-14c16bd3b18c}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Inf Include="AmtPtpDevice.inf" />
Expand Down Expand Up @@ -184,7 +187,7 @@
<SignMode>TestSign</SignMode>
</PropertyGroup>
<!-- For release signed config on Azure pipeline, CI pipeline don't sign it. We do that locally -->
<PropertyGroup Condition="'$(Configuration)'=='ReleaseSigned'">
<PropertyGroup Condition="'$(Configuration)'=='ReleaseSigned'">
<TimeStampServer>http://timestamp.digicert.com</TimeStampServer>
<ProductionCertificate>$(ProductionCertPath)</ProductionCertificate>
<SignMode Condition="'$(BuildEnvironment)'!='AzurePipeline'">ProductionSign</SignMode>
Expand All @@ -200,6 +203,30 @@
<Inf>
<TimeStamp Condition="'$(BuildEnvironment)'!='AzurePipeline'">*</TimeStamp>
</Inf>
<PreBuildEvent>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
</Command>
</PreBuildEvent>
<PreBuildEvent>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</Command>
</PreBuildEvent>
<PreBuildEvent>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
</Command>
</PreBuildEvent>
<PreLinkEvent>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
</Command>
</PreLinkEvent>
<PreLinkEvent>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</Command>
</PreLinkEvent>
<PreLinkEvent>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
</Command>
</PreLinkEvent>
</ItemDefinitionGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseSigned|Win32'">
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
Expand Down Expand Up @@ -295,4 +322,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
4 changes: 3 additions & 1 deletion src/AmtPtpDeviceUsbUm/Hid.c
Expand Up @@ -222,7 +222,9 @@ AmtPtpGetDeviceAttribs(

pDeviceAttributes->Size = sizeof(HID_DEVICE_ATTRIBUTES);
pDeviceAttributes->ProductID = pContext->DeviceDescriptor.idProduct;
pDeviceAttributes->VendorID = pContext->DeviceDescriptor.idVendor;
// Okay here's one thing: we cannot report the real ID here, otherwise there's will be some great conflict with the USB/BT driver.
// Therefore Vendor ID is changed to a hardcoded number
pDeviceAttributes->VendorID = DEVICE_VID;
pDeviceAttributes->VersionNumber = DEVICE_VERSION;

WdfRequestSetInformation(
Expand Down
1 change: 1 addition & 0 deletions src/AmtPtpDeviceUsbUm/include/Hid.h
Expand Up @@ -17,6 +17,7 @@
typedef UCHAR HID_REPORT_DESCRIPTOR, *PHID_REPORT_DESCRIPTOR;

#define DEVICE_VERSION 0x01
#define DEVICE_VID 0x8910

#define AAPL_PTP_USERMODE_CONFIGURATION_APP_TLC \
USAGE_PAGE_1, 0x00, 0xff, /* Usage Page: Vendor defined */ \
Expand Down
4 changes: 3 additions & 1 deletion src/AmtPtpHidFilter/Hid.c
Expand Up @@ -76,8 +76,10 @@ PtpFilterGetDeviceAttribs(
}

pDeviceAttributes->Size = sizeof(HID_DEVICE_ATTRIBUTES);
// Okay here's one thing: we cannot report the real ID here, otherwise there's will be some great conflict with the USB/BT driver.
// Therefore Vendor ID is changed to a hardcoded number
pDeviceAttributes->ProductID = deviceContext->ProductID;
pDeviceAttributes->VendorID = deviceContext->VendorID;
pDeviceAttributes->VendorID = DEVICE_VID;
pDeviceAttributes->VersionNumber = DEVICE_VERSION;
WdfRequestSetInformation(Request, sizeof(HID_DEVICE_ATTRIBUTES));

Expand Down
1 change: 1 addition & 0 deletions src/AmtPtpHidFilter/include/HidCommon.h
Expand Up @@ -39,4 +39,5 @@
#define BEGIN_COLLECTION 0xa1
#define END_COLLECTION 0xc0

#define DEVICE_VID 0x8910
#define DEVICE_VERSION 0x100

0 comments on commit dd364d6

Please sign in to comment.