1. 程式人生 > >windows wdf 驅動開發總結(4)--usb驅動

windows wdf 驅動開發總結(4)--usb驅動

(73) WdfIoTargetStart

函式功能:starts sending queued requests to a local or remote I/O target.

NTSTATUS WdfIoTargetStart(

[in]WDFIOTARGET IoTarget

);

引數:IoTarget [in]

A handle to a local or remote I/O target object that was obtained from a previous call to WdfDeviceGetIoTarget or WdfIoTargetCreate

, or from a method that a specialized I/O target provides.

74WdfDeviceGetIoTarget

函式功能:returns a handle to a function or filter driver's local I/O target, for a specified device

WDFIOTARGET WdfDeviceGetIoTarget(

[in]WDFDEVICE Device

);

引數:A handle to a framework device object.

(75)

WdfIoTargetCreate

函式功能:creates a remote I/O target for a specified device.

NTSTATUS WdfIoTargetCreate(

[in]WDFDEVICE Device,

[in, optional]PWDF_OBJECT_ATTRIBUTES IoTargetAttributes,

[out]WDFIOTARGET *IoTarget

);

引數:

Device [in]

A handle to a framework device object.

IoTargetAttributes

[in, optional]

A pointer to a caller-allocated WDF_OBJECT_ATTRIBUTES structure that specifies object attributes for the I/O target object. This parameter is optional and can be WDF_NO_OBJECT_ATTRIBUTES.

IoTarget [out]

A pointer to a location that receives a handle to an I/O target object.

評論:

WdfIoTargetCreate returns STATUS_SUCCESS if the operation succeeds. Otherwise, this method might return one of the following values:

76WdfUsbTargetPipeGetIoTarget

函式功能:a handle to the I/O target object that is associated with a specified USB pipe.

WDFIOTARGET WdfUsbTargetPipeGetIoTarget(

[in]WDFUSBPIPE Pipe

);

引數:

Pipe [in]

A handle to a framework pipe object that was obtained by calling WdfUsbInterfaceGetConfiguredPipe.

返回值:

returns a handle to the I/O target object that is associated with the specified pipe object.

(77) WdfIoTargetStop

函式功能:sending queued requests to a local or remote I/O target.

VOID WdfIoTargetStop(

[in]WDFIOTARGET IoTarget,

[in]WDF_IO_TARGET_SENT_IO_ACTION Action

);

引數:

IoTarget [in]

A handle to a local or remote I/O target object that was obtained from a previous call to WdfDeviceGetIoTarget or WdfIoTargetCreate, or from a method that a specialized I/O target supplies.

Action [in]

A WDF_IO_TARGET_SENT_IO_ACTION-typed value that specifies how the framework should handle I/O requests that the driver has sent to the I/O target, if the target has not completed the requests.

評論:

If your driver can detect recoverable device errors, you might want your driver to call to temporarily stop sending requests, then later call WdfIoTargetStart to resume sending requests.

typedef enum _WDF_IO_TARGET_SENT_IO_ACTION {

WdfIoTargetSentIoUndefined= 0,

WdfIoTargetCancelSentIo= 1,

WdfIoTargetWaitForSentIoToComplete= 2,

WdfIoTargetLeaveSentIoPending= 3

} WDF_IO_TARGET_SENT_IO_ACTION;

引數:

WdfIoTargetSentIoUndefined

Reserved for system use.

WdfIoTargetCancelSentIo

Before the framework stops the I/O target, it will attempt to cancel I/O requests that are in the I/O target's queue. The framework cancels all of the target queue's I/O requests, and waits for all I/O requests to complete, before WdfIoTargetStop returns.

WdfIoTargetWaitForSentIoToComplete

Before the framework stops the I/O target, it will wait for I/O requests that are in the I/O target's queue to be completed. The framework completes all of the target queue's I/O requests, and calls each request's CompletionRoutine callback function, before WdfIoTargetStop returns.

WdfIoTargetLeaveSentIoPending

The framework will leave I/O requests in the I/O target's queue. The requests remain in the target's queue until the driver calls WdfIoTargetStart or the device is removed.

78WDF_USB_DEVICE_SELECT_CONFIG_PARAMS_INIT_SINGLE_INTERFACE

函式功能:initializes a WDF_USB_DEVICE_SELECT_CONFIG_PARAMS structure so that a driver can configure a device to use a single, specified interface

VOID WDF_USB_DEVICE_SELECT_CONFIG_PARAMS_INIT_SINGLE_INTERFACE(

__outPWDF_USB_DEVICE_SELECT_CONFIG_PARAMS Params

);

引數:

Params [out]

評論:

The WDF_USB_DEVICE_SELECT_CONFIG_PARAMS structure specifies USB device configuration parameters.

