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 VUHID_VIRTHID_H_ 00036 #define VUHID_VIRTHID_H_ 00037 00038 #include <usb/usb.h> 00039 #include <usbvirt/device.h> 00040 #include <fibril_synch.h> 00041 00042 #define VUHID_ENDPOINT_MAX USB11_ENDPOINT_MAX 00043 #define VUHID_INTERFACE_MAX 8 00044 00045 typedef struct vuhid_interface vuhid_interface_t; 00046 00047 typedef struct { 00048 vuhid_interface_t *in_endpoints_mapping[VUHID_ENDPOINT_MAX]; 00049 size_t in_endpoint_first_free; 00050 vuhid_interface_t *out_endpoints_mapping[VUHID_ENDPOINT_MAX]; 00051 size_t out_endpoint_first_free; 00052 vuhid_interface_t *interface_mapping[VUHID_INTERFACE_MAX]; 00053 00054 fibril_mutex_t iface_count_mutex; 00055 fibril_condvar_t iface_count_cv; 00056 size_t iface_count; 00057 size_t iface_died_count; 00058 } vuhid_data_t; 00059 00060 struct vuhid_interface { 00061 const char *name; 00062 const char *id; 00063 int usb_subclass; 00064 int usb_protocol; 00065 00066 uint8_t *report_descriptor; 00067 size_t report_descriptor_size; 00068 00069 size_t in_data_size; 00070 size_t out_data_size; 00071 00072 int (*on_data_in)(vuhid_interface_t *, void *, size_t, size_t *); 00073 int (*on_data_out)(vuhid_interface_t *, void *, size_t); 00074 void (*live)(vuhid_interface_t *); 00075 00076 int set_protocol; 00077 00078 void *interface_data; 00079 00080 vuhid_data_t *vuhid_data; 00081 }; 00082 00083 typedef struct { 00084 uint8_t length; 00085 uint8_t type; 00086 uint16_t hid_spec_release; 00087 uint8_t country_code; 00088 uint8_t descriptor_count; 00089 uint8_t descriptor1_type; 00090 uint16_t descriptor1_length; 00091 } __attribute__ ((packed)) hid_descriptor_t; 00092 00093 int add_interface_by_id(vuhid_interface_t **, const char *, usbvirt_device_t *); 00094 void wait_for_interfaces_death(usbvirt_device_t *); 00095 00096 #endif 00097