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

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

libusbdev: usb_destroy_pipes would only ever return EOK.

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