1 | /*
|
---|
2 | * Copyright (c) 2011 Vojtech Horky
|
---|
3 | * Copyright (c) 2018 Petr Manek
|
---|
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 | */
|
---|
29 |
|
---|
30 | /** @addtogroup drvusbfallback
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 | /**
|
---|
34 | * @file
|
---|
35 | * Main routines of USB fallback driver.
|
---|
36 | */
|
---|
37 | #include <usb/dev/driver.h>
|
---|
38 | #include <usb/debug.h>
|
---|
39 | #include <errno.h>
|
---|
40 | #include <str_error.h>
|
---|
41 |
|
---|
42 | #define NAME "usbflbk"
|
---|
43 |
|
---|
44 | /** Callback when new device is attached and recognized by DDF.
|
---|
45 | *
|
---|
46 | * @param dev Representation of a generic DDF device.
|
---|
47 | * @return Error code.
|
---|
48 | */
|
---|
49 | static errno_t usbfallback_device_add(usb_device_t *dev)
|
---|
50 | {
|
---|
51 | usb_log_info("Pretending to control %s `%s'.",
|
---|
52 | usb_device_get_iface_number(dev) < 0 ? "device" : "interface",
|
---|
53 | usb_device_get_name(dev));
|
---|
54 | return EOK;
|
---|
55 | }
|
---|
56 |
|
---|
57 | /** Callback when new device is removed and recognized as gone by DDF.
|
---|
58 | *
|
---|
59 | * @param dev Representation of a generic DDF device.
|
---|
60 | * @return Error code.
|
---|
61 | */
|
---|
62 | static errno_t usbfallback_device_gone(usb_device_t *dev)
|
---|
63 | {
|
---|
64 | assert(dev);
|
---|
65 | usb_log_info("Device '%s' gone.", usb_device_get_name(dev));
|
---|
66 | return EOK;
|
---|
67 | }
|
---|
68 |
|
---|
69 | static errno_t usbfallback_device_remove(usb_device_t *dev)
|
---|
70 | {
|
---|
71 | assert(dev);
|
---|
72 | usb_log_info("Device '%s' removed.", usb_device_get_name(dev));
|
---|
73 | return EOK;
|
---|
74 | }
|
---|
75 |
|
---|
76 | /** USB fallback driver ops. */
|
---|
77 | static const usb_driver_ops_t usbfallback_driver_ops = {
|
---|
78 | .device_add = usbfallback_device_add,
|
---|
79 | .device_remove = usbfallback_device_remove,
|
---|
80 | .device_gone = usbfallback_device_gone,
|
---|
81 | };
|
---|
82 |
|
---|
83 | /** USB fallback driver. */
|
---|
84 | static const usb_driver_t usbfallback_driver = {
|
---|
85 | .name = NAME,
|
---|
86 | .ops = &usbfallback_driver_ops,
|
---|
87 | .endpoints = NULL
|
---|
88 | };
|
---|
89 |
|
---|
90 | int main(int argc, char *argv[])
|
---|
91 | {
|
---|
92 | log_init(NAME);
|
---|
93 |
|
---|
94 | return usb_driver_main(&usbfallback_driver);
|
---|
95 | }
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * @}
|
---|
99 | */
|
---|