From d665981884b6e9b2f222e1349c59fda00ea01630 Mon Sep 17 00:00:00 2001 From: Bingxing Wang Date: Wed, 9 Oct 2019 17:18:53 -0400 Subject: [PATCH] Add generic T2 fallback for all T2 devices. Experience might not be optimal for a few devices due to the lack of region data. Resolved #142. --- README.md | 4 +- src/AmtPtpDeviceUsbKm/AmtPtpDeviceUsbKm.inf | 14 ++++-- src/AmtPtpDeviceUsbKm/Device.c | 9 +++- src/AmtPtpDeviceUsbKm/Hid.c | 54 +++++++++++++++++++-- 4 files changed, 69 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index c6ea4b4..330a88e 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,8 @@ There is a bring-up issue for certain MacBook Pro and MacBook Air. I am looking - [x] Apple Magic Trackpad 2 (Not stable) - [x] MacBook Pro with Retina Display (2013, 2014, 2015, 13-inch & 15-inch) - [x] New MacBook (12-inch) -- [x] MacBook Pro 2015, 2016, 2017 -- [ ] _(Work in progress)_ T2-based devices: MacBook Air 2018, MacBook Pro 2017/2018/2019: a few is supported as of now +- [x] MacBook Pro 2015, 2016, 2017 (a few SPI devices are in work-in-progress state) +- [x] T2-based devices: MacBook Air 2018, MacBook Pro 2017/2018/2019: Use default fallback, experience might not be optimal. Open a issue if you encountered dead touch regions. ## Roadmap diff --git a/src/AmtPtpDeviceUsbKm/AmtPtpDeviceUsbKm.inf b/src/AmtPtpDeviceUsbKm/AmtPtpDeviceUsbKm.inf index 1d70213..2ba6056 100644 --- a/src/AmtPtpDeviceUsbKm/AmtPtpDeviceUsbKm.inf +++ b/src/AmtPtpDeviceUsbKm/AmtPtpDeviceUsbKm.inf @@ -29,11 +29,15 @@ WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll=1 ; make sure the number matches with %ManufacturerName%=Standard,NT$ARCH$ [Standard.NT$ARCH$] -; T2 trackpad -%AmtPtpDeviceUsbKm.DeviceDesc%=AmtPtpDeviceUsbKm_Device, USB\Vid_05ac&Pid_027a&MI_02 -%AmtPtpDeviceUsbKm.DeviceDesc%=AmtPtpDeviceUsbKm_Device, USB\Vid_05ac&Pid_027b&MI_02 -%AmtPtpDeviceUsbKm.DeviceDesc%=AmtPtpDeviceUsbKm_Device, USB\Vid_05ac&Pid_027c&MI_02 -%AmtPtpDeviceUsbKm.DeviceDesc%=AmtPtpDeviceUsbKm_Device, USB\Vid_05ac&Pid_027d&MI_02 +%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 +%AmtPtpDeviceUsbKm.DeviceDesc%=AmtPtpDeviceUsbKm_Device, USB\Vid_05ac&Pid_027A&MI_02 +%AmtPtpDeviceUsbKm.DeviceDesc%=AmtPtpDeviceUsbKm_Device, USB\Vid_05ac&Pid_027B&MI_02 +%AmtPtpDeviceUsbKm.DeviceDesc%=AmtPtpDeviceUsbKm_Device, USB\Vid_05ac&Pid_027C&MI_02 +%AmtPtpDeviceUsbKm.DeviceDesc%=AmtPtpDeviceUsbKm_Device, USB\Vid_05ac&Pid_027D&MI_02 +%AmtPtpDeviceUsbKm.DeviceDesc%=AmtPtpDeviceUsbKm_Device, USB\Vid_05ac&Pid_0290&MI_02 +%AmtPtpDeviceUsbKm.DeviceDesc%=AmtPtpDeviceUsbKm_Device, USB\Vid_05ac&Pid_0291&MI_02 [AmtPtpDeviceUsbKm_Device.NT] CopyFiles=Drivers_Dir diff --git a/src/AmtPtpDeviceUsbKm/Device.c b/src/AmtPtpDeviceUsbKm/Device.c index 3647ee7..d3b0714 100644 --- a/src/AmtPtpDeviceUsbKm/Device.c +++ b/src/AmtPtpDeviceUsbKm/Device.c @@ -37,7 +37,14 @@ AmtPtpGetDeviceConfig( } } - return NULL; + // Generic fallback + TraceEvents( + TRACE_LEVEL_WARNING, + TRACE_DRIVER, + "%!FUNC! Selected a generic fallback configuration" + ); + + return &Bcm5974ConfigTable[0]; } NTSTATUS diff --git a/src/AmtPtpDeviceUsbKm/Hid.c b/src/AmtPtpDeviceUsbKm/Hid.c index 131a488..71460ee 100644 --- a/src/AmtPtpDeviceUsbKm/Hid.c +++ b/src/AmtPtpDeviceUsbKm/Hid.c @@ -84,10 +84,27 @@ AmtPtpGetHidDescriptor( { TraceEvents( TRACE_LEVEL_WARNING, TRACE_DRIVER, - "%!FUNC! Device HID registry is not found" + "%!FUNC! Device HID registry is not found, use a generic fallback" ); - status = STATUS_INVALID_DEVICE_STATE; + szCopy = AmtPtpT2DefaultHidDescriptor.bLength; + status = WdfMemoryCopyFromBuffer( + requestMemory, + 0, + (PVOID)&AmtPtpT2DefaultHidDescriptor, + szCopy + ); + + if (!NT_SUCCESS(status)) { + TraceEvents( + TRACE_LEVEL_ERROR, TRACE_DRIVER, + "%!FUNC! WdfMemoryCopyFromBuffer failed with %!STATUS!", + status + ); + goto exit; + } + + WdfRequestSetInformation(Request, szCopy); break; } }; @@ -222,9 +239,38 @@ AmtPtpGetReportDescriptor( { TraceEvents( TRACE_LEVEL_WARNING, TRACE_DRIVER, - "%!FUNC! Device HID registry is not found" + "%!FUNC! Device HID registry is not found, use a generic fallback" ); - status = STATUS_INVALID_DEVICE_STATE; + + szCopy = AmtPtpT2DefaultHidDescriptor.DescriptorList[0].wReportLength; + if (szCopy == 0) { + + status = STATUS_INVALID_DEVICE_STATE; + TraceEvents( + TRACE_LEVEL_ERROR, TRACE_DRIVER, + "%!FUNC! Device HID report length is zero" + ); + goto exit; + } + + status = WdfMemoryCopyFromBuffer( + requestMemory, + 0, + (PVOID)&AmtPtpT2ReportDescriptor, + szCopy + ); + + if (!NT_SUCCESS(status)) { + + TraceEvents( + TRACE_LEVEL_ERROR, TRACE_DRIVER, + "%!FUNC! WdfMemoryCopyFromBuffer failed with %!STATUS!", + status + ); + goto exit; + } + + WdfRequestSetInformation(Request, szCopy); break; } }