Tell your client they don’t need a driver. You could easily do the same thing with a service or per user app. You can’t open a handle to your own stack in adddevjce, the stack needs to be fully started to open a handle.
d
dent from pjone
From: xxxxx@gmail.commailto:xxxxx
Sent: ?12/?2/?2012 6:49 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] USB HID Touch
hi doran,
1. got some idea … will do further reading on that…
2. yes …but our requirement from the client is for a filter driver which can control the USB HID Touch device. Hence our method of implementing a filter driver.
3. we have removed the BSOD and currently we are getting the handle to the IOTarget Device but not able to Open the device …throws up an error : 0xC000000E.[NO_SUCH_DEVICE].
i have attached the code below … please let us know if we have something wrong in our implementation. We have taken Firefly USB Client Upper Filter Driver as a reference. Modified its inf file to include input.inf so that we will have hidclass.sys, hidusb.sys and hidparse.sys.
On the device connected to PC, it enumerates with two USB HID interfaces. We load our driver for the HID control interface via Device Manager.
Below is the code,
#ifdef ENABLE_HID_IO
NTSTATUS
test_func_get_collec(WDFDEVICE device,
PDEVICE_CONTEXT pDeviceContext
)
{
//send HID ioctls to our device
//IOCTLs will be handled by HIDUSB and converted into USB requests
WDFIOTARGET hidTarget = NULL;
NTSTATUS status = STATUS_SUCCESS;
WDF_IO_TARGET_OPEN_PARAMS openParams;
WDF_MEMORY_DESCRIPTOR outputDescriptor;
HID_COLLECTION_INFORMATION collectionInformation = {0};
//create IOTarget
KdPrint((“test_func_get_collec: create IOTarget\n”));
status = WdfIoTargetCreate(device,
WDF_NO_OBJECT_ATTRIBUTES,
&hidTarget);
if (!NT_SUCCESS(status))
{
KdPrint((“test_func_get_collec: WdfIoTargetCreate failed 0x%x\n”, status));
return status;
}
WDF_IO_TARGET_OPEN_PARAMS_INIT_OPEN_BY_NAME(
&openParams,
&pDeviceContext->PdoName,
FILE_WRITE_ACCESS);
openParams.ShareAccess = FILE_SHARE_WRITE | FILE_SHARE_READ;
//Open the target
KdPrint((“test_func_get_collec: open IOTarget\n”));
status = WdfIoTargetOpen(hidTarget, &openParams);
if (!NT_SUCCESS(status)) {
KdPrint((“test_func_get_collec: WdfIoTargetOpen failed 0x%x\n”, status));
return status;
}
WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&outputDescriptor,
(PVOID) &collectionInformation,
sizeof(HID_COLLECTION_INFORMATION));
//send IOCTL
KdPrint((“test_func_get_collec: send IOCTL\n”));
status = WdfIoTargetSendIoctlSynchronously(hidTarget,
NULL,
IOCTL_HID_GET_COLLECTION_INFORMATION,
NULL,
&outputDescriptor,
NULL,
NULL);
if (!NT_SUCCESS(status)) {
KdPrint((“test_func_get_collec: WdfIoTargetSendIoctlSynchronously failed 0x%x\n”, status));
return status;
}
KdPrint((“test_func_get_collec: collectionInformation:0x%x\n”, collectionInformation.DescriptorSize));
KdPrint((“test_func_get_collec: collectionInformation:0x%x\n”, collectionInformation.Polled));
KdPrint((“test_func_get_collec: collectionInformation:0x%x\n”, collectionInformation.ProductID));
KdPrint((“test_func_get_collec: collectionInformation:0x%x\n”, collectionInformation.VendorID));
KdPrint((“test_func_get_collec: collectionInformation:0x%x\n”, collectionInformation.VersionNumber));
return status;
}
#endif
NTSTATUS
FireFlyEvtDeviceAdd(
WDFDRIVER Driver,
PWDFDEVICE_INIT DeviceInit
)
/++
Routine Description:
EvtDeviceAdd is called by the framework in response to AddDevice
call from the PnP manager. We create and initialize a device object to
represent to be part of the device stack as a filter.
Arguments:
Driver - Handle to a framework driver object created in DriverEntry
DeviceInit - Pointer to a framework-allocated WDFDEVICE_INIT structure.
Return Value:
NTSTATUS
–/
{
WDF_OBJECT_ATTRIBUTES attributes;
NTSTATUS status;
PDEVICE_CONTEXT pDeviceContext;
WDFDEVICE device;
WDFMEMORY memory;
size_t bufferLength;
PDEVICE_OBJECT pnext_obj = NULL;
PDEVICE_OBJECT pcurrent_obj = NULL;
UNREFERENCED_PARAMETER(Driver);
PAGED_CODE();
//
// Configure the device as a filter driver
//
WdfFdoInitSetFilter(DeviceInit);
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, DEVICE_CONTEXT);
status = WdfDeviceCreate(&DeviceInit, &attributes, &device);
if (!NT_SUCCESS(status)) {
KdPrint((“FireFly: WdfDeviceCreate, Error %x\n”, status));
return status;
}
#ifdef ENABLE_HID_IO
KdPrint((“======================Firefly Original=======================\n”));
KdPrint((“FireFlyEvtDeviceAdd: WdfDeviceCreate: wdfdevice: 0x%x\n”,device));
pcurrent_obj = WdfDeviceWdmGetDeviceObject(device);
KdPrint((“FireFlyEvtDeviceAdd: WdfDeviceCreate: pdev_obj: 0x%x\n”,pcurrent_obj));
if(pcurrent_obj)
{
KdPrint((“FireFlyEvtDeviceAdd: AttachedDevice: 0x%x\n”,pcurrent_obj->AttachedDevice));
KdPrint((“FireFlyEvtDeviceAdd: NextDevice: 0x%x\n”,pcurrent_obj->NextDevice));
KdPrint((“FireFlyEvtDeviceAdd: DeviceType: 0x%x\n”,pcurrent_obj->DeviceType));
KdPrint((“FireFlyEvtDeviceAdd: : Characteristics: 0x%x\n”,pcurrent_obj->Characteristics));
KdPrint((“FireFlyEvtDeviceAdd: : AttachedTo: 0x%x\n”,pcurrent_obj->DeviceObjectExtension->AttachedTo));
KdPrint((“FireFlyEvtDeviceAdd: : owning_device_object: 0x%x\n”,pcurrent_obj->DeviceObjectExtension->DeviceObject));
KdPrint((“FireFlyEvtDeviceAdd: : Type: 0x%x\n”,pcurrent_obj->DeviceObjectExtension->Type));
}
pnext_obj = WdfDeviceWdmGetAttachedDevice(device);
KdPrint((“FireFlyEvtDeviceAdd: : pnext_obj: 0x%x\n”,pnext_obj));
KdPrint((“================================================================\n”));
#endif
//
// Driver Framework always zero initializes an objects context memory
//
pDeviceContext = WdfObjectGet_DEVICE_CONTEXT(device);
//
// Initialize our WMI support
//
status = WmiInitialize(device, pDeviceContext);
if (!NT_SUCCESS(status)) {
KdPrint((“FireFly: Error initializing WMI 0x%x\n”, status));
return status;
}
//
// In order to send ioctls to our PDO, we have open to open it
// by name so that we have a valid filehandle (fileobject).
// When we send ioctls using the IoTarget, framework automatically
// sets the filobject in the stack location.
//
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
//
// By parenting it to device, we don’t have to worry about
// deleting explicitly. It will be deleted along witht the device.
//
attributes.ParentObject = device;
status = WdfDeviceAllocAndQueryProperty(device,
DevicePropertyPhysicalDeviceObjectName,
NonPagedPool,
&attributes,
&memory);
if (!NT_SUCCESS(status)) {
KdPrint((“FireFly: WdfDeviceAllocAndQueryProperty failed 0x%x\n”, status));
return STATUS_UNSUCCESSFUL;
}
pDeviceContext->PdoName.Buffer = WdfMemoryGetBuffer(memory, &bufferLength);
if (pDeviceContext->PdoName.Buffer == NULL) {
return STATUS_UNSUCCESSFUL;
}
pDeviceContext->PdoName.MaximumLength = (USHORT) bufferLength;
pDeviceContext->PdoName.Length = (USHORT) bufferLength-sizeof(UNICODE_NULL);
#ifdef ENABLE_HID_IO
//try to initiate IOCTL
test_func_get_collec(device,pDeviceContext);
#endif
return status;
}
please let us know if anything wrong in our implementation,
thanks,
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>