Question

I am trying to write a filter driver for MTP devices on Windows 7 for the purpose of logging file operations and block certain file operations. I found that the driver that handles MTP in windows is a UMDF driver named WpdMtpDr.dll and I wrote a UMDF filter driver for it according to this example (Sample UMDF Filter Driver above UMDF Function Driver) as I treated WpdMtpDr.dll as the function driver. I also used this as a reference to determine if the driver is installed as an upper or lower filter. I installed the driver using dpinst.exe . Below is my INF file.

The installation had no errors, but when plugging in an MTP device (Samsung Galaxy S3), the filter driver was not in its drivers list (seen through device manager) and its DllMain was never called.

I tried to switch between lower and upper filter and it didn't help either.

What am I doing wrong?

;
; umdffilter.inf
;

[Version]
Signature="$Windows NT$"
Class=WPD
ClassGuid={EEC5AD98-8080-425f-922A-DABF3DE3F69A}
Provider=%ManufacturerName%
CatalogFile=umdffilter.cat
DriverVer=01/02/2013,18.8.52.851`

[Manufacturer]
%ManufacturerName%=Standard,NTamd64

[Standard.NTamd64]
%DeviceName%=MyDevice_Install, usb\vid_04e8&pid_6860

[SourceDisksFiles]
umdffilter.dll=1
WudfUpdate_01011.dll=1
WdfCoInstaller01011.dll=1
WinUsbCoinstaller2.dll=1

[SourceDisksNames]
1 = %DiskName%

; =================== UMDF Filter Driver ==================================

[MyDevice_Install.NT]
CopyFiles=UMDriverCopy
Include=wpdmtp.inf, WINUSB.INF          ; Import sections from wpdmtp.inf and WINUSB.INF
Needs=WPD.MTP, WINUSB.NT                ; Run the CopyFiles & AddReg directives for wpdmtp.inf and WINUSB.INF

[MyDevice_Install.NT.hw]
Include = wpdmtp.inf
Needs   = WPD.MTP.Registration
AddReg  = MyDevice_AddReg

[MyDevice_Install.NT.Services]
AddService=WUDFRd,0x000001fa,WUDFRD_ServiceInstall  ; flag 0x2 sets this as the service for the device
AddService=WinUsb,0x000001f8,WinUsb_ServiceInstall  ; this service is installed because its a filter.

[MyDevice_Install.NT.CoInstallers]
CopyFiles=CoInstallers_CopyFiles
AddReg=CoInstallers_AddReg

[MyDevice_Install.NT.Wdf]
Include = wpdmtp.inf
Needs = WPD.MTP.Wdf
KmdfService=WINUSB, WinUsb_Install
UmdfService=umdffilter,umdffilter_Install
UmdfServiceOrder=umdffilter,WpdMtpDriver    ; upper filter

[WinUsb_Install]
KmdfLibraryVersion=1.11

[WpdMtpDriver_Install]
UmdfLibraryVersion=1.11.0 

[umdffilter_Install]
UmdfLibraryVersion=1.11.0 
ServiceBinary=%12%\UMDF\umdffilter.dll
DriverCLSID={8cec927c-219a-4777-baea-8626d6a0ce50}

[MyDevice_AddReg]
HKR,,"LowerFilters",0x00010008,"WinUsb" ; FLG_ADDREG_TYPE_MULTI_SZ | FLG_ADDREG_APPEND

[WUDFRD_ServiceInstall]
DisplayName = %WudfRdDisplayName%
ServiceType = 1
StartType = 3
ErrorControl = 1
ServiceBinary = %12%\WUDFRd.sys
LoadOrderGroup = Base

[WinUsb_ServiceInstall]
DisplayName     = %WinUsb_SvcDesc%
ServiceType     = 1
StartType       = 3
ErrorControl    = 1
ServiceBinary   = %12%\WinUSB.sys

[CoInstallers_CopyFiles]
WdfCoInstaller01011.dll
WudfUpdate_01011.dll
WinUsbCoinstaller2.dll

[CoInstallers_AddReg]
HKR,,CoInstallers32,0x00010000,"WudfUpdate_01011.dll", "WinUsbCoinstaller2.dll", "WdfCoInstaller01011.dll,WdfCoInstaller"

[DestinationDirs]
UMDriverCopy=12,UMDF        ; copy to drivers\umdf
CoInstallers_CopyFiles=11   ; copy to system32

[UMDriverCopy]
umdffilter.dll

; =================== Generic ==================================

[Strings]
ManufacturerName="Me"
ClassName="Samples" ; TODO: edit ClassName
DiskName = "umdffilter Installation Disk"
WinUsb_SvcDesc="WinUSB Driver"
WudfRdDisplayName="Windows Driver Foundation - User-mode Driver Framework Reflector"
DeviceName="umdffilter Device"`

