2019-04-30 13:33:34 +00:00
|
|
|
// Copyright 2019, Collabora, Ltd.
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief Main prober code.
|
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
|
|
|
* @ingroup st_prober
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-03-02 15:44:00 +00:00
|
|
|
#include "xrt/xrt_config_have.h"
|
2020-03-03 22:39:03 +00:00
|
|
|
#include "xrt/xrt_config_os.h"
|
2019-04-30 13:33:34 +00:00
|
|
|
#include "xrt/xrt_compiler.h"
|
|
|
|
#include "xrt/xrt_prober.h"
|
2020-04-08 11:27:41 +00:00
|
|
|
#include "xrt/xrt_settings.h"
|
2019-04-30 13:33:34 +00:00
|
|
|
|
|
|
|
#ifdef XRT_HAVE_LIBUSB
|
2020-07-16 02:39:36 +00:00
|
|
|
#include <libusb.h>
|
2019-04-30 13:33:34 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XRT_HAVE_LIBUVC
|
|
|
|
#include <libuvc/libuvc.h>
|
|
|
|
#endif
|
|
|
|
|
2020-09-16 08:44:06 +00:00
|
|
|
#ifndef __KERNEL__
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
2019-04-30 13:33:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Struct and defines
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define P_SPEW(p, ...) \
|
|
|
|
do { \
|
|
|
|
if (p->print_spew) { \
|
|
|
|
fprintf(stderr, "%s - ", __func__); \
|
|
|
|
fprintf(stderr, __VA_ARGS__); \
|
|
|
|
fprintf(stderr, "\n"); \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
|
|
|
|
#define P_DEBUG(p, ...) \
|
|
|
|
do { \
|
|
|
|
if (p->print_debug) { \
|
|
|
|
fprintf(stderr, "%s - ", __func__); \
|
|
|
|
fprintf(stderr, __VA_ARGS__); \
|
|
|
|
fprintf(stderr, "\n"); \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
|
|
|
|
#define P_ERROR(p, ...) \
|
|
|
|
do { \
|
|
|
|
fprintf(stderr, "%s - ", __func__); \
|
|
|
|
fprintf(stderr, __VA_ARGS__); \
|
|
|
|
fprintf(stderr, "\n"); \
|
|
|
|
} while (false)
|
|
|
|
|
|
|
|
#define MAX_AUTO_PROBERS 8
|
|
|
|
|
|
|
|
|
2019-06-20 14:14:53 +00:00
|
|
|
#ifdef XRT_OS_LINUX
|
2019-04-30 13:33:34 +00:00
|
|
|
/*!
|
|
|
|
* A hidraw interface that a @ref prober_device exposes.
|
|
|
|
*/
|
|
|
|
struct prober_hidraw
|
|
|
|
{
|
|
|
|
ssize_t interface;
|
2019-09-29 10:44:00 +00:00
|
|
|
const char *path;
|
2019-04-30 13:33:34 +00:00
|
|
|
};
|
2019-06-20 17:27:21 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* A v4l interface that a @ref prober_device exposes.
|
|
|
|
*/
|
|
|
|
struct prober_v4l
|
|
|
|
{
|
2019-09-29 10:44:00 +00:00
|
|
|
const char *path;
|
2019-06-20 17:27:21 +00:00
|
|
|
int32_t usb_iface;
|
|
|
|
uint32_t v4l_index;
|
|
|
|
};
|
2019-06-20 14:14:53 +00:00
|
|
|
#endif
|
2019-04-30 13:33:34 +00:00
|
|
|
|
|
|
|
/*!
|
2020-06-03 16:43:30 +00:00
|
|
|
* A single device found by a @ref prober.
|
|
|
|
*
|
|
|
|
* @implements xrt_prober_device
|
2019-04-30 13:33:34 +00:00
|
|
|
*/
|
|
|
|
struct prober_device
|
|
|
|
{
|
|
|
|
struct xrt_prober_device base;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint16_t bus;
|
|
|
|
uint16_t addr;
|
|
|
|
|
2019-09-29 10:44:00 +00:00
|
|
|
const char *product;
|
2020-04-25 10:29:28 +00:00
|
|
|
const char *manufacturer;
|
|
|
|
const char *serial;
|
2019-09-29 10:44:00 +00:00
|
|
|
const char *path;
|
2019-06-26 14:10:32 +00:00
|
|
|
|
2019-06-20 13:51:34 +00:00
|
|
|
uint8_t ports[8];
|
|
|
|
uint32_t num_ports;
|
|
|
|
|
2019-04-30 13:33:34 +00:00
|
|
|
#ifdef XRT_HAVE_LIBUSB
|
2019-09-29 10:44:00 +00:00
|
|
|
libusb_device *dev;
|
2019-04-30 13:33:34 +00:00
|
|
|
#endif
|
|
|
|
} usb;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint64_t id;
|
|
|
|
} bluetooth;
|
|
|
|
|
|
|
|
#ifdef XRT_HAVE_LIBUVC
|
|
|
|
struct
|
|
|
|
{
|
2019-09-29 10:44:00 +00:00
|
|
|
uvc_device_t *dev;
|
2019-04-30 13:33:34 +00:00
|
|
|
} uvc;
|
|
|
|
#endif
|
|
|
|
|
2020-07-15 19:11:22 +00:00
|
|
|
#ifdef XRT_HAVE_V4L2
|
2019-06-20 17:27:21 +00:00
|
|
|
size_t num_v4ls;
|
2019-09-29 10:44:00 +00:00
|
|
|
struct prober_v4l *v4ls;
|
2020-07-15 19:11:22 +00:00
|
|
|
#endif
|
2019-04-30 13:33:34 +00:00
|
|
|
|
2020-07-15 19:11:22 +00:00
|
|
|
#ifdef XRT_OS_LINUX
|
2019-04-30 13:33:34 +00:00
|
|
|
size_t num_hidraws;
|
2019-09-29 10:44:00 +00:00
|
|
|
struct prober_hidraw *hidraws;
|
2019-06-20 14:14:53 +00:00
|
|
|
#endif
|
2019-04-30 13:33:34 +00:00
|
|
|
};
|
|
|
|
|
2020-06-03 16:43:30 +00:00
|
|
|
/*!
|
|
|
|
* @implements xrt_prober
|
|
|
|
*/
|
2019-04-30 13:33:34 +00:00
|
|
|
struct prober
|
|
|
|
{
|
|
|
|
struct xrt_prober base;
|
|
|
|
|
2019-09-29 10:44:00 +00:00
|
|
|
struct xrt_prober_entry_lists *lists;
|
2019-04-30 13:33:34 +00:00
|
|
|
|
2020-04-08 11:27:41 +00:00
|
|
|
struct
|
|
|
|
{
|
2020-05-01 17:11:27 +00:00
|
|
|
//! For error reporting, was it loaded but not parsed?
|
|
|
|
bool file_loaded;
|
|
|
|
|
2020-04-08 11:27:41 +00:00
|
|
|
cJSON *root;
|
|
|
|
} json;
|
|
|
|
|
2019-06-20 13:51:34 +00:00
|
|
|
#ifdef XRT_HAVE_LIBUSB
|
2019-04-30 13:33:34 +00:00
|
|
|
struct
|
|
|
|
{
|
2019-09-29 10:44:00 +00:00
|
|
|
libusb_context *ctx;
|
|
|
|
libusb_device **list;
|
2019-04-30 13:33:34 +00:00
|
|
|
ssize_t count;
|
|
|
|
} usb;
|
2019-06-20 13:51:34 +00:00
|
|
|
#endif
|
2019-04-30 13:33:34 +00:00
|
|
|
|
|
|
|
#ifdef XRT_HAVE_LIBUVC
|
|
|
|
struct
|
|
|
|
{
|
2019-09-29 10:44:00 +00:00
|
|
|
uvc_context_t *ctx;
|
|
|
|
uvc_device_t **list;
|
2019-04-30 13:33:34 +00:00
|
|
|
ssize_t count;
|
|
|
|
} uvc;
|
|
|
|
#endif
|
|
|
|
|
2019-09-29 10:44:00 +00:00
|
|
|
struct xrt_auto_prober *auto_probers[MAX_AUTO_PROBERS];
|
2019-04-30 13:33:34 +00:00
|
|
|
|
|
|
|
size_t num_devices;
|
2019-09-29 10:44:00 +00:00
|
|
|
struct prober_device *devices;
|
2019-04-30 13:33:34 +00:00
|
|
|
|
|
|
|
size_t num_entries;
|
2019-09-29 10:44:00 +00:00
|
|
|
struct xrt_prober_entry **entries;
|
2019-04-30 13:33:34 +00:00
|
|
|
|
|
|
|
bool print_debug;
|
|
|
|
bool print_spew;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Functions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-04-08 11:27:41 +00:00
|
|
|
/*!
|
|
|
|
* Load the JSON config file.
|
2020-06-03 16:43:30 +00:00
|
|
|
*
|
|
|
|
* @public @memberof prober
|
2020-04-08 11:27:41 +00:00
|
|
|
*/
|
2020-05-01 17:11:27 +00:00
|
|
|
void
|
|
|
|
p_json_open_or_create_main_file(struct prober *p);
|
2020-04-08 11:27:41 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Extract tracking settings from the JSON.
|
2020-06-03 16:43:30 +00:00
|
|
|
*
|
|
|
|
* @public @memberof prober
|
|
|
|
* @relatesalso xrt_settings_tracking
|
2020-04-08 11:27:41 +00:00
|
|
|
*/
|
|
|
|
bool
|
2020-05-01 17:11:27 +00:00
|
|
|
p_json_get_tracking_settings(struct prober *p, struct xrt_settings_tracking *s);
|
2020-04-08 11:27:41 +00:00
|
|
|
|
2019-04-30 13:33:34 +00:00
|
|
|
/*!
|
|
|
|
* Dump the given device to stdout.
|
2020-06-03 16:43:30 +00:00
|
|
|
*
|
|
|
|
* @public @memberof prober
|
2019-04-30 13:33:34 +00:00
|
|
|
*/
|
|
|
|
void
|
2019-09-29 10:44:00 +00:00
|
|
|
p_dump_device(struct prober *p, struct prober_device *pdev, int id);
|
2019-04-30 13:33:34 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Get or create a @ref prober_device from the device.
|
2020-06-03 16:43:30 +00:00
|
|
|
*
|
|
|
|
* @public @memberof prober
|
2019-04-30 13:33:34 +00:00
|
|
|
*/
|
|
|
|
int
|
2019-09-29 10:44:00 +00:00
|
|
|
p_dev_get_usb_dev(struct prober *p,
|
2019-04-30 13:33:34 +00:00
|
|
|
uint16_t bus,
|
|
|
|
uint16_t addr,
|
|
|
|
uint16_t vendor_id,
|
|
|
|
uint16_t product_id,
|
2019-09-29 10:44:00 +00:00
|
|
|
struct prober_device **out_pdev);
|
2019-04-30 13:33:34 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Get or create a @ref prober_device from the device.
|
2020-06-03 16:43:30 +00:00
|
|
|
*
|
|
|
|
* @public @memberof prober
|
2019-04-30 13:33:34 +00:00
|
|
|
*/
|
|
|
|
int
|
2019-09-29 10:44:00 +00:00
|
|
|
p_dev_get_bluetooth_dev(struct prober *p,
|
2019-04-30 13:33:34 +00:00
|
|
|
uint64_t id,
|
|
|
|
uint16_t vendor_id,
|
|
|
|
uint16_t product_id,
|
2019-09-29 10:44:00 +00:00
|
|
|
struct prober_device **out_pdev);
|
2019-04-30 13:33:34 +00:00
|
|
|
|
2020-06-03 16:43:30 +00:00
|
|
|
/*!
|
|
|
|
* @name Tracking systems
|
|
|
|
* @{
|
|
|
|
*/
|
2019-09-21 18:08:26 +00:00
|
|
|
/*!
|
|
|
|
* Init the tracking factory.
|
2020-06-03 16:43:30 +00:00
|
|
|
*
|
|
|
|
* @private @memberof prober
|
|
|
|
* @relatesalso xrt_tracking_factory
|
2019-09-21 18:08:26 +00:00
|
|
|
*/
|
|
|
|
int
|
2019-09-29 10:44:00 +00:00
|
|
|
p_tracking_init(struct prober *p);
|
2019-09-21 18:08:26 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Teardown the tracking factory.
|
2020-06-03 16:43:30 +00:00
|
|
|
*
|
|
|
|
* @private @memberof prober
|
|
|
|
* @relatesalso xrt_tracking_factory
|
2019-09-21 18:08:26 +00:00
|
|
|
*/
|
|
|
|
void
|
2019-09-29 10:44:00 +00:00
|
|
|
p_tracking_teardown(struct prober *p);
|
2019-09-21 18:08:26 +00:00
|
|
|
|
2020-06-03 16:43:30 +00:00
|
|
|
/*!
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2019-06-20 13:51:34 +00:00
|
|
|
#ifdef XRT_HAVE_LIBUSB
|
2020-06-03 16:43:30 +00:00
|
|
|
/*!
|
|
|
|
* @name libusb
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
* @private @memberof prober
|
|
|
|
*/
|
2019-06-20 13:51:34 +00:00
|
|
|
int
|
2019-09-29 10:44:00 +00:00
|
|
|
p_libusb_init(struct prober *p);
|
2019-06-20 13:51:34 +00:00
|
|
|
|
2020-06-03 16:43:30 +00:00
|
|
|
/*!
|
|
|
|
* @private @memberof prober
|
|
|
|
*/
|
2019-06-20 13:51:34 +00:00
|
|
|
void
|
2019-09-29 10:44:00 +00:00
|
|
|
p_libusb_teardown(struct prober *p);
|
2019-06-20 13:51:34 +00:00
|
|
|
|
2020-06-03 16:43:30 +00:00
|
|
|
/*!
|
|
|
|
* @private @memberof prober
|
|
|
|
*/
|
2019-06-20 13:51:34 +00:00
|
|
|
int
|
2019-09-29 10:44:00 +00:00
|
|
|
p_libusb_probe(struct prober *p);
|
2019-06-21 17:33:41 +00:00
|
|
|
|
2020-06-03 16:43:30 +00:00
|
|
|
/*!
|
|
|
|
* @private @memberof prober
|
|
|
|
*/
|
2019-06-21 17:33:41 +00:00
|
|
|
int
|
2019-09-29 10:44:00 +00:00
|
|
|
p_libusb_get_string_descriptor(struct prober *p,
|
|
|
|
struct prober_device *pdev,
|
2019-06-21 17:33:41 +00:00
|
|
|
enum xrt_prober_string which_string,
|
2019-09-29 10:44:00 +00:00
|
|
|
unsigned char *buffer,
|
2019-06-21 17:33:41 +00:00
|
|
|
int length);
|
2019-10-05 09:22:26 +00:00
|
|
|
|
2020-06-03 16:43:30 +00:00
|
|
|
/*!
|
|
|
|
* @private @memberof prober
|
|
|
|
*/
|
2019-10-05 09:22:26 +00:00
|
|
|
bool
|
|
|
|
p_libusb_can_open(struct prober *p, struct prober_device *pdev);
|
2020-06-03 16:43:30 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* @}
|
|
|
|
*/
|
2019-06-20 13:51:34 +00:00
|
|
|
#endif
|
2019-04-30 13:33:34 +00:00
|
|
|
|
2019-06-20 14:14:09 +00:00
|
|
|
#ifdef XRT_HAVE_LIBUVC
|
2020-06-03 16:43:30 +00:00
|
|
|
/*!
|
|
|
|
* @name libuvc
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
* @private @memberof prober
|
|
|
|
*/
|
2019-06-20 14:14:09 +00:00
|
|
|
int
|
2019-09-29 10:44:00 +00:00
|
|
|
p_libuvc_init(struct prober *p);
|
2019-06-20 14:14:09 +00:00
|
|
|
|
2020-06-03 16:43:30 +00:00
|
|
|
/*!
|
|
|
|
* @private @memberof prober
|
|
|
|
*/
|
2019-06-20 14:14:09 +00:00
|
|
|
void
|
2019-09-29 10:44:00 +00:00
|
|
|
p_libuvc_teardown(struct prober *p);
|
2019-06-20 14:14:09 +00:00
|
|
|
|
2020-06-03 16:43:30 +00:00
|
|
|
/*!
|
|
|
|
* @private @memberof prober
|
|
|
|
*/
|
2019-06-20 14:14:09 +00:00
|
|
|
int
|
2019-09-29 10:44:00 +00:00
|
|
|
p_libuvc_probe(struct prober *p);
|
2020-06-03 16:43:30 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* @}
|
|
|
|
*/
|
2019-06-20 14:14:09 +00:00
|
|
|
#endif
|
|
|
|
|
2019-04-30 13:33:34 +00:00
|
|
|
#ifdef XRT_HAVE_LIBUDEV
|
2020-06-03 16:43:30 +00:00
|
|
|
/*!
|
|
|
|
* @name udev
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
* @private @memberof prober
|
|
|
|
*/
|
2019-04-30 13:33:34 +00:00
|
|
|
int
|
2019-09-29 10:44:00 +00:00
|
|
|
p_udev_probe(struct prober *p);
|
2020-06-03 16:43:30 +00:00
|
|
|
/*!
|
|
|
|
* @}
|
|
|
|
*/
|
2019-04-30 13:33:34 +00:00
|
|
|
#endif
|