📄 usb.h
字号:
//
// returned if client driver attempts to close an endpoint/interface
// or configuration with outstanding transfers.
//
#define USBD_STATUS_ERROR_BUSY ((USBD_STATUS)0x80000400L)
//
// returned by USBD if it cannot complete a URB request, typically this
// will be returned in the URB status field when the Irp is completed
// with a more specific NT error code in the irp.status field.
//
//#define USBD_STATUS_REQUEST_FAILED ((USBD_STATUS)0x80000500L)
#define USBD_STATUS_INVALID_PIPE_HANDLE ((USBD_STATUS)0x80000600L)
// returned when there is not enough bandwidth avialable
// to open a requested endpoint
#define USBD_STATUS_NO_BANDWIDTH ((USBD_STATUS)0x80000700L)
//
// generic HC error
//
#define USBD_STATUS_INTERNAL_HC_ERROR ((USBD_STATUS)0x80000800L)
//
// returned when a short packet terminates the transfer
// ie USBD_SHORT_TRANSFER_OK bit not set
//
#define USBD_STATUS_ERROR_SHORT_TRANSFER ((USBD_STATUS)0x80000900L)
//
// returned if the requested start frame is not within
// USBD_ISO_START_FRAME_RANGE of the current USB frame,
// note that the stall bit is set
//
#define USBD_STATUS_BAD_START_FRAME ((USBD_STATUS)0xC0000A00L)
//
// returned by HCD if all packets in an iso transfer complete with an error
//
#define USBD_STATUS_ISOCH_REQUEST_FAILED ((USBD_STATUS)0xC0000B00L)
//
// returned by USBD if the frame length control for a given
// HC is already taken by anothe driver
//
#define USBD_STATUS_FRAME_CONTROL_OWNED ((USBD_STATUS)0xC0000C00L)
//
// returned by USBD if the caller does not own frame length control and
// attempts to release or modify the HC frame length
//
#define USBD_STATUS_FRAME_CONTROL_NOT_OWNED ((USBD_STATUS)0xC0000D00L)
//
// additonal software error codes added for usb 2.0
//
//
// returned for APIS not supported/implemented
//
#define USBD_STATUS_NOT_SUPPORTED ((USBD_STATUS)0xC0000E00L)
#define USBD_STATUS_INAVLID_CONFIGURATION_DESCRIPTOR \
((USBD_STATUS)0xC0000F00L)
#define USBD_STATUS_INSUFFICIENT_RESOURCES ((USBD_STATUS)0xC0001000L)
#define USBD_STATUS_SET_CONFIG_FAILED ((USBD_STATUS)0xC0002000L)
#define USBD_STATUS_BUFFER_TOO_SMALL ((USBD_STATUS)0xC0003000L)
#define USBD_STATUS_INTERFACE_NOT_FOUND ((USBD_STATUS)0xC0004000L)
#define USBD_STATUS_INAVLID_PIPE_FLAGS ((USBD_STATUS)0xC0005000L)
#define USBD_STATUS_TIMEOUT ((USBD_STATUS)0xC0006000L)
#define USBD_STATUS_DEVICE_GONE ((USBD_STATUS)0xC0007000L)
#define USBD_STATUS_STATUS_NOT_MAPPED ((USBD_STATUS)0xC0008000L)
//
// set when a transfers is completed due to an AbortPipe request from
// the client driver
//
//
#define USBD_STATUS_CANCELED ((USBD_STATUS)0xC0010000L)
//
// extended isochronous error codes, these errors appear in the
// packet status field of an isochronous transfer
//
// for some reason the controller did not access the TD asocated with this
// packet
#define USBD_STATUS_ISO_NOT_ACCESSED_BY_HW ((USBD_STATUS)0xC0020000L)
// controller reported an error in the TD
// since TD errors are controoler specific they are reorted
// generically with this error code
#define USBD_STATUS_ISO_TD_ERROR ((USBD_STATUS)0xC0030000L)
// the packet was submitted in time by the client but
// failed to reach the miniport in time
#define USBD_STATUS_ISO_NA_LATE_USBPORT ((USBD_STATUS)0xC0040000L)
// the packet was not sent because the client submitted it too late
// to transmit
#define USBD_STATUS_ISO_NOT_ACCESSED_LATE ((USBD_STATUS)0xC0050000L)
typedef PVOID USBD_PIPE_HANDLE;
typedef PVOID USBD_CONFIGURATION_HANDLE;
typedef PVOID USBD_INTERFACE_HANDLE;
//
// Value used to indicate the default max transfer size
//
/*
MAX TRANSFER SIZE
Specified during select_configuration or
selec_interface. This is the largest
transfer a client driver will do to an
endpoint.
This value may be from 0x00000001 to
0xFFFFFFFF (1 to 4GB)
*/
//
#define USBD_DEFAULT_MAXIMUM_TRANSFER_SIZE 0xFFFFFFFF
//
// structure returned from USBD_GetVersion function
//
typedef struct _USBD_VERSION_INFORMATION {
ULONG USBDI_Version; //BCD usb interface version number
ULONG Supported_USB_Version; //BCD USB spec version number
} USBD_VERSION_INFORMATION, *PUSBD_VERSION_INFORMATION;
typedef enum _USBD_PIPE_TYPE {
UsbdPipeTypeControl,
UsbdPipeTypeIsochronous,
UsbdPipeTypeBulk,
UsbdPipeTypeInterrupt
} USBD_PIPE_TYPE;
#define USBD_PIPE_DIRECTION_IN(pipeInformation) ((pipeInformation)->EndpointAddress & \
USB_ENDPOINT_DIRECTION_MASK)
typedef struct _USBD_DEVICE_INFORMATION {
ULONG OffsetNext;
PVOID UsbdDeviceHandle;
USB_DEVICE_DESCRIPTOR DeviceDescriptor;
} USBD_DEVICE_INFORMATION, *PUSBD_DEVICE_INFORMATION;
//
// URB request structures
//
//
// USBD pipe information structure, this structure
// is returned for each pipe opened thru an
// SELECT_CONFIGURATION or SELECT_INTERFACE request.
//
typedef struct _USBD_PIPE_INFORMATION {
//
// OUTPUT
// These fields are filled in by USBD
//
USHORT MaximumPacketSize; // Maximum packet size for this pipe
UCHAR EndpointAddress; // 8 bit USB endpoint address (includes direction)
// taken from endpoint descriptor
UCHAR Interval; // Polling interval in ms if interrupt pipe
USBD_PIPE_TYPE PipeType; // PipeType identifies type of transfer valid for this pipe
USBD_PIPE_HANDLE PipeHandle;
//
// INPUT
// These fields are filled in by the client driver
//
ULONG MaximumTransferSize; // Maximum size for a single request
// in bytes.
ULONG PipeFlags;
} USBD_PIPE_INFORMATION, *PUSBD_PIPE_INFORMATION;
//
// values for PipeFlags field in USBD_PIPE_INFORMATION field
//
// override the enpoint max_packet size
// with the value in pipe_information
// field
#define USBD_PF_CHANGE_MAX_PACKET 0x00000001
// optimize for short packets
// 'bulk optimization #1'
#define USBD_PF_SHORT_PACKET_OPT 0x00000002
// optimize transfers for use
// with 'real time threads
#define USBD_PF_ENABLE_RT_THREAD_ACCESS 0x00000004
// causes the driver to allocate map
// map more transfers in the queue.
#define USBD_PF_MAP_ADD_TRANSFERS 0x00000008
#define USBD_PF_VALID_MASK (USBD_PF_CHANGE_MAX_PACKET | \
USBD_PF_SHORT_PACKET_OPT | \
USBD_PF_ENABLE_RT_THREAD_ACCESS | \
USBD_PF_MAP_ADD_TRANSFERS)
//
// USBD interface information structure, this structure
// is returned for each interface opened thru an
// SELECT_CONFIGURATION or SELECT_INTERFACE request.
//
typedef struct _USBD_INTERFACE_INFORMATION {
USHORT Length; // Length of this structure, including
// all pipe information structures that
// follow.
//
// INPUT
//
// Interface number and Alternate setting this
// structure is associated with
//
UCHAR InterfaceNumber;
UCHAR AlternateSetting;
//
// OUTPUT
// These fields are filled in by USBD
//
UCHAR Class;
UCHAR SubClass;
UCHAR Protocol;
UCHAR Reserved;
USBD_INTERFACE_HANDLE InterfaceHandle;
ULONG NumberOfPipes;
//
// INPUT/OUPUT
// see PIPE_INFORMATION
USBD_PIPE_INFORMATION Pipes[1];
} USBD_INTERFACE_INFORMATION, *PUSBD_INTERFACE_INFORMATION;
//
// work space provided for HCDs
//
struct _URB_HCD_AREA {
PVOID Reserved8[8];
};
struct _URB_HEADER {
//
// Fields filled in by client driver
//
USHORT Length;
USHORT Function;
USBD_STATUS Status;
//
// Fields used only by USBD
//
PVOID UsbdDeviceHandle; // device handle assigned to this device
// by USBD
ULONG UsbdFlags; // flags field reserved for USBD use.
};
struct _URB_SELECT_INTERFACE {
struct _URB_HEADER Hdr; // function code indicates get or set.
USBD_CONFIGURATION_HANDLE ConfigurationHandle;
// client must input AlternateSetting & Interface Number
// class driver returns interface and handle
// for new alternate setting
USBD_INTERFACE_INFORMATION Interface;
};
struct _URB_SELECT_CONFIGURATION {
struct _URB_HEADER Hdr; // function code indicates get or set.
// NULL indicates to set the device
// to the 'unconfigured' state
// ie set to configuration 0
PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
USBD_CONFIGURATION_HANDLE ConfigurationHandle;
USBD_INTERFACE_INFORMATION Interface;
};
//
// This structure used for ABORT_PIPE & RESET_PIPE
//
struct _URB_PIPE_REQUEST {
struct _URB_HEADER Hdr; // function code indicates get or set.
USBD_PIPE_HANDLE PipeHandle;
ULONG Reserved;
};
//
// This structure used for
// TAKE_FRAME_LENGTH_CONTROL &
// RELEASE_FRAME_LENGTH_CONTROL
//
struct _URB_FRAME_LENGTH_CONTROL {
struct _URB_HEADER Hdr; // function code indicates get or set.
};
struct _URB_GET_FRAME_LENGTH {
struct _URB_HEADER Hdr; // function code indicates get or set.
ULONG FrameLength;
ULONG FrameNumber;
};
struct _URB_SET_FRAME_LENGTH {
struct _URB_HEADER Hdr; // function code indicates get or set.
LONG FrameLengthDelta;
};
struct _URB_GET_CURRENT_FRAME_NUMBER {
struct _URB_HEADER Hdr; // function code indicates get or set.
ULONG FrameNumber;
};
//
// Structures for specific control transfers
// on the default pipe.
//
// GET_DESCRIPTOR
// SET_DESCRIPTOR
struct _URB_CONTROL_DESCRIPTOR_REQUEST {
struct _URB_HEADER Hdr; // function code indicates get or set.
PVOID Reserved;
ULONG Reserved0;
ULONG TransferBufferLength;
PVOID TransferBuffer;
PMDL TransferBufferMDL; // *optional*
struct _URB *UrbLink; // *optional* link to next urb request
// if this is a chain of commands
struct _URB_HCD_AREA hca; // fields for HCD use
USHORT Reserved1;
UCHAR Index;
UCHAR DescriptorType;
USHORT LanguageId;
USHORT Reserved2;
};
// GET_STATUS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -