2016-03-10 1 views
3

Je travaille sur la création d'un périphérique HID virtuel dans Windows 10. J'essaie d'utiliser le Windows Virtual HID Framework (comme décrit ici: https://msdn.microsoft.com/en-us/library/windows/hardware/dn925056(v=vs.85).aspx) pour générer le pilote. Au stade actuel, je travaille juste sur l'installation correcte du pilote sur une machine virtuelle Windows 10. Mon code pilote est la suivante:Windows Virtual HID Framework Méthode VhfCreate retournant STATUS_INVALID_DEVICE_REQUEST

#include <ntddk.h> 
#include <wdf.h> 
#include <vhf.h> 

DRIVER_INITIALIZE DriverEntry; 
EVT_WDF_DRIVER_DEVICE_ADD BBKbdEvtDeviceAdd; 

typedef struct _DEVICE_CONTEXT 
{ 
    VHFHANDLE VhfHandle; 
    HID_XFER_PACKET VhfHidReport; 

} DEVICE_CONTEXT, *PDEVICE_CONTEXT; 

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DEVICE_CONTEXT, DeviceGetContext) 

UCHAR MouseReportDescriptor[] = { 
    0x05, 0x01,     // USAGE_PAGE (Generic Desktop) 
    0x09, 0x02,     // USAGE (Mouse) 
    0xa1, 0x01,     // COLLECTION (Application) 
    0x09, 0x01,     // USAGE (Pointer) 
    0xa1, 0x00,     // COLLECTION (Physical) 
    0x05, 0x09,     //  USAGE_PAGE (Button)   
    0x19, 0x01,     //  USAGE_MINIMUM (Button 1) 
    0x29, 0x03,     //  USAGE_MAXIMUM (Button 3) 
    0x15, 0x00,     //  LOGICAL_MINIMUM (0) 
    0x25, 0x01,     //  LOGICAL_MAXIMUM (1) 
    0x95, 0x03,     //  REPORT_COUNT (3) 
    0x75, 0x01,     //  REPORT_SIZE (1) 
    0x81, 0x02,     //  INPUT (Data,Var,Abs) 
    0x95, 0x01,     //  REPORT_COUNT (1) 
    0x75, 0x05,     //  REPORT_SIZE (5) 
    0x81, 0x03,     //  INPUT (Cnst,Var,Abs) 
    0x05, 0x01,     //  USAGE_PAGE (Generic Desktop) 
    0x09, 0x30,     //  USAGE (X) 
    0x09, 0x31,     //  USAGE (Y) 
    0x15, 0x81,     //  LOGICAL_MINIMUM (-127) 
    0x25, 0x7f,     //  LOGICAL_MAXIMUM (127) 
    0x75, 0x08,     //  REPORT_SIZE (8) 
    0x95, 0x02,     //  REPORT_COUNT (2) 
    0x81, 0x06,     //  INPUT (Data,Var,Rel) 
    0xc0,       // END_COLLECTION 
    0xc0       // END_COLLECTION 
    }; 

NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_  PUNICODE_STRING RegistryPath) 
{ 
    NTSTATUS status; 
    WDF_DRIVER_CONFIG config; 

    WDF_DRIVER_CONFIG_INIT(&config, BBKbdEvtDeviceAdd); 
    status = WdfDriverCreate(DriverObject, RegistryPath,  WDF_NO_OBJECT_ATTRIBUTES, &config, WDF_NO_HANDLE); 
    return status; 
} 

NTSTATUS BBKbdEvtDeviceAdd(_In_ WDFDRIVER Driver, _Inout_ PWDFDEVICE_INIT DeviceInit) 
{ 
    WDF_OBJECT_ATTRIBUTES deviceAttributes; 
    PDEVICE_CONTEXT deviceContext; 
    VHF_CONFIG vhfConfig; 
    WDFDEVICE device; 
    NTSTATUS status; 

    WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&deviceAttributes, DEVICE_CONTEXT); 

    status = WdfDeviceCreate(&DeviceInit, &deviceAttributes, &device); 

    if (NT_SUCCESS(status)) 
    { 
     deviceContext = DeviceGetContext(device); 

     VHF_CONFIG_INIT(&vhfConfig, 
      WdfDeviceWdmGetDeviceObject(device), 
      sizeof(MouseReportDescriptor), 
      MouseReportDescriptor); 

     status = VhfCreate(&vhfConfig, &(deviceContext->VhfHandle)); 

     if (NT_SUCCESS(status)) 
      status = VhfStart(deviceContext->VhfHandle); 

    } 

    return status; 
} 

