source: mainline/uspace/lib/usbdev/include/usb/dev/pipes.h

Last change on this file was ae3a941, checked in by Ondřej Hlavatý <aearsis@…>, 7 years ago

usb: cstyle

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 * Copyright (c) 2011 Vojtech Horky
3 * Copyright (c) 2018 Ondrej Hlavaty
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29/** @addtogroup libusbdev
30 * @{
31 */
32/** @file
33 * USB pipes representation.
34 */
35#ifndef LIBUSBDEV_PIPES_H_
36#define LIBUSBDEV_PIPES_H_
37
38#include <usb/usb.h>
39#include <usb/descriptor.h>
40#include <usb_iface.h>
41
42#include <stdbool.h>
43#include <stddef.h>
44#include <stdint.h>
45
46#define CTRL_PIPE_MIN_PACKET_SIZE 8
47
48/** Abstraction of a logical connection to USB device endpoint.
49 * It contains some vital information about the pipe.
50 * This endpoint must be bound with existing usb_device_connection_t
51 * (i.e. the wire to send data over).
52 */
53typedef struct {
54 /** Pipe description received from HC */
55 usb_pipe_desc_t desc;
56
57 /** Whether to automatically reset halt on the endpoint.
58 * Valid only for control endpoint zero.
59 */
60 bool auto_reset_halt;
61 /** The connection used for sending the data. */
62 usb_dev_session_t *bus_session;
63} usb_pipe_t;
64
65/** Description of endpoint characteristics. */
66typedef struct {
67 /** Transfer type (e.g. control or interrupt). */
68 usb_transfer_type_t transfer_type;
69 /** Transfer direction (to or from a device). */
70 usb_direction_t direction;
71 /** Interface class this endpoint belongs to (-1 for any). */
72 int interface_class;
73 /** Interface subclass this endpoint belongs to (-1 for any). */
74 int interface_subclass;
75 /** Interface protocol this endpoint belongs to (-1 for any). */
76 int interface_protocol;
77 /** Extra endpoint flags. */
78 unsigned int flags;
79} usb_endpoint_description_t;
80
81/** Mapping of endpoint pipes and endpoint descriptions. */
82typedef struct {
83 /** Endpoint pipe. */
84 usb_pipe_t pipe;
85 /** Endpoint description. */
86 const usb_endpoint_description_t *description;
87 /** Interface number the endpoint must belong to (-1 for any). */
88 int interface_no;
89 /** Alternate interface setting to choose. */
90 int interface_setting;
91 /** Found descriptor fitting the description. */
92 const usb_standard_endpoint_descriptor_t *descriptor;
93 /** Relevant superspeed companion descriptor. */
94 const usb_superspeed_endpoint_companion_descriptor_t
95 *companion_descriptor;
96 /** Interface descriptor the endpoint belongs to. */
97 const usb_standard_interface_descriptor_t *interface;
98 /** Whether the endpoint was actually found. */
99 bool present;
100} usb_endpoint_mapping_t;
101
102errno_t usb_pipe_initialize(usb_pipe_t *, usb_dev_session_t *);
103errno_t usb_pipe_initialize_default_control(usb_pipe_t *, usb_dev_session_t *);
104
105errno_t usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
106 size_t, const uint8_t *, size_t, usb_dev_session_t *);
107
108errno_t usb_pipe_register(usb_pipe_t *,
109 const usb_standard_endpoint_descriptor_t *,
110 const usb_superspeed_endpoint_companion_descriptor_t *);
111errno_t usb_pipe_unregister(usb_pipe_t *);
112
113errno_t usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *);
114errno_t usb_pipe_write(usb_pipe_t *, const void *, size_t);
115
116errno_t usb_pipe_read_dma(usb_pipe_t *, void *, void *, size_t, size_t *);
117errno_t usb_pipe_write_dma(usb_pipe_t *, void *, void *, size_t);
118
119errno_t usb_pipe_control_read(usb_pipe_t *, const void *, size_t,
120 void *, size_t, size_t *);
121errno_t usb_pipe_control_write(usb_pipe_t *, const void *, size_t,
122 const void *, size_t);
123
124void *usb_pipe_alloc_buffer(usb_pipe_t *, size_t);
125void usb_pipe_free_buffer(usb_pipe_t *, void *);
126#endif
127/**
128 * @}
129 */
Note: See TracBrowser for help on using the repository browser.