Example #1
0
struct libusb_device_handle *usb_init(struct libusb_context* context, int devid) {
	struct libusb_device **device_list;
	struct libusb_device_handle *handle = NULL;

	int deviceCount = libusb_get_device_list(context, &device_list);

	int i;
	for (i = 0; i < deviceCount; i++) {
		struct libusb_device* device = device_list[i];
		struct libusb_device_descriptor desc;
		libusb_get_device_descriptor(device, &desc);	
		if (desc.idVendor == VENDOR_ID && desc.idProduct == devid) {
			libusb_open(device, &handle);
			break;
		}
	}
	
	libusb_free_device_list(device_list, 1);

	return handle;
}
Example #2
0
void openAuxDevice(int index = 0)
{
	libusb_device **devs; //pointer to pointer of device, used to retrieve a list of devices
	ssize_t cnt = libusb_get_device_list (0, &devs); //get the list of devices
	if (cnt < 0)
	{
		ROS_ERROR("No device on USB");
		return;
	}
	
	int nr_mot(0);
	for (int i = 0; i < cnt; ++i)
	{
		struct libusb_device_descriptor desc;
		const int r = libusb_get_device_descriptor (devs[i], &desc);
		if (r < 0)
			continue;

		// Search for the aux
		if (desc.idVendor == MS_MAGIC_VENDOR && desc.idProduct == MS_MAGIC_MOTOR_PRODUCT)
		{
			// If the index given by the user matches our camera index
			if (nr_mot == index)
			{
				if ((libusb_open (devs[i], &dev) != 0) || (dev == 0))
				{
					ROS_ERROR_STREAM("Cannot open aux " << index);
					return;
				}
				// Claim the aux
				libusb_claim_interface (dev, 0);
				break;
			}
			else
				nr_mot++;
		}
	}

	libusb_free_device_list (devs, 1);  // free the list, unref the devices in it
}
LIBMTP_raw_device_t *smtpfs_raw_device_new(const std::string &path)
{
    libusb_context *ctx;
    int err = libusb_init(&ctx);
    if (err)
        return nullptr;

    std::string dev_path(smtpfs_realpath(path));
    libusb_device **dev_list;
    ssize_t num_devs = libusb_get_device_list(ctx, &dev_list);
    if (num_devs < 1) {
        libusb_exit(ctx);
        return nullptr;
    }

    libusb_device *dev = nullptr;
    for (auto i = 0; i < num_devs; ++i) {
        dev = dev_list[i];
        uint8_t bnum = libusb_get_bus_number(dev_list[i]);
        uint8_t dnum = libusb_get_device_address(dev_list[i]);

        std::stringstream ss;
        ss << smtpfs_devbususb
           << std::setw(3) << std::setfill('0')
           << static_cast<uint16_t>(bnum) << "/"
           << std::setw(3) << std::setfill('0')
           << static_cast<uint16_t>(dnum);

        if (ss.str() == dev_path)
            break;
        dev = nullptr;
    }

    LIBMTP_raw_device_t *raw_device = smtpfs_raw_device_new_priv(dev);

    libusb_free_device_list(dev_list, 0);
    libusb_exit(ctx);

    return raw_device;
}
Example #4
0
int fnusb_num_devices(fnusb_ctx *ctx)
{
	libusb_device **devs; 
	//pointer to pointer of device, used to retrieve a list of devices	
	ssize_t cnt = libusb_get_device_list (ctx->ctx, &devs); 
	//get the list of devices	
	if (cnt < 0)
		return (-1);
	int nr = 0, i = 0;
	struct libusb_device_descriptor desc;
	for (i = 0; i < cnt; ++i)
	{
		int r = libusb_get_device_descriptor (devs[i], &desc);
		if (r < 0)
			continue;
		if (desc.idVendor == VID_MICROSOFT && desc.idProduct == PID_NUI_CAMERA)
			nr++;
	}
	libusb_free_device_list (devs, 1);
	// free the list, unref the devices in it
	return nr;
}
Example #5
0
uint32_t auc_getcounts(void)
{
	static int32_t usb_init = 0;
	struct libusb_device **devs = NULL;
	struct libusb_device_descriptor info;
	uint32_t count, i;

	if (!usb_init) {
		if (libusb_init(NULL) < 0) {
			printf("libusb_init failed!\n");
			return 1;
		}
		usb_init = 1;
	} else {
		if (devs) {
			libusb_free_device_list(devs, 1);
			devs = NULL;
		}
		for (i = 0; i < auc_devctx.auc_cnt; i++)
			auc_devctx.auc_devlist[i] = NULL;
		auc_devctx.auc_cnt = 0;
	}

	count = libusb_get_device_list(NULL, &devs);
	if (count <= 0) {
		printf("libusb_get_device_list get NULL\n");
		return 0;
	}

	for (i = 0; i < count; i++) {
		libusb_get_device_descriptor(devs[i], &info);
		if ((info.idVendor == AUC_VID) && (info.idProduct == AUC_PID)) {
			auc_devctx.auc_devlist[auc_devctx.auc_cnt] = devs[i];
			auc_devctx.auc_cnt++;
		}
	}

	return auc_devctx.auc_cnt;
}
Example #6
0
static libusb_device* find_device()
{
    // return value
    libusb_device* r = NULL;

    int errno;

    // number of devices found
    ssize_t cnt;

    cnt = libusb_get_device_list(usb_context, &devices);

    for (ssize_t i = 0; i < cnt; i++)
    {
        struct libusb_device_descriptor desc;
        errno = libusb_get_device_descriptor(devices[i], &desc);
        if (errno < 0)
        {
            printf("Failed getting device descriptor of device %zd %s\n", i, libusb_error_name(errno));
        }

        if (desc.idVendor == VENDOR_LOGITECH && desc.idProduct == PRODUCT_G930)
        {
            r = devices[i];
            printf("Found Logitech G930!\n");
            device_found = DEVICE_G930;
            break;
        }
        else if (desc.idVendor == VENDOR_CORSAIR && desc.idProduct == PRODUCT_VOID)
        {
            r = devices[i];
            printf("Found Corsair VOID!\n");
            device_found = DEVICE_VOID;
            break;
        }
    }

    return r;
}
libusb_device_handle* InfinityPortal::connect(int deviceId) {
	
	libusb_device** devices;
	libusb_context* context;
	struct libusb_device_handle* tryDeviceHandler;

	libusb_init(&context);
	int devicesCount = libusb_get_device_list(context, &devices);
	
	int error;

	struct libusb_device_descriptor descriptor;
	
	int retVal = libusb_open(devices[deviceId], &tryDeviceHandler);
	
	libusb_get_device_descriptor(devices[deviceId], &descriptor);

	if(descriptor.idVendor == 0x0e6f && descriptor.idProduct == 0x0129) {

		return tryDeviceHandler;
	}
}
Example #8
0
libusb_device* usb_find_device_by_path(uint8_t busnum, uint8_t devnum)
{
  libusb_device* ret_device = 0;

  libusb_device** list;
  ssize_t num_devices = libusb_get_device_list(NULL, &list);
  for(ssize_t dev_it = 0; dev_it < num_devices; ++dev_it)
  {
    libusb_device* dev = list[dev_it];

    if (busnum == libusb_get_bus_number(dev) &&
        devnum == libusb_get_device_address(dev))
    {
      ret_device = dev;
      libusb_ref_device(ret_device);
      break;
    }
  }
  libusb_free_device_list(list, 1 /* unref_devices */);

  return ret_device;
}
vector<TreehopperBoard>* TreehopperManager::ScanForDevices()
{
	ssize_t cnt;
	cnt = libusb_get_device_list(NULL, &devs);
	if (cnt < 0)
		return &BoardList;

	libusb_device *dev;
	int i = 0;
	while ((dev = devs[i++]) != NULL)
	{
		struct libusb_device_descriptor desc;
		int r = libusb_get_device_descriptor(dev, &desc);
		if (r < 0) {
			return &BoardList;
		}
		if (desc.idProduct == TreehopperBoard::pid && desc.idVendor == TreehopperBoard::vid)
		{

			// Get the name and serial number
			libusb_device_handle* candidate;

			libusb_open(dev, &candidate);
			unsigned char buffer[64];

			libusb_get_string_descriptor_ascii(candidate, 4, buffer, 128);
			string name = string((const char*)buffer);

			libusb_get_string_descriptor_ascii(candidate, 3, buffer, 128);
			string serialNumber = string((const char*)buffer);

			libusb_close(candidate);

			BoardList.push_back(TreehopperBoard(serialNumber));
		}
	}

	return &BoardList;
}
Example #10
0
int main(int argc, char *argv[])
{
	libusb_device **devs;
	libusb_context *context = NULL;
	
	size_t list;
	size_t i;
	int ret;

	ret = libusb_init(&context);

	if(ret < 0)
	{
		perror("libusb_init");
		exit(1);
	}

	list = libusb_get_device_list(context, &devs);

	if(list < 0)
	{
		fprinf(stderr, "Error in getting device list\n");
		libusb_free_device_list(devs,1);
		libusb_exit(context);
		exit(1);
	}

	printf("There are %d devices found", list);

	for(i = 0; i < list; i++)
	{
		print_devices(devs[i]);
	}
	
	libusb_free_device_list(devs, 1);
	libusb_exit(context);

	return 0;
}
Example #11
0
int main(void)
{
	libusb_device **devs;
	int r;
	ssize_t cnt;

	r = libusb_init(NULL);
	if (r < 0)
		return r;

	cnt = libusb_get_device_list(NULL, &devs);
	if (cnt < 0){
		libusb_exit(NULL);
		return (int) cnt;
	}

	print_devs(devs);
	libusb_free_device_list(devs, 1);

	libusb_exit(NULL);
	return 0;
}
Example #12
0
int main(int argc,char **argv)
{
    (void)argc;
    (void)argv;
    
    assert(libusb_init(NULL)==0);
    
    libusb_set_debug(NULL,3);
    
    libusb_device **device_list;
    ssize_t list_size=libusb_get_device_list(NULL,&device_list);
    
    assert(list_size>=0);
    
    libusb_device *found = NULL;
    for(ssize_t i=0;i<list_size;i++)
    {
        if(is_debug(device_list[i]))
            found=device_list[i];
    }
    
    if(found)
    {
        libusb_device_handle *handle;
        int err = libusb_open(found,&handle);
        assert(err==0);

        main_loop(handle);

        libusb_close(handle);
    }
    
    libusb_free_device_list(device_list,1);
    
    libusb_exit(NULL);
    
    return 0;
}
Example #13
0
int irecv_usb_get_device_list(libusb_context *context,
                              libusb_device ***usb_device_list) {
    struct libusb_device **ret;
    ssize_t len;
    size_t i;
    
    if (libirecovery_usage_context == IRECV_CTX_LOCAL) {
        return libusb_get_device_list(context, usb_device_list);
    }
    
    libusbip_get_device_list(&libirecovery_connection_info,
                             &libirecovery_device_list);
    
    len = libirecovery_device_list.n_devices;
    ret = malloc(sizeof(void *) * (len + 1));
    if (!ret) {
        return -1;
    }
    
    ret[len] = NULL;
    for (i = 0; i < len; i++) {
        libusb_device *dev
        = malloc(sizeof(struct libusb_device));
        if (!dev) {
            free(ret);
            return -1;
        }
        
        struct libusbip_device *idev = &libirecovery_device_list.devices[i];
        dev->bus_number = idev->bus_number;
        dev->device_address = idev->device_address;
        dev->num_configurations = idev->num_configurations;
        dev->session_data = idev->session_data;
        ret[i] = dev;
    }
    *usb_device_list = ret;
    return len;
}
bool isConnctedUsbDevice(){

		libusb_device **devs;
		int r;
		ssize_t cnt;

		r = libusb_init(NULL);
		if (r < 0)
			return r;

		cnt = libusb_get_device_list(NULL, &devs);
		if (cnt < 0)
			return (int) cnt;

		print_devs(devs);
		libusb_free_device_list(devs, 1);

		libusb_exit(NULL);


		return 0;

}
/** Tests that devices can be listed 1000 times. */
static libusb_testlib_result test_get_device_list(libusb_testlib_ctx * tctx)
{
	libusb_context * ctx = NULL;
	int r, i;
	r = libusb_init(&ctx);
	if (r != LIBUSB_SUCCESS) {
		libusb_testlib_logf(tctx, "Failed to init libusb: %d", r);
		return TEST_STATUS_FAILURE;
	}
	for (i = 0; i < 1000; ++i) {
		libusb_device ** device_list;
		ssize_t list_size = libusb_get_device_list(ctx, &device_list);
		if (list_size < 0 || device_list == NULL) {
			libusb_testlib_logf(tctx,
				"Failed to get device list on iteration %d: %d (%p)",
				i, -list_size, device_list);
			return TEST_STATUS_FAILURE;
		}
		libusb_free_device_list(device_list, 1);
	}
	libusb_exit(ctx);
	return TEST_STATUS_SUCCESS;
}
Example #16
0
ssize_t hwstub_get_device_list(libusb_context *ctx, libusb_device ***list)
{
    libusb_device **great_list;
    ssize_t great_cnt = libusb_get_device_list(ctx, &great_list);
    if(great_cnt < 0)
        return great_cnt;
    /* allocate a list (size at least one NULL entry at the end) */
    libusb_device **mylist = malloc(sizeof(libusb_device *) * (great_cnt + 1));
    memset(mylist, 0, sizeof(libusb_device *) * (great_cnt + 1));
    /* list hwstub devices */
    ssize_t cnt = 0;
    for(int i = 0; i < great_cnt; i++)
        if(hwstub_probe(great_list[i]) >= 0)
        {
            libusb_ref_device(great_list[i]);
            mylist[cnt++] = great_list[i];
        }
    /* free old list */
    libusb_free_device_list(great_list, 1);
    /* return */
    *list = mylist;
    return cnt;
}
Example #17
0
int freenect_num_devices(freenect_context *ctx)
{
	libusb_device **devs; //pointer to pointer of device, used to retrieve a list of devices
	ssize_t cnt = libusb_get_device_list (ctx->usb.ctx, &devs); //get the list of devices

	if (cnt < 0)
		return (-1);

	int nr = 0, i = 0;
	struct libusb_device_descriptor desc;
	for (i = 0; i < cnt; ++i)
	{
		int r = libusb_get_device_descriptor (devs[i], &desc);
		if (r < 0)
			continue;
		if (desc.idVendor == MS_MAGIC_VENDOR && desc.idProduct == MS_MAGIC_CAMERA_PRODUCT)
			nr++;
	}

	libusb_free_device_list (devs, 1);  // free the list, unref the devices in it

	return (nr);
}
Example #18
0
int32_t main(void)
{
	libusb_device **devs;
	int32_t r;
	ssize_t cnt;

	r = libusb_init(NULL);
	if(r < 0)
		{ return r; }

	printf("Looking for smartreader compatible devices...\n");

	cnt = libusb_get_device_list(NULL, &devs);
	if(cnt < 0)
		{ return (int32_t) cnt; }

	print_devs(devs);
	libusb_free_device_list(devs, 1);

	libusb_exit(NULL);

	return 0;
}
Example #19
0
/**
 * find in the usb tree if the device is present
 */
    bool DomusEngineUSBDevice::isPresent() {
        if (device != nullptr || demo) {
            return true;
        } else {
            libusb_device **devices{};

            handle = nullptr;
            ssize_t devicesNum = libusb_get_device_list((libusb_context *) usbContext, &devices);

            for (int index = 0; index < devicesNum; index++) {
                libusb_device_descriptor deviceDescriptor;
                libusb_get_device_descriptor(devices[index], &deviceDescriptor);
                if (deviceDescriptor.bDeviceClass == deviceClass && deviceDescriptor.idVendor == vendorID &&
                    deviceDescriptor.idProduct == productID) {
                    device = devices[index];
                    libusb_ref_device((libusb_device *) device);
                    int result = libusb_open((libusb_device *) device, (libusb_device_handle **) &handle);
                    if (result != 0) {
                        std::cerr << "Unable to open device: " << strUsbError(result) << std::endl;
                        return false;
                    }
                    break;
                }
            }
            libusb_free_device_list(devices, 1);
            if (handle != nullptr) {
                BOOST_LOG_TRIVIAL(info) << "device found";
                int result = libusb_claim_interface((libusb_device_handle *) handle, 0);
                if (result != 0) {
                    BOOST_LOG_TRIVIAL(error) << "Unable to claim interface 0: " << strUsbError(result);
                }
            } else {
                BOOST_LOG_TRIVIAL(error) << "device not found";
            }
        }
        return device != nullptr;
    }
