source: mainline/uspace/lib/usbdev/include/usb/pipes.h@ 3e4f2e0

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

libusb divided into sublibraries

Also removed address keeper test from tester as it is useless.

Directory reorganization of the include/ will follow.

  • Property mode set to 100644
File size: 6.8 KB
RevLine 
[6865243c]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 libusb
30 * @{
31 */
32/** @file
[d714945]33 * USB pipes representation.
[6865243c]34 */
35#ifndef LIBUSB_PIPES_H_
36#define LIBUSB_PIPES_H_
37
38#include <sys/types.h>
39#include <usb/usb.h>
[d714945]40#include <usb/usbdevice.h>
[93ef8f6]41#include <usb/descriptor.h>
[6865243c]42#include <ipc/devman.h>
[eb1a2f4]43#include <ddf/driver.h>
[d5ac90f]44#include <fibril_synch.h>
[6865243c]45
[a6add7a]46/** Abstraction of a physical connection to the device.
[6865243c]47 * This type is an abstraction of the USB wire that connects the host and
48 * the function (device).
49 */
50typedef struct {
51 /** Handle of the host controller device is connected to. */
52 devman_handle_t hc_handle;
[43f698b]53 /** Address of the device. */
54 usb_address_t address;
[6865243c]55} usb_device_connection_t;
56
[a6add7a]57/** Abstraction of a logical connection to USB device endpoint.
[6865243c]58 * It encapsulates endpoint attributes (transfer type etc.) as well
59 * as information about currently running sessions.
60 * This endpoint must be bound with existing usb_device_connection_t
61 * (i.e. the wire to send data over).
[d48fcc0]62 *
63 * Locking order: if you want to lock both mutexes
64 * (@c guard and @c hc_phone_mutex), lock @c guard first.
65 * It is not necessary to lock @c guard if you want to lock @c hc_phone_mutex
66 * only.
[6865243c]67 */
68typedef struct {
[d48fcc0]69 /** Guard of the whole pipe. */
70 fibril_mutex_t guard;
71
[6865243c]72 /** The connection used for sending the data. */
73 usb_device_connection_t *wire;
74
75 /** Endpoint number. */
76 usb_endpoint_t endpoint_no;
77
78 /** Endpoint transfer type. */
79 usb_transfer_type_t transfer_type;
80
81 /** Endpoint direction. */
82 usb_direction_t direction;
83
[25971d2]84 /** Maximum packet size for the endpoint. */
85 size_t max_packet_size;
86
[6865243c]87 /** Phone to the host controller.
88 * Negative when no session is active.
[d48fcc0]89 * It is an error to access this member without @c hc_phone_mutex
90 * being locked.
91 * If call over the phone is to be made, it must be preceeded by
92 * call to pipe_add_ref() [internal libusb function].
[6865243c]93 */
94 int hc_phone;
[d5ac90f]95
96 /** Guard for serialization of requests over the phone. */
97 fibril_mutex_t hc_phone_mutex;
[a546687]98
99 /** Number of active transfers over the pipe. */
100 int refcount;
[2c2cbcf]101 /** Number of failed attempts to open the HC phone.
102 * When user requests usb_pipe_start_long_transfer() and the operation
103 * fails, there is no way to report this to the user.
104 * That the soft reference counter is increased to record the attempt.
105 * When the user then request e.g. usb_pipe_read(), it will try to
106 * add reference as well.
107 * If that fails, it is reported to the user. If it is okay, the
108 * real reference counter is incremented.
109 * The problem might arise when ending the long transfer (since
110 * the number of references would be only 1, but logically it shall be
111 * two).
112 * Decrementing the soft counter first shall solve this.
113 */
114 int refcount_soft;
[fa0f53b]115
116 /** Whether to automatically reset halt on the endpoint.
117 * Valid only for control endpoint zero.
118 */
119 bool auto_reset_halt;
[a372663]120} usb_pipe_t;
[6865243c]121
[93ef8f6]122
123/** Description of endpoint characteristics. */
124typedef struct {
125 /** Transfer type (e.g. control or interrupt). */
126 usb_transfer_type_t transfer_type;
127 /** Transfer direction (to or from a device). */
128 usb_direction_t direction;
129 /** Interface class this endpoint belongs to (-1 for any). */
130 int interface_class;
131 /** Interface subclass this endpoint belongs to (-1 for any). */
132 int interface_subclass;
[1110ebd]133 /** Interface protocol this endpoint belongs to (-1 for any). */
[93ef8f6]134 int interface_protocol;
135 /** Extra endpoint flags. */
136 unsigned int flags;
137} usb_endpoint_description_t;
138
139/** Mapping of endpoint pipes and endpoint descriptions. */
140typedef struct {
141 /** Endpoint pipe. */
[a372663]142 usb_pipe_t *pipe;
[93ef8f6]143 /** Endpoint description. */
144 const usb_endpoint_description_t *description;
[18cb870]145 /** Interface number the endpoint must belong to (-1 for any). */
[6105fc0]146 int interface_no;
[159b91f4]147 /** Alternate interface setting to choose. */
148 int interface_setting;
[93ef8f6]149 /** Found descriptor fitting the description. */
150 usb_standard_endpoint_descriptor_t *descriptor;
[a6add7a]151 /** Interface descriptor the endpoint belongs to. */
[9d4579e]152 usb_standard_interface_descriptor_t *interface;
[93ef8f6]153 /** Whether the endpoint was actually found. */
154 bool present;
155} usb_endpoint_mapping_t;
[6865243c]156
[d714945]157int usb_device_connection_initialize_on_default_address(
158 usb_device_connection_t *, usb_hc_connection_t *);
[23c7f4d]159int usb_device_connection_initialize_from_device(usb_device_connection_t *,
[eb1a2f4]160 ddf_dev_t *);
[52fb76e]161int usb_device_connection_initialize(usb_device_connection_t *,
162 devman_handle_t, usb_address_t);
[6865243c]163
[eb1a2f4]164int usb_device_get_assigned_interface(ddf_dev_t *);
[c2343cc]165usb_address_t usb_device_get_assigned_address(devman_handle_t);
[27a0012]166
[3954a63b]167int usb_pipe_initialize(usb_pipe_t *, usb_device_connection_t *,
[25971d2]168 usb_endpoint_t, usb_transfer_type_t, size_t, usb_direction_t);
[3954a63b]169int usb_pipe_initialize_default_control(usb_pipe_t *,
[6865243c]170 usb_device_connection_t *);
[3954a63b]171int usb_pipe_probe_default_control(usb_pipe_t *);
172int usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
[93ef8f6]173 size_t, uint8_t *, size_t, usb_device_connection_t *);
[1998bcd]174int usb_pipe_register_with_speed(usb_pipe_t *, usb_speed_t,
175 unsigned int, usb_hc_connection_t *);
[3954a63b]176int usb_pipe_register(usb_pipe_t *, unsigned int, usb_hc_connection_t *);
177int usb_pipe_unregister(usb_pipe_t *, usb_hc_connection_t *);
[6865243c]178
[2c2cbcf]179void usb_pipe_start_long_transfer(usb_pipe_t *);
[e9ce696]180void usb_pipe_end_long_transfer(usb_pipe_t *);
181
[3954a63b]182int usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *);
183int usb_pipe_write(usb_pipe_t *, void *, size_t);
[6865243c]184
[3954a63b]185int usb_pipe_control_read(usb_pipe_t *, void *, size_t,
[6865243c]186 void *, size_t, size_t *);
[3954a63b]187int usb_pipe_control_write(usb_pipe_t *, void *, size_t,
[6865243c]188 void *, size_t);
189
190#endif
191/**
192 * @}
193 */
Note: See TracBrowser for help on using the repository browser.