硬體支援應用程式 (HSA):驅動程式開發人員的步驟

硬體支援應用程式 (HSA) 是與特定驅動程式或 RPC(遠端過程呼叫) 端點配對的裝置特定應用程式。

若要將市集應用程式與驅動程式產生關聯,請先保留稱為自定義功能的特殊值。 然後允許存取公告功能的應用程式,並將功能提供給應用程式開發人員。 此頁面說明驅動程式開發人員的這些步驟。

應用程式開發人員的步驟描述於 硬體支援應用程式 (HSA):應用程式開發人員的步驟。

HSA 是三 個「DCH」設計原則之一。

保留自定義功能

首先,保留自定義功能:

  1. 以下列資訊傳送電子郵件Microsoft硬體支援應用程式檢閱 (HSAReview@microsoft.com) :

    • 連絡人資訊

    • 公司名稱

    • 功能的名稱(必須是唯一的,並參考擁有者)

    • 功能需要存取哪些資源?

    • 任何安全性或隱私權考慮

    • 哪些數據事件會處理給合作夥伴?

      • 事件會包含個人識別碼,例如精確的使用者位置、密碼、IP 位址、PUID、裝置識別碼、CID、使用者名稱和聯繫人數據嗎?

      • 數據事件會保留在用戶裝置上,還是傳送給合作夥伴?

    • 您的功能提供存取權的數據為何?

    • 這項功能的使用者有哪些優點?

    • 包含Microsoft市集應用程式發行者標識碼。 若要取得一個專案,請在 [Microsoft市集] 頁面上建立基本架構應用程式專案。 如需保留 App PFN 的詳細資訊,請參閱 保留名稱來建立您的應用程式。

  2. 如果已核准要求,Microsoft電子郵件以CompanyName.capabilityName_PublisherID格式傳回唯一的自定義功能字串名稱。

現在您可以使用自訂功能來允許存取 RPC 端點或驅動程式。

允許使用自定義功能存取 UWP 應用程式的 RPC 端點

若要允許存取具有自定義功能的 UWP 應用程式 RPC 端點,請遵循下列步驟:

  1. 呼叫 DeriveCapabilitySidsFromName ,將自定義功能名稱轉換成安全性識別碼 (SID)。

  2. 將 SID 新增至您允許的 ACE 存取,以及 RPC 端點之安全性描述元所需的任何其他 SID。

  3. 使用安全性描述元中的資訊建立 RPC 端點。

您可以在自訂功能範例的 RPC 伺服器程式代碼 中看到 上述 的實作。

允許使用自定義功能存取 UWP 應用程式的驅動程式

若要允許使用自定義功能存取 UWP 應用程式的驅動程式,請將幾行新增至 INF 檔案或驅動程式來源。

在 INF 檔案中,指定您的自訂功能,如下所示:

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

[AddInterfaceSection]
AddProperty= AddInterfaceSection.AddProps

[AddInterfaceSection.AddProps]
; DEVPKEY_DeviceInterface_UnrestrictedAppCapabilities
{026e516e-b814-414b-83cd-856d6fef4822}, 8, 0x2012,, "CompanyName.myCustomCapabilityName_MyStorePubId"

或者,在驅動程式中執行下列動作:

WDF_DEVICE_INTERFACE_PROPERTY_DATA PropertyData = {};
WCHAR customCapabilities[] = L"CompanyName.myCustomCapabilityName_MyStorePubId\0";

WDF_DEVICE_INTERFACE_PROPERTY_DATA_INIT(
   &PropertyData,
   &m_VendorDefinedSubType,
   &DEVPKEY_DeviceInterface_UnrestrictedAppCapabilities);

Status = WdfDeviceAssignInterfaceProperty(
    m_FxDevice,
    &PropertyData,
    DEVPROP_TYPE_STRING_LIST,
    ARRAYSIZE(customCapabilities),
    reinterpret_cast<PVOID>(customCapabilities));

將 取代 zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz 為要公開之介面的 GUID。 將 CompanyName 取代為您的公司名稱、myCustomCapabilityName 取代為您公司內唯一的名稱,並以您的發行者市集標識碼取代 MyStorePubId

如需上述驅動程式程式代碼的範例,請參閱適用於通用驅動程式驅動程式套件安裝工具組。

若要在核心模式中設定 屬性,請使用程式代碼,如下所示:

