Monado OpenXR Runtime
Loading...
Searching...
No Matches
p_prober.h
Go to the documentation of this file.
1// Copyright 2019, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Main prober code.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @ingroup st_prober
8 */
9
10#pragma once
11
12#include "xrt/xrt_config_have.h"
13#include "xrt/xrt_config_os.h"
14#include "xrt/xrt_compiler.h"
15#include "xrt/xrt_prober.h"
16#include "xrt/xrt_settings.h"
17
18#include "util/u_logging.h"
19#include "util/u_config_json.h"
20
21#ifdef XRT_HAVE_LIBUSB
22#include <libusb.h>
23#endif
24
25#ifdef XRT_HAVE_LIBUVC
26#include <libuvc/libuvc.h>
27#endif
28
29#ifndef __KERNEL__
30#include <sys/types.h>
31#endif
32
33/*
34 *
35 * Struct and defines
36 *
37 */
38
39#define P_PROBER_BLUETOOTH_PRODUCT_COUNT 64
40
41#define P_TRACE(d, ...) U_LOG_IFL_T(d->log_level, __VA_ARGS__)
42#define P_DEBUG(d, ...) U_LOG_IFL_D(d->log_level, __VA_ARGS__)
43#define P_INFO(d, ...) U_LOG_IFL_I(d->log_level, __VA_ARGS__)
44#define P_WARN(d, ...) U_LOG_IFL_W(d->log_level, __VA_ARGS__)
45#define P_ERROR(d, ...) U_LOG_IFL_E(d->log_level, __VA_ARGS__)
46
47#ifdef XRT_OS_LINUX
48/*!
49 * A hidraw interface that a @ref prober_device exposes.
50 */
52{
53 ssize_t hid_iface;
54 const char *path;
55};
56
57/*!
58 * A v4l interface that a @ref prober_device exposes.
59 */
61{
62 const char *path;
63 int32_t usb_iface;
64 uint32_t v4l_index;
65};
66#endif
67
68/*!
69 * A single device found by a @ref prober.
70 *
71 * @implements xrt_prober_device
72 */
74{
75 struct xrt_prober_device base;
76
77 struct
78 {
79 uint16_t bus;
80 uint16_t addr;
81
82 const char *product;
83 const char *manufacturer;
84 const char *serial;
85 const char *path;
86
87 uint8_t ports[8];
88 uint32_t num_ports;
89
90#ifdef XRT_HAVE_LIBUSB
91 libusb_device *dev;
92#endif
93 } usb;
94
95 struct
96 {
97 const char *path;
98 } serial;
99
100 struct
101 {
102 uint64_t id;
103
104 char product[P_PROBER_BLUETOOTH_PRODUCT_COUNT];
105 } bluetooth;
106
107#ifdef XRT_HAVE_LIBUVC
108 struct
109 {
110 uvc_device_t *dev;
111 } uvc;
112#endif
113
114#ifdef XRT_HAVE_V4L2
115 size_t num_v4ls;
116 struct prober_v4l *v4ls;
117#endif
118
119#ifdef XRT_OS_LINUX
120 size_t num_hidraws;
121 struct prober_hidraw *hidraws;
122#endif
123};
124
125/*!
126 * @implements xrt_prober
127 */
128struct prober
129{
130 struct xrt_prober base;
131
132 struct xrt_prober_entry_lists *lists;
133
134 struct u_config_json json;
135
136 /*!
137 * List of created builder.
138 */
140
141 /*!
142 * The number of created builders.
143 */
145
146 /*!
147 * Has the list been locked.
148 */
150
151#ifdef XRT_HAVE_LIBUSB
152 struct
153 {
154 libusb_context *ctx;
155 libusb_device **list;
156 ssize_t count;
157 } usb;
158#endif
159
160#ifdef XRT_HAVE_LIBUVC
161 struct
162 {
163 uvc_context_t *ctx;
164 uvc_device_t **list;
165 ssize_t count;
166 } uvc;
167#endif
168
169
170 struct xrt_auto_prober *auto_probers[XRT_MAX_AUTO_PROBERS];
171
172 size_t device_count;
173 struct prober_device *devices;
174
175 size_t num_entries;
176 struct xrt_prober_entry **entries;
177
178 // must not be accessed after freeing json
179 size_t num_disabled_drivers;
180 char **disabled_drivers;
181
182 enum u_logging_level log_level;
183};
184
185
186/*
187 *
188 * Functions.
189 *
190 */
191
192/*!
193 * Dump the given device to stdout.
194 *
195 * @public @memberof prober
196 */
197void
198p_dump_device(struct prober *p, struct prober_device *pdev, int id, bool use_stdout);
199
200/*!
201 * Get or create a @ref prober_device from the device.
202 *
203 * @public @memberof prober
204 */
205int
206p_dev_get_usb_dev(struct prober *p,
207 uint16_t bus,
208 uint16_t addr,
209 uint16_t vendor_id,
210 uint16_t product_id,
211 struct prober_device **out_pdev);
212
213/*!
214 * Get or create a @ref prober_device from the device.
215 *
216 * @public @memberof prober
217 */
218int
219p_dev_get_bluetooth_dev(struct prober *p,
220 uint64_t id,
221 uint16_t vendor_id,
222 uint16_t product_id,
223 const char *product_name,
224 struct prober_device **out_pdev);
225
226/*!
227 * @name Tracking systems
228 * @{
229 */
230/*!
231 * Init the tracking factory.
232 *
233 * @private @memberof prober
234 * @see xrt_tracking_factory
235 */
236int
237p_tracking_init(struct prober *p);
238
239/*!
240 * Teardown the tracking factory.
241 *
242 * @private @memberof prober
243 * @see xrt_tracking_factory
244 */
245void
246p_tracking_teardown(struct prober *p);
247
248/*!
249 * @}
250 */
251
252#ifdef XRT_HAVE_LIBUSB
253/*!
254 * @name libusb
255 * @{
256 */
257/*!
258 * @private @memberof prober
259 */
260int
261p_libusb_init(struct prober *p);
262
263/*!
264 * @private @memberof prober
265 */
266void
267p_libusb_teardown(struct prober *p);
268
269/*!
270 * @private @memberof prober
271 */
272int
273p_libusb_probe(struct prober *p);
274
275/*!
276 * @private @memberof prober
277 */
278int
279p_libusb_get_string_descriptor(struct prober *p,
280 struct prober_device *pdev,
281 enum xrt_prober_string which_string,
282 unsigned char *buffer,
283 int length);
284
285/*!
286 * @private @memberof prober
287 */
288bool
289p_libusb_can_open(struct prober *p, struct prober_device *pdev);
290
291/*!
292 * @}
293 */
294#endif
295
296#ifdef XRT_HAVE_LIBUVC
297/*!
298 * @name libuvc
299 * @{
300 */
301/*!
302 * @private @memberof prober
303 */
304int
305p_libuvc_init(struct prober *p);
306
307/*!
308 * @private @memberof prober
309 */
310void
311p_libuvc_teardown(struct prober *p);
312
313/*!
314 * @private @memberof prober
315 */
316int
317p_libuvc_probe(struct prober *p);
318
319/*!
320 * @}
321 */
322#endif
323
324#ifdef XRT_HAVE_LIBUDEV
325/*!
326 * @name udev
327 * @{
328 */
329/*!
330 * @private @memberof prober
331 */
332int
333p_udev_probe(struct prober *p);
334/*!
335 * @}
336 */
337#endif
u_logging_level
Logging level enum.
Definition u_logging.h:45
#define XRT_MAX_AUTO_PROBERS
The maximum number of xrt_auto_prober instances that can be handled.
Definition xrt_prober.h:60
A single device found by a prober.
Definition p_prober.h:74
A hidraw interface that a prober_device exposes.
Definition p_prober.h:52
A v4l interface that a prober_device exposes.
Definition p_prober.h:61
Definition p_prober.h:129
size_t builder_count
The number of created builders.
Definition p_prober.h:144
bool list_locked
Has the list been locked.
Definition p_prober.h:149
struct xrt_builder ** builders
List of created builder.
Definition p_prober.h:139
Definition u_config_json.h:30
An interface to be exposed by a device driver that should probe for the existence of its own device o...
Definition xrt_prober.h:795
Sets up a collection of devices and builds a system, a setter upper.
Definition xrt_prober.h:594
A probed device, may or may not be opened.
Definition xrt_prober.h:88
Main root of all of the probing device.
Definition xrt_prober.h:843
Entry for a single device.
Definition xrt_prober.h:740
uint16_t product_id
USB/Bluetooth product ID (PID) to filter on.
Definition xrt_prober.h:749
uint16_t vendor_id
USB/Bluetooth vendor ID (VID) to filter on.
Definition xrt_prober.h:744
The main prober that probes and manages found but not opened HMD devices that are connected to the sy...
Definition xrt_prober.h:135
Code to manage the settings file.
Basic logging functionality.
Header holding common defines.
Auto detect OS and certain features.
Common interface to probe for devices.
xrt_prober_string
String descriptor types.
Definition xrt_prober.h:76
Common settings structs to be transferred between different parts of Monado, mainly for tracking and ...