Example #20
0
std::string getFullPortUSB(std::string id) {

	std::string port;

	libusb_device **devs; //pointer to pointer of device, used to retrieve a list of devices
	libusb_context *ctx = NULL; //a libusb session
	int r; //for return values
	ssize_t cnt; //holding number of devices in list
	r = libusb_init(&ctx); //initialize a library session
	if(r < 0) {
		std::cout<<"Init Error "<<r<<std::endl; //there was an error
		return NULL;
	}

	libusb_set_debug(ctx, 3); //set verbosity level to 3, as suggested in the documentation
	cnt = libusb_get_device_list(ctx, &devs); //get the list of devices

	if(cnt < 0)
		std::cout<<"Get Device Error"<<std::endl; //there was an error

	std::cout<<cnt<<" Devices in list."<<std::endl; //print total number of usb devices

	for(ssize_t i = 0; i < cnt; i++)
	{
		std::string tmpid = get_device_id(devs[i]);
		if (tmpid.compare(id)==0)
		{
			port = get_device_port(devs[i]);
			std::cout << " usb device " << tmpid << " found with port=" << port<< std::endl;
		}
	}

	libusb_free_device_list(devs, 1); //free the list, unref the devices in it
	libusb_exit(ctx); //close the session

	return port;
}
Example #21
0
usb_device_info *
enumerate(unsigned short vendor_id, unsigned short product_id)
{
    return usb_executor->await([=] {
            libusb_device **devs = NULL;
            libusb_device *dev = NULL;
            struct usb_device_info *root = NULL; /* return object */
            struct usb_device_info *cur_dev = NULL;
            int i = 0;

            libusb_get_device_list(NULL, &devs);
            while ((dev = devs[i++]) != NULL) {
                    struct libusb_device_descriptor desc;
                    libusb_get_device_descriptor(dev, &desc);
                    if ((vendor_id == 0 || vendor_id == desc.idVendor) && (product_id == 0 || product_id == desc.idProduct)) {
                            struct usb_device_info *tmp;
                            tmp = (struct usb_device_info *) calloc(1, sizeof(struct usb_device_info));
                            if (cur_dev) {
                                    cur_dev->next = tmp;
                            } else {
                                    root = tmp;
                            }
                            cur_dev = tmp;

                            cur_dev->next = NULL;
                            snprintf(cur_dev->path, sizeof(cur_dev->path), "%04x:%04x",
                                    libusb_get_bus_number(dev),
                                    libusb_get_device_address(dev));

                            cur_dev->vendor_id = desc.idVendor;
                            cur_dev->product_id = desc.idProduct;
                    }
            }
            libusb_free_device_list(devs, 1);
            return root;
        });
}
/*
 * If hotplug isn't supported, this is called periodically to checked for
 * USB devices that have been added or removed.
 *
 * This is run within the main thread, since the libusb thread only runs if at
 * least one USB device is used.
 */
