source: mainline/uspace/lib/usbvirt/device.h@ 08af5a6

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

Virtual USB device handles set_configuration

No checks etc. are done but it must be sufficient for now.

  • Property mode set to 100644
File size: 5.3 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/** Callbacks for standard device requests.
49 * When these functions are NULL or return EFORWARD, this
50 * framework will try to satisfy the request by itself.
51 */
52typedef struct {
53 usbvirt_on_device_request_t on_get_status;
54 usbvirt_on_device_request_t on_clear_feature;
55 usbvirt_on_device_request_t on_set_feature;
56 usbvirt_on_device_request_t on_set_address;
57 usbvirt_on_device_request_t on_get_descriptor;
58 usbvirt_on_device_request_t on_set_descriptor;
59 usbvirt_on_device_request_t on_get_configuration;
60 usbvirt_on_device_request_t on_set_configuration;
61 usbvirt_on_device_request_t on_get_interface;
62 usbvirt_on_device_request_t on_set_interface;
63 usbvirt_on_device_request_t on_synch_frame;
64} usbvirt_standard_device_request_ops_t;
65
66/** Device operations. */
67typedef struct {
68 /** Callbacks for standard deivce requests. */
69 usbvirt_standard_device_request_ops_t *standard_request_ops;
70 /** Callback for class-specific USB request. */
71 usbvirt_on_device_request_t on_class_device_request;
72 /** Callback for all other incoming data. */
73 int (*on_data)(struct usbvirt_device *dev,
74 usb_endpoint_t endpoint, void *buffer, size_t size);
75} usbvirt_device_ops_t;
76
77/** Extra configuration data for GET_CONFIGURATION request. */
78typedef struct {
79 /** Actual data. */
80 uint8_t *data;
81 /** Data length. */
82 size_t length;
83} usbvirt_device_configuration_extras_t;
84
85/** Single device configuration. */
86typedef struct {
87 /** Standard configuration descriptor. */
88 usb_standard_configuration_descriptor_t *descriptor;
89 /** Array of extra data. */
90 usbvirt_device_configuration_extras_t *extra;
91 /** Length of @c extra array. */
92 size_t extra_count;
93} usbvirt_device_configuration_t;
94
95/** Standard USB descriptors. */
96typedef struct {
97 /** Standard device descriptor.
98 * There is always only one such descriptor for the device.
99 */
100 usb_standard_device_descriptor_t *device;
101
102 /** Configurations. */
103 usbvirt_device_configuration_t *configuration;
104 /** Number of configurations. */
105 size_t configuration_count;
106 /** Index of currently selected configuration. */
107 uint8_t current_configuration;
108} usbvirt_descriptors_t;
109
110/** Possible states of virtual USB device.
111 * Notice that these are not 1:1 mappings to those in USB specification.
112 */
113typedef enum {
114 USBVIRT_STATE_DEFAULT,
115 USBVIRT_STATE_ADDRESS,
116 USBVIRT_STATE_CONFIGURED
117} usbvirt_device_state_t;
118
119/** Virtual USB device. */
120typedef struct usbvirt_device {
121 /** Callback device operations. */
122 usbvirt_device_ops_t *ops;
123
124 /** Send data to HC.
125 * @warning Do not change after initializing with
126 * usbvirt_device_init().
127 * This function is here merely to make the interface more OOP.
128 */
129 int (*send_data)(struct usbvirt_device *dev,
130 usb_endpoint_t endpoint, void *buffer, size_t size);
131
132 /* Device attributes. */
133
134 /** Standard descriptors. */
135 usbvirt_descriptors_t *descriptors;
136
137 /** Current device state. */
138 usbvirt_device_state_t state;
139 /** Device address. */
140 usb_address_t address;
141
142 /* Private attributes. */
143
144 /** Phone to HC.
145 * @warning Do not change, this is private variable.
146 */
147 int vhcd_phone_;
148
149 /** Device id.
150 * This item will be removed when device enumeration and
151 * recognition is implemented.
152 */
153 int device_id_;
154
155 /** Main routine called when data is received from HC.
156 * @warning Do not change after initializing with
157 * usbvirt_device_init().
158 * This function is here merely to make the interface more OOP.
159 */
160 int (*receive_data)(struct usbvirt_device *dev,
161 usb_endpoint_t endpoint, void *buffer, size_t size);
162
163} usbvirt_device_t;
164
165#endif
166/**
167 * @}
168 */
Note: See TracBrowser for help on using the repository browser.