00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #ifndef LIBUSBVIRT_DEVICE_H_
00036 #define LIBUSBVIRT_DEVICE_H_
00037
00038 #include <usb/usb.h>
00039 #include <usb/dev/request.h>
00040
00042 #define USBVIRT_ENDPOINT_MAX 16
00043
00044 typedef struct usbvirt_device usbvirt_device_t;
00045
00055 typedef int (*usbvirt_on_data_to_device_t)(usbvirt_device_t *dev,
00056 usb_endpoint_t endpoint, usb_transfer_type_t transfer_type,
00057 void *buffer, size_t buffer_size);
00058
00069 typedef int (*usbvirt_on_data_from_device_t)(usbvirt_device_t *dev,
00070 usb_endpoint_t endpoint, usb_transfer_type_t transfer_type,
00071 void *buffer, size_t buffer_size, size_t *act_buffer_size);
00072
00084 typedef int (*usbvirt_on_control_t)(usbvirt_device_t *dev,
00085 const usb_device_request_setup_packet_t *setup_packet,
00086 uint8_t *data, size_t *act_data_size);
00087
00093 typedef struct {
00095 usb_direction_t req_direction;
00097 usb_request_recipient_t req_recipient;
00099 usb_request_type_t req_type;
00101 uint8_t request;
00103 const char *name;
00105 usbvirt_on_control_t callback;
00106 } usbvirt_control_request_handler_t;
00107
00109 typedef struct {
00111 uint8_t *data;
00113 size_t length;
00114 } usbvirt_device_configuration_extras_t;
00115
00117 typedef struct {
00119 usb_standard_configuration_descriptor_t *descriptor;
00121 usbvirt_device_configuration_extras_t *extra;
00123 size_t extra_count;
00124 } usbvirt_device_configuration_t;
00125
00127 typedef struct {
00131 usb_standard_device_descriptor_t *device;
00132
00134 usbvirt_device_configuration_t *configuration;
00136 size_t configuration_count;
00137 } usbvirt_descriptors_t;
00138
00142 typedef enum {
00144 USBVIRT_STATE_DEFAULT,
00146 USBVIRT_STATE_ADDRESS,
00148 USBVIRT_STATE_CONFIGURED
00149 } usbvirt_device_state_t;
00150
00152 typedef struct {
00156 usbvirt_on_data_to_device_t data_out[USBVIRT_ENDPOINT_MAX];
00160 usbvirt_on_data_from_device_t data_in[USBVIRT_ENDPOINT_MAX];
00164 usbvirt_control_request_handler_t *control;
00174 void (*state_changed)(usbvirt_device_t *dev,
00175 usbvirt_device_state_t old_state, usbvirt_device_state_t new_state);
00176 } usbvirt_device_ops_t;
00177
00179 struct usbvirt_device {
00181 const char *name;
00183 void *device_data;
00185 usbvirt_device_ops_t *ops;
00187 usbvirt_descriptors_t *descriptors;
00191 usb_address_t address;
00195 usbvirt_device_state_t state;
00199 int vhc_phone;
00200 };
00201
00202 int usbvirt_device_plug(usbvirt_device_t *, const char *);
00203 void usbvirt_device_unplug(usbvirt_device_t *);
00204
00205 void usbvirt_control_reply_helper(const usb_device_request_setup_packet_t *,
00206 uint8_t *, size_t *, void *, size_t);
00207
00208 int usbvirt_control_write(usbvirt_device_t *, void *, size_t, void *, size_t);
00209 int usbvirt_control_read(usbvirt_device_t *, void *, size_t, void *, size_t, size_t *);
00210 int usbvirt_data_out(usbvirt_device_t *, usb_transfer_type_t, usb_endpoint_t,
00211 void *, size_t);
00212 int usbvirt_data_in(usbvirt_device_t *, usb_transfer_type_t, usb_endpoint_t,
00213 void *, size_t, size_t *);
00214
00215
00216 #endif
00217