bool AsyncPluginImpl::ScanUSBDevices() {
  OLA_INFO << "Scanning USB devices....";
  std::set<USBDeviceID> current_device_ids;

  libusb_device **device_list;
  size_t device_count = libusb_get_device_list(m_context, &device_list);

  OLA_INFO << "Got " << device_count << " devices";
  for (unsigned int i = 0; i < device_count; i++) {
    libusb_device *usb_device = device_list[i];

    USBDeviceID device_id(libusb_get_bus_number(usb_device),
                          libusb_get_device_address(usb_device));

    current_device_ids.insert(device_id);

    if (!STLContains(m_seen_usb_devices, device_id)) {
      OLA_INFO << "  " << usb_device;
      bool claimed = USBDeviceAdded(usb_device);
      STLReplace(&m_seen_usb_devices, device_id, claimed ? usb_device : NULL);
    }
  }
  libusb_free_device_list(device_list, 1);  // unref devices

  USBDeviceIDs::iterator iter = m_seen_usb_devices.begin();
  while (iter != m_seen_usb_devices.end()) {
    if (!STLContains(current_device_ids, iter->first)) {
      if (iter->second) {
        USBDeviceRemoved(iter->second);
      }
      m_seen_usb_devices.erase(iter++);
    } else {
      iter++;
    }
  }
  return true;
}
/** Tests that 100 concurrent device lists can be open at a time. */
static libusb_testlib_result test_many_device_lists(libusb_testlib_ctx * tctx)
{
#define LIST_COUNT 100
	libusb_context * ctx = NULL;
	libusb_device ** device_lists[LIST_COUNT];
	int r, i;
	memset(device_lists, 0, sizeof(device_lists));

	r = libusb_init(&ctx);
	if (r != LIBUSB_SUCCESS) {
		libusb_testlib_logf(tctx, "Failed to init libusb: %d", r);
		return TEST_STATUS_FAILURE;
	}

	/* Create the 100 device lists. */
	for (i = 0; i < LIST_COUNT; ++i) {
		ssize_t list_size = libusb_get_device_list(ctx, &(device_lists[i]));
		if (list_size < 0 || device_lists[i] == NULL) {
			libusb_testlib_logf(tctx,
				"Failed to get device list on iteration %d: %d (%p)",
				i, -list_size, device_lists[i]);
			return TEST_STATUS_FAILURE;
		}
	}

	/* Destroy the 100 device lists. */
	for (i = 0; i < LIST_COUNT; ++i) {
		if (device_lists[i]) {
			libusb_free_device_list(device_lists[i], 1);
			device_lists[i] = NULL;
		}
	}

	libusb_exit(ctx);
	return TEST_STATUS_SUCCESS;
#undef LIST_COUNT
}
int main(void)
{
#ifdef USE_LIBUSB_1_0
    libusb_device_handle *usbhandle;
#else
    usb_dev_handle *usbhandle;
#endif

#if 0
    libusb_device **devs;
	int r;
	ssize_t cnt;

	r = libusb_init(NULL);
	if (r < 0)
		return r;

	cnt = libusb_get_device_list(NULL, &devs);
	if (cnt < 0)
		return (int) cnt;

	print_devs(devs);

	libusb_free_device_list(devs, 1);

    libusb_exit(NULL);
#endif

	if(!usbdevice_open(&usbhandle))
	{
	    testWrite(usbhandle);
        usbasp_initialize(usbhandle);
	}


	return 0;
}
vector<TreehopperBoard>* TreehopperManager::ScanForDevices()
{
	ssize_t cnt;
	cnt = libusb_get_device_list(NULL, &devs);
	if (cnt < 0)
		return &BoardList;

	libusb_device *dev;
	int i = 0;
	while ((dev = devs[i++]) != NULL)
	{
		struct libusb_device_descriptor desc;
		int r = libusb_get_device_descriptor(dev, &desc);
		if (r < 0) {
			return &BoardList;
		}
		if (desc.idProduct == TreehopperBoard::pid && desc.idVendor == TreehopperBoard::vid)
		{
			BoardList.push_back(TreehopperBoard(dev));
		}
	}

	return &BoardList;
}
Example #26
0
 int USBMgr::listDevices( std::vector<PS3EYECam::PS3EYERef>& list )
 {
     libusb_device *dev;
     libusb_device **devs;
     libusb_device_handle *devhandle;
     int i = 0;
     int cnt;
     
     cnt = libusb_get_device_list(instance()->usb_context, &devs);
     
     if (cnt < 0)
         debug("Error Device scan\n");
     
     cnt = 0;
     while ((dev = devs[i++]) != NULL)
     {
         struct libusb_device_descriptor desc;
         libusb_get_device_descriptor(dev, &desc);
         if(desc.idVendor == PS3EYECam::VENDOR_ID && desc.idProduct == PS3EYECam::PRODUCT_ID)
         {
             int err = libusb_open(dev, &devhandle);
             if (err == 0)
             {
                 libusb_close(devhandle);
                 list.push_back( PS3EYECam::PS3EYERef( new PS3EYECam(dev) ) );
                 libusb_ref_device(dev);
                 cnt++;
                 
             }
         }
     }
     
     libusb_free_device_list(devs, 1);
     
     return cnt;
 }
