2009-08-14 13:19:32 +00:00
|
|
|
/*
|
2012-12-12 17:04:51 +00:00
|
|
|
* virusb.h: helper APIs for managing host USB devices
|
|
|
|
*
|
2009-08-14 13:19:32 +00:00
|
|
|
* Copyright (C) 2009 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2009-08-14 13:19:32 +00:00
|
|
|
*/
|
|
|
|
|
2019-06-18 16:13:08 +00:00
|
|
|
#pragma once
|
2009-08-14 13:19:32 +00:00
|
|
|
|
2019-06-18 16:13:08 +00:00
|
|
|
#include "internal.h"
|
|
|
|
#include "virobject.h"
|
|
|
|
#include "virautoclean.h"
|
2009-08-14 13:19:32 +00:00
|
|
|
|
2019-06-18 16:13:08 +00:00
|
|
|
#define USB_DEVFS "/dev/bus/usb/"
|
2012-12-17 19:37:11 +00:00
|
|
|
|
2013-01-14 22:11:44 +00:00
|
|
|
typedef struct _virUSBDevice virUSBDevice;
|
|
|
|
typedef virUSBDevice *virUSBDevicePtr;
|
|
|
|
typedef struct _virUSBDeviceList virUSBDeviceList;
|
|
|
|
typedef virUSBDeviceList *virUSBDeviceListPtr;
|
2009-08-14 13:19:32 +00:00
|
|
|
|
2019-10-04 16:14:10 +00:00
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virUSBDeviceList, virObjectUnref);
|
|
|
|
|
|
|
|
|
2013-01-14 22:11:44 +00:00
|
|
|
virUSBDevicePtr virUSBDeviceNew(unsigned int bus,
|
|
|
|
unsigned int devno,
|
|
|
|
const char *vroot);
|
2012-05-04 07:49:58 +00:00
|
|
|
|
2013-01-14 22:11:44 +00:00
|
|
|
int virUSBDeviceFindByBus(unsigned int bus,
|
|
|
|
unsigned int devno,
|
2012-11-27 16:17:47 +00:00
|
|
|
const char *vroot,
|
2012-10-03 14:57:28 +00:00
|
|
|
bool mandatory,
|
2013-01-14 22:11:44 +00:00
|
|
|
virUSBDevicePtr *usb);
|
|
|
|
|
|
|
|
int virUSBDeviceFindByVendor(unsigned int vendor,
|
|
|
|
unsigned int product,
|
|
|
|
const char *vroot,
|
|
|
|
bool mandatory,
|
|
|
|
virUSBDeviceListPtr *devices);
|
2012-10-03 14:57:28 +00:00
|
|
|
|
2013-01-14 22:11:44 +00:00
|
|
|
int virUSBDeviceFind(unsigned int vendor,
|
|
|
|
unsigned int product,
|
|
|
|
unsigned int bus,
|
|
|
|
unsigned int devno,
|
|
|
|
const char *vroot,
|
|
|
|
bool mandatory,
|
|
|
|
virUSBDevicePtr *usb);
|
2012-05-04 07:49:58 +00:00
|
|
|
|
2013-01-14 22:11:44 +00:00
|
|
|
void virUSBDeviceFree(virUSBDevicePtr dev);
|
2014-03-01 06:28:56 +00:00
|
|
|
int virUSBDeviceSetUsedBy(virUSBDevicePtr dev,
|
|
|
|
const char *drv_name,
|
|
|
|
const char *dom_name);
|
|
|
|
void virUSBDeviceGetUsedBy(virUSBDevicePtr dev,
|
|
|
|
const char **drv_name,
|
|
|
|
const char **dom_name);
|
2013-01-14 22:11:44 +00:00
|
|
|
const char *virUSBDeviceGetName(virUSBDevicePtr dev);
|
2016-11-16 14:26:59 +00:00
|
|
|
const char *virUSBDeviceGetPath(virUSBDevicePtr usb);
|
2010-03-04 11:48:16 +00:00
|
|
|
|
2013-01-14 22:11:44 +00:00
|
|
|
unsigned int virUSBDeviceGetBus(virUSBDevicePtr dev);
|
|
|
|
unsigned int virUSBDeviceGetDevno(virUSBDevicePtr dev);
|
2009-08-14 13:19:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback that will be invoked once for each file
|
|
|
|
* associated with / used for USB host device access.
|
|
|
|
*
|
|
|
|
* Should return 0 if successfully processed, or
|
|
|
|
* -1 to indicate error and abort iteration
|
|
|
|
*/
|
2013-01-14 22:11:44 +00:00
|
|
|
typedef int (*virUSBDeviceFileActor)(virUSBDevicePtr dev,
|
|
|
|
const char *path, void *opaque);
|
2009-08-14 13:19:32 +00:00
|
|
|
|
2013-01-14 22:11:44 +00:00
|
|
|
int virUSBDeviceFileIterate(virUSBDevicePtr dev,
|
|
|
|
virUSBDeviceFileActor actor,
|
|
|
|
void *opaque);
|
2009-08-14 13:19:32 +00:00
|
|
|
|
2013-01-14 22:11:44 +00:00
|
|
|
virUSBDeviceListPtr virUSBDeviceListNew(void);
|
|
|
|
int virUSBDeviceListAdd(virUSBDeviceListPtr list,
|
2018-07-24 15:52:23 +00:00
|
|
|
virUSBDevicePtr *dev);
|
2013-01-14 22:11:44 +00:00
|
|
|
virUSBDevicePtr virUSBDeviceListGet(virUSBDeviceListPtr list,
|
|
|
|
int idx);
|
2014-01-07 14:44:27 +00:00
|
|
|
size_t virUSBDeviceListCount(virUSBDeviceListPtr list);
|
2013-01-14 22:11:44 +00:00
|
|
|
virUSBDevicePtr virUSBDeviceListSteal(virUSBDeviceListPtr list,
|
|
|
|
virUSBDevicePtr dev);
|
|
|
|
void virUSBDeviceListDel(virUSBDeviceListPtr list,
|
|
|
|
virUSBDevicePtr dev);
|
|
|
|
virUSBDevicePtr virUSBDeviceListFind(virUSBDeviceListPtr list,
|
|
|
|
virUSBDevicePtr dev);
|
2009-08-14 13:19:32 +00:00
|
|
|
|
2019-02-07 17:18:52 +00:00
|
|
|
VIR_DEFINE_AUTOPTR_FUNC(virUSBDevice, virUSBDeviceFree);
|