[57c7050] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Vojtech Horky
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup usbvirthid
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | *
|
---|
| 35 | */
|
---|
| 36 | #include <errno.h>
|
---|
| 37 | #include <usb/debug.h>
|
---|
| 38 | #include <usb/descriptor.h>
|
---|
| 39 | #include "stdreq.h"
|
---|
| 40 | #include "virthid.h"
|
---|
| 41 |
|
---|
| 42 | #define VUHID_DATA(vuhid, device) \
|
---|
| 43 | vuhid_data_t *vuhid = device->device_data
|
---|
| 44 |
|
---|
[b7fd2a0] | 45 | errno_t req_get_descriptor(usbvirt_device_t *device,
|
---|
[57c7050] | 46 | const usb_device_request_setup_packet_t *setup_packet,
|
---|
| 47 | uint8_t *data, size_t *act_size)
|
---|
| 48 | {
|
---|
| 49 | VUHID_DATA(vuhid, device);
|
---|
| 50 |
|
---|
| 51 | if (setup_packet->value_high == USB_DESCTYPE_HID_REPORT) {
|
---|
[3bacee1] | 52 | vuhid_interface_t *iface =
|
---|
| 53 | vuhid->interface_mapping[setup_packet->index];
|
---|
[57c7050] | 54 | if (iface == NULL) {
|
---|
| 55 | return EFORWARD;
|
---|
| 56 | }
|
---|
| 57 | if (iface->report_descriptor != NULL) {
|
---|
| 58 | usbvirt_control_reply_helper(setup_packet,
|
---|
| 59 | data, act_size,
|
---|
| 60 | iface->report_descriptor,
|
---|
| 61 | iface->report_descriptor_size);
|
---|
| 62 | return EOK;
|
---|
| 63 | } else {
|
---|
| 64 | return ENOENT;
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
[a35b458] | 67 |
|
---|
[57c7050] | 68 | /* Let the framework handle all the rest. */
|
---|
| 69 | return EFORWARD;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[b7fd2a0] | 72 | errno_t req_set_protocol(usbvirt_device_t *device,
|
---|
[57c7050] | 73 | const usb_device_request_setup_packet_t *setup_packet,
|
---|
| 74 | uint8_t *data, size_t *act_size)
|
---|
| 75 | {
|
---|
| 76 | VUHID_DATA(vuhid, device);
|
---|
| 77 |
|
---|
| 78 | size_t iface_index = setup_packet->index;
|
---|
| 79 | int protocol = setup_packet->value;
|
---|
| 80 |
|
---|
| 81 | // FIXME - check ranges
|
---|
| 82 | vuhid_interface_t *iface = vuhid->interface_mapping[iface_index];
|
---|
| 83 | if (iface == NULL) {
|
---|
| 84 | return ENOENT;
|
---|
| 85 | }
|
---|
| 86 | iface->set_protocol = protocol;
|
---|
| 87 |
|
---|
| 88 | return EOK;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[b7fd2a0] | 91 | errno_t req_set_report(usbvirt_device_t *device,
|
---|
[57c7050] | 92 | const usb_device_request_setup_packet_t *setup_packet,
|
---|
| 93 | uint8_t *data, size_t *act_size)
|
---|
| 94 | {
|
---|
| 95 | VUHID_DATA(vuhid, device);
|
---|
| 96 |
|
---|
| 97 | size_t iface_index = setup_packet->index;
|
---|
| 98 |
|
---|
| 99 | // FIXME - check ranges
|
---|
| 100 | vuhid_interface_t *iface = vuhid->interface_mapping[iface_index];
|
---|
| 101 | if (iface == NULL) {
|
---|
| 102 | return ENOENT;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | size_t data_length = setup_packet->length;
|
---|
| 106 | if (iface->on_data_out == NULL) {
|
---|
| 107 | return ENOTSUP;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | /* SET_REPORT is translated to data out */
|
---|
[b7fd2a0] | 111 | errno_t rc = iface->on_data_out(iface, data, data_length);
|
---|
[57c7050] | 112 |
|
---|
| 113 | return rc;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | /** @}
|
---|
| 117 | */
|
---|