1 | /*
|
---|
2 | * Copyright (c) 2010 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 usb
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | * @brief
|
---|
34 | */
|
---|
35 | #ifndef VHCD_HUBINTERN_H_
|
---|
36 | #define VHCD_HUBINTERN_H_
|
---|
37 |
|
---|
38 | #include "hub.h"
|
---|
39 |
|
---|
40 | /** Endpoint number for status change pipe. */
|
---|
41 | #define HUB_STATUS_CHANGE_PIPE 1
|
---|
42 | /** Configuration value for hub configuration. */
|
---|
43 | #define HUB_CONFIGURATION_ID 1
|
---|
44 |
|
---|
45 | /** Hub descriptor.
|
---|
46 | */
|
---|
47 | typedef struct {
|
---|
48 | /** Size of this descriptor in bytes. */
|
---|
49 | uint8_t length;
|
---|
50 | /** Descriptor type (USB_DESCTYPE_HUB). */
|
---|
51 | uint8_t type;
|
---|
52 | /** Number of downstream ports. */
|
---|
53 | uint8_t port_count;
|
---|
54 | /** Hub characteristics. */
|
---|
55 | uint16_t characteristics;
|
---|
56 | /** Time from power-on to stabilized current.
|
---|
57 | * Expressed in 2ms unit.
|
---|
58 | */
|
---|
59 | uint8_t power_on_warm_up;
|
---|
60 | /** Maximum current (in mA). */
|
---|
61 | uint8_t max_current;
|
---|
62 | /** Whether device at given port is removable. */
|
---|
63 | uint8_t removable_device[BITS2BYTES(HUB_PORT_COUNT+1)];
|
---|
64 | /** Port power control.
|
---|
65 | * This is USB1.0 compatibility field, all bits must be 1.
|
---|
66 | */
|
---|
67 | uint8_t port_power[BITS2BYTES(HUB_PORT_COUNT+1)];
|
---|
68 | } __attribute__ ((packed)) hub_descriptor_t;
|
---|
69 |
|
---|
70 | /** Hub port internal state.
|
---|
71 | * Some states (e.g. port over current) are not covered as they are not
|
---|
72 | * simulated at all.
|
---|
73 | */
|
---|
74 | typedef enum {
|
---|
75 | HUB_PORT_STATE_NOT_CONFIGURED,
|
---|
76 | HUB_PORT_STATE_POWERED_OFF,
|
---|
77 | HUB_PORT_STATE_DISCONNECTED,
|
---|
78 | HUB_PORT_STATE_DISABLED,
|
---|
79 | HUB_PORT_STATE_RESETTING,
|
---|
80 | HUB_PORT_STATE_ENABLED,
|
---|
81 | HUB_PORT_STATE_SUSPENDED,
|
---|
82 | HUB_PORT_STATE_RESUMING,
|
---|
83 | /* HUB_PORT_STATE_, */
|
---|
84 | } hub_port_state_t;
|
---|
85 |
|
---|
86 | /** Convert hub port state to a char. */
|
---|
87 | static inline char hub_port_state_as_char(hub_port_state_t state) {
|
---|
88 | switch (state) {
|
---|
89 | case HUB_PORT_STATE_NOT_CONFIGURED:
|
---|
90 | return '-';
|
---|
91 | case HUB_PORT_STATE_POWERED_OFF:
|
---|
92 | return 'O';
|
---|
93 | case HUB_PORT_STATE_DISCONNECTED:
|
---|
94 | return 'X';
|
---|
95 | case HUB_PORT_STATE_DISABLED:
|
---|
96 | return 'D';
|
---|
97 | case HUB_PORT_STATE_RESETTING:
|
---|
98 | return 'R';
|
---|
99 | case HUB_PORT_STATE_ENABLED:
|
---|
100 | return 'E';
|
---|
101 | case HUB_PORT_STATE_SUSPENDED:
|
---|
102 | return 'S';
|
---|
103 | case HUB_PORT_STATE_RESUMING:
|
---|
104 | return 'F';
|
---|
105 | default:
|
---|
106 | return '?';
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | /** Hub status change mask bits. */
|
---|
111 | typedef enum {
|
---|
112 | HUB_STATUS_C_PORT_CONNECTION = (1 << 0),
|
---|
113 | HUB_STATUS_C_PORT_ENABLE = (1 << 1),
|
---|
114 | HUB_STATUS_C_PORT_SUSPEND = (1 << 2),
|
---|
115 | HUB_STATUS_C_PORT_OVER_CURRENT = (1 << 3),
|
---|
116 | HUB_STATUS_C_PORT_RESET = (1 << 4),
|
---|
117 | /* HUB_STATUS_C_ = (1 << ), */
|
---|
118 | } hub_status_change_t;
|
---|
119 |
|
---|
120 | /** Hub port information. */
|
---|
121 | typedef struct {
|
---|
122 | virtdev_connection_t *device;
|
---|
123 | int index;
|
---|
124 | hub_port_state_t state;
|
---|
125 | uint16_t status_change;
|
---|
126 | } hub_port_t;
|
---|
127 |
|
---|
128 | /** Hub device type. */
|
---|
129 | typedef struct {
|
---|
130 | hub_port_t ports[HUB_PORT_COUNT];
|
---|
131 | } hub_device_t;
|
---|
132 |
|
---|
133 | extern hub_device_t hub_dev;
|
---|
134 |
|
---|
135 | extern hub_descriptor_t hub_descriptor;
|
---|
136 |
|
---|
137 | extern usbvirt_device_ops_t hub_ops;
|
---|
138 |
|
---|
139 | void clear_port_status_change(hub_port_t *, uint16_t);
|
---|
140 | void set_port_status_change(hub_port_t *, uint16_t);
|
---|
141 |
|
---|
142 |
|
---|
143 | #endif
|
---|
144 | /**
|
---|
145 | * @}
|
---|
146 | */
|
---|