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 drvusbvhc
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | * @brief USB hub as a virtual USB device.
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef VHC_HUB_VIRTHUB_H_
|
---|
37 | #define VHC_HUB_VIRTHUB_H_
|
---|
38 |
|
---|
39 | #include <usbvirt/device.h>
|
---|
40 | #include "hub.h"
|
---|
41 |
|
---|
42 | #ifdef STANDALONE_HUB
|
---|
43 | #define virtdev_connection_t int
|
---|
44 | #else
|
---|
45 | #include "../vhcd.h"
|
---|
46 | #endif
|
---|
47 |
|
---|
48 | /** Endpoint number for status change pipe. */
|
---|
49 | #define HUB_STATUS_CHANGE_PIPE 1
|
---|
50 | /** Configuration value for hub configuration. */
|
---|
51 | #define HUB_CONFIGURATION_ID 1
|
---|
52 |
|
---|
53 | /** Hub descriptor.
|
---|
54 | */
|
---|
55 | typedef struct {
|
---|
56 | /** Size of this descriptor in bytes. */
|
---|
57 | uint8_t length;
|
---|
58 | /** Descriptor type (USB_DESCTYPE_HUB). */
|
---|
59 | uint8_t type;
|
---|
60 | /** Number of downstream ports. */
|
---|
61 | uint8_t port_count;
|
---|
62 | /** Hub characteristics. */
|
---|
63 | uint16_t characteristics;
|
---|
64 | /** Time from power-on to stabilized current.
|
---|
65 | * Expressed in 2ms unit.
|
---|
66 | */
|
---|
67 | uint8_t power_on_warm_up;
|
---|
68 | /** Maximum current (in mA). */
|
---|
69 | uint8_t max_current;
|
---|
70 | /** Whether device at given port is removable. */
|
---|
71 | uint8_t removable_device[BITS2BYTES(HUB_PORT_COUNT + 1)];
|
---|
72 | /** Port power control.
|
---|
73 | * This is USB1.0 compatibility field, all bits must be 1.
|
---|
74 | */
|
---|
75 | uint8_t port_power[BITS2BYTES(HUB_PORT_COUNT + 1)];
|
---|
76 | } __attribute__((packed)) hub_descriptor_t;
|
---|
77 |
|
---|
78 | extern usbvirt_device_ops_t hub_ops;
|
---|
79 | extern hub_descriptor_t hub_descriptor;
|
---|
80 |
|
---|
81 | errno_t virthub_init(usbvirt_device_t *, const char *name);
|
---|
82 | int virthub_connect_device(usbvirt_device_t *, vhc_virtdev_t *);
|
---|
83 | errno_t virthub_disconnect_device(usbvirt_device_t *, vhc_virtdev_t *);
|
---|
84 | bool virthub_is_device_enabled(usbvirt_device_t *, vhc_virtdev_t *);
|
---|
85 | void virthub_get_status(usbvirt_device_t *, char *, size_t);
|
---|
86 |
|
---|
87 | #endif
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * @}
|
---|
91 | */
|
---|