source: mainline/uspace/lib/usbvirt/device.h@ cbc00a4d

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

virtusb: add get_descriptor(config) handling

The virtusb framework is now able to handle the standard request for
obtaining configuration descriptor. This includes sending extra data
such as interface or endpoint descriptor.

Using this approach, the virtual keyboard sends also its HID descriptor.

  • Property mode set to 100644
File size: 3.9 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 Virtual USB device.
34 */
35#ifndef LIBUSBVIRT_DEVICE_H_
36#define LIBUSBVIRT_DEVICE_H_
37
38#include <usb/hcd.h>
39#include <usb/descriptor.h>
40#include <usb/devreq.h>
41
42struct usbvirt_device;
43
44typedef int (*usbvirt_on_device_request_t)(struct usbvirt_device *dev,
45 usb_device_request_setup_packet_t *request,
46 uint8_t *data);
47
48/** Device operations. */
49typedef struct {
50 /** Callback for standard USB request.
51 * Called only when the request could not be handled by this
52 * framework.
53 */
54 usbvirt_on_device_request_t on_devreq_std;
55 /** Callback for class-specific USB request. */
56 usbvirt_on_device_request_t on_devreq_class;
57 /** Callback for all other incoming data. */
58 int (*on_data)(struct usbvirt_device *dev,
59 usb_endpoint_t endpoint, void *buffer, size_t size);
60} usbvirt_device_ops_t;
61
62/** Extra configuration data for GET_CONFIGURATION request. */
63typedef struct {
64 /** Actual data. */
65 uint8_t *data;
66 /** Data length. */
67 size_t length;
68} usbvirt_device_configuration_extras_t;
69
70/** Single device configuration. */
71typedef struct {
72 /** Standard configuration descriptor. */
73 usb_standard_configuration_descriptor_t *descriptor;
74 /** Array of extra data. */
75 usbvirt_device_configuration_extras_t *extra;
76 /** Length of @c extra array. */
77 size_t extra_count;
78} usbvirt_device_configuration_t;
79
80/** Standard USB descriptors. */
81typedef struct {
82 /** Standard device descriptor.
83 * There is always only one such descriptor for the device.
84 */
85 usb_standard_device_descriptor_t *device;
86
87 /** Configurations. */
88 usbvirt_device_configuration_t *configuration;
89 /** Number of configurations. */
90 size_t configuration_count;
91} usbvirt_descriptors_t;
92
93
94typedef struct usbvirt_device {
95 /** Callback device operations. */
96 usbvirt_device_ops_t *ops;
97
98 /** Send data to HC.
99 * @warning Do not change after initializing with
100 * usbvirt_device_init().
101 * This function is here merely to make the interface more OOP.
102 */
103 int (*send_data)(struct usbvirt_device *dev,
104 usb_endpoint_t endpoint, void *buffer, size_t size);
105
106
107
108 /* Device attributes. */
109
110 /** Standard descriptors. */
111 usbvirt_descriptors_t *descriptors;
112
113
114 /* Private attributes. */
115
116 /** Phone to HC.
117 * @warning Do not change, this is private variable.
118 */
119 int vhcd_phone_;
120
121 /** Device id.
122 * This item will be removed when device enumeration and
123 * recognition is implemented.
124 */
125 int device_id_;
126} usbvirt_device_t;
127
128#endif
129/**
130 * @}
131 */
Note: See TracBrowser for help on using the repository browser.