2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "PeripheralBusUSBLibUSB.h"
22 #include "peripherals/Peripherals.h"
24 #include "utils/log.h"
26 using namespace PERIPHERALS;
28 CPeripheralBusUSB::CPeripheralBusUSB(CPeripherals *manager) :
29 CPeripheralBus("PeripBusUSB", manager, PERIPHERAL_BUS_USB)
33 m_busses = usb_get_busses();
34 CLog::Log(LOGDEBUG, "%s - using libusb peripheral scanning", __FUNCTION__);
37 bool CPeripheralBusUSB::PerformDeviceScan(PeripheralScanResults &results)
41 for (bus = m_busses; bus; bus = bus->next)
43 struct usb_device *dev;
44 for (dev = bus->devices; dev; dev = dev->next)
46 PeripheralScanResult result(m_type);
47 result.m_iVendorId = dev->descriptor.idVendor;
48 result.m_iProductId = dev->descriptor.idProduct;
49 result.m_type = (dev->descriptor.bDeviceClass == USB_CLASS_PER_INTERFACE && dev->descriptor.bNumConfigurations > 0 &&
50 dev->config[0].bNumInterfaces > 0 && dev->config[0].interface[0].num_altsetting > 0) ?
51 GetType(dev->config[0].interface[0].altsetting[0].bInterfaceClass) :
52 GetType(dev->descriptor.bDeviceClass);
54 result.m_strLocation.Format("%s", dev->filename);
56 result.m_strLocation.Format("/bus%s/dev%s", bus->dirname, dev->filename);
58 result.m_iSequence = GetNumberOfPeripheralsWithId(result.m_iVendorId, result.m_iProductId);
59 if (!results.ContainsResult(result))
60 results.m_results.push_back(result);
67 const PeripheralType CPeripheralBusUSB::GetType(int iDeviceClass)
72 return PERIPHERAL_HID;
74 return PERIPHERAL_NIC;
75 case USB_CLASS_MASS_STORAGE:
76 return PERIPHERAL_DISK;
77 case USB_CLASS_PER_INTERFACE:
79 case USB_CLASS_PRINTER:
83 case USB_CLASS_VENDOR_SPEC:
85 return PERIPHERAL_UNKNOWN;