Help me understand HSA

So I’m experimenting with HSA. I created a driver (kmdf), and it works fine from a desktop test app. I am appending the INF at the end of this post.
I used this as a guide: https://docs.microsoft.com/en-us/windows-hardware/drivers/devapps/hardware-support-app--hsa--steps-for-driver-developers and made the
following assumptions:

  1. I don’t need anything signed as long as i’m in dev mode and have test signing on.
  2. I can name my own custom capability and I don’t need my app to have a real store ID.

Now on to the app, using this guide:
https://docs.microsoft.com/en-us/windows-hardware/drivers/devapps/hardware-support-app--hsa--steps-for-app-developers

I created a SCCD and modified the app manifest accordingly.

I tried to get connected to it from UWP, and that’s where things broke. My attempt was something like this:

var selector = CustomDevice.GetDeviceSelector(new Guid(“{4D8E7CE0-5CF2-4831-A89D-AE4C760FD151}”));
var info = await DeviceInformation.FindAllAsync(selector, null, DeviceInformationKind.DeviceInterface);

but I get back an empty set (the 4D… guid is the GUID in [*_Device.NT.Interfaces] , see the INF at the end of this post). What am I doing wrong? Or did I go off the rails somewhere ealier? I suspect I’m getting confused by all the GUIDs in play here.


This is my SCCD (the app package family name matches the one from the app):

<?xml version="1.0" encoding="utf-8"?>








FFFF


This is my app manifest:

<?xml version="1.0" encoding="utf-8"?>



<mp:phoneidentity phoneproductid=“6185cbda-baf7-4db3-b572-59d32453ebac” phonepublisherid=“00000000-0000-0000-0000-000000000000”></mp:phoneidentity>

Test Lab
NRomanov
Assets\StoreLogo.png









<uap:visualelements displayname=“Test Lab” square150x150logo=“Assets\Square150x150Logo.png” square44x44logo=“Assets\Square44x44Logo.png” description=“biosed” backgroundcolor=“transparent”>
<uap:defaulttile wide310x150logo=“Assets\Wide310x150Logo.png”>
</uap:defaulttile>
<uap:splashscreen image=“Assets\SplashScreen.png”></uap:splashscreen>
</uap:visualelements>




<uap4:customcapability name=“Test.Lab_qfffwpkpf5cy2”></uap4:customcapability>


This is my driver’s INF (driver shows up correctly in device manger and I can start/stop it, and do ioctls from desktop test app):

[Version]
Signature=“$WINDOWS NT$”
Class=%ClassName%
ClassGuid=%ClassGuid%
Provider=%ManufacturerName%
CatalogFile=testlab1.cat
DriverVer= ; TODO: set DriverVer in stampinf property pages

[DestinationDirs]
DefaultDestDir = 12
testlab1_Device_CoInstaller_CopyFiles = 11

; ================= Class section =====================

[ClassInstall32]
Addreg=TestlabReg

[TestlabReg]
HKR,0,%ClassName%
HKR,Icon,-5

[SourceDisksNames]
1 = %DiskName%,“”

[SourceDisksFiles]
testlab1.sys = 1,
WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll=1 ; make sure the number matches with SourceDisksNames

;*****************************************
; Install Section
;*****************************************

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

[Standard.NT$ARCH$]
%testlab1.DeviceDesc%=testlab1_Device, Root\testlab1

[testlab1_Device.NT]
CopyFiles=Drivers_Dir

[Drivers_Dir]
testlab1.sys

;-------------- Service installation
[testlab1_Device.NT.Services]
AddService = testlab1,%SPSVCINST_ASSOCSERVICE%, testlab1_Service_Inst

; -------------- testlab1 driver install sections
[testlab1_Service_Inst]
DisplayName = %testlab1.SVCDESC%
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 3 ; SERVICE_DEMAND_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %12%\testlab1.sys

;
;— testlab1_Device Coinstaller installation ------
;

[testlab1_Device.NT.CoInstallers]
AddReg=testlab1_Device_CoInstaller_AddReg
CopyFiles=testlab1_Device_CoInstaller_CopyFiles

[testlab1_Device_CoInstaller_AddReg]
HKR,CoInstallers32,0x00010000, “WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll,WdfCoInstaller”