Pour contexte supplémentaire, voici mon fichier .inf:

; 
; BBKbdKernalMode.inf 
; 

[Version] 
Signature="$WINDOWS NT$" 
Class=Mouse ; TODO: edit Class 
ClassGuid={4d36e96f-e325-11ce-bfc1-08002be10318} ; TODO: edit ClassGuid 
Provider=%ManufacturerName% 
CatalogFile=BBKbdKernalMode.cat 
DriverVer= ; TODO: set DriverVer in stampinf property pages 

[DestinationDirs] 
DefaultDestDir = 12 

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

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

[SourceDisksNames] 
1 = %DiskName%,,,"" 

[SourceDisksFiles] 
BBKbdKernalMode.sys = 1,, 

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

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

[Standard.NT$ARCH$] 
%BBKbdKernalMode.DeviceDesc%=BBKbdKernalMode_Device, Root\BBKbdKernalMode ; TODO: edit hw-id 

[BBKbdKernalMode_Device.NT] 
CopyFiles=Drivers_Dir 

[Drivers_Dir] 
BBKbdKernalMode.sys 

[HIDVHF_Inst.NT.HW] 
AddReg = HIDVHF_Inst.NT.AddReg 

[HIDVHF_Inst.NT.AddReg] 
HKR,,"LowerFilters",0x00010000,"vhf" 

;-------------- Service installation 
[BBKbdKernalMode_Device.NT.Services] 
AddService = BBKbdKernalMode,%SPSVCINST_ASSOCSERVICE%,  BBKbdKernalMode_Service_Inst 

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

; 
;--- BBKbdKernalMode_Device Coinstaller installation ------ 
; 

[DestinationDirs] 
BBKbdKernalMode_Device_CoInstaller_CopyFiles = 11 

[BBKbdKernalMode_Device.NT.CoInstallers] 
AddReg=BBKbdKernalMode_Device_CoInstaller_AddReg 
CopyFiles=BBKbdKernalMode_Device_CoInstaller_CopyFiles 

[BBKbdKernalMode_Device_CoInstaller_AddReg] 
HKR,,CoInstallers32,0x00010000,  "WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll,WdfCoInstaller" 

[BBKbdKernalMode_Device_CoInstaller_CopyFiles] 
WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll 

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

[BBKbdKernalMode_Device.NT.Wdf] 
KmdfService = BBKbdKernalMode, BBKbdKernalMode_wdfsect 
[BBKbdKernalMode_wdfsect] 
KmdfLibraryVersion = $KMDFVERSION$ 

[Strings] 
SPSVCINST_ASSOCSERVICE= 0x00000002 
ManufacturerName="<Your manufacturer name>" ;TODO: Replace with your manufacturer name 
ClassName="Samples" ; TODO: edit ClassName 
DiskName = "BBKbdKernalMode Installation Disk" 
BBKbdKernalMode.DeviceDesc = "BBKbdKernalMode Device" 
BBKbdKernalMode.SVCDESC = "BBKbdKernalMode Service" 

J'ai suivi le guide que je lié à mieux que je pouvais, mais l'appel à VhfCreate renvoie STATUS_INVALID_DEVICE_REQUEST. Je me demande ce qui conduirait VhfCreate à retourner cette erreur, et comment y remédier.

Répondre

1

Modifier ce qui suit dans votre fichier .inf de

[HIDVHF_Inst.NT.HW] 
AddReg = HIDVHF_Inst.NT.AddReg 

à

[BBKbdKernalMode_Device.NT.HW] 
AddReg = HIDVHF_Inst.NT.AddReg 
+0

pendant un certain temps que je sorte de cette question négligé, mais ce que je fini par avoir à faire. Merci! – bacowan