Access is denied when trying to CustomDevice.FromIdAsync using a Software KMDF Driver

0

I have prepared a KMDF driver meant to be accessed by a UWP using the guidelines found within MSDN (HSA for Driver, HSA for UWP)

The UWP App I used is the CustomCapability example found under Universal Windows Samples The KMDF is a sample driver with only the DriverEntry, Unload, and EvtDeviceAdd implemented. Also, the driver has been installed, and is visible in Device Manager, but there is no actual/external device plugged in.

In the UWP App, I can see the Sample Driver from the device watcher. However, when attempting to connect/open the driver using :

var device = await CustomDevice.FromIdAsync(Id, DeviceAccessMode.Read, DeviceSharingMode.Exclusive);

An exception System.UnauthorizedAccessException' in System.Private.CoreLib.ni.dll is being thrown as seen below:

exception

I have matched the required information that needs to get across both apps, and I have gone and tried this one out with the assumption that the SCCD does not require signing if it is only meant to run in development mode.

Aside from the SCCD configuration, I have also tried adding a <DeviceCapability> for the class interface of the driver, as well as for lowLevel devices, but it did not seem to do anything related to the exception.

I don't see any other places for issues aside from the SCCD and the INF file, but I would like to show them just in case I missed something:

SCCD:

<?xml version="1.0" encoding="utf-8"?>
<CustomCapabilityDescriptor xmlns="http://schemas.microsoft.com/appx/2016/sccd" xmlns:s="http://schemas.microsoft.com/appx/2016/sccd">
    <CustomCapabilities>
        <CustomCapability Name="microsoft.firmwareRead_cw5n1h2txyewy"></CustomCapability> <!-- this one is not used by the way -->
        <CustomCapability Name="microsoft.hsaTestCustomCapability_q536wpkpf5cy2"></CustomCapability> 
    </CustomCapabilities>
    <AuthorizedEntities>
        <AuthorizedEntity AppPackageFamilyName="Microsoft.SDKSamples.CustomCapability.CS_8wekyb3d8bbwe" CertificateSignatureHash="1db5ceeaa4c97c6f6e91c0ce76830361776c64635ecfecdb2f157ca818ae3b69"></AuthorizedEntity>
  </AuthorizedEntities>
    <Catalog>xxxx</Catalog>
</CustomCapabilityDescriptor>

INF Strings and Interface section:

[Strings]
SPSVCINST_ASSOCSERVICE= 0x00000002
ManufacturerName="Samples" ;TODO: Replace with your manufacturer name
ClassName="Samples" ; TODO: edit ClassName
DiskName = "Samples_Driver Installation Disk"
Samples_Driver.DeviceDesc = "Samples_Driver Device"
Samples_Driver.SVCDESC = "Samples_Driver Service"
GUID_DEVINTERFACE_OSRUSBFX2="573E8C73-0CB4-4471-A1BF-FAB26C31D384"
DEVPKEY_DeviceInterface_UnrestrictedAppCapabilities="026e516e-b814-414b-83cd-856d6fef4822"
CustomCapability="microsoft.hsaTestCustomCapability_q536wpkpf5cy2"

;
;----------------- Interface Section ----------------------
;
[WDMPNPB003_Device.NT.Interfaces] 
AddInterface= {%GUID_DEVINTERFACE_OSRUSBFX2%},,AddInterfaceSection 

[AddInterfaceSection] 
AddProperty= AddInterfaceSection.AddProps 

[AddInterfaceSection.AddProps] 
; DEVPKEY_DeviceInterface_UnrestrictedAppCapabilities 
{%DEVPKEY_DeviceInterface_UnrestrictedAppCapabilities%}, 8, 0x2012,, %CustomCapability%
uwp
uwp-xaml
inf
kmdf
asked on Stack Overflow Nov 26, 2019 by Jer Yango

1 Answer

0

I managed to find the problem on the INF file. The section labeled Interface Section has been copied directly from the HSA for Drivers guide by Microsoft. The modifications done were only those that were explicitly written within the guidelines.

The INF snippet below describes the starting point of the interface section:

[WDMPNPB003_Device.NT.Interfaces] 
AddInterface= {zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz},,AddInterfaceSection 

What the guide did not explicitly mention is that we would have to replace WDMPNPB003_Device with your own Driver_name/Root namespace.

A petty mistake, but will most likely be what driver development new comers will encounter.

answered on Stack Overflow Nov 27, 2019 by Jer Yango

User contributions licensed under CC BY-SA 3.0