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 | */
|
---|
28 |
|
---|
29 | /** @addtogroup usbvirthid
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | *
|
---|
34 | */
|
---|
35 | #ifndef VUHID_VIRTHID_H_
|
---|
36 | #define VUHID_VIRTHID_H_
|
---|
37 |
|
---|
38 | #include <usb/usb.h>
|
---|
39 | #include <usbvirt/device.h>
|
---|
40 | #include <fibril_synch.h>
|
---|
41 |
|
---|
42 | #define VUHID_ENDPOINT_MAX USB_ENDPOINT_MAX
|
---|
43 | #define VUHID_INTERFACE_MAX 8
|
---|
44 |
|
---|
45 | typedef struct vuhid_interface vuhid_interface_t;
|
---|
46 |
|
---|
47 | typedef struct {
|
---|
48 | vuhid_interface_t *in_endpoints_mapping[VUHID_ENDPOINT_MAX];
|
---|
49 | size_t in_endpoint_first_free;
|
---|
50 | vuhid_interface_t *out_endpoints_mapping[VUHID_ENDPOINT_MAX];
|
---|
51 | size_t out_endpoint_first_free;
|
---|
52 | vuhid_interface_t *interface_mapping[VUHID_INTERFACE_MAX];
|
---|
53 |
|
---|
54 | fibril_mutex_t iface_count_mutex;
|
---|
55 | fibril_condvar_t iface_count_cv;
|
---|
56 | size_t iface_count;
|
---|
57 | size_t iface_died_count;
|
---|
58 | } vuhid_data_t;
|
---|
59 |
|
---|
60 | struct vuhid_interface {
|
---|
61 | const char *name;
|
---|
62 | const char *id;
|
---|
63 | int usb_subclass;
|
---|
64 | int usb_protocol;
|
---|
65 |
|
---|
66 | uint8_t *report_descriptor;
|
---|
67 | size_t report_descriptor_size;
|
---|
68 |
|
---|
69 | size_t in_data_size;
|
---|
70 | size_t out_data_size;
|
---|
71 |
|
---|
72 | errno_t (*on_data_in)(vuhid_interface_t *, void *, size_t, size_t *);
|
---|
73 | errno_t (*on_data_out)(vuhid_interface_t *, const void *, size_t);
|
---|
74 | void (*live)(vuhid_interface_t *);
|
---|
75 |
|
---|
76 | int set_protocol;
|
---|
77 |
|
---|
78 | void *interface_data;
|
---|
79 |
|
---|
80 | vuhid_data_t *vuhid_data;
|
---|
81 | };
|
---|
82 |
|
---|
83 | typedef struct {
|
---|
84 | /** Buffer with data from device to the host. */
|
---|
85 | uint8_t *data_in;
|
---|
86 | /** Number of items in @c data_in.
|
---|
87 | * The total size of @c data_in buffer shall be
|
---|
88 | * <code>data_in_count * vuhid_interface_t.in_data_size</code>.
|
---|
89 | */
|
---|
90 | size_t data_in_count;
|
---|
91 |
|
---|
92 | /** Current position in the data buffer. */
|
---|
93 | size_t data_in_pos;
|
---|
94 | /** Previous position. */
|
---|
95 | size_t data_in_last_pos;
|
---|
96 |
|
---|
97 | /** Delay between transition to "next" input buffer (in ms). */
|
---|
98 | size_t data_in_pos_change_delay;
|
---|
99 |
|
---|
100 | /** Message to print when interface becomes alive. */
|
---|
101 | const char *msg_born;
|
---|
102 | /** Message to print when interface dies. */
|
---|
103 | const char *msg_die;
|
---|
104 | } vuhid_interface_life_t;
|
---|
105 |
|
---|
106 | typedef struct {
|
---|
107 | uint8_t length;
|
---|
108 | uint8_t type;
|
---|
109 | uint16_t hid_spec_release;
|
---|
110 | uint8_t country_code;
|
---|
111 | uint8_t descriptor_count;
|
---|
112 | uint8_t descriptor1_type;
|
---|
113 | uint16_t descriptor1_length;
|
---|
114 | } __attribute__((packed)) hid_descriptor_t;
|
---|
115 |
|
---|
116 | errno_t add_interface_by_id(vuhid_interface_t **, const char *, usbvirt_device_t *);
|
---|
117 | void wait_for_interfaces_death(usbvirt_device_t *);
|
---|
118 |
|
---|
119 | void interface_life_live(vuhid_interface_t *);
|
---|
120 | errno_t interface_live_on_data_in(vuhid_interface_t *, void *, size_t, size_t *);
|
---|
121 |
|
---|
122 | #endif
|
---|
123 | /**
|
---|
124 | * @}
|
---|
125 | */
|
---|