none
why the WdfUsbTargetDeviceCreateWithParameters or WdfUsbTargetDeviceCreate method return value is 0x0000010 RRS feed

  • Question

  • hello,

    I'm a noob to WDF.

    I'm trying to write a lower usb filter for class 4d36e967-...-08002be10318(DiskDrive),but when i  call WdfUsbTargetDeviceCreate in my FilterEvtDevicePrepareHardware. But it faled with error STATUS_INVALID_DEVICE_REQUEST.

    Wednesday, December 18, 2013 3:49 AM

Answers

  • The disk class contains more than just usb disk devices, it can contain other types of connections. This API will fail in non USB connected disks.

    also, I am not sure this is the right level in the stack to filter urbs. You probably want to be one level up in the tree. What bigger problem are you trying to solve?


    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Wednesday, December 18, 2013 4:52 AM

All replies

  • The disk class contains more than just usb disk devices, it can contain other types of connections. This API will fail in non USB connected disks.

    also, I am not sure this is the right level in the stack to filter urbs. You probably want to be one level up in the tree. What bigger problem are you trying to solve?


    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Wednesday, December 18, 2013 4:52 AM
  • I'm trying to solve a usb filter.

    now i want to call WdfUsbTargetDeviceGetDeviceDescriptor function to get the usb device's pid and vid,but it require the paramter WDFUSBDEVICE,so i call the WdfUsbTargetDeviceCreate function  to get the WDFUSBDEVICE object.but it reture value is failed(the status code is STATUS_NOT_SUPPORTED).

    I dont't know what point is wrong...

    my code is:

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


        WPP_INIT_TRACING( DriverObject, RegistryPath );

        TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, "%!FUNC! Entry");
        WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
        attributes.EvtCleanupCallback = MyFilterEvtDriverContextCleanup;

        WDF_DRIVER_CONFIG_INIT(&config,
                               MyFilterEvtDeviceAdd
                               );

        status = WdfDriverCreate(DriverObject,
                                 RegistryPath,
                                 &attributes,
                                 &config,
                                 WDF_NO_HANDLE
                                 );

     if (!NT_SUCCESS(status)) {
      TraceEvents(TRACE_LEVEL_ERROR, TRACE_DRIVER, "WdfDriverCreate failed %!STATUS!", status);
      WPP_CLEANUP(DriverObject);
      return status;
     }

        TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, "%!FUNC! Exit");

        return status;
    }

    NTSTATUS
    MyFilterEvtDeviceAdd(
        _In_    WDFDRIVER       Driver,
        _Inout_ PWDFDEVICE_INIT DeviceInit
        )
    {
        NTSTATUS status;

        UNREFERENCED_PARAMETER(Driver);

        PAGED_CODE();
     KdPrint(("MyFilterEvtDeviceAdd begin...\r\n"));

        TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, "%!FUNC! Entry");

        status = MyFilterCreateDevice(DeviceInit);

        TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, "%!FUNC! Exit");

        return status;
    }

    NTSTATUS
    MyFilterCreateDevice(
        _Inout_ PWDFDEVICE_INIT DeviceInit
        )

    {
     WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks;
        WDF_OBJECT_ATTRIBUTES   deviceAttributes;
        PDEVICE_CONTEXT deviceContext;
        WDFDEVICE device;
        NTSTATUS status;
     WDF_OBJECT_ATTRIBUTES   requestAttributes;

        PAGED_CODE();

     WdfFdoInitSetFilter(DeviceInit);
     WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&requestAttributes, REQUEST_CONTEXT);
     WdfDeviceInitSetRequestAttributes(DeviceInit, &requestAttributes);
     WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks);

     pnpPowerCallbacks.EvtDevicePrepareHardware = MyFilterEvtDevicePrepareHardware;
     pnpPowerCallbacks.EvtDeviceReleaseHardware = MyFilterEvtDeviceRealeaseHardware;


     WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks); 

        WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&deviceAttributes, DEVICE_CONTEXT);

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

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

            status = WdfDeviceCreateDeviceInterface(
                device,
                &GUID_DEVINTERFACE_MyFilter,
                NULL // ReferenceString
                );

            if (NT_SUCCESS(status)) {
                status = MyFilterQueueInitialize(device);
            }
      else
      {
       KdPrint(("WdfDeviceCreateDeviceInterface failed...\r\n"));
       return status;
      }
    }

    return status;
    }

    NTSTATUS
    MyFilterEvtDevicePrepareHardware(
    IN WDFDEVICE Device,
    IN WDFCMRESLIST ResourceList,
    IN WDFCMRESLIST ResourceListTranslated
    )
    {
     NTSTATUS status;
     PDEVICE_CONTEXT pDeviceContext;
     WDF_USB_DEVICE_CREATE_CONFIG  Config;
     UNREFERENCED_PARAMETER(ResourceList);
     UNREFERENCED_PARAMETER(ResourceListTranslated);

     PAGED_CODE();
     status = STATUS_SUCCESS;
     pDeviceContext = DeviceGetContext(Device);
     pDeviceContext->PrivateDeviceData = 0;
     if (pDeviceContext->UsbDevice == NULL)
     {

      status = WdfUsbTargetDeviceCreate(Device,
       WDF_NO_OBJECT_ATTRIBUTES,
       &pDeviceContext->UsbDevice);
      if (!NT_SUCCESS(status))
      {
       KdPrint(("WdfUsbTargetDeviceCreate failed.Status Code:0x%x\n", status));
       return status;
      }

     }

     return status;
    }

    Wednesday, December 18, 2013 6:08 AM