Example #27
0
static ssize_t
load_devicelist (GPPortPrivateLibrary *pl) {
	time_t	xtime;

	time(&xtime);
	if (xtime != pl->devslastchecked) {
		if (pl->nrofdevs)
			libusb_free_device_list (pl->devs, 1);
		free (pl->descs);
		pl->nrofdevs = 0;
		pl->devs = NULL;
		pl->descs = NULL;
	}
	if (!pl->nrofdevs) {
		int 	i;

		pl->nrofdevs = libusb_get_device_list (pl->ctx, &pl->devs);
		C_MEM (pl->descs = calloc (pl->nrofdevs, sizeof(pl->descs[0])));
		for (i=0;i<pl->nrofdevs;i++)
			LOG_ON_LIBUSB_E (libusb_get_device_descriptor(pl->devs[i], &pl->descs[i]));
	}
	time (&pl->devslastchecked);
	return pl->nrofdevs;
}
Example #28
0
QVector<CameraInfo> CameraUSB::avaibleCams(const CameraInfo &info)
{
    QVector<CameraInfo> avaibleCams;

    libusb_context *ctx = NULL;
    libusb_device **devs;
    ssize_t cnt;

    int vendorId = info.getParam("vendorId").toString().toInt(0, 16);
    int productId = info.getParam("productId").toString().toInt(0, 16);

    // create context
    if(libusb_init(&ctx) != LIBUSB_SUCCESS)
        return avaibleCams;

    // get list usb device
    cnt = libusb_get_device_list(ctx, &devs);
    for(int i = 0; i < cnt; i++)
    {
        libusb_device_descriptor desc;
        if(libusb_get_device_descriptor(devs[i], &desc)==LIBUSB_SUCCESS)
        {
            if(desc.idVendor==vendorId && desc.idProduct==productId)
            {
                QString addr = QString("%1.%2").arg((int)libusb_get_bus_number(devs[i]))
                                               .arg((int)libusb_get_device_address(devs[i]));
                avaibleCams.append(CameraInfo("DreamCam USB", "USB", addr));
            }
        }
    }
    libusb_free_device_list(devs, 1);

    // destroy usb context
    libusb_exit(ctx);
    return avaibleCams;
}
Example #29
0
static int renumerate(void)
{
	cyusb_device *dev = NULL;
	cyusb_handle *handle = NULL;
	int found = 0;
	int i;
	int r;

	numdev = libusb_get_device_list(NULL, &list);
	if ( numdev < 0 ) {
	   printf("Library: Error in enumerating devices...\n");
	   return -4;
	}

	nid = 0;

	for ( i = 0; i < numdev; ++i ) {
		cyusb_device *tdev = list[i];
		if ( device_is_of_interest(tdev) ) {
		   cydev[nid].dev = tdev;
		   r = libusb_open(tdev, &cydev[nid].handle);
		   if ( r ) {
		      printf("Error in opening device\n");
		      return -5;
		   }
		   else handle = cydev[nid].handle;
		   cydev[nid].vid     = cyusb_getvendor(handle);
		   cydev[nid].pid     = cyusb_getproduct(handle);
		   cydev[nid].is_open = 1;
		   cydev[nid].busnum  = cyusb_get_busnumber(handle);
		   cydev[nid].devaddr = cyusb_get_devaddr(handle);
		   ++nid;
		}
	}
	return nid;
}
Example #30
0
/* Iterate over all matching DFU capable devices within system */
static int iterate_dfu_devices(libusb_context *ctx, struct dfu_if *dif,
                               int (*action)(struct libusb_device *dev, void *user), void *user)
{
    libusb_device **list;
    ssize_t num_devs, i;

    num_devs = libusb_get_device_list(ctx, &list);
    for (i = 0; i < num_devs; ++i) {
        int retval;
        struct libusb_device_descriptor desc;
        struct libusb_device *dev = list[i];

        if (dif && (dif->flags & DFU_IFF_DEVNUM) &&
                (libusb_get_bus_number(dev) != dif->bus ||
                 libusb_get_device_address(dev) != dif->devnum))
            continue;
        if (libusb_get_device_descriptor(dev, &desc))
            continue;
        if (dif && (dif->flags & DFU_IFF_VENDOR) &&
                desc.idVendor != dif->vendor)
            continue;
        if (dif && (dif->flags & DFU_IFF_PRODUCT) &&
                desc.idProduct != dif->product)
            continue;
        if (!count_dfu_interfaces(dev))
            continue;

        retval = action(dev, user);
        if (retval) {
            libusb_free_device_list(list, 0);
            return retval;
        }
    }
    libusb_free_device_list(list, 0);
    return 0;
}