[6865243c] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Vojtech Horky
|
---|
[e0a5d4c] | 3 | * Copyright (c) 2018 Ondrej Hlavaty
|
---|
[6865243c] | 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 | */
|
---|
[160b75e] | 29 | /** @addtogroup libusbdev
|
---|
[6865243c] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
[d714945] | 33 | * USB pipes representation.
|
---|
[6865243c] | 34 | */
|
---|
[7d521e24] | 35 | #ifndef LIBUSBDEV_PIPES_H_
|
---|
| 36 | #define LIBUSBDEV_PIPES_H_
|
---|
[6865243c] | 37 |
|
---|
[1a38701] | 38 | #include <usb/usb.h>
|
---|
| 39 | #include <usb/descriptor.h>
|
---|
[3cdaa7f] | 40 | #include <usb_iface.h>
|
---|
[6865243c] | 41 |
|
---|
[c01987c] | 42 | #include <stdbool.h>
|
---|
[8d2dd7f2] | 43 | #include <stddef.h>
|
---|
| 44 | #include <stdint.h>
|
---|
[c01987c] | 45 |
|
---|
[c804484] | 46 | #define CTRL_PIPE_MIN_PACKET_SIZE 8
|
---|
[9efad54] | 47 |
|
---|
[a6add7a] | 48 | /** Abstraction of a logical connection to USB device endpoint.
|
---|
[9efad54] | 49 | * It contains some vital information about the pipe.
|
---|
[6865243c] | 50 | * This endpoint must be bound with existing usb_device_connection_t
|
---|
| 51 | * (i.e. the wire to send data over).
|
---|
| 52 | */
|
---|
| 53 | typedef struct {
|
---|
[9efad54] | 54 | /** Pipe description received from HC */
|
---|
| 55 | usb_pipe_desc_t desc;
|
---|
| 56 |
|
---|
[fa0f53b] | 57 | /** Whether to automatically reset halt on the endpoint.
|
---|
| 58 | * Valid only for control endpoint zero.
|
---|
| 59 | */
|
---|
| 60 | bool auto_reset_halt;
|
---|
[d93f5afb] | 61 | /** The connection used for sending the data. */
|
---|
[8582076] | 62 | usb_dev_session_t *bus_session;
|
---|
[a372663] | 63 | } usb_pipe_t;
|
---|
[6865243c] | 64 |
|
---|
[93ef8f6] | 65 | /** Description of endpoint characteristics. */
|
---|
| 66 | typedef 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;
|
---|
[1110ebd] | 75 | /** Interface protocol this endpoint belongs to (-1 for any). */
|
---|
[93ef8f6] | 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. */
|
---|
| 82 | typedef struct {
|
---|
| 83 | /** Endpoint pipe. */
|
---|
[b77931d] | 84 | usb_pipe_t pipe;
|
---|
[93ef8f6] | 85 | /** Endpoint description. */
|
---|
| 86 | const usb_endpoint_description_t *description;
|
---|
[18cb870] | 87 | /** Interface number the endpoint must belong to (-1 for any). */
|
---|
[6105fc0] | 88 | int interface_no;
|
---|
[159b91f4] | 89 | /** Alternate interface setting to choose. */
|
---|
| 90 | int interface_setting;
|
---|
[93ef8f6] | 91 | /** Found descriptor fitting the description. */
|
---|
[b77931d] | 92 | const usb_standard_endpoint_descriptor_t *descriptor;
|
---|
[ec700c7] | 93 | /** Relevant superspeed companion descriptor. */
|
---|
[ae3a941] | 94 | const usb_superspeed_endpoint_companion_descriptor_t
|
---|
| 95 | *companion_descriptor;
|
---|
[a6add7a] | 96 | /** Interface descriptor the endpoint belongs to. */
|
---|
[b77931d] | 97 | const usb_standard_interface_descriptor_t *interface;
|
---|
[93ef8f6] | 98 | /** Whether the endpoint was actually found. */
|
---|
| 99 | bool present;
|
---|
| 100 | } usb_endpoint_mapping_t;
|
---|
[6865243c] | 101 |
|
---|
[5a6cc679] | 102 | errno_t usb_pipe_initialize(usb_pipe_t *, usb_dev_session_t *);
|
---|
| 103 | errno_t usb_pipe_initialize_default_control(usb_pipe_t *, usb_dev_session_t *);
|
---|
[bd575647] | 104 |
|
---|
[5a6cc679] | 105 | errno_t usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
|
---|
[d93f5afb] | 106 | size_t, const uint8_t *, size_t, usb_dev_session_t *);
|
---|
[c804484] | 107 |
|
---|
[ae3a941] | 108 | errno_t usb_pipe_register(usb_pipe_t *,
|
---|
| 109 | const usb_standard_endpoint_descriptor_t *,
|
---|
| 110 | const usb_superspeed_endpoint_companion_descriptor_t *);
|
---|
[5a6cc679] | 111 | errno_t usb_pipe_unregister(usb_pipe_t *);
|
---|
[6865243c] | 112 |
|
---|
[5a6cc679] | 113 | errno_t usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *);
|
---|
| 114 | errno_t usb_pipe_write(usb_pipe_t *, const void *, size_t);
|
---|
[6865243c] | 115 |
|
---|
[d345ce2] | 116 | errno_t usb_pipe_read_dma(usb_pipe_t *, void *, void *, size_t, size_t *);
|
---|
| 117 | errno_t usb_pipe_write_dma(usb_pipe_t *, void *, void *, size_t);
|
---|
[4e17d54] | 118 |
|
---|
[5a6cc679] | 119 | errno_t usb_pipe_control_read(usb_pipe_t *, const void *, size_t,
|
---|
[6865243c] | 120 | void *, size_t, size_t *);
|
---|
[5a6cc679] | 121 | errno_t usb_pipe_control_write(usb_pipe_t *, const void *, size_t,
|
---|
[3875af65] | 122 | const void *, size_t);
|
---|
[6865243c] | 123 |
|
---|
[50206e9] | 124 | void *usb_pipe_alloc_buffer(usb_pipe_t *, size_t);
|
---|
| 125 | void usb_pipe_free_buffer(usb_pipe_t *, void *);
|
---|
[6865243c] | 126 | #endif
|
---|
| 127 | /**
|
---|
| 128 | * @}
|
---|
| 129 | */
|
---|