Monado OpenXR Runtime
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 interface;
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 uint64_t id;
98
99 char product[P_PROBER_BLUETOOTH_PRODUCT_COUNT];
100 } bluetooth;
101
102#ifdef XRT_HAVE_LIBUVC
103 struct
104 {
105 uvc_device_t *dev;
106 } uvc;
107#endif
108
109#ifdef XRT_HAVE_V4L2
110 size_t num_v4ls;
111 struct prober_v4l *v4ls;
112#endif
113
114#ifdef XRT_OS_LINUX
115 size_t num_hidraws;
116 struct prober_hidraw *hidraws;
117#endif
118};
119
120/*!
121 * @implements xrt_prober
122 */
123struct prober
124{
125 struct xrt_prober base;
126
127 struct xrt_prober_entry_lists *lists;
128
129 struct u_config_json json;
130
131 /*!
132 * List of created builder.
133 */
135
136 /*!
137 * The number of created builders.
138 */
140
141 /*!
142 * Has the list been locked.
143 */
145
146#ifdef XRT_HAVE_LIBUSB
147 struct
148 {
149 libusb_context *ctx;
150 libusb_device **list;
151 ssize_t count;
152 } usb;
153#endif
154
155#ifdef XRT_HAVE_LIBUVC
156 struct
157 {
158 uvc_context_t *ctx;
159 uvc_device_t **list;
160 ssize_t count;
161 } uvc;
162#endif
163
164
165 struct xrt_auto_prober *auto_probers[XRT_MAX_AUTO_PROBERS];
166
167 size_t device_count;
168 struct prober_device *devices;
169
170 size_t num_entries;
171 struct xrt_prober_entry **entries;
172
173 // must not be accessed after freeing json
174 size_t num_disabled_drivers;
175 char **disabled_drivers;
176
177 enum u_logging_level log_level;
178};
179
180
181/*
182 *
183 * Functions.
184 *
185 */
186
187/*!
188 * Dump the given device to stdout.
189 *
190 * @public @memberof prober
191 */
192void
193p_dump_device(struct prober *p, struct prober_device *pdev, int id, bool use_stdout);
194
195/*!
196 * Get or create a @ref prober_device from the device.
197 *
198 * @public @memberof prober
199 */
200int
201p_dev_get_usb_dev(struct prober *p,
202 uint16_t bus,
203 uint16_t addr,
204 uint16_t vendor_id,
205 uint16_t product_id,
206 struct prober_device **out_pdev);
207
208/*!
209 * Get or create a @ref prober_device from the device.
210 *
211 * @public @memberof prober
212 */
213int
215 uint64_t id,
216 uint16_t vendor_id,
217 uint16_t product_id,
218 const char *product_name,
219 struct prober_device **out_pdev);
220
221/*!
222 * @name Tracking systems
223 * @{
224 */
225/*!
226 * Init the tracking factory.
227 *
228 * @private @memberof prober
229 * @see xrt_tracking_factory
230 */
231int
232p_tracking_init(struct prober *p);
233
234/*!
235 * Teardown the tracking factory.
236 *
237 * @private @memberof prober
238 * @see xrt_tracking_factory
239 */
240void
241p_tracking_teardown(struct prober *p);
242
243/*!
244 * @}
245 */
246
247#ifdef XRT_HAVE_LIBUSB
248/*!
249 * @name libusb
250 * @{
251 */
252/*!
253 * @private @memberof prober
254 */
255int
256p_libusb_init(struct prober *p);
257
258/*!
259 * @private @memberof prober
260 */
261void
262p_libusb_teardown(struct prober *p);
263
264/*!
265 * @private @memberof prober
266 */
267int
268p_libusb_probe(struct prober *p);
269
270/*!
271 * @private @memberof prober
272 */
273int
274p_libusb_get_string_descriptor(struct prober *p,
275 struct prober_device *pdev,
276 enum xrt_prober_string which_string,
277 unsigned char *buffer,
278 int length);
279
280/*!
281 * @private @memberof prober
282 */
283bool
284p_libusb_can_open(struct prober *p, struct prober_device *pdev);
285
286/*!
287 * @}
288 */
289#endif
290
291#ifdef XRT_HAVE_LIBUVC
292/*!
293 * @name libuvc
294 * @{
295 */
296/*!
297 * @private @memberof prober
298 */
299int
300p_libuvc_init(struct prober *p);
301
302/*!
303 * @private @memberof prober
304 */
305void
306p_libuvc_teardown(struct prober *p);
307
308/*!
309 * @private @memberof prober
310 */
311int
312p_libuvc_probe(struct prober *p);
313
314/*!
315 * @}
316 */
317#endif
318
319#ifdef XRT_HAVE_LIBUDEV
320/*!
321 * @name udev
322 * @{
323 */
324/*!
325 * @private @memberof prober
326 */
327int
328p_udev_probe(struct prober *p);
329/*!
330 * @}
331 */
332#endif
u_logging_level
Logging level enum.
Definition: u_logging.h:40
#define XRT_MAX_AUTO_PROBERS
The maximum number of xrt_auto_prober instances that can be handled.
Definition: xrt_prober.h:57
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:124
size_t builder_count
The number of created builders.
Definition: p_prober.h:139
void p_dump_device(struct prober *p, struct prober_device *pdev, int id, bool use_stdout)
Dump the given device to stdout.
Definition: p_dump.c:75
int p_dev_get_usb_dev(struct prober *p, uint16_t bus, uint16_t addr, uint16_t vendor_id, uint16_t product_id, struct prober_device **out_pdev)
Get or create a prober_device from the device.
Definition: p_prober.c:161
int p_dev_get_bluetooth_dev(struct prober *p, uint64_t id, uint16_t vendor_id, uint16_t product_id, const char *product_name, struct prober_device **out_pdev)
Get or create a prober_device from the device.
Definition: p_prober.c:203
bool list_locked
Has the list been locked.
Definition: p_prober.h:144
struct xrt_builder ** builders
List of created builder.
Definition: p_prober.h:134
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:761
Sets up a collection of devices and builds a system, a setter upper.
Definition: xrt_prober.h:560
A probed device, may or may not be opened.
Definition: xrt_prober.h:85
enum xrt_bus_type bus
Device bus type.
Definition: xrt_prober.h:99
Main root of all of the probing device.
Definition: xrt_prober.h:809
Entry for a single device.
Definition: xrt_prober.h:706
uint16_t product_id
USB/Bluetooth product ID (PID) to filter on.
Definition: xrt_prober.h:715
uint16_t vendor_id
USB/Bluetooth vendor ID (VID) to filter on.
Definition: xrt_prober.h:710
The main prober that probes and manages found but not opened HMD devices that are connected to the sy...
Definition: xrt_prober.h:132
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:73
Common settings structs to be transferred between different parts of Monado, mainly for tracking and ...