stdreq.c

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 
00036 #include <errno.h>
00037 #include <usb/debug.h>
00038 #include <usb/descriptor.h>
00039 #include "stdreq.h"
00040 #include "virthid.h"
00041 
00042 #define VUHID_DATA(vuhid, device) \
00043         vuhid_data_t *vuhid = device->device_data
00044 
00045 int req_get_descriptor(usbvirt_device_t *device,
00046     const usb_device_request_setup_packet_t *setup_packet,
00047     uint8_t *data, size_t *act_size)
00048 {
00049         VUHID_DATA(vuhid, device);
00050 
00051         if (setup_packet->value_high == USB_DESCTYPE_HID_REPORT) {
00052                 vuhid_interface_t *iface
00053                     = vuhid->interface_mapping[setup_packet->index];
00054                 if (iface == NULL) {
00055                         return EFORWARD;
00056                 }
00057                 if (iface->report_descriptor != NULL) {
00058                         usbvirt_control_reply_helper(setup_packet,
00059                             data, act_size,
00060                             iface->report_descriptor,
00061                             iface->report_descriptor_size);
00062                         return EOK;
00063                 } else {
00064                         return ENOENT;
00065                 }
00066         }
00067         
00068         /* Let the framework handle all the rest. */
00069         return EFORWARD;
00070 }
00071 
00072 int req_set_protocol(usbvirt_device_t *device,
00073     const usb_device_request_setup_packet_t *setup_packet,
00074     uint8_t *data, size_t *act_size)
00075 {
00076         VUHID_DATA(vuhid, device);
00077 
00078         size_t iface_index = setup_packet->index;
00079         int protocol = setup_packet->value;
00080 
00081         // FIXME - check ranges
00082         vuhid_interface_t *iface = vuhid->interface_mapping[iface_index];
00083         if (iface == NULL) {
00084                 return ENOENT;
00085         }
00086         iface->set_protocol = protocol;
00087 
00088         return EOK;
00089 }
00090 
00091 int req_set_report(usbvirt_device_t *device,
00092     const usb_device_request_setup_packet_t *setup_packet,
00093     uint8_t *data, size_t *act_size)
00094 {
00095         VUHID_DATA(vuhid, device);
00096 
00097         size_t iface_index = setup_packet->index;
00098 
00099         // FIXME - check ranges
00100         vuhid_interface_t *iface = vuhid->interface_mapping[iface_index];
00101         if (iface == NULL) {
00102                 return ENOENT;
00103         }
00104 
00105         size_t data_length = setup_packet->length;
00106         if (iface->on_data_out == NULL) {
00107                 return ENOTSUP;
00108         }
00109 
00110         /* SET_REPORT is translated to data out */
00111         int rc = iface->on_data_out(iface, data, data_length);
00112 
00113         return rc;
00114 }
00115 
00116 
00117 

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