[93855d4] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Vojtech Horky
|
---|
[e0a5d4c] | 3 | * Copyright (c) 2018 Petr Manek
|
---|
[93855d4] | 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 | */
|
---|
[7d521e24] | 37 | #include <usb/dev/driver.h>
|
---|
[93855d4] | 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 | */
|
---|
[5a6cc679] | 49 | static errno_t usbfallback_device_add(usb_device_t *dev)
|
---|
[93855d4] | 50 | {
|
---|
[a1732929] | 51 | usb_log_info("Pretending to control %s `%s'.",
|
---|
[8e10ef4] | 52 | usb_device_get_iface_number(dev) < 0 ? "device" : "interface",
|
---|
[6785b538] | 53 | usb_device_get_name(dev));
|
---|
[93855d4] | 54 | return EOK;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
[05a119b] | 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 | */
|
---|
[5a6cc679] | 62 | static errno_t usbfallback_device_gone(usb_device_t *dev)
|
---|
[05a119b] | 63 | {
|
---|
| 64 | assert(dev);
|
---|
[46c5dc2] | 65 | usb_log_info("Device '%s' gone.", usb_device_get_name(dev));
|
---|
| 66 | return EOK;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[860bf94] | 69 | static errno_t usbfallback_device_remove(usb_device_t *dev)
|
---|
[46c5dc2] | 70 | {
|
---|
| 71 | assert(dev);
|
---|
| 72 | usb_log_info("Device '%s' removed.", usb_device_get_name(dev));
|
---|
[05a119b] | 73 | return EOK;
|
---|
| 74 | }
|
---|
[cf7561f] | 75 |
|
---|
[93855d4] | 76 | /** USB fallback driver ops. */
|
---|
[cf7561f] | 77 | static const usb_driver_ops_t usbfallback_driver_ops = {
|
---|
[1a4ea01d] | 78 | .device_add = usbfallback_device_add,
|
---|
[46c5dc2] | 79 | .device_remove = usbfallback_device_remove,
|
---|
[05a119b] | 80 | .device_gone = usbfallback_device_gone,
|
---|
[93855d4] | 81 | };
|
---|
| 82 |
|
---|
| 83 | /** USB fallback driver. */
|
---|
[cf7561f] | 84 | static const usb_driver_t usbfallback_driver = {
|
---|
[93855d4] | 85 | .name = NAME,
|
---|
| 86 | .ops = &usbfallback_driver_ops,
|
---|
| 87 | .endpoints = NULL
|
---|
| 88 | };
|
---|
| 89 |
|
---|
| 90 | int main(int argc, char *argv[])
|
---|
| 91 | {
|
---|
[920d0fc] | 92 | log_init(NAME);
|
---|
[93855d4] | 93 |
|
---|
| 94 | return usb_driver_main(&usbfallback_driver);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | /**
|
---|
| 98 | * @}
|
---|
| 99 | */
|
---|