#if defined(NTDDI_WIN10_RS2) && (NTDDI_VERSION >= NTDDI_WIN10_RS2)

//
// Adding Custom Capability:
//
// Adds a custom capability to device interface instance that allows a Windows
// Store device app to access this interface using Windows.Devices.Custom namespace.
// This capability can be defined either in INF or here as shown below. In order
// to define it from the INF, uncomment the section "OsrUsb Interface installation"
// from the INF and remove the block of code below.
//

static const wchar_t customCapabilities[] = L"microsoft.hsaTestCustomCapability_q536wpkpf5cy2\0";

status = g_pIoSetDeviceInterfacePropertyData(&symbolicLinkName,
                                              &DEVPKEY_DeviceInterface_UnrestrictedAppCapabilities,
                                              0,
                                              0,
                                              DEVPROP_TYPE_STRING_LIST,
                                              sizeof(customCapabilities),
                                              (PVOID)&customCapabilities);

if (!NT_SUCCESS(status)) {
    TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP,
                "IoSetDeviceInterfacePropertyData failed to set custom capability property  %!STATUS!\n", status);
    goto Error;
}

#endif

準備已簽署的自定義功能描述元 (SCCD) 檔案

已簽署的自定義功能描述元 (SCCD) 檔案是已簽署的 XML 檔案,授權使用一或多個自定義功能。 驅動程式或 RPC 端點的擁有者會提供此檔案,以授與應用程式開發人員的自定義功能。

若要準備 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.hsaTestCustomCapability_q536wpkpf5cy2"></CustomCapability>
</CustomCapabilities>
<AuthorizedEntities>
    <AuthorizedEntity AppPackageFamilyName="MicrosoftHSATest.Microsoft.SDKSamples.Hsa.CPP_q536wpkpf5cy2" CertificateSignatureHash="ca9fc964db7e0c2938778f4559946833e7a8cfde0f3eaa07650766d4764e86c4"></AuthorizedEntity>
</AuthorizedEntities>
<Catalog>0000</Catalog>
</CustomCapabilityDescriptor>

接下來,自定義功能擁有者會從應用程式開發人員取得套件系列名稱 (PFN) 和簽章哈希,並更新 SCCD 檔案中的這些字串。

注意

應用程式不需要直接使用憑證簽署,但指定的憑證必須是簽署應用程式的憑證鏈結的一部分。

完成 SCCD 之後,功能擁有者會將電子郵件傳送給Microsoft以進行簽署。 Microsoft會將已簽署的 SCCD 傳回給功能擁有者。

功能擁有者接著會將 SCCD 傳送給應用程式開發人員。 應用程式開發人員在應用程式指令清單中包含已簽署的 SCCD。 若要瞭解應用程式開發人員需要做什麼,請參閱 硬體支援應用程式 (HSA):應用程式開發人員的步驟。

限制 SCCD 的範圍

為了進行測試,自定義功能擁有者可以將硬體支援應用程式的安裝限制為開發人員模式中的計算機。

若要這樣做,請在取得由 Microsoft 簽署的 SCCD 之前,新增 DeveloperModeOnly

<?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.hsaTestCustomCapability_q536wpkpf5cy2"></CustomCapability>
</CustomCapabilities>
<AuthorizedEntities>
    <AuthorizedEntity AppPackageFamilyName="MicrosoftHSATest.Microsoft.SDKSamples.Hsa.CPP_q536wpkpf5cy2" CertificateSignatureHash="ca9fc964db7e0c2938778f4559946833e7a8cfde0f3eaa07650766d4764e86c4"></AuthorizedEntity>
</AuthorizedEntities>
<Catalog>0000</Catalog>
<DeveloperModeOnly Value="true" />
</CustomCapabilityDescriptor>

產生的已簽署 SCCD 僅適用於開發人員模式中的裝置。

允許任何應用程式使用自定義功能

建議您指定可使用自定義功能的授權實體(應用程式)。 不過,在某些情況下,您可能想要允許任何應用程式包含 SCCD。 從 Windows 10 版本 1809 開始,您可以將 AllowAny 新增至 AuthorizedEntities 元素來執行此動作。 因為最佳做法是在 SCCD 檔案中宣告授權的實體,因此請在提交要由Microsoft簽署的 SCCD 時,提供使用 AllowAny 的理由。

