source: mainline/uspace/drv/bus/usb/usbdiag/device.c@ 41ebc36

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 41ebc36 was 41ebc36, checked in by Petr Mánek <petr.manek@…>, 8 years ago

usbdiag: move contents of libusbdiag to libdrv, registered usbdiag interface into the master routing table, repaired broken references

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 * Copyright (c) 2017 Petr Manek
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 drvusbdiag
30 * @{
31 */
32/**
33 * @file
34 * Code for managing debug device structures.
35 */
36#include <errno.h>
37#include <usb/debug.h>
38#include <usbdiag_iface.h>
39
40#include "device.h"
41
42#define NAME "usbdiag"
43
44static int some_test(ddf_fun_t *fun, int x, int *y)
45{
46 *y = x + 42;
47 return EOK;
48}
49
50static usbdiag_iface_t diag_interface = {
51 .test = some_test,
52};
53
54static ddf_dev_ops_t diag_ops = {
55 .interfaces[USBDIAG_DEV_IFACE] = &diag_interface
56};
57
58static int device_init(usb_diag_dev_t *dev)
59{
60 ddf_fun_t *fun = usb_device_ddf_fun_create(dev->usb_dev, fun_exposed, "tmon");
61 if (!fun)
62 return ENOMEM;
63
64 ddf_fun_set_ops(fun, &diag_ops);
65
66 dev->fun = fun;
67 return EOK;
68}
69
70static void device_fini(usb_diag_dev_t *dev)
71{
72 ddf_fun_destroy(dev->fun);
73}
74
75int usb_diag_dev_create(usb_device_t *dev, usb_diag_dev_t **out_diag_dev)
76{
77 assert(dev);
78 assert(out_diag_dev);
79
80 usb_diag_dev_t *diag_dev = usb_device_data_alloc(dev, sizeof(usb_diag_dev_t));
81 if (!diag_dev)
82 return ENOMEM;
83
84 diag_dev->usb_dev = dev;
85
86 int err;
87 if ((err = device_init(diag_dev)))
88 goto err_init;
89
90 *out_diag_dev = diag_dev;
91 return EOK;
92
93err_init:
94 /* There is no usb_device_data_free. */
95 return err;
96}
97
98void usb_diag_dev_destroy(usb_diag_dev_t *dev)
99{
100 assert(dev);
101
102 device_fini(dev);
103 /* There is no usb_device_data_free. */
104}
105
106/**
107 * @}
108 */
Note: See TracBrowser for help on using the repository browser.