예제 #1
0
static int run_spec(int i, xusb_filter_t filter, char *devpath, int timeout)
{
	const struct xusb_spec	*s = &known_devices[i].spec;
	int			interface_num = known_devices[i].interface_num;
	struct xlist_node	*xlist;
	struct xlist_node	*curr;
	struct xusb_device	*xusb_device;
	int			success = 1;

	if (!s->name)
		return 0;
	xlist = xusb_find_byproduct(s, 1, filter, devpath);
	if (!xlist_length(xlist))
		return 1;
	INFO("total %zd devices of type %s\n", xlist_length(xlist), s->name);
	for (curr = xlist_shift(xlist); curr; curr = xlist_shift(xlist)) {
		struct xusb_iface *xusb_iface;
		int ret;

		xusb_device = curr->data;
		xusb_showinfo(xusb_device);
		INFO("Testing interface %d\n", interface_num);
		ret = xusb_claim(xusb_device, interface_num, &xusb_iface);
		if (ret == 0) {
			ret = test_device(xusb_iface, timeout);
			if (ret < 0)
				success = 0;
		}
		xusb_destroy(xusb_device);
	}
	xlist_destroy(xlist, xusb_destructor);
	return success;
}
예제 #2
0
static int run_spec(int i, xusb_filter_t filter, char *devpath)
{
	struct xusb_iface_description *desc = &test_specs[i];
	struct xusb_spec	*s = &desc->spec;
	struct xlist_node	*xlist;
	struct xlist_node	*curr;
	int interface_num = desc->interface_num;
	int num_devs;

	if (!s->name)
		return 0;
	xlist = xusb_find_byproduct(s, 1, filter, devpath);
	num_devs = (xlist) ? xlist_length(xlist) : 0;
	INFO("total %d devices of type %s (interface=%d)\n",
		num_devs, s->name, interface_num);
	for (curr = xlist_shift(xlist); curr; curr = xlist_shift(xlist)) {
		struct xusb_device	*xusb_device;
		struct xusb_iface	*iface;
                int ret;

		xusb_device = curr->data;
                ret = xusb_claim(xusb_device, interface_num, &iface);
                if (ret < 0) {
                        ERR("%s: xusb_claim() failed (ret = %d)\n",
                                xusb_devpath(xusb_device), ret);
                        continue;
                }
		xusb_showinfo(xusb_device);
                xusb_release(iface);
	}
	xlist_destroy(xlist, xusb_destructor);
	return 1;
}
예제 #3
0
struct xusb *xusb_open_one(const struct xusb_spec *specs, int numspecs, xusb_filter_t filterfunc, void *data)
{
	struct xlist_node	*xusb_list;
	struct xlist_node	*curr;
	int			num;
	struct xusb		*xusb = NULL;

	xusb_list = xusb_find_byproduct(specs, numspecs, filterfunc, data);
	num = xlist_length(xusb_list);
	DBG("total %d devices\n", num);
	switch(num) {
	case 0:
		ERR("No matching device.\n");
		break;
	case 1:
		curr = xlist_shift(xusb_list);
		xusb = curr->data;
		xlist_destroy(curr, NULL);
		xlist_destroy(xusb_list, NULL);
		xusb_claim_interface(xusb);
		xusb_showinfo(xusb);
		break;
	default:
		ERR("Too many devices (%d). Aborting.\n", num);
		break;
	}
	return xusb;
}
예제 #4
0
struct xusb *xusb_find_bypath(const struct xusb_spec *specs, int numspecs, const char *path)
{
	struct xlist_node	*xlist;
	struct xlist_node	*head;
	struct xusb		*xusb;

	xlist = xusb_find_byproduct(specs, numspecs, xusb_filter_bypath, (void *)path);
	head = xlist_shift(xlist);
	if (!head)
		return NULL;
	if (! xlist_empty(xlist)) {
		ERR("Too many matches (extra %zd) to '%s'\n", xlist_length(xlist), path);
		return NULL;
	}
	xusb = head->data;
	xlist_destroy(xlist, NULL);
	return xusb;
}