Misc: Trim and consolidate header file usage
[platform/upstream/libusb.git] / libusb / os / null_usb.c
1 /*
2  * Copyright © 2019 Pino Toscano <toscano.pino@tiscali.it>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 #include "libusbi.h"
20
21 static int
22 null_get_device_list(struct libusb_context * ctx,
23         struct discovered_devs **discdevs)
24 {
25         return LIBUSB_SUCCESS;
26 }
27
28 static int
29 null_open(struct libusb_device_handle *handle)
30 {
31         return LIBUSB_ERROR_NOT_SUPPORTED;
32 }
33
34 static void
35 null_close(struct libusb_device_handle *handle)
36 {
37 }
38
39 static int
40 null_get_device_descriptor(struct libusb_device *dev, unsigned char *buf,
41     int *host_endian)
42 {
43         return LIBUSB_ERROR_NOT_SUPPORTED;
44 }
45
46 static int
47 null_get_active_config_descriptor(struct libusb_device *dev,
48     unsigned char *buf, size_t len, int *host_endian)
49 {
50         return LIBUSB_ERROR_NOT_SUPPORTED;
51 }
52
53 static int
54 null_get_config_descriptor(struct libusb_device *dev, uint8_t idx,
55     unsigned char *buf, size_t len, int *host_endian)
56 {
57         return LIBUSB_ERROR_NOT_SUPPORTED;
58 }
59
60 static int
61 null_set_configuration(struct libusb_device_handle *handle, int config)
62 {
63         return LIBUSB_ERROR_NOT_SUPPORTED;
64 }
65
66 static int
67 null_claim_interface(struct libusb_device_handle *handle, int iface)
68 {
69         return LIBUSB_ERROR_NOT_SUPPORTED;
70 }
71
72 static int
73 null_release_interface(struct libusb_device_handle *handle, int iface)
74 {
75         return LIBUSB_ERROR_NOT_SUPPORTED;
76 }
77
78 static int
79 null_set_interface_altsetting(struct libusb_device_handle *handle, int iface,
80     int altsetting)
81 {
82         return LIBUSB_ERROR_NOT_SUPPORTED;
83 }
84
85 static int
86 null_clear_halt(struct libusb_device_handle *handle, unsigned char endpoint)
87 {
88         return LIBUSB_ERROR_NOT_SUPPORTED;
89 }
90
91 static int
92 null_reset_device(struct libusb_device_handle *handle)
93 {
94         return LIBUSB_ERROR_NOT_SUPPORTED;
95 }
96
97 static int
98 null_submit_transfer(struct usbi_transfer *itransfer)
99 {
100         return LIBUSB_ERROR_NOT_SUPPORTED;
101 }
102
103 static int
104 null_cancel_transfer(struct usbi_transfer *itransfer)
105 {
106         return LIBUSB_ERROR_NOT_SUPPORTED;
107 }
108
109 static void
110 null_clear_transfer_priv(struct usbi_transfer *itransfer)
111 {
112 }
113
114 static int
115 null_handle_transfer_completion(struct usbi_transfer *itransfer)
116 {
117         return LIBUSB_ERROR_NOT_SUPPORTED;
118 }
119
120 static int
121 null_clock_gettime(int clkid, struct timespec *tp)
122 {
123         switch (clkid) {
124         case USBI_CLOCK_MONOTONIC:
125                 return clock_gettime(CLOCK_REALTIME, tp);
126         case USBI_CLOCK_REALTIME:
127                 return clock_gettime(CLOCK_REALTIME, tp);
128         default:
129                 return LIBUSB_ERROR_INVALID_PARAM;
130         }
131 }
132
133 const struct usbi_os_backend usbi_backend = {
134         .name = "Null backend",
135         .caps = 0,
136         .init = NULL,
137         .exit = NULL,
138         .set_option = NULL,
139         .get_device_list = null_get_device_list,
140         .hotplug_poll = NULL,
141         .wrap_sys_device = NULL,
142         .open = null_open,
143         .close = null_close,
144         .get_device_descriptor = null_get_device_descriptor,
145         .get_active_config_descriptor = null_get_active_config_descriptor,
146         .get_config_descriptor = null_get_config_descriptor,
147         .get_config_descriptor_by_value = NULL,
148         .get_configuration = NULL,
149         .set_configuration = null_set_configuration,
150         .claim_interface = null_claim_interface,
151         .release_interface = null_release_interface,
152         .set_interface_altsetting = null_set_interface_altsetting,
153         .clear_halt = null_clear_halt,
154         .reset_device = null_reset_device,
155         .alloc_streams = NULL,
156         .free_streams = NULL,
157         .dev_mem_alloc = NULL,
158         .dev_mem_free = NULL,
159         .kernel_driver_active = NULL,
160         .detach_kernel_driver = NULL,
161         .attach_kernel_driver = NULL,
162         .destroy_device = NULL,
163         .submit_transfer = null_submit_transfer,
164         .cancel_transfer = null_cancel_transfer,
165         .clear_transfer_priv = null_clear_transfer_priv,
166         .handle_events = NULL,
167         .handle_transfer_completion = null_handle_transfer_completion,
168         .clock_gettime = null_clock_gettime,
169 #ifdef USBI_TIMERFD_AVAILABLE
170         .get_timerfd_clockid = NULL,
171 #endif
172         .context_priv_size = 0,
173         .device_priv_size = 0,
174         .device_handle_priv_size = 0,
175         .transfer_priv_size = 0,
176 };