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
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
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
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
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
00111 int rc = iface->on_data_out(iface, data, data_length);
00112
00113 return rc;
00114 }
00115
00116
00117