bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync/* $Id$ */
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync/** @file
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync * VirtualBox Linux host USB device enumeration.
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync */
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync/*
c58f1213e628a545081c70e26c6b67a841cff880vboxsync * Copyright (C) 2006-2011 Oracle Corporation
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync *
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync * available from http://www.virtualbox.org. This file is free software;
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync * you can redistribute it and/or modify it under the terms of the GNU
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync * General Public License (GPL) as published by the Free Software
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync */
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync#ifndef ___USBGetDevices_h
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync# define ___USBGetDevices_h
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync#include <VBox/usb.h>
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync#include <iprt/mem.h>
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync#include <iprt/string.h>
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync/**
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync * Free all the members of a USB device created by the Linux enumeration code.
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync * @note this duplicates a USBProxyService method which we needed access too
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync * without pulling in the rest of the proxy service code.
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync *
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync * @param pDevice Pointer to the device.
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync */
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsyncstatic inline void deviceFreeMembers(PUSBDEVICE pDevice)
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync{
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync RTStrFree((char *)pDevice->pszManufacturer);
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync pDevice->pszManufacturer = NULL;
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync RTStrFree((char *)pDevice->pszProduct);
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync pDevice->pszProduct = NULL;
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync RTStrFree((char *)pDevice->pszSerialNumber);
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync pDevice->pszSerialNumber = NULL;
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync RTStrFree((char *)pDevice->pszAddress);
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync pDevice->pszAddress = NULL;
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync}
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync/**
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync * Free one USB device created by the Linux enumeration code.
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync * @note this duplicates a USBProxyService method which we needed access too
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync * without pulling in the rest of the proxy service code.
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync *
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync * @param pDevice Pointer to the device.
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync */
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsyncstatic inline void deviceFree(PUSBDEVICE pDevice)
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync{
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync deviceFreeMembers(pDevice);
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync RTMemFree(pDevice);
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync}
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync/**
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync * Free a linked list of USB devices created by the Linux enumeration code.
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync * @param pHead Pointer to the first device in the linked list
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync */
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsyncstatic inline void deviceListFree(PUSBDEVICE *ppHead)
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync{
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync PUSBDEVICE pHead, pNext;
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync pHead = *ppHead;
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync while (pHead)
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync {
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync pNext = pHead->pNext;
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync deviceFree(pHead);
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync pHead = pNext;
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync }
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync *ppHead = NULL;
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync}
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsyncRT_C_DECLS_BEGIN
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync
e0f4842c86fb19b491179200b2e74fa6e9a57b85vboxsyncextern bool USBProxyLinuxCheckDeviceRoot(const char *pcszRoot,
e0f4842c86fb19b491179200b2e74fa6e9a57b85vboxsync bool fIsDeviceNodes);
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync#ifdef UNIT_TEST
15560e9bb8e85bdbe311a5c02139b487a306859dvboxsyncvoid TestUSBSetupInit(const char *pcszUsbfsRoot, bool fUsbfsAccessible,
15560e9bb8e85bdbe311a5c02139b487a306859dvboxsync const char *pcszDevicesRoot, bool fDevicesAccessible,
15560e9bb8e85bdbe311a5c02139b487a306859dvboxsync int rcMethodInitResult);
15560e9bb8e85bdbe311a5c02139b487a306859dvboxsyncvoid TestUSBSetEnv(const char *pcszEnvUsb, const char *pcszEnvUsbRoot);
15560e9bb8e85bdbe311a5c02139b487a306859dvboxsync#endif
15560e9bb8e85bdbe311a5c02139b487a306859dvboxsync
15560e9bb8e85bdbe311a5c02139b487a306859dvboxsyncextern int USBProxyLinuxChooseMethod(bool *pfUsingUsbfsDevices,
15560e9bb8e85bdbe311a5c02139b487a306859dvboxsync const char **ppcszDevicesRoot);
15560e9bb8e85bdbe311a5c02139b487a306859dvboxsync#ifdef UNIT_TEST
37c53e9b2c955f92dff6f11aff63809004945f17vboxsyncextern void TestUSBSetAvailableUsbfsDevices(const char **pacszDeviceAddresses);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsyncextern void TestUSBSetAccessibleFiles(const char **pacszAccessibleFiles);
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync#endif
37c53e9b2c955f92dff6f11aff63809004945f17vboxsync
dff7b61dd3fdc4026a02236298516db1d8ac6516vboxsyncextern PUSBDEVICE USBProxyLinuxGetDevices(const char *pcszDevicesRoot,
dff7b61dd3fdc4026a02236298516db1d8ac6516vboxsync bool fUseSysfs);
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsyncRT_C_DECLS_END
90ec3d0d2ad4d28845757ca92dc889d76622b935vboxsync
bbd8414a6c9e8c73fbe9cffd73b5747c0570b118vboxsync#endif /* ___USBGetDevices_h */