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

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

Standard requests in virtual USB device

The virtual USB device framework can handle some standard requests
alone. Again, this is more about bones than about meat. Meat will
come later.

Update `vuk' app to provide standard device descriptor.

  • Property mode set to 100644
File size: 3.3 KB
RevLine 
[4971812]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_direction_t direction, int recipient,
84 uint16_t request, uint16_t value, uint16_t index, uint16_t length,
85 uint8_t *remaining_data)
86{
87 int rc;
88
89 switch (request) {
90 case USB_DEVREQ_GET_DESCRIPTOR:
91 rc = handle_get_descriptor(value >> 8, (uint8_t) value,
92 index, length);
93 break;
94
95 case USB_DEVREQ_SET_ADDRESS:
96 rc = handle_set_address(value, index, 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, direction,
111 recipient,
112 request, value, index,
113 length, remaining_data);
114 }
115 }
116
117 return EOK;
118}
119
120/**
121 * @}
122 */
Note: See TracBrowser for help on using the repository browser.