source: mainline/uspace/lib/usbvirt/stdreq.c@ fd17ab5

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fd17ab5 was d97d209, checked in by Vojtech Horky <vojtechhorky@…>, 15 years ago

API change in virtual USB device

Instead of passing individual items of device request, the whole
structure is passed-in.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * Copyright (c) 2010 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 libusbvirt usb
30 * @{
31 */
32/** @file
33 * @brief Preprocessing of standard device requests.
34 */
35#include <errno.h>
36#include <usb/devreq.h>
37
38#include "private.h"
39
40/*
41 * All sub handlers must return EFORWARD to inform the caller that
42 * they were not able to process the request (yes, it is abuse of
43 * this error code but such error code shall not collide with anything
44 * else in this context).
45 */
46
47static int handle_get_descriptor(uint8_t type, uint8_t index, uint16_t language,
48 uint16_t length)
49{
50 /*
51 * Standard device descriptor.
52 */
53 if ((type == USB_DESCTYPE_DEVICE) && (index == 0)) {
54 if (device->standard_descriptor) {
55 return device->send_data(device, 0,
56 device->standard_descriptor,
57 device->standard_descriptor->length);
58 } else {
59 return EFORWARD;
60 }
61 }
62
63 return EFORWARD;
64}
65
66static int handle_set_address(uint16_t new_address,
67 uint16_t zero1, uint16_t zero2)
68{
69 if ((zero1 != 0) || (zero2 != 0)) {
70 return EINVAL;
71 }
72
73 if (new_address > 127) {
74 return EINVAL;
75 }
76
77 /*
78 * TODO: inform the HC that device has new address assigned.
79 */
80 return EOK;
81}
82
83int handle_std_request(usb_device_request_setup_packet_t *request, uint8_t *data)
84{
85 int rc;
86
87 switch (request->request) {
88 case USB_DEVREQ_GET_DESCRIPTOR:
89 rc = handle_get_descriptor(
90 request->value_low, request->value_high,
91 request->index, request->length);
92 break;
93
94 case USB_DEVREQ_SET_ADDRESS:
95 rc = handle_set_address(request->value,
96 request->index, request->length);
97 break;
98
99 default:
100 rc = EFORWARD;
101 break;
102 }
103
104 /*
105 * We preprocessed all we could.
106 * If it was not enough, pass the request to the actual driver.
107 */
108 if (rc == EFORWARD) {
109 if (DEVICE_HAS_OP(device, on_devreq_std)) {
110 return device->ops->on_devreq_std(device,
111 request, data);
112 }
113 }
114
115 return EOK;
116}
117
118/**
119 * @}
120 */
Note: See TracBrowser for help on using the repository browser.