[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>
|
---|
[8582076] | 39 | #include <usb_iface.h>
|
---|
[6865243c] | 40 |
|
---|
[c01987c] | 41 | #include <stdbool.h>
|
---|
| 42 | #include <sys/types.h>
|
---|
| 43 |
|
---|
[c804484] | 44 | #define CTRL_PIPE_MIN_PACKET_SIZE 8
|
---|
[a6add7a] | 45 | /** Abstraction of a logical connection to USB device endpoint.
|
---|
[bdb23c63] | 46 | * It encapsulates endpoint attributes (transfer type etc.).
|
---|
[6865243c] | 47 | * This endpoint must be bound with existing usb_device_connection_t
|
---|
| 48 | * (i.e. the wire to send data over).
|
---|
| 49 | */
|
---|
| 50 | typedef struct {
|
---|
| 51 | /** Endpoint number. */
|
---|
| 52 | usb_endpoint_t endpoint_no;
|
---|
| 53 |
|
---|
| 54 | /** Endpoint transfer type. */
|
---|
| 55 | usb_transfer_type_t transfer_type;
|
---|
| 56 |
|
---|
| 57 | /** Endpoint direction. */
|
---|
| 58 | usb_direction_t direction;
|
---|
| 59 |
|
---|
[25971d2] | 60 | /** Maximum packet size for the endpoint. */
|
---|
| 61 | size_t max_packet_size;
|
---|
| 62 |
|
---|
[4e732f1a] | 63 | /** Number of packets per frame/uframe.
|
---|
| 64 | * Only valid for HS INT and ISO transfers. All others should set to 1*/
|
---|
| 65 | unsigned packets;
|
---|
| 66 |
|
---|
[fa0f53b] | 67 | /** Whether to automatically reset halt on the endpoint.
|
---|
| 68 | * Valid only for control endpoint zero.
|
---|
| 69 | */
|
---|
| 70 | bool auto_reset_halt;
|
---|
[8582076] | 71 |
|
---|
[d93f5afb] | 72 | /** The connection used for sending the data. */
|
---|
[8582076] | 73 | usb_dev_session_t *bus_session;
|
---|
[a372663] | 74 | } usb_pipe_t;
|
---|
[6865243c] | 75 |
|
---|
[93ef8f6] | 76 | /** Description of endpoint characteristics. */
|
---|
| 77 | typedef struct {
|
---|
| 78 | /** Transfer type (e.g. control or interrupt). */
|
---|
| 79 | usb_transfer_type_t transfer_type;
|
---|
| 80 | /** Transfer direction (to or from a device). */
|
---|
| 81 | usb_direction_t direction;
|
---|
| 82 | /** Interface class this endpoint belongs to (-1 for any). */
|
---|
| 83 | int interface_class;
|
---|
| 84 | /** Interface subclass this endpoint belongs to (-1 for any). */
|
---|
| 85 | int interface_subclass;
|
---|
[1110ebd] | 86 | /** Interface protocol this endpoint belongs to (-1 for any). */
|
---|
[93ef8f6] | 87 | int interface_protocol;
|
---|
| 88 | /** Extra endpoint flags. */
|
---|
| 89 | unsigned int flags;
|
---|
| 90 | } usb_endpoint_description_t;
|
---|
| 91 |
|
---|
| 92 | /** Mapping of endpoint pipes and endpoint descriptions. */
|
---|
| 93 | typedef struct {
|
---|
| 94 | /** Endpoint pipe. */
|
---|
[b77931d] | 95 | usb_pipe_t pipe;
|
---|
[93ef8f6] | 96 | /** Endpoint description. */
|
---|
| 97 | const usb_endpoint_description_t *description;
|
---|
[18cb870] | 98 | /** Interface number the endpoint must belong to (-1 for any). */
|
---|
[6105fc0] | 99 | int interface_no;
|
---|
[159b91f4] | 100 | /** Alternate interface setting to choose. */
|
---|
| 101 | int interface_setting;
|
---|
[93ef8f6] | 102 | /** Found descriptor fitting the description. */
|
---|
[b77931d] | 103 | const usb_standard_endpoint_descriptor_t *descriptor;
|
---|
[a6add7a] | 104 | /** Interface descriptor the endpoint belongs to. */
|
---|
[b77931d] | 105 | const usb_standard_interface_descriptor_t *interface;
|
---|
[93ef8f6] | 106 | /** Whether the endpoint was actually found. */
|
---|
| 107 | bool present;
|
---|
| 108 | } usb_endpoint_mapping_t;
|
---|
[6865243c] | 109 |
|
---|
[d93f5afb] | 110 | int usb_pipe_initialize(usb_pipe_t *, usb_endpoint_t, usb_transfer_type_t,
|
---|
[4e732f1a] | 111 | size_t, usb_direction_t, unsigned, usb_dev_session_t *);
|
---|
[d93f5afb] | 112 | int usb_pipe_initialize_default_control(usb_pipe_t *, usb_dev_session_t *);
|
---|
[bd575647] | 113 |
|
---|
[3954a63b] | 114 | int usb_pipe_probe_default_control(usb_pipe_t *);
|
---|
| 115 | int usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
|
---|
[d93f5afb] | 116 | size_t, const uint8_t *, size_t, usb_dev_session_t *);
|
---|
[c804484] | 117 |
|
---|
[bd575647] | 118 | int usb_pipe_register(usb_pipe_t *, unsigned);
|
---|
| 119 | int usb_pipe_unregister(usb_pipe_t *);
|
---|
[6865243c] | 120 |
|
---|
[3954a63b] | 121 | int usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *);
|
---|
[b4292e7] | 122 | int usb_pipe_write(usb_pipe_t *, const void *, size_t);
|
---|
[6865243c] | 123 |
|
---|
[7a05ced0] | 124 | int usb_pipe_control_read(usb_pipe_t *, const void *, size_t,
|
---|
[6865243c] | 125 | void *, size_t, size_t *);
|
---|
[3875af65] | 126 | int usb_pipe_control_write(usb_pipe_t *, const void *, size_t,
|
---|
| 127 | const void *, size_t);
|
---|
[6865243c] | 128 |
|
---|
| 129 | #endif
|
---|
| 130 | /**
|
---|
| 131 | * @}
|
---|
| 132 | */
|
---|