1*1501c2bfSNiels Sascha Reedijk /* 2*1501c2bfSNiels Sascha Reedijk ** USB.h - Version 2 USB Device Driver API 3*1501c2bfSNiels Sascha Reedijk ** 4*1501c2bfSNiels Sascha Reedijk ** Copyright 1999, Be Incorporated. All Rights Reserved. 5*1501c2bfSNiels Sascha Reedijk ** 6*1501c2bfSNiels Sascha Reedijk */ 7*1501c2bfSNiels Sascha Reedijk 8*1501c2bfSNiels Sascha Reedijk #ifndef _USB_H 9*1501c2bfSNiels Sascha Reedijk #define _USB_H 10*1501c2bfSNiels Sascha Reedijk 11*1501c2bfSNiels Sascha Reedijk #include <KernelExport.h> 12*1501c2bfSNiels Sascha Reedijk #include <bus_manager.h> 13*1501c2bfSNiels Sascha Reedijk 14*1501c2bfSNiels Sascha Reedijk #include <USB_spec.h> 15*1501c2bfSNiels Sascha Reedijk #include <USB_rle.h> 16*1501c2bfSNiels Sascha Reedijk 17*1501c2bfSNiels Sascha Reedijk #ifdef __cplusplus 18*1501c2bfSNiels Sascha Reedijk extern "C" { 19*1501c2bfSNiels Sascha Reedijk #endif 20*1501c2bfSNiels Sascha Reedijk 21*1501c2bfSNiels Sascha Reedijk typedef struct usb_module_info usb_module_info; 22*1501c2bfSNiels Sascha Reedijk 23*1501c2bfSNiels Sascha Reedijk /* these are opaque handles to internal stack objects */ 24*1501c2bfSNiels Sascha Reedijk typedef struct usb_device usb_device; 25*1501c2bfSNiels Sascha Reedijk typedef struct usb_interface usb_interface; 26*1501c2bfSNiels Sascha Reedijk typedef struct usb_pipe usb_pipe; 27*1501c2bfSNiels Sascha Reedijk 28*1501c2bfSNiels Sascha Reedijk typedef struct usb_endpoint_info usb_endpoint_info; 29*1501c2bfSNiels Sascha Reedijk typedef struct usb_interface_info usb_interface_info; 30*1501c2bfSNiels Sascha Reedijk typedef struct usb_interface_list usb_interface_list; 31*1501c2bfSNiels Sascha Reedijk typedef struct usb_configuration_info usb_configuration_info; 32*1501c2bfSNiels Sascha Reedijk 33*1501c2bfSNiels Sascha Reedijk typedef struct usb_notify_hooks { 34*1501c2bfSNiels Sascha Reedijk status_t (*device_added)(const usb_device *device, void **cookie); 35*1501c2bfSNiels Sascha Reedijk status_t (*device_removed)(void *cookie); 36*1501c2bfSNiels Sascha Reedijk } usb_notify_hooks; 37*1501c2bfSNiels Sascha Reedijk 38*1501c2bfSNiels Sascha Reedijk typedef struct usb_support_descriptor { 39*1501c2bfSNiels Sascha Reedijk uint8 dev_class; 40*1501c2bfSNiels Sascha Reedijk uint8 dev_subclass; 41*1501c2bfSNiels Sascha Reedijk uint8 dev_protocol; 42*1501c2bfSNiels Sascha Reedijk uint16 vendor; 43*1501c2bfSNiels Sascha Reedijk uint16 product; 44*1501c2bfSNiels Sascha Reedijk } usb_support_descriptor; 45*1501c2bfSNiels Sascha Reedijk 46*1501c2bfSNiels Sascha Reedijk /* ie, I support any hub device: 47*1501c2bfSNiels Sascha Reedijk ** usb_support_descriptor hub_devs = { 9, 0, 0, 0, 0 }; 48*1501c2bfSNiels Sascha Reedijk */ 49*1501c2bfSNiels Sascha Reedijk 50*1501c2bfSNiels Sascha Reedijk struct usb_endpoint_info { 51*1501c2bfSNiels Sascha Reedijk usb_endpoint_descriptor *descr; /* descriptor and handle */ 52*1501c2bfSNiels Sascha Reedijk usb_pipe *handle; /* of this endpoint/pipe */ 53*1501c2bfSNiels Sascha Reedijk }; 54*1501c2bfSNiels Sascha Reedijk 55*1501c2bfSNiels Sascha Reedijk struct usb_interface_info { 56*1501c2bfSNiels Sascha Reedijk usb_interface_descriptor *descr; /* descriptor and handle */ 57*1501c2bfSNiels Sascha Reedijk usb_interface *handle; /* of this interface */ 58*1501c2bfSNiels Sascha Reedijk 59*1501c2bfSNiels Sascha Reedijk size_t endpoint_count; /* count and list of endpoints */ 60*1501c2bfSNiels Sascha Reedijk usb_endpoint_info *endpoint; /* in this interface */ 61*1501c2bfSNiels Sascha Reedijk 62*1501c2bfSNiels Sascha Reedijk size_t generic_count; /* unparsed descriptors in this */ 63*1501c2bfSNiels Sascha Reedijk usb_descriptor **generic; /* interface */ 64*1501c2bfSNiels Sascha Reedijk }; 65*1501c2bfSNiels Sascha Reedijk 66*1501c2bfSNiels Sascha Reedijk struct usb_interface_list { 67*1501c2bfSNiels Sascha Reedijk size_t alt_count; /* count and list of alternate */ 68*1501c2bfSNiels Sascha Reedijk usb_interface_info *alt; /* interfaces available */ 69*1501c2bfSNiels Sascha Reedijk 70*1501c2bfSNiels Sascha Reedijk usb_interface_info *active; /* currently active alternate */ 71*1501c2bfSNiels Sascha Reedijk }; 72*1501c2bfSNiels Sascha Reedijk 73*1501c2bfSNiels Sascha Reedijk struct usb_configuration_info { 74*1501c2bfSNiels Sascha Reedijk usb_configuration_descriptor *descr; /* descriptor of this config */ 75*1501c2bfSNiels Sascha Reedijk 76*1501c2bfSNiels Sascha Reedijk size_t interface_count; /* interfaces in this config */ 77*1501c2bfSNiels Sascha Reedijk usb_interface_list *interface; 78*1501c2bfSNiels Sascha Reedijk }; 79*1501c2bfSNiels Sascha Reedijk 80*1501c2bfSNiels Sascha Reedijk 81*1501c2bfSNiels Sascha Reedijk typedef void (*usb_callback_func)(void *cookie, uint32 status, 82*1501c2bfSNiels Sascha Reedijk void *data, uint32 actual_len); 83*1501c2bfSNiels Sascha Reedijk 84*1501c2bfSNiels Sascha Reedijk struct usb_module_info { 85*1501c2bfSNiels Sascha Reedijk bus_manager_info binfo; 86*1501c2bfSNiels Sascha Reedijk 87*1501c2bfSNiels Sascha Reedijk /* inform the bus manager of our intent to support a set of devices */ 88*1501c2bfSNiels Sascha Reedijk status_t (*register_driver)(const char *driver_name, 89*1501c2bfSNiels Sascha Reedijk const usb_support_descriptor *descriptors, 90*1501c2bfSNiels Sascha Reedijk size_t count, 91*1501c2bfSNiels Sascha Reedijk const char *optional_republish_driver_name); 92*1501c2bfSNiels Sascha Reedijk 93*1501c2bfSNiels Sascha Reedijk /* request notification from the bus manager for add/remove of devices we 94*1501c2bfSNiels Sascha Reedijk support */ 95*1501c2bfSNiels Sascha Reedijk status_t (*install_notify)(const char *driver_name, 96*1501c2bfSNiels Sascha Reedijk const usb_notify_hooks *hooks); 97*1501c2bfSNiels Sascha Reedijk status_t (*uninstall_notify)(const char *driver_name); 98*1501c2bfSNiels Sascha Reedijk 99*1501c2bfSNiels Sascha Reedijk /* get the device descriptor */ 100*1501c2bfSNiels Sascha Reedijk const usb_device_descriptor *(*get_device_descriptor)(const usb_device *dev); 101*1501c2bfSNiels Sascha Reedijk 102*1501c2bfSNiels Sascha Reedijk /* get the nth supported configuration */ 103*1501c2bfSNiels Sascha Reedijk const usb_configuration_info *(*get_nth_configuration)(const usb_device *dev, uint index); 104*1501c2bfSNiels Sascha Reedijk 105*1501c2bfSNiels Sascha Reedijk /* get the active configuration */ 106*1501c2bfSNiels Sascha Reedijk const usb_configuration_info *(*get_configuration)(const usb_device *dev); 107*1501c2bfSNiels Sascha Reedijk 108*1501c2bfSNiels Sascha Reedijk /* set the active configuration */ 109*1501c2bfSNiels Sascha Reedijk status_t (*set_configuration)(const usb_device *dev, 110*1501c2bfSNiels Sascha Reedijk const usb_configuration_info *configuration); 111*1501c2bfSNiels Sascha Reedijk 112*1501c2bfSNiels Sascha Reedijk status_t (*set_alt_interface)(const usb_device *dev, 113*1501c2bfSNiels Sascha Reedijk const usb_interface_info *ifc); 114*1501c2bfSNiels Sascha Reedijk 115*1501c2bfSNiels Sascha Reedijk /* standard device requests -- convenience functions */ 116*1501c2bfSNiels Sascha Reedijk /* obj may be a usb_device*, usb_pipe*, or usb_interface* */ 117*1501c2bfSNiels Sascha Reedijk status_t (*set_feature)(const void *object, uint16 selector); 118*1501c2bfSNiels Sascha Reedijk status_t (*clear_feature)(const void *object, uint16 selector); 119*1501c2bfSNiels Sascha Reedijk status_t (*get_status)(const void *object, uint16 *status); 120*1501c2bfSNiels Sascha Reedijk 121*1501c2bfSNiels Sascha Reedijk status_t (*get_descriptor)(const usb_device *d, 122*1501c2bfSNiels Sascha Reedijk uint8 type, uint8 index, uint16 lang, 123*1501c2bfSNiels Sascha Reedijk void *data, size_t len, size_t *actual_len); 124*1501c2bfSNiels Sascha Reedijk 125*1501c2bfSNiels Sascha Reedijk /* generic device request function */ 126*1501c2bfSNiels Sascha Reedijk status_t (*send_request)(const usb_device *d, 127*1501c2bfSNiels Sascha Reedijk uint8 request_type, uint8 request, 128*1501c2bfSNiels Sascha Reedijk uint16 value, uint16 index, uint16 length, 129*1501c2bfSNiels Sascha Reedijk void *data, size_t data_len, size_t *actual_len); 130*1501c2bfSNiels Sascha Reedijk 131*1501c2bfSNiels Sascha Reedijk /* async request queueing */ 132*1501c2bfSNiels Sascha Reedijk status_t (*queue_interrupt)(const usb_pipe *handle, 133*1501c2bfSNiels Sascha Reedijk void *data, size_t len, 134*1501c2bfSNiels Sascha Reedijk usb_callback_func notify, void *cookie); 135*1501c2bfSNiels Sascha Reedijk 136*1501c2bfSNiels Sascha Reedijk status_t (*queue_bulk)(const usb_pipe *handle, 137*1501c2bfSNiels Sascha Reedijk void *data, size_t len, 138*1501c2bfSNiels Sascha Reedijk usb_callback_func notify, void *cookie); 139*1501c2bfSNiels Sascha Reedijk 140*1501c2bfSNiels Sascha Reedijk status_t (*queue_isochronous)(const usb_pipe *handle, 141*1501c2bfSNiels Sascha Reedijk void *data, size_t len, 142*1501c2bfSNiels Sascha Reedijk rlea* rle_array, uint16 buffer_duration_ms, 143*1501c2bfSNiels Sascha Reedijk usb_callback_func notify, void *cookie); 144*1501c2bfSNiels Sascha Reedijk 145*1501c2bfSNiels Sascha Reedijk status_t (*queue_request)(const usb_device *d, 146*1501c2bfSNiels Sascha Reedijk uint8 request_type, uint8 request, 147*1501c2bfSNiels Sascha Reedijk uint16 value, uint16 index, uint16 length, 148*1501c2bfSNiels Sascha Reedijk void *data, size_t data_len, 149*1501c2bfSNiels Sascha Reedijk usb_callback_func notify, void *cookie); 150*1501c2bfSNiels Sascha Reedijk 151*1501c2bfSNiels Sascha Reedijk status_t (*set_pipe_policy)(const usb_pipe *handle, uint8 max_num_queued_packets, 152*1501c2bfSNiels Sascha Reedijk uint16 max_buffer_duration_ms, uint16 sample_size); 153*1501c2bfSNiels Sascha Reedijk 154*1501c2bfSNiels Sascha Reedijk /* cancel pending async requests to an endpoint */ 155*1501c2bfSNiels Sascha Reedijk status_t (*cancel_queued_transfers)(const usb_pipe *handle); 156*1501c2bfSNiels Sascha Reedijk 157*1501c2bfSNiels Sascha Reedijk /* tuning, timeouts, etc */ 158*1501c2bfSNiels Sascha Reedijk status_t (*usb_ioctl)(uint32 opcode, void* buf, size_t buf_size); 159*1501c2bfSNiels Sascha Reedijk }; 160*1501c2bfSNiels Sascha Reedijk 161*1501c2bfSNiels Sascha Reedijk /* status code for usb callback functions */ 162*1501c2bfSNiels Sascha Reedijk #define B_USB_STATUS_SUCCESS 0x0000 163*1501c2bfSNiels Sascha Reedijk #define B_USB_STATUS_DEVICE_CRC_ERROR 0x0002 164*1501c2bfSNiels Sascha Reedijk #define B_USB_STATUS_DEVICE_TIMEOUT 0x0004 165*1501c2bfSNiels Sascha Reedijk #define B_USB_STATUS_DEVICE_STALLED 0x0008 166*1501c2bfSNiels Sascha Reedijk #define B_USB_STATUS_IRP_CANCELLED_BY_REQUEST 0x0010 167*1501c2bfSNiels Sascha Reedijk #define B_USB_STATUS_DRIVER_INTERNAL_ERROR 0x0020 168*1501c2bfSNiels Sascha Reedijk #define B_USB_STATUS_ADAPTER_HARDWARE_ERROR 0x0040 169*1501c2bfSNiels Sascha Reedijk #define B_USB_STATUS_ISOCH_IRP_ABORTED 0x0080 170*1501c2bfSNiels Sascha Reedijk 171*1501c2bfSNiels Sascha Reedijk /* result codes for usb bus manager functions */ 172*1501c2bfSNiels Sascha Reedijk #define B_USBD_SUCCESS 0 173*1501c2bfSNiels Sascha Reedijk #define B_USBD_BAD_HANDLE 1 174*1501c2bfSNiels Sascha Reedijk #define B_USBD_BAD_ARGS 2 175*1501c2bfSNiels Sascha Reedijk #define B_USBD_NO_DATA 3 176*1501c2bfSNiels Sascha Reedijk #define B_USBD_DEVICE_FAILURE 4 177*1501c2bfSNiels Sascha Reedijk #define B_USBD_COMMAND_FAILED 5 178*1501c2bfSNiels Sascha Reedijk #define B_USBD_PIPE_NOT_CONFIGURED 6 179*1501c2bfSNiels Sascha Reedijk #define B_USBD_DEVICE_ERROR 7 180*1501c2bfSNiels Sascha Reedijk #define B_USBD_PIPE_ERROR 8 181*1501c2bfSNiels Sascha Reedijk #define B_USBD_NO_MEMORY 9 182*1501c2bfSNiels Sascha Reedijk 183*1501c2bfSNiels Sascha Reedijk #define B_USB_MODULE_NAME "bus_managers/usb/v2" 184*1501c2bfSNiels Sascha Reedijk 185*1501c2bfSNiels Sascha Reedijk #ifdef __cplusplus 186*1501c2bfSNiels Sascha Reedijk } 187*1501c2bfSNiels Sascha Reedijk #endif 188*1501c2bfSNiels Sascha Reedijk 189*1501c2bfSNiels Sascha Reedijk #endif 190