Ejemplo n.º 1
0
static IUDEVICE*
udevman_get_udevice_by_addr(IUDEVMAN * idevman, int bus_number, int dev_number)
{
	IUDEVICE * pdev;

	idevman->rewind (idevman);
	while (idevman->has_next (idevman))
	{
		pdev = idevman->get_next (idevman);
		if (pdev->get_bus_number(pdev) == bus_number && 
			pdev->get_dev_number(pdev) == dev_number)
		{
			idevman->loading_unlock(idevman);
			return pdev;
		}
	}

	printf("udevman_get_udevice_by_addr: bus:%d dev:%d ERROR!!\n", 
		bus_number, dev_number);
	return NULL;
}
Ejemplo n.º 2
0
static IUDEVICE*
udevman_get_udevice_by_addr(IUDEVMAN * idevman, int bus_number, int dev_number)
{
	IUDEVICE * pdev;

	idevman->loading_lock(idevman);
	idevman->rewind (idevman);
	while (idevman->has_next (idevman))
	{
		pdev = idevman->get_next (idevman);
		if (pdev->get_bus_number(pdev) == bus_number && 
			pdev->get_dev_number(pdev) == dev_number)
		{
			idevman->loading_unlock(idevman);
			return pdev;
		}
	}
	idevman->loading_unlock(idevman);
	LLOGLN(libusb_debug, ("%s: bus:%d dev:%d not exist in udevman", 
		__func__, bus_number, dev_number));
	return NULL;
}
Ejemplo n.º 3
0
static int
udevman_register_udevice(IUDEVMAN* idevman, int bus_number, int dev_number, 
	int UsbDevice, 
	uint16 idVendor, 
	uint16 idProduct, 
	int flag)
{
	UDEVMAN * udevman = (UDEVMAN *) idevman;
	IUDEVICE * pdev = NULL;
	IUDEVICE ** devArray;
	int i, num, addnum = 0;
	
	pdev = (IUDEVICE *)udevman_get_udevice_by_addr(idevman, bus_number, dev_number);
	if (pdev != NULL)
		return 0;
	
	if (flag == UDEVMAN_FLAG_ADD_BY_ADDR)
	{
		pdev = udev_new_by_addr(bus_number, dev_number);
		if (pdev == NULL)
			return 0;

		pdev->set_UsbDevice(pdev, UsbDevice);
		idevman->loading_lock(idevman);
		if (udevman->head == NULL)
		{
			/* linked list is empty */
			udevman->head = pdev;
			udevman->tail = pdev;
		}
		else
		{
			/* append device to the end of the linked list */
			udevman->tail->set_p_next(udevman->tail, pdev);
			pdev->set_p_prev(pdev, udevman->tail);
			udevman->tail = pdev;
		}
		udevman->device_num += 1;
		idevman->loading_unlock(idevman);
	}
	else if (flag == UDEVMAN_FLAG_ADD_BY_VID_PID)
	{
		addnum = 0;
		/* register all device that match pid vid */
		num = udev_new_by_id(idVendor, idProduct, &devArray);
		for (i = 0; i < num; i++)
		{
			pdev = devArray[i];
			if (udevman_get_udevice_by_addr(idevman, 
					pdev->get_bus_number(pdev), 
					pdev->get_dev_number(pdev)) 
				!= NULL)
			{
				zfree(pdev);
				continue;
			}

			pdev->set_UsbDevice(pdev, UsbDevice);
			idevman->loading_lock(idevman);
			if (udevman->head == NULL)
			{
				/* linked list is empty */
				udevman->head = pdev;
				udevman->tail = pdev;
			}
			else
			{
				/* append device to the end of the linked list */
				udevman->tail->set_p_next(udevman->tail, pdev);
				pdev->set_p_prev(pdev, udevman->tail);
				udevman->tail = pdev;
			}
			udevman->device_num += 1;
			idevman->loading_unlock(idevman);
			addnum++;
		}
		zfree(devArray);
		return addnum;
	}
	else
	{
		printf("udevman_register_udevice: function error!!");
		return 0;
	}
	return 1;
}