source: mainline/uspace/lib/usb/include/usb/pipes.h@ 18cb870

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

Extend pipe initialization with interface number

  • Property mode set to 100644
File size: 5.1 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 libusb
30 * @{
31 */
32/** @file
33 * USB pipes representation.
34 */
35#ifndef LIBUSB_PIPES_H_
36#define LIBUSB_PIPES_H_
37
38#include <sys/types.h>
39#include <usb/usb.h>
40#include <usb/usbdevice.h>
41#include <usb/descriptor.h>
42#include <ipc/devman.h>
43#include <driver.h>
44
45/**
46 * Abstraction of a physical connection to the device.
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;
53 /** Address of the device. */
54 usb_address_t address;
55} usb_device_connection_t;
56
57/**
58 * Abstraction of a logical connection to USB device endpoint.
59 * It encapsulates endpoint attributes (transfer type etc.) as well
60 * as information about currently running sessions.
61 * This endpoint must be bound with existing usb_device_connection_t
62 * (i.e. the wire to send data over).
63 */
64typedef struct {
65 /** The connection used for sending the data. */
66 usb_device_connection_t *wire;
67
68 /** Endpoint number. */
69 usb_endpoint_t endpoint_no;
70
71 /** Endpoint transfer type. */
72 usb_transfer_type_t transfer_type;
73
74 /** Endpoint direction. */
75 usb_direction_t direction;
76
77 /** Maximum packet size for the endpoint. */
78 size_t max_packet_size;
79
80 /** Phone to the host controller.
81 * Negative when no session is active.
82 */
83 int hc_phone;
84} usb_endpoint_pipe_t;
85
86
87/** Description of endpoint characteristics. */
88typedef struct {
89 /** Transfer type (e.g. control or interrupt). */
90 usb_transfer_type_t transfer_type;
91 /** Transfer direction (to or from a device). */
92 usb_direction_t direction;
93 /** Interface class this endpoint belongs to (-1 for any). */
94 int interface_class;
95 /** Interface subclass this endpoint belongs to (-1 for any). */
96 int interface_subclass;
97 /** Interface protocol this endpoint belongs to (-1 for any). */
98 int interface_protocol;
99 /** Extra endpoint flags. */
100 unsigned int flags;
101} usb_endpoint_description_t;
102
103/** Mapping of endpoint pipes and endpoint descriptions. */
104typedef struct {
105 /** Endpoint pipe. */
106 usb_endpoint_pipe_t *pipe;
107 /** Endpoint description. */
108 const usb_endpoint_description_t *description;
109 /** Interface number the endpoint must belong to (-1 for any). */
110 const int interface_no;
111 /** Found descriptor fitting the description. */
112 usb_standard_endpoint_descriptor_t *descriptor;
113 /** Interface the endpoint belongs to. */
114 usb_standard_interface_descriptor_t *interface;
115 /** Whether the endpoint was actually found. */
116 bool present;
117} usb_endpoint_mapping_t;
118
119int usb_device_connection_initialize_on_default_address(
120 usb_device_connection_t *, usb_hc_connection_t *);
121int usb_device_connection_initialize_from_device(usb_device_connection_t *,
122 device_t *);
123int usb_device_connection_initialize(usb_device_connection_t *,
124 devman_handle_t, usb_address_t);
125
126int usb_device_get_assigned_interface(device_t *);
127
128int usb_endpoint_pipe_initialize(usb_endpoint_pipe_t *,
129 usb_device_connection_t *,
130 usb_endpoint_t, usb_transfer_type_t, size_t, usb_direction_t);
131int usb_endpoint_pipe_initialize_default_control(usb_endpoint_pipe_t *,
132 usb_device_connection_t *);
133int usb_endpoint_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
134 size_t, uint8_t *, size_t, usb_device_connection_t *);
135
136
137int usb_endpoint_pipe_start_session(usb_endpoint_pipe_t *);
138int usb_endpoint_pipe_end_session(usb_endpoint_pipe_t *);
139
140int usb_endpoint_pipe_read(usb_endpoint_pipe_t *, void *, size_t, size_t *);
141int usb_endpoint_pipe_write(usb_endpoint_pipe_t *, void *, size_t);
142
143int usb_endpoint_pipe_control_read(usb_endpoint_pipe_t *, void *, size_t,
144 void *, size_t, size_t *);
145int usb_endpoint_pipe_control_write(usb_endpoint_pipe_t *, void *, size_t,
146 void *, size_t);
147
148#endif
149/**
150 * @}
151 */
Note: See TracBrowser for help on using the repository browser.