source: mainline/uspace/app/vuhid/stdreq.c@ 1abcf1d

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1abcf1d was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 3.3 KB
Line 
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
45errno_t req_get_descriptor(usbvirt_device_t *device,
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) {
52 vuhid_interface_t *iface
53 = vuhid->interface_mapping[setup_packet->index];
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 }
67
68 /* Let the framework handle all the rest. */
69 return EFORWARD;
70}
71
72errno_t req_set_protocol(usbvirt_device_t *device,
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
91errno_t req_set_report(usbvirt_device_t *device,
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 */
111 errno_t rc = iface->on_data_out(iface, data, data_length);
112
113 return rc;
114}
115
116
117
118/** @}
119 */
Note: See TracBrowser for help on using the repository browser.