[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 | */
|
---|
[160b75e] | 28 | /** @addtogroup libusbdev
|
---|
[6865243c] | 29 | * @{
|
---|
| 30 | */
|
---|
| 31 | /** @file
|
---|
[d714945] | 32 | * USB pipes representation.
|
---|
[6865243c] | 33 | */
|
---|
[7d521e24] | 34 | #ifndef LIBUSBDEV_PIPES_H_
|
---|
| 35 | #define LIBUSBDEV_PIPES_H_
|
---|
[6865243c] | 36 |
|
---|
| 37 | #include <sys/types.h>
|
---|
| 38 | #include <ipc/devman.h>
|
---|
[eb1a2f4] | 39 | #include <ddf/driver.h>
|
---|
[d5ac90f] | 40 | #include <fibril_synch.h>
|
---|
[79ae36dd] | 41 | #include <async.h>
|
---|
[1a38701] | 42 | #include <usb/usb.h>
|
---|
| 43 | #include <usb/descriptor.h>
|
---|
| 44 | #include <usb/dev/usb_device_connection.h>
|
---|
[6865243c] | 45 |
|
---|
[c804484] | 46 | #define CTRL_PIPE_MIN_PACKET_SIZE 8
|
---|
[a6add7a] | 47 | /** Abstraction of a logical connection to USB device endpoint.
|
---|
[6865243c] | 48 | * It encapsulates endpoint attributes (transfer type etc.) as well
|
---|
| 49 | * as information about currently running sessions.
|
---|
| 50 | * This endpoint must be bound with existing usb_device_connection_t
|
---|
| 51 | * (i.e. the wire to send data over).
|
---|
[d48fcc0] | 52 | *
|
---|
| 53 | * Locking order: if you want to lock both mutexes
|
---|
[79ae36dd] | 54 | * (@c guard and @c hc_sess_mutex), lock @c guard first.
|
---|
| 55 | * It is not necessary to lock @c guard if you want to lock @c hc_sess_mutex
|
---|
[d48fcc0] | 56 | * only.
|
---|
[6865243c] | 57 | */
|
---|
| 58 | typedef struct {
|
---|
[d48fcc0] | 59 | /** Guard of the whole pipe. */
|
---|
| 60 | fibril_mutex_t guard;
|
---|
| 61 |
|
---|
[6865243c] | 62 | /** The connection used for sending the data. */
|
---|
| 63 | usb_device_connection_t *wire;
|
---|
| 64 |
|
---|
| 65 | /** Endpoint number. */
|
---|
| 66 | usb_endpoint_t endpoint_no;
|
---|
| 67 |
|
---|
| 68 | /** Endpoint transfer type. */
|
---|
| 69 | usb_transfer_type_t transfer_type;
|
---|
| 70 |
|
---|
| 71 | /** Endpoint direction. */
|
---|
| 72 | usb_direction_t direction;
|
---|
| 73 |
|
---|
[25971d2] | 74 | /** Maximum packet size for the endpoint. */
|
---|
| 75 | size_t max_packet_size;
|
---|
| 76 |
|
---|
[fa0f53b] | 77 | /** Whether to automatically reset halt on the endpoint.
|
---|
| 78 | * Valid only for control endpoint zero.
|
---|
| 79 | */
|
---|
| 80 | bool auto_reset_halt;
|
---|
[a372663] | 81 | } usb_pipe_t;
|
---|
[6865243c] | 82 |
|
---|
[93ef8f6] | 83 | /** Description of endpoint characteristics. */
|
---|
| 84 | typedef struct {
|
---|
| 85 | /** Transfer type (e.g. control or interrupt). */
|
---|
| 86 | usb_transfer_type_t transfer_type;
|
---|
| 87 | /** Transfer direction (to or from a device). */
|
---|
| 88 | usb_direction_t direction;
|
---|
| 89 | /** Interface class this endpoint belongs to (-1 for any). */
|
---|
| 90 | int interface_class;
|
---|
| 91 | /** Interface subclass this endpoint belongs to (-1 for any). */
|
---|
| 92 | int interface_subclass;
|
---|
[1110ebd] | 93 | /** Interface protocol this endpoint belongs to (-1 for any). */
|
---|
[93ef8f6] | 94 | int interface_protocol;
|
---|
| 95 | /** Extra endpoint flags. */
|
---|
| 96 | unsigned int flags;
|
---|
| 97 | } usb_endpoint_description_t;
|
---|
| 98 |
|
---|
| 99 | /** Mapping of endpoint pipes and endpoint descriptions. */
|
---|
| 100 | typedef struct {
|
---|
| 101 | /** Endpoint pipe. */
|
---|
[b77931d] | 102 | usb_pipe_t pipe;
|
---|
[93ef8f6] | 103 | /** Endpoint description. */
|
---|
| 104 | const usb_endpoint_description_t *description;
|
---|
[18cb870] | 105 | /** Interface number the endpoint must belong to (-1 for any). */
|
---|
[6105fc0] | 106 | int interface_no;
|
---|
[159b91f4] | 107 | /** Alternate interface setting to choose. */
|
---|
| 108 | int interface_setting;
|
---|
[93ef8f6] | 109 | /** Found descriptor fitting the description. */
|
---|
[b77931d] | 110 | const usb_standard_endpoint_descriptor_t *descriptor;
|
---|
[a6add7a] | 111 | /** Interface descriptor the endpoint belongs to. */
|
---|
[b77931d] | 112 | const usb_standard_interface_descriptor_t *interface;
|
---|
[93ef8f6] | 113 | /** Whether the endpoint was actually found. */
|
---|
| 114 | bool present;
|
---|
| 115 | } usb_endpoint_mapping_t;
|
---|
[6865243c] | 116 |
|
---|
[3954a63b] | 117 | int usb_pipe_initialize(usb_pipe_t *, usb_device_connection_t *,
|
---|
[25971d2] | 118 | usb_endpoint_t, usb_transfer_type_t, size_t, usb_direction_t);
|
---|
[3954a63b] | 119 | int usb_pipe_initialize_default_control(usb_pipe_t *,
|
---|
[6865243c] | 120 | usb_device_connection_t *);
|
---|
[bd575647] | 121 |
|
---|
[3954a63b] | 122 | int usb_pipe_probe_default_control(usb_pipe_t *);
|
---|
| 123 | int usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
|
---|
[7c95d6f5] | 124 | size_t, const uint8_t *, size_t, usb_device_connection_t *);
|
---|
[c804484] | 125 |
|
---|
[bd575647] | 126 | int usb_pipe_register(usb_pipe_t *, unsigned);
|
---|
| 127 | int usb_pipe_unregister(usb_pipe_t *);
|
---|
[6865243c] | 128 |
|
---|
[47dfb34] | 129 | int usb_pipe_start_long_transfer(usb_pipe_t *);
|
---|
| 130 | int usb_pipe_end_long_transfer(usb_pipe_t *);
|
---|
[e9ce696] | 131 |
|
---|
[3954a63b] | 132 | int usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *);
|
---|
[b4292e7] | 133 | int usb_pipe_write(usb_pipe_t *, const void *, size_t);
|
---|
[6865243c] | 134 |
|
---|
[7a05ced0] | 135 | int usb_pipe_control_read(usb_pipe_t *, const void *, size_t,
|
---|
[6865243c] | 136 | void *, size_t, size_t *);
|
---|
[3875af65] | 137 | int usb_pipe_control_write(usb_pipe_t *, const void *, size_t,
|
---|
| 138 | const void *, size_t);
|
---|
[6865243c] | 139 |
|
---|
| 140 | #endif
|
---|
| 141 | /**
|
---|
| 142 | * @}
|
---|
| 143 | */
|
---|