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

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

libusbvirt allows local device

By local device is meant virtual device in current task
(i.e. not connected through phones but called statically).

  • Property mode set to 100644
File size: 5.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 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} usbvirt_descriptors_t;
107
108/** Possible states of virtual USB device.
109 * Notice that these are not 1:1 mappings to those in USB specification.
110 */
111typedef enum {
112 USBVIRT_STATE_DEFAULT,
113 USBVIRT_STATE_ADDRESS,
114 USBVIRT_STATE_CONFIGURED
115} usbvirt_device_state_t;
116
117/** Virtual USB device. */
118typedef struct usbvirt_device {
119 /** Callback device operations. */
120 usbvirt_device_ops_t *ops;
121
122 /** Send data to HC.
123 * @warning Do not change after initializing with
124 * usbvirt_device_init().
125 * This function is here merely to make the interface more OOP.
126 */
127 int (*send_data)(struct usbvirt_device *dev,
128 usb_endpoint_t endpoint, void *buffer, size_t size);
129
130 /* Device attributes. */
131
132 /** Standard descriptors. */
133 usbvirt_descriptors_t *descriptors;
134
135 /** Current device state. */
136 usbvirt_device_state_t state;
137 /** Device address. */
138 usb_address_t address;
139
140 /* Private attributes. */
141
142 /** Phone to HC.
143 * @warning Do not change, this is private variable.
144 */
145 int vhcd_phone_;
146
147 /** Device id.
148 * This item will be removed when device enumeration and
149 * recognition is implemented.
150 */
151 int device_id_;
152
153 /** Main routine called when data is received from HC.
154 * @warning Do not change after initializing with
155 * usbvirt_device_init().
156 * This function is here merely to make the interface more OOP.
157 */
158 int (*receive_data)(struct usbvirt_device *dev,
159 usb_endpoint_t endpoint, void *buffer, size_t size);
160
161} usbvirt_device_t;
162
163#endif
164/**
165 * @}
166 */
Note: See TracBrowser for help on using the repository browser.