source: mainline/uspace/lib/usbdev/include/usb/dev/driver.h@ b6812a1

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b6812a1 was b6812a1, checked in by Jan Vesely <jano.vesely@…>, 13 years ago

libusbdev: Make list of alternate interfaces const.

  • Property mode set to 100644
File size: 6.7 KB
Line 
1/*
2 * Copyright (c) 2011 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 libusbdev
30 * @{
31 */
32/** @file
33 * USB device driver framework.
34 */
35
36#ifndef LIBUSBDEV_DRIVER_H_
37#define LIBUSBDEV_DRIVER_H_
38
39#include <usb/hc.h>
40#include <usb/dev/usb_device_connection.h>
41#include <usb/dev/pipes.h>
42#include <usb_iface.h>
43
44
45/** Wrapper for data related to alternate interface setting.
46 * The pointers will typically point inside configuration descriptor and
47 * thus you shall not deallocate them.
48 */
49typedef struct {
50 /** Interface descriptor. */
51 const usb_standard_interface_descriptor_t *interface;
52 /** Pointer to start of descriptor tree bound with this interface. */
53 const uint8_t *nested_descriptors;
54 /** Size of data pointed by nested_descriptors in bytes. */
55 size_t nested_descriptors_size;
56} usb_alternate_interface_descriptors_t;
57
58/** Alternate interface settings. */
59typedef struct {
60 /** Array of alternate interfaces descriptions. */
61 const usb_alternate_interface_descriptors_t *alternatives;
62 /** Size of @c alternatives array. */
63 size_t alternative_count;
64 /** Index of currently selected one. */
65 size_t current;
66} usb_alternate_interfaces_t;
67
68/** USB device structure. */
69typedef struct {
70 /** Connection to USB hc, used by wire and arbitrary requests. */
71 usb_hc_connection_t hc_conn;
72 /** Connection backing the pipes.
73 * Typically, you will not need to use this attribute at all.
74 */
75 usb_device_connection_t wire;
76 /** The default control pipe. */
77 usb_pipe_t ctrl_pipe;
78
79 /** Other endpoint pipes.
80 * This is an array of other endpoint pipes in the same order as
81 * in usb_driver_t.
82 */
83 usb_endpoint_mapping_t *pipes;
84 /** Number of other endpoint pipes. */
85 size_t pipes_count;
86 /** Current interface.
87 * Usually, drivers operate on single interface only.
88 * This item contains the value of the interface or -1 for any.
89 */
90 int interface_no;
91 /** Alternative interfaces. */
92 usb_alternate_interfaces_t alternate_interfaces;
93
94 /** Some useful descriptors for USB device. */
95 struct {
96 /** Standard device descriptor. */
97 usb_standard_device_descriptor_t device;
98 /** Full configuration descriptor of current configuration. */
99 const uint8_t *configuration;
100 size_t configuration_size;
101 } descriptors;
102
103 /** Generic DDF device backing this one. DO NOT TOUCH! */
104 ddf_dev_t *ddf_dev;
105 /** Custom driver data.
106 * Do not use the entry in generic device, that is already used
107 * by the framework.
108 */
109 void *driver_data;
110
111 usb_dev_session_t *bus_session;
112} usb_device_t;
113
114/** USB driver ops. */
115typedef struct {
116 /** Callback when a new device was added to the system. */
117 int (*device_add)(usb_device_t *);
118 /** Callback when a device is about to be removed from the system. */
119 int (*device_rem)(usb_device_t *);
120 /** Callback when a device was removed from the system. */
121 int (*device_gone)(usb_device_t *);
122} usb_driver_ops_t;
123
124/** USB driver structure. */
125typedef struct {
126 /** Driver name.
127 * This name is copied to the generic driver name and must be exactly
128 * the same as the directory name where the driver executable resides.
129 */
130 const char *name;
131 /** Expected endpoints description.
132 * This description shall exclude default control endpoint (pipe zero)
133 * and must be NULL terminated.
134 * When only control endpoint is expected, you may set NULL directly
135 * without creating one item array containing NULL.
136 *
137 * When the driver expect single interrupt in endpoint,
138 * the initialization may look like this:
139\code
140static usb_endpoint_description_t poll_endpoint_description = {
141 .transfer_type = USB_TRANSFER_INTERRUPT,
142 .direction = USB_DIRECTION_IN,
143 .interface_class = USB_CLASS_HUB,
144 .interface_subclass = 0,
145 .interface_protocol = 0,
146 .flags = 0
147};
148
149static usb_endpoint_description_t *hub_endpoints[] = {
150 &poll_endpoint_description,
151 NULL
152};
153
154static usb_driver_t hub_driver = {
155 .endpoints = hub_endpoints,
156 ...
157};
158\endcode
159 */
160 const usb_endpoint_description_t **endpoints;
161 /** Driver ops. */
162 const usb_driver_ops_t *ops;
163} usb_driver_t;
164
165int usb_driver_main(const usb_driver_t *);
166
167int usb_device_init(usb_device_t *, ddf_dev_t *,
168 const usb_endpoint_description_t **, const char **);
169void usb_device_deinit(usb_device_t *);
170
171const char* usb_device_get_name(usb_device_t *);
172ddf_fun_t *usb_device_ddf_fun_create(usb_device_t *, fun_type_t, const char *);
173
174async_exch_t * usb_device_bus_exchange_begin(usb_device_t *);
175void usb_device_bus_exchange_end(async_exch_t *);
176
177int usb_device_select_interface(usb_device_t *, uint8_t,
178 const usb_endpoint_description_t **);
179
180int usb_device_create_pipes(usb_device_connection_t *,
181 const usb_endpoint_description_t **, const uint8_t *, size_t, int, int,
182 usb_endpoint_mapping_t **, size_t *);
183void usb_device_destroy_pipes(usb_endpoint_mapping_t *, size_t);
184usb_pipe_t *usb_device_get_default_pipe(usb_device_t *);
185usb_pipe_t *usb_device_get_pipe(usb_device_t *, usb_endpoint_t, usb_direction_t);
186
187const usb_standard_device_descriptor_t *
188usb_device_get_device_descriptor(usb_device_t *);
189const void * usb_device_get_configuration_descriptor(usb_device_t *, size_t *);
190
191
192void * usb_device_data_alloc(usb_device_t *, size_t);
193void * usb_device_data_get(usb_device_t *);
194
195size_t usb_interface_count_alternates(const uint8_t *, size_t, uint8_t);
196int usb_alternate_interfaces_init(usb_alternate_interfaces_t *,
197 const uint8_t *, size_t, int);
198void usb_alternate_interfaces_deinit(usb_alternate_interfaces_t *);
199#endif
200/**
201 * @}
202 */
Note: See TracBrowser for help on using the repository browser.