device.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011 Vojtech Horky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 

Generated on Thu Jun 2 07:45:47 2011 for HelenOS/USB by  doxygen 1.4.7