| [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 |
|
|---|
| [1a38701] | 37 | #include <usb/usb.h>
|
|---|
| 38 | #include <usb/descriptor.h>
|
|---|
| [3cdaa7f] | 39 | #include <usb_iface.h>
|
|---|
| [6865243c] | 40 |
|
|---|
| [c01987c] | 41 | #include <stdbool.h>
|
|---|
| [8d2dd7f2] | 42 | #include <stddef.h>
|
|---|
| 43 | #include <stdint.h>
|
|---|
| [c01987c] | 44 |
|
|---|
| [c804484] | 45 | #define CTRL_PIPE_MIN_PACKET_SIZE 8
|
|---|
| [9efad54] | 46 |
|
|---|
| [a6add7a] | 47 | /** Abstraction of a logical connection to USB device endpoint.
|
|---|
| [9efad54] | 48 | * It contains some vital information about the pipe.
|
|---|
| [6865243c] | 49 | * This endpoint must be bound with existing usb_device_connection_t
|
|---|
| 50 | * (i.e. the wire to send data over).
|
|---|
| 51 | */
|
|---|
| 52 | typedef struct {
|
|---|
| [9efad54] | 53 | /** Pipe description received from HC */
|
|---|
| 54 | usb_pipe_desc_t desc;
|
|---|
| 55 |
|
|---|
| [fa0f53b] | 56 | /** Whether to automatically reset halt on the endpoint.
|
|---|
| 57 | * Valid only for control endpoint zero.
|
|---|
| 58 | */
|
|---|
| 59 | bool auto_reset_halt;
|
|---|
| [d93f5afb] | 60 | /** The connection used for sending the data. */
|
|---|
| [8582076] | 61 | usb_dev_session_t *bus_session;
|
|---|
| [ba2fc2c] | 62 | /** The session used for isochronous endpoints.
|
|---|
| 63 | * Required as isochronous sends/receive can block the session.
|
|---|
| 64 | */
|
|---|
| 65 | usb_dev_session_t *isoch_session;
|
|---|
| [a372663] | 66 | } usb_pipe_t;
|
|---|
| [6865243c] | 67 |
|
|---|
| [93ef8f6] | 68 | /** Description of endpoint characteristics. */
|
|---|
| 69 | typedef struct {
|
|---|
| 70 | /** Transfer type (e.g. control or interrupt). */
|
|---|
| 71 | usb_transfer_type_t transfer_type;
|
|---|
| 72 | /** Transfer direction (to or from a device). */
|
|---|
| 73 | usb_direction_t direction;
|
|---|
| 74 | /** Interface class this endpoint belongs to (-1 for any). */
|
|---|
| 75 | int interface_class;
|
|---|
| 76 | /** Interface subclass this endpoint belongs to (-1 for any). */
|
|---|
| 77 | int interface_subclass;
|
|---|
| [1110ebd] | 78 | /** Interface protocol this endpoint belongs to (-1 for any). */
|
|---|
| [93ef8f6] | 79 | int interface_protocol;
|
|---|
| 80 | /** Extra endpoint flags. */
|
|---|
| 81 | unsigned int flags;
|
|---|
| 82 | } usb_endpoint_description_t;
|
|---|
| 83 |
|
|---|
| 84 | /** Mapping of endpoint pipes and endpoint descriptions. */
|
|---|
| 85 | typedef struct {
|
|---|
| 86 | /** Endpoint pipe. */
|
|---|
| [b77931d] | 87 | usb_pipe_t pipe;
|
|---|
| [93ef8f6] | 88 | /** Endpoint description. */
|
|---|
| 89 | const usb_endpoint_description_t *description;
|
|---|
| [18cb870] | 90 | /** Interface number the endpoint must belong to (-1 for any). */
|
|---|
| [6105fc0] | 91 | int interface_no;
|
|---|
| [159b91f4] | 92 | /** Alternate interface setting to choose. */
|
|---|
| 93 | int interface_setting;
|
|---|
| [93ef8f6] | 94 | /** Found descriptor fitting the description. */
|
|---|
| [b77931d] | 95 | const usb_standard_endpoint_descriptor_t *descriptor;
|
|---|
| [ec700c7] | 96 | /** Relevant superspeed companion descriptor. */
|
|---|
| 97 | const usb_superspeed_endpoint_companion_descriptor_t *companion_descriptor;
|
|---|
| [a6add7a] | 98 | /** Interface descriptor the endpoint belongs to. */
|
|---|
| [b77931d] | 99 | const usb_standard_interface_descriptor_t *interface;
|
|---|
| [93ef8f6] | 100 | /** Whether the endpoint was actually found. */
|
|---|
| 101 | bool present;
|
|---|
| 102 | } usb_endpoint_mapping_t;
|
|---|
| [6865243c] | 103 |
|
|---|
| [9efad54] | 104 | int usb_pipe_initialize(usb_pipe_t *, usb_dev_session_t *, usb_transfer_type_t);
|
|---|
| [d93f5afb] | 105 | int usb_pipe_initialize_default_control(usb_pipe_t *, usb_dev_session_t *);
|
|---|
| [bd575647] | 106 |
|
|---|
| [3954a63b] | 107 | int usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
|
|---|
| [d93f5afb] | 108 | size_t, const uint8_t *, size_t, usb_dev_session_t *);
|
|---|
| [c804484] | 109 |
|
|---|
| [9efad54] | 110 | int usb_pipe_register(usb_pipe_t *, const usb_standard_endpoint_descriptor_t *, const usb_superspeed_endpoint_companion_descriptor_t *);
|
|---|
| [bd575647] | 111 | int usb_pipe_unregister(usb_pipe_t *);
|
|---|
| [6865243c] | 112 |
|
|---|
| [3954a63b] | 113 | int usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *);
|
|---|
| [b4292e7] | 114 | int usb_pipe_write(usb_pipe_t *, const void *, size_t);
|
|---|
| [6865243c] | 115 |
|
|---|
| [7a05ced0] | 116 | int usb_pipe_control_read(usb_pipe_t *, const void *, size_t,
|
|---|
| [6865243c] | 117 | void *, size_t, size_t *);
|
|---|
| [3875af65] | 118 | int usb_pipe_control_write(usb_pipe_t *, const void *, size_t,
|
|---|
| 119 | const void *, size_t);
|
|---|
| [6865243c] | 120 |
|
|---|
| 121 | #endif
|
|---|
| 122 | /**
|
|---|
| 123 | * @}
|
|---|
| 124 | */
|
|---|