No correct solution

OTHER TIPS

@oren671: You should be able to install a UMDF filter driver on a MTP stack as an upper filter. I tried using the same inf shared above and found that the WpdMtpDriver_Install section defined in your inf caused an error since it is already included from in wpdmtp.inf 'WPD.MTP.Wdf' section (see Include/Needs under DDInstall.Wdf).

Error found in %SystemDrive%\Windows\setupact.log: "...Error reading section [WpdMtpDriver_Install] key UmdfLibraryVersion - duplicate key found..." Please check SystemDrive%\Windows\Inf\setupapi.dev.log & %SystemDrive%\Windows\setupact.log for failures.

Removing the 'WpdMtpDriver_Install' section from the above inf, I was able to install the UMDF filter on the MTP stack.

I’ve modified the sample inf to use the MTP Setup inf directions link. MTP with USB transport uses both WPD (which is UMDF) and WINUSB, so including the relevant sections (DDInstall, DDInstall.hw, DDInstall.Services, DDInstall.CoInstallers, DDInstall.Wdf) from wpdmtp.inf in your filter inf should eliminate the need to duplicate them.

;
; WUDFOsrUsbFilterOnMTPDriver.inf - Install a UM Filter driver on an MTP device'
;

[Version]
Signature="$Windows NT$"
Class=WPD
ClassGuid={EEC5AD98-8080-425f-922A-DABF3DE3F69A}
Provider=%MSFTUMDF%
DriverVer=02/03/2014,18.8.52.851
CatalogFile=wudf.cat

[Manufacturer]
%MSFTUMDF%=Microsoft,NTamd64

[Microsoft.NTamd64]
%OsrUsbDeviceName%=OsrUsb_Install, USB\VID_04E8&PID_6860&MI_00
%OsrUsbDeviceName%=OsrUsb_Install, USB\VID_04E8&PID_6860

[SourceDisksFiles]
WudfOsrUsbFilter.dll=1

[SourceDisksNames]
1 = %MediaDescription%

; =================== UMDF OSR Filter Driver ==================================

[OsrUsb_Install.NT]
CopyFiles=UMDriverCopy
Include = wpdmtp.inf, WINUSB.INF
Needs   = WPD.MTP, WINUSB.NT

[OsrUsb_Install.NT.hw]
Include = wpdmtp.inf
Needs   = WPD.MTP.Registration

[OsrUsb_Install.NT.Services]
Include = wpdmtp.inf
Needs   = WPD.MTP.Services

[OsrUsb_Install.NT.Wdf]
Include = wpdmtp.inf
Needs = WPD.MTP.Wdf
UmdfService=WudfOsrUsbFilter, WudfOsrUsbFilter_Install
UmdfServiceOrder=WpdMtpDriver, WUDFOsrUsbFilter

[OsrUsb_Install.NT.CoInstallers]
Include = wpdmtp.inf
Needs = WPD.MTP.CoInstallers

[WudfOsrUsbFilter_Install]
UmdfLibraryVersion=1.11.0
DriverCLSID = "{422d8dbc-520d-4d7e-8f53-920e5c867e6c}"
ServiceBinary = "%12%\UMDF\WUDFOsrUsbFilter.dll"

[DestinationDirs]
UMDriverCopy=12,UMDF        ; copy to drivers\umdf

[UMDriverCopy]
WudfOsrUsbFilter.dll

; =================== Generic ==================================

[Strings]
MSFTUMDF="Microsoft Internal (WDF:UMDF)"
MediaDescription="Microsoft UMDF OSR USB Sample Device Installation Media"
OsrUsbDeviceName="Microsoft UMDF OSR Usb Sample Device With Filter on User-mode Driver"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top