typedef struct _WDF_USB_DEVICE_SELECT_CONFIG_PARAMS {

ULONGSize;

WdfUsbTargetDeviceSelectConfigType Type;

union {

struct {

PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;

PUSB_INTERFACE_DESCRIPTOR*InterfaceDescriptors;

ULONGNumInterfaceDescriptors;

} Descriptor;

struct {

PURB Urb;

} Urb;

struct {

UCHARNumberConfiguredPipes;

WDFUSBINTERFACE ConfiguredUsbInterface;

} SingleInterface;

struct {

UCHARNumberInterfaces;

PWDF_USB_INTERFACE_SETTING_PAIR Pairs;

UCHARNumberOfConfiguredInterfaces;

} MultiInterface;

} Types;

} WDF_USB_DEVICE_SELECT_CONFIG_PARAMS, *PWDF_USB_DEVICE_SELECT_CONFIG_PARAMS;

(79) WdfUsbTargetDeviceSelectConfig

函式功能:selects a USB configuration for a device, or it deconfigures the device.

NTSTATUS WdfUsbTargetDeviceSelectConfig(

[in]WDFUSBDEVICE UsbDevice,

[in, optional]PWDF_OBJECT_ATTRIBUTES PipeAttributes,

[in, out]PWDF_USB_DEVICE_SELECT_CONFIG_PARAMS Params

);

引數:

UsbDevice [in]

A handle to a USB device object that was obtained from a previous call to WdfUsbTargetDeviceCreate.

PipeAttributes [in, optional]

A pointer to a caller-allocated WDF_OBJECT_ATTRIBUTES structure that contains attributes for new framework USB pipe objects that the framework creates for the device's interfaces. This parameter is optional and can be WDF_NO_OBJECT_ATTRIBUTES.

Params [in, out]

A pointer to a caller-allocated WDF_USB_DEVICE_SELECT_CONFIG_PARAMS structure that the caller and the framework use to specify configuration parameters.

(80) WdfUsbTargetPipeSetNoMaximumPacketSizeCheck(檢查是否buffermaximum packet size的整數倍)

函式功能:disables the framework's test of whether the size of a driver's read buffer is a multiple of a USB pipe's maximum packet size.

VOID WdfUsbTargetPipeSetNoMaximumPacketSizeCheck(

[in]WDFUSBPIPE Pipe

);

Pipe [in]

A handle to a framework pipe object that was obtained by calling WdfUsbInterfaceGetConfiguredPipe.

評論:

To avoid receiving extra data from unexpected bus activity, which is sometimes called babble, drivers usually specify read buffers that are a multiple of the pipe's maximum packet size. (Drivers receive a USB pipe's maximum packet size in a WDF_USB_PIPE_INFORMATION structure.) By default, the framework reports an error if a driver specifies a read buffer that is not a multiple of the pipe's maximum packet size. If the driver calls, the framework does not report an error if a read buffer is not a multiple of the maximum packet size.For more information about the method and USB I/O targets, see USB I/O Targets.

(81) WDF_USB_CONTINUOUS_READER_CONFIG_INIT

VOID WDF_USB_CONTINUOUS_READER_CONFIG_INIT(

__out PWDF_USB_CONTINUOUS_READER_CONFIG Config,

__in PFN_WDF_USB_READER_COMPLETION_ROUTINE EvtUsbTargetPipeReadComplete,

__in WDFCONTEXT EvtUsbTargetPipeReadCompleteContext,

__in size_t TransferLength

);

引數:

Config [out]

EvtUsbTargetPipeReadComplete [in]

EvtUsbTargetPipeReadCompleteContext [in]

An untyped pointer to driver-defined context information that the framework passes to the driver's EvtUsbTargetPipeReadComplete callback function.

TransferLength [in]

The maximum length, in bytes, of data that can be received from the device.

評論:

The WDF_USB_CONTINUOUS_READER_CONFIG_INIT function zeros the specified WDF_USB_CONTINUOUS_READER_CONFIG structure and sets the structure's Size member. It also sets the structure's EvtUsbTargetPipeReadComplete, EvtUsbTargetPipeReadCompleteContext, and TransferLength members to the specified values.

WDF_USB_CONTINUOUS_READ_CONFIG 結構:

typedef struct _WDF_USB_CONTINUOUS_READER_CONFIG {

ULONGSize;

size_tTransferLength;

size_tHeaderLength;

size_tTrailerLength;

UCHARNumPendingReads;

PWDF_OBJECT_ATTRIBUTESBufferAttributes;

PFN_WDF_USB_READER_COMPLETION_ROUTINE EvtUsbTargetPipeReadComplete;

WDFCONTEXTEvtUsbTargetPipeReadCompleteContext;

PFN_WDF_USB_READERS_FAILEDEvtUsbTargetPipeReadersFailed;

} WDF_USB_CONTINUOUS_READER_CONFIG, *PWDF_USB_CONTINUOUS_READER_CONFIG;

引數:

Size

The size, in bytes, of this structure.

TransferLength

The maximum length, in bytes, of data that can be received from the device.

HeaderLength

An offset, in bytes, into the buffer that receives data from the device. The framework will store data from the device in a read buffer, beginning at the offset value. In other words, this space precedes the TransferLength-sized space in which the framework stores data from the device.

