📄 usb.h
字号:
* are to be used for matching. */ __u16 match_flags; /* * vendor/product codes are checked, if vendor is nonzero * Range is for device revision (bcdDevice), inclusive; * zero values here mean range isn't considered */ __u16 idVendor; __u16 idProduct; __u16 bcdDevice_lo, bcdDevice_hi; /* * if device class != 0, these can be match criteria; * but only if this bDeviceClass value is nonzero */ __u8 bDeviceClass; __u8 bDeviceSubClass; __u8 bDeviceProtocol; /* * if interface class != 0, these can be match criteria; * but only if this bInterfaceClass value is nonzero */ __u8 bInterfaceClass; __u8 bInterfaceSubClass; __u8 bInterfaceProtocol; /* * for driver's use; not involved in driver matching. */ unsigned long driver_info;};struct usb_driver { const char *name; void *(*probe)( struct usb_device *dev, /* the device */ unsigned intf, /* what interface */ const struct usb_device_id *id /* from id_table */ ); void (*disconnect)(struct usb_device *, void *); struct list_head driver_list; struct file_operations *fops; int minor; struct semaphore serialize; /* ioctl -- userspace apps can talk to drivers through usbdevfs */ int (*ioctl)(struct usb_device *dev, unsigned int code, void *buf); /* support for "new-style" USB hotplugging * binding policy can be driven from user mode too */ const struct usb_device_id *id_table; /* suspend before the bus suspends; * disconnect or resume when the bus resumes */ // void (*suspend)(struct usb_device *dev); // void (*resume)(struct usb_device *dev);}; /*----------------------------------------------------------------------------* * New USB Structures * *----------------------------------------------------------------------------*//* * urb->transfer_flags: */#define USB_DISABLE_SPD 0x0001#define USB_ISO_ASAP 0x0002#define USB_ASYNC_UNLINK 0x0008#define USB_QUEUE_BULK 0x0010#define USB_NO_FSBR 0x0020#define USB_ZERO_PACKET 0x0040 // Finish bulk OUTs always with zero length packet#define URB_NO_INTERRUPT 0x0080 /* HINT: no non-error interrupt needed */ /* ... less overhead for QUEUE_BULK */#define USB_TIMEOUT_KILLED 0x1000 // only set by HCD!typedef struct{ unsigned int offset; unsigned int length; // expected length unsigned int actual_length; unsigned int status;} iso_packet_descriptor_t, *piso_packet_descriptor_t;struct urb;typedef void (*usb_complete_t)(struct urb *);typedef struct urb{ spinlock_t lock; // lock for the URB void *hcpriv; // private data for host controller struct list_head urb_list; // list pointer to all active urbs struct urb *next; // pointer to next URB struct usb_device *dev; // pointer to associated USB device unsigned int pipe; // pipe information int status; // returned status unsigned int transfer_flags; // USB_DISABLE_SPD | USB_ISO_ASAP | etc. void *transfer_buffer; // associated data buffer int transfer_buffer_length; // data buffer length int actual_length; // actual data buffer length int bandwidth; // bandwidth for this transfer request (INT or ISO) unsigned char *setup_packet; // setup packet (control only) // int start_frame; // start frame (iso/irq only) int number_of_packets; // number of packets in this request (iso) int interval; // polling interval (irq only) int error_count; // number of errors in this transfer (iso only) int timeout; // timeout (in jiffies) // void *context; // context for completion routine usb_complete_t complete; // pointer to completion routine // iso_packet_descriptor_t iso_frame_desc[0];} urb_t, *purb_t;/** * FILL_CONTROL_URB - macro to help initialize a control urb * @URB: pointer to the urb to initialize. * @DEV: pointer to the struct usb_device for this urb. * @PIPE: the endpoint pipe * @SETUP_PACKET: pointer to the setup_packet buffer * @TRANSFER_BUFFER: pointer to the transfer buffer * @BUFFER_LENGTH: length of the transfer buffer * @COMPLETE: pointer to the usb_complete_t function * @CONTEXT: what to set the urb context to. * * Initializes a control urb with the proper information needed to submit * it to a device. This macro is depreciated, the usb_fill_control_urb() * function should be used instead. */#define FILL_CONTROL_URB(URB,DEV,PIPE,SETUP_PACKET,TRANSFER_BUFFER,BUFFER_LENGTH,COMPLETE,CONTEXT) \ do {\ spin_lock_init(&(URB)->lock);\ (URB)->dev=DEV;\ (URB)->pipe=PIPE;\ (URB)->setup_packet=SETUP_PACKET;\ (URB)->transfer_buffer=TRANSFER_BUFFER;\ (URB)->transfer_buffer_length=BUFFER_LENGTH;\ (URB)->complete=COMPLETE;\ (URB)->context=CONTEXT;\ } while (0)/** * FILL_BULK_URB - macro to help initialize a bulk urb * @URB: pointer to the urb to initialize. * @DEV: pointer to the struct usb_device for this urb. * @PIPE: the endpoint pipe * @TRANSFER_BUFFER: pointer to the transfer buffer * @BUFFER_LENGTH: length of the transfer buffer * @COMPLETE: pointer to the usb_complete_t function * @CONTEXT: what to set the urb context to. * * Initializes a bulk urb with the proper information needed to submit it * to a device. This macro is depreciated, the usb_fill_bulk_urb() * function should be used instead. */#define FILL_BULK_URB(URB,DEV,PIPE,TRANSFER_BUFFER,BUFFER_LENGTH,COMPLETE,CONTEXT) \ do {\ spin_lock_init(&(URB)->lock);\ (URB)->dev=DEV;\ (URB)->pipe=PIPE;\ (URB)->transfer_buffer=TRANSFER_BUFFER;\ (URB)->transfer_buffer_length=BUFFER_LENGTH;\ (URB)->complete=COMPLETE;\ (URB)->context=CONTEXT;\ } while (0) /** * FILL_INT_URB - macro to help initialize a interrupt urb * @URB: pointer to the urb to initialize. * @DEV: pointer to the struct usb_device for this urb. * @PIPE: the endpoint pipe * @TRANSFER_BUFFER: pointer to the transfer buffer * @BUFFER_LENGTH: length of the transfer buffer * @COMPLETE: pointer to the usb_complete_t function * @CONTEXT: what to set the urb context to. * @INTERVAL: what to set the urb interval to. * * Initializes a interrupt urb with the proper information needed to submit * it to a device. This macro is depreciated, the usb_fill_int_urb() * function should be used instead. */#define FILL_INT_URB(URB,DEV,PIPE,TRANSFER_BUFFER,BUFFER_LENGTH,COMPLETE,CONTEXT,INTERVAL) \ do {\ spin_lock_init(&(URB)->lock);\ (URB)->dev=DEV;\ (URB)->pipe=PIPE;\ (URB)->transfer_buffer=TRANSFER_BUFFER;\ (URB)->transfer_buffer_length=BUFFER_LENGTH;\ (URB)->complete=COMPLETE;\ (URB)->context=CONTEXT;\ (URB)->interval=INTERVAL;\ (URB)->start_frame=-1;\ } while (0)#define FILL_CONTROL_URB_TO(a,aa,b,c,d,e,f,g,h) \ do {\ spin_lock_init(&(a)->lock);\ (a)->dev=aa;\ (a)->pipe=b;\ (a)->setup_packet=c;\ (a)->transfer_buffer=d;\ (a)->transfer_buffer_length=e;\ (a)->complete=f;\ (a)->context=g;\ (a)->timeout=h;\ } while (0)#define FILL_BULK_URB_TO(a,aa,b,c,d,e,f,g) \ do {\ spin_lock_init(&(a)->lock);\ (a)->dev=aa;\ (a)->pipe=b;\ (a)->transfer_buffer=c;\ (a)->transfer_buffer_length=d;\ (a)->complete=e;\ (a)->context=f;\ (a)->timeout=g;\ } while (0) /** * usb_fill_control_urb - initializes a control urb * @urb: pointer to the urb to initialize. * @dev: pointer to the struct usb_device for this urb. * @pipe: the endpoint pipe * @setup_packet: pointer to the setup_packet buffer * @transfer_buffer: pointer to the transfer buffer * @buffer_length: length of the transfer buffer * @complete: pointer to the usb_complete_t function * @context: what to set the urb context to. * * Initializes a control urb with the proper information needed to submit * it to a device. */static inline void usb_fill_control_urb (struct urb *urb, struct usb_device *dev, unsigned int pipe, unsigned char *setup_packet, void *transfer_buffer, int buffer_length, usb_complete_t complete, void *context){ spin_lock_init(&urb->lock); urb->dev = dev; urb->pipe = pipe; urb->setup_packet = setup_packet; urb->transfer_buffer = transfer_buffer; urb->transfer_buffer_length = buffer_length; urb->complete = complete; urb->context = context;}/** * usb_fill_bulk_urb - macro to help initialize a bulk urb * @urb: pointer to the urb to initialize. * @dev: pointer to the struct usb_device for this urb. * @pipe: the endpoint pipe * @transfer_buffer: pointer to the transfer buffer * @buffer_length: length of the transfer buffer * @complete: pointer to the usb_complete_t function * @context: what to set the urb context to. * * Initializes a bulk urb with the proper information needed to submit it * to a device. */static inline void usb_fill_bulk_urb (struct urb *urb, struct usb_device *dev, unsigned int pipe, void *transfer_buffer, int buffer_length, usb_complete_t complete, void *context) { spin_lock_init(&urb->lock); urb->dev = dev; urb->pipe = pipe; urb->transfer_buffer = transfer_buffer; urb->transfer_buffer_length = buffer_length; urb->complete = complete; urb->context = context;} /** * usb_fill_int_urb - macro to help initialize a interrupt urb * @urb: pointer to the urb to initialize. * @dev: pointer to the struct usb_device for this urb. * @pipe: the endpoint pipe * @transfer_buffer: pointer to the transfer buffer * @buffer_length: length of the transfer buffer * @complete: pointer to the usb_complete_t function * @context: what to set the urb context to. * @interval: what to set the urb interval to. * * Initializes a interrupt urb with the proper information needed to submit * it to a device. */static inline void usb_fill_int_urb (struct urb *urb, struct usb_device *dev, unsigned int pipe, void *transfer_buffer, int buffer_length, usb_complete_t complete, void *context, int interval){ spin_lock_init(&urb->lock); urb->dev = dev; urb->pipe = pipe; urb->transfer_buffer = transfer_buffer; urb->transfer_buffer_length = buffer_length; urb->complete = complete; urb->context = context; urb->interval = interval; urb->start_frame = -1;}purb_t usb_alloc_urb(int iso_packets);void usb_free_urb (purb_t purb);int usb_submit_urb(purb_t purb);int usb_unlink_urb(purb_t purb);int usb_internal_control_msg(struct usb_device *usb_dev, unsigned int pipe, devrequest *cmd, void *data, int len, int timeout);int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, void *data, int len, int *actual_length, int timeout);/*-------------------------------------------------------------------* * SYNCHRONOUS CALL SUPPORT * *-------------------------------------------------------------------*/struct usb_api_data{ wait_queue_head_t wqh; int done; /* void* stuff; */ /* Possible extension later. */};/* -------------------------------------------------------------------------- */struct usb_operations { int (*allocate)(struct usb_device *); int (*deallocate)(struct usb_device *); int (*get_frame_number) (struct usb_device *usb_dev); int (*submit_urb) (struct urb* purb); int (*unlink_urb) (struct urb* purb);};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -