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