<?xml version="1.0" encoding="utf-8"?>
<CustomCapabilityDescriptor xmlns="http://schemas.microsoft.com/appx/2018/sccd" xmlns:s="http://schemas.microsoft.com/appx/2018/sccd">
<CustomCapabilities>
    <CustomCapability Name="microsoft.hsaTestCustomCapability_q536wpkpf5cy2"></CustomCapability>
</CustomCapabilities>
<AuthorizedEntities AllowAny="true"/>
<Catalog>0000</Catalog>
</CustomCapabilityDescriptor>

產生的已簽署 SCCD 將會在任何應用程式套件中驗證。

多個 SCCD

從 Windows 10 版本 1803 開始,應用程式可以從一或多個 SCCD 檔案宣告自定義功能。 將 SCCD 檔案放在應用程式套件的根目錄中。

SCCD 簽署順序的摘要

下圖摘要說明上述順序:

取得 SCCD 簽署。

SCCD XML 架構

以下是 SCCD 檔案的正式 XML XSD 架構。 在提交 SCCD 以供檢閱之前,請使用此架構來驗證您的 SCCD。 如需使用 IntelliSense 匯入架構和驗證的資訊,請參閱 架構快取XML 文件驗證

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
  xmlns:xs="https://www.w3.org/2001/XMLSchema"
  targetNamespace="http://schemas.microsoft.com/appx/2016/sccd"
  xmlns:s="http://schemas.microsoft.com/appx/2016/sccd"
  xmlns="http://schemas.microsoft.com/appx/2016/sccd">

  <xs:element name="CustomCapabilityDescriptor" type="CT_CustomCapabilityDescriptor">
    <xs:unique name="Unique_CustomCapability_Name">
      <xs:selector xpath="s:CustomCapabilities/s:CustomCapability"/>
      <xs:field xpath="@Name"/>
    </xs:unique>
  </xs:element>

  <xs:complexType name="CT_CustomCapabilityDescriptor">
    <xs:sequence>
      <xs:element ref="CustomCapabilities" minOccurs="1" maxOccurs="1"/>
      <xs:element ref="AuthorizedEntities" minOccurs="1" maxOccurs="1"/>
      <xs:element ref="DeveloperModeOnly" minOccurs="0" maxOccurs="1"/>
      <xs:element ref="Catalog" minOccurs="1" maxOccurs="1"/>
      <xs:any minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:element name="CustomCapabilities" type="CT_CustomCapabilities" />

  <xs:complexType name="CT_CustomCapabilities">
    <xs:sequence>
      <xs:element ref="CustomCapability" minOccurs="1" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:element name="CustomCapability">
    <xs:complexType>
      <xs:attribute name="Name" type="ST_CustomCapability" use="required"/>
    </xs:complexType>
  </xs:element>

  <xs:simpleType name="ST_NonEmptyString">
    <xs:restriction base="xs:string">
      <xs:minLength value="1"/>
      <xs:maxLength value="32767"/>
      <xs:pattern value="[^\s]|([^\s].*[^\s])"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_CustomCapability">
    <xs:annotation>
      <xs:documentation>Custom capabilities should be a string in the form of Company.capabilityName_PublisherId</xs:documentation>
    </xs:annotation>
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="[A-Za-z0-9][-_.A-Za-z0-9]*_[a-hjkmnp-z0-9]{13}"/>
      <xs:minLength value="15"/>
      <xs:maxLength value="255"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:element name="AuthorizedEntities" type="CT_AuthorizedEntities" />

  <xs:complexType name="CT_AuthorizedEntities">
    <xs:sequence>
      <xs:element ref="AuthorizedEntity" minOccurs="1" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:element name="AuthorizedEntity" type="CT_AuthorizedEntity" />

  <xs:complexType name="CT_AuthorizedEntity">
    <xs:attribute name="CertificateSignatureHash" type="ST_CertificateSignatureHash" use="required"/>
    <xs:attribute name="AppPackageFamilyName" type="ST_NonEmptyString" use="required"/>
  </xs:complexType>

  <xs:simpleType name="ST_CertificateSignatureHash">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="[A-Fa-f0-9]+"/>
      <xs:minLength value="64"/>
      <xs:maxLength value="64"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:element name="DeveloperModeOnly">
    <xs:complexType>
      <xs:attribute name="Value" type="xs:boolean" use="required"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="Catalog" type="ST_Catalog" />

  <xs:simpleType name="ST_Catalog">
    <xs:restriction base="xs:string">
      <xs:pattern value="[A-Za-z0-9\+\/\=]+"/>
      <xs:minLength value="4"/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>

從 Windows 10 版本 1809 起,下列架構也是有效的。 它可讓 SCCD 宣告任何應用程式套件為授權實體。

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
  xmlns:xs="https://www.w3.org/2001/XMLSchema"
  targetNamespace="http://schemas.microsoft.com/appx/2018/sccd"
  xmlns:s="http://schemas.microsoft.com/appx/2018/sccd"
  xmlns="http://schemas.microsoft.com/appx/2018/sccd">

  <xs:element name="CustomCapabilityDescriptor" type="CT_CustomCapabilityDescriptor">
    <xs:unique name="Unique_CustomCapability_Name">
      <xs:selector xpath="s:CustomCapabilities/s:CustomCapability"/>
      <xs:field xpath="@Name"/>
    </xs:unique>
  </xs:element>

  <xs:complexType name="CT_CustomCapabilityDescriptor">
    <xs:sequence>
      <xs:element ref="CustomCapabilities" minOccurs="1" maxOccurs="1"/>
      <xs:element ref="AuthorizedEntities" minOccurs="1" maxOccurs="1"/>
      <xs:element ref="DeveloperModeOnly" minOccurs="0" maxOccurs="1"/>
      <xs:element ref="Catalog" minOccurs="1" maxOccurs="1"/>
      <xs:any minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
  
  <xs:element name="CustomCapabilities" type="CT_CustomCapabilities" />

  <xs:complexType name="CT_CustomCapabilities">
    <xs:sequence>
      <xs:element ref="CustomCapability" minOccurs="1" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:element name="CustomCapability">
    <xs:complexType>
      <xs:attribute name="Name" type="ST_CustomCapability" use="required"/>
    </xs:complexType>
  </xs:element>

  <xs:simpleType name="ST_NonEmptyString">
    <xs:restriction base="xs:string">
      <xs:minLength value="1"/>
      <xs:maxLength value="32767"/>
      <xs:pattern value="[^\s]|([^\s].*[^\s])"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="ST_CustomCapability">
    <xs:annotation>
      <xs:documentation>Custom capabilities should be a string in the form of Company.capabilityName_PublisherId</xs:documentation>
    </xs:annotation>
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="[A-Za-z0-9][-_.A-Za-z0-9]*_[a-hjkmnp-z0-9]{13}"/>
      <xs:minLength value="15"/>
      <xs:maxLength value="255"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:element name="AuthorizedEntities" type="CT_AuthorizedEntities" />

  <xs:complexType name="CT_AuthorizedEntities">
    <xs:sequence>
      <xs:element ref="AuthorizedEntity" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="AllowAny" type="xs:boolean" use="optional"/>
  </xs:complexType>
  
  <xs:element name="AuthorizedEntity" type="CT_AuthorizedEntity" />
  
  <xs:complexType name="CT_AuthorizedEntity">
    <xs:attribute name="CertificateSignatureHash" type="ST_CertificateSignatureHash" use="required"/>
    <xs:attribute name="AppPackageFamilyName" type="ST_NonEmptyString" use="required"/>
  </xs:complexType>

  <xs:simpleType name="ST_CertificateSignatureHash">
    <xs:restriction base="ST_NonEmptyString">
      <xs:pattern value="[A-Fa-f0-9]+"/>
      <xs:minLength value="64"/>
      <xs:maxLength value="64"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:element name="DeveloperModeOnly">
    <xs:complexType>
      <xs:attribute name="Value" type="xs:boolean" use="required"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="Catalog" type="ST_Catalog" />

  <xs:simpleType name="ST_Catalog">
    <xs:restriction base="xs:string">
      <xs:pattern value="[A-Za-z0-9\+\/\=]+"/>
      <xs:minLength value="4"/>
    </xs:restriction>
  </xs:simpleType>
  
</xs:schema>

另請參閱

開始使用 Windows 驅動程式

通用 Windows 平台簡介

通用 Windows 平台 (UWP)

應用程式功能

使用 Visual Studio 開發 UWP 應用程式

將驅動程式與 通用 Windows 平台 配對 (UWP) 應用程式

開發 UWP 應用程式

使用傳統型應用程式轉換器封裝應用程式 (傳統型橋接器)

自定義功能範例應用程式

自定義功能驅動程式範例

在 Windows 10 中側載應用程式

自定義功能的常見問題