TrailerLength

The length, in bytes, of a trailing buffer space. This space follows the TransferLength-sized space in which the framework stores data from the device.

NumPendingReads

The number of read requests that the framework will queue to receive data from the I/O target. If this value is zero, the framework uses a default number of read requests. If the specified value is greater than the permitted maximum, the framework uses the permitted maximum. For more information about the NumPendingReads member, see the following Remarks section.

BufferAttributes

A WDF_OBJECT_ATTRIBUTES structure that specifies object attributes for the framework memory object that the framework creates for each read request. This member can be NULL. You cannot set the ParentObject member of the WDF_OBJECT_ATTRIBUTES structure.

EvtUsbTargetPipeReadComplete

EvtUsbTargetPipeReadCompleteContext

An untyped pointer to driver-defined context information that the framework passes to the driver's EvtUsbTargetPipeReadComplete callback function.

EvtUsbTargetPipeReadersFailed

評論:

The WDF_USB_CONTINUOUS_READER_CONFIG

To initialize a WDF_USB_CONTINUOUS_READER_CONFIG structure, the driver must call WDF_USB_CONTINUOUS_READER_CONFIG_INIT.

(82) WdfUsbTargetPipeConfigContinuousReader

函式功能:configures the framework to continuously read from a specified USB pipe.

NTSTATUS WdfUsbTargetPipeConfigContinuousReader(

[in]WDFUSBPIPE Pipe,

[in]PWDF_USB_CONTINUOUS_READER_CONFIG Config

);

引數:

Pipe [in]

A handle to a framework pipe object that was obtained by calling WdfUsbInterfaceGetConfiguredPipe.

Config [in]

返回值: returns STATUS_SUCCESS if the operation succeeds. Otherwise, this method can return one of the following values:STATUS_INFO_LENGTH_MISMATCH,STATUS_INVALID_PARAMETER,

STATUS_INSUFFICIENT_RESOURCES,STATUS_INVALID_DEVICE_REQUEST, STATUS_INTEGER_OVERFLOW ,STATUS_INVALID_BUFFER_SIZE

評論:

可以配置continuous reader ,bulkinterrupt 傳輸,管道必須有一個輸入端點,在使用WdfusbTargetPipeConfigContinuousReader配置continuous reader,驅動必須呼叫WdfIoTargetStart開始讀請求,呼叫WdfIoTargetStop停止讀請求。一般,驅動在EvtDevicePrepareHardware的回撥函式中呼叫WdfusbTargetPipeConfigContinuousReader,在EvtDeviceD0Entry回撥函式中呼叫WdfIoTargetStart,EvtDeviceD0Exit回撥函式中呼叫WdfIoTargetStop.

每次管道 I/O target 成功完成一個read requestframework呼叫驅動的EVtUsbTargetPipeREadComplete 回撥函式。如果I/O target 報告失敗,framework呼叫回撥函式(在所有的read requests 都完成以後)。(Therefore, the EvtUsbTargetPipeReadComplete callback function will not be called while the EvtUsbTargetPipeReadersFailed callback function is executing.)

After a driver has called WdfusbTargetPipeConfigContinuousReader

The framework sets the USBD_SHORT_TRANSFER_OK flag in its internal URB. Setting this flag allows the last packet of a data transfer to be less than the maximum packet size.

83WdfRequestRetrieveUnsafeUserInputBuffer

函式功能:retrieves an I/O request's input buffer, if the request's technique for accessing data buffers is neither buffered nor direct I/O.

NTSTATUS WdfRequestRetrieveUnsafeUserInputBuffer(

[in]WDFREQUEST Request,

[in]size_t MinimumRequiredLength,

[out]PVOID *InputBuffer,

[out, optional]size_t *Length

);

引數:

Request [in]

A handle to a framework request object.

MinimumRequiredLength [in]

The minimum buffer size, in bytes, that the driver needs to process the I/O request.

InputBuffer [out]

A pointer to a location that receives the buffer's address.

Length [out, optional]

A pointer to a location that receives the buffer's size, in bytes. This parameter is optional and can be NULL.

(84)WdfRequestRetrieveUnsafeUserOutputBuffer

函式功能:retrieves an I/O request's output buffer, if the request's technique for accessing data buffers is neither buffered nor direct I/O.

NTSTATUS WdfRequestRetrieveUnsafeUserOutputBuffer(

[in]WDFREQUEST Request,

[in]size_t MinimumRequiredLength,

[out]PVOID *OutputBuffer,

[out, optional]size_t *Length

);

引數:

Request [in]

A handle to a framework request object.

MinimumRequiredLength [in]

The minimum buffer size, in bytes, that the driver needs to process the I/O request.

OutputBuffer [out]

A pointer to a location that receives the buffer's address.

Length [out, optional]

A pointer to a location that receives the buffer's size, in bytes. This parameter is optional and can be NULL.

評論:

The WdfRequestRetrieveUnsafeUserOutputBuffer method must be called from an EvtIoInCallerContext callback function. After calli