[testlab1_Device_CoInstaller_CopyFiles]
WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll

[testlab1_Device.NT.Wdf]
KmdfService = testlab1, testlab1_wdfsect

[testlab1_wdfsect]
KmdfLibraryVersion = $KMDFVERSION$

[Strings]
SPSVCINST_ASSOCSERVICE= 0x00000002
ManufacturerName=“ChangeMe”
ClassName=“TestLab”
ClassGuid=“{A7DC9878-C387-4E3E-B785-91323C695BC4}”
DiskName = “testlab1 Installation Disk”
testlab1.DeviceDesc = “Test Lab Driver”
testlab1.SVCDESC = “Test Lab Driver”
KMYFACE=“{4D8E7CE0-5CF2-4831-A89D-AE4C760FD151}”

[testlab1_Device.NT.Interfaces]
AddInterface= %KMYFACE%,AddInterfaceSection

[AddInterfaceSection]
AddProperty= AddInterfaceSection.AddProps

[AddInterfaceSection.AddProps]
{A4DE9E9E-83E9-494A-A3C2-584DF8982E55}, 8, 0x2012, “Test.Lab_qfffwpkpf5cy2”

Are you registering and enabling the device interface (as described in the INF) in your driver at runtime? This code,

var selector = CustomDevice.GetDeviceSelector(new Guid(“{4D8E7CE0-5CF2-4831-A89D-AE4C760FD151}”));
var info = await DeviceInformation.FindAllAsync(selector, null, DeviceInformationKind.DeviceInterface);

works without an SCCD or the additional property you added to the device interface in your INF. The code just finds all instances of the device interface. The property and the SCCD allow you open the discovered instance of the interface.

d

-----Original Message-----
From: xxxxx@lists.osr.com On Behalf Of xxxxx@redsigil.com
Sent: Thursday, August 30, 2018 4:35 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Help me understand HSA

So I’m experimenting with HSA. I created a driver (kmdf), and it works fine from a desktop test app. I am appending the INF at the end of this post.
I used this as a guide: https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows-hardware%2Fdrivers%2Fdevapps%2Fhardware-support-app--hsa--steps-for-driver-developers&amp;data=02|01|Doron.Holan%40microsoft.com|fa64f543bd834cae962608d60ed138dd|72f988bf86f141af91ab2d7cd011db47|1|0|636712689100304210&amp;sdata=Hof%2B5MMHsyxO%2FtV28%2FWk92RGowi%2Fy3rXl2I60tLojJo%3D&amp;reserved=0 and made the following assumptions:

1. I don’t need anything signed as long as i’m in dev mode and have test signing on.
2. I can name my own custom capability and I don’t need my app to have a real store ID.

Now on to the app, using this guide:
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows-hardware%2Fdrivers%2Fdevapps%2Fhardware-support-app--hsa--steps-for-app-developers&amp;data=02|01|Doron.Holan%40microsoft.com|fa64f543bd834cae962608d60ed138dd|72f988bf86f141af91ab2d7cd011db47|1|0|636712689100304210&amp;sdata=fD3EWbwC2dMO0JfVazmnKTEEm8mvKhL3SatpPkLgKpI%3D&amp;reserved=0

I created a SCCD and modified the app manifest accordingly.

I tried to get connected to it from UWP, and that’s where things broke. My attempt was something like this:

var selector = CustomDevice.GetDeviceSelector(new Guid(“{4D8E7CE0-5CF2-4831-A89D-AE4C760FD151}”));
var info = await DeviceInformation.FindAllAsync(selector, null, DeviceInformationKind.DeviceInterface);

but I get back an empty set (the 4D… guid is the GUID in [*_Device.NT.Interfaces] , see the INF at the end of this post). What am I doing wrong? Or did I go off the rails somewhere ealier? I suspect I’m getting confused by all the GUIDs in play here.


This is my SCCD (the app package family name matches the one from the app):

<?xml version="1.0" encoding="utf-8"?>







FFFF




This is my app manifest:

<?xml version="1.0" encoding="utf-8"?>


<mp:phoneidentity phoneproductid=“6185cbda-baf7-4db3-b572-59d32453ebac” phonepublisherid=“00000000-0000-0000-0000-000000000000”></mp:phoneidentity>

Test Lab
NRomanov
Assets\StoreLogo.png









<uap:visualelements displayname=“Test Lab” square150x150logo=“Assets\Square150x150Logo.png” square44x44logo=“Assets\Square44x44Logo.png” description=“biosed” backgroundcolor=“transparent”>
<uap:defaulttile wide310x150logo=“Assets\Wide310x150Logo.png”>
</uap:defaulttile>
<uap:splashscreen image=“Assets\SplashScreen.png”></uap:splashscreen>
</uap:visualelements>




<uap4:customcapability name=“Test.Lab_qfffwpkpf5cy2”></uap4:customcapability>




This is my driver’s INF (driver shows up correctly in device manger and I can start/stop it, and do ioctls from desktop test app):

[Version]
Signature=“$WINDOWS NT$”
Class=%ClassName%
ClassGuid=%ClassGuid%
Provider=%ManufacturerName%
CatalogFile=testlab1.cat
DriverVer= ; TODO: set DriverVer in stampinf property pages

[DestinationDirs]
DefaultDestDir = 12
testlab1_Device_CoInstaller_CopyFiles = 11

; ================= Class section =====================

[ClassInstall32]
Addreg=TestlabReg

[TestlabReg]
HKR,0,%ClassName%
HKR,Icon,-5

[SourceDisksNames]
1 = %DiskName%,“”

[SourceDisksFiles]
testlab1.sys = 1,
WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll=1 ; make sure the number matches with SourceDisksNames

;
; Install Section
;


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

[Standard.NT$ARCH$]
%testlab1.DeviceDesc%=testlab1_Device, Root\testlab1

[testlab1_Device.NT]
CopyFiles=Drivers_Dir

[Drivers_Dir]
testlab1.sys

;-------------- Service installation
[testlab1_Device.NT.Services]
AddService = testlab1,%SPSVCINST_ASSOCSERVICE%, testlab1_Service_Inst

; -------------- testlab1 driver install sections [testlab1_Service_Inst]
DisplayName = %testlab1.SVCDESC%
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 3 ; SERVICE_DEMAND_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %12%\testlab1.sys

;
;— testlab1_Device Coinstaller installation ------ ;

[testlab1_Device.NT.CoInstallers]
AddReg=testlab1_Device_CoInstaller_AddReg
CopyFiles=testlab1_Device_CoInstaller_CopyFiles

[testlab1_Device_CoInstaller_AddReg]
HKR,CoInstallers32,0x00010000, “WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll,WdfCoInstaller”

[testlab1_Device_CoInstaller_CopyFiles]
WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll

[testlab1_Device.NT.Wdf]
KmdfService = testlab1, testlab1_wdfsect

[testlab1_wdfsect]
KmdfLibraryVersion = $KMDFVERSION$

[Strings]
SPSVCINST_ASSOCSERVICE= 0x00000002
ManufacturerName=“ChangeMe”
ClassName=“TestLab”
ClassGuid=“{A7DC9878-C387-4E3E-B785-91323C695BC4}”
DiskName = “testlab1 Installation Disk”
testlab1.DeviceDesc = “Test Lab Driver”
testlab1.SVCDESC = “Test Lab Driver”
KMYFACE=“{4D8E7CE0-5CF2-4831-A89D-AE4C760FD151}”

[testlab1_Device.NT.Interfaces]
AddInterface= %KMYFACE%,AddInterfaceSection

[AddInterfaceSection]
AddProperty= AddInterfaceSection.AddProps

[AddInterfaceSection.AddProps]
{A4DE9E9E-83E9-494A-A3C2-584DF8982E55}, 8, 0x2012, “Test.Lab_qfffwpkpf5cy2”


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

I think I am, but I don’t know if I’m doing it right. Here’s the skeleton of my AddDevice:

DosDeviceLinkName = "\
NTSTATUS MyAdd(In PDRIVER_OBJECT driverObject, In PDEVICE_OBJECT pdo)
{

IoCreateDevice( driverObject, sizeof(DEVICE_EXTENSION), &deviceName, FILE_DEVICE_UNKNOWN, 0, FALSE, &fdo);

dext= (PDEVICE_EXTENSION)fdo->DeviceExtension;
GUID myGuid= DriverInterfaceGuid; // this is the GUID from the INF file, 4D8e…

… = IoRegisterDeviceInterface(pdo, myGuid= NULL, &dext->InterfaceName);
… = IoCreateSymbolicLink(&DosDevicesLinkName, &deviceExtension->InterfaceName);
… = IoSetDeviceInterfaceState(&dext->InterfaceName, TRUE);
}

It installs okay, shows up in device manager, and starts ok.

I did notice that if I query via FindAllAsync (with no selector), I see the interface in there:
Device is \?\ROOT#TestLab#0000#{4d8e7ce0-5cf2-4831-a89d-ae4c760fd151} and the kind is “Device Interface”.

When I try to use that string with CustomDevice.FromIdAsync(), I get a “file not found” error (0x80070002). So it doesn’t seem like that’s the right string.

Why are you writing a WDM driver and not using kmdf?

Bent from my phone


From: 30301652600n behalf of
Sent: Friday, August 31, 2018 10:56 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Help me understand HSA

I think I am, but I don’t know if I’m doing it right. Here’s the skeleton of my AddDevice:

DosDeviceLinkName = "\
NTSTATUS MyAdd(In PDRIVER_OBJECT driverObject, In PDEVICE_OBJECT pdo)
{

IoCreateDevice( driverObject, sizeof(DEVICE_EXTENSION), &deviceName, FILE_DEVICE_UNKNOWN, 0, FALSE, &fdo);

dext= (PDEVICE_EXTENSION)fdo->DeviceExtension;
GUID myGuid= DriverInterfaceGuid; // this is the GUID from the INF file, 4D8e…

… = IoRegisterDeviceInterface(pdo, myGuid= NULL, &dext->InterfaceName);
… = IoCreateSymbolicLink(&DosDevicesLinkName, &deviceExtension->InterfaceName);
… = IoSetDeviceInterfaceState(&dext->InterfaceName, TRUE);
}

It installs okay, shows up in device manager, and starts ok.

I did notice that if I query via FindAllAsync (with no selector), I see the interface in there:
Device is \?\ROOT#TestLab#0000#{4d8e7ce0-5cf2-4831-a89d-ae4c760fd151} and the kind is “Device Interface”.

When I try to use that string with CustomDevice.FromIdAsync(), I get a “file not found” error (0x80070002). So it doesn’t seem like that’s the right string.


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

I don’t know, does it matter? I can backtrack if that is the problem.

Okay, since I can’t get it to work this way, I am going to redo it as KMDF. Thanks for the pointer, maybe that is the problem.

It likely isn?t the underlying problem but you can eliminate other driver errors and other stability issues by using kmdf.

d

Bent from my phone


From: 30561760000n behalf of
Sent: Saturday, September 1, 2018 6:12 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Help me understand HSA

Okay, since I can’t get it to work this way, I am going to redo it as KMDF. Thanks for the pointer, maybe that is the problem.


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

Just to close this topic, in my particular case, changing to KMDF did indeed fix the problem. I also noticed that the MSFT documentation calls for KMDF/UMDF. I am not rulling out there was a bug in my WDM, but I imagine the SCCD-based authorization model may not work in WDM… at least not without additional work.

Sccd knows nothing of driver model or how it is implemented. Kmdf gives you the correct driver implementation out of the box so you probably had a wdm related bug previously.

d

Bent from my phone


From: Nicholai_Romanov
Sent: Monday, November 26, 2018 8:57:22 AM
To: Doron Holan
Subject: Re: [NTDEV] Help me understand HSA

OSR https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcommunity.osr.com%2F&amp;data=02|01|doron.holan%40microsoft.com|22936390f6f44048ea1a08d653c03c6d|72f988bf86f141af91ab2d7cd011db47|1|1|636788482457709973&amp;sdata=ymD8bI7xD92MKe33hXFot%2Fv6z2XmhnzSL9fJkfM4foo%3D&amp;reserved=0
Nicholai_Romanov commented on Help me understand HSA

Just to close this topic, in my particular case, changing to KMDF did indeed fix the problem. I also noticed that the MSFT documentation calls for KMDF/UMDF. I am not rulling out there was a bug in my WDM, but I imagine the SCCD-based authorization model may not work in WDM… at least not without additional work.