11 static int ncusb_match_string(libusb_device_handle
*dev
, int index
, const char* string
)
13 unsigned char tmp
[256];
14 libusb_get_string_descriptor_ascii(dev
, index
, tmp
, 256);
16 return 1; /* NULL matches anything */
17 return (strcmp(string
, (char*) tmp
)==0);
21 struct libusb_device_handle
*ncusb_find_and_open(struct libusb_context
*ctx
,
22 int vendor
, int product
,
23 const char *vendor_name
,
24 const char *product_name
,
27 libusb_device_handle
*found
= NULL
;
29 ssize_t cnt
= libusb_get_device_list(ctx
, &list
);
36 for(i
= 0; i
< cnt
; i
++) {
38 libusb_device
*device
= list
[i
];
39 struct libusb_device_descriptor desc
;
40 libusb_device_handle
*handle
;
41 err
= libusb_open(device
, &handle
);
45 int r
= libusb_get_device_descriptor( device
, &desc
);
51 if ( desc
.idVendor
== vendor
&& desc
.idProduct
== product
&&
52 ncusb_match_string(handle
, desc
.iManufacturer
, vendor_name
) &&
53 ncusb_match_string(handle
, desc
.iProduct
, product_name
) &&
54 ncusb_match_string(handle
, desc
.iSerialNumber
, serial
)
64 libusb_free_device_list(list
, 1);
70 void check_handle(libusb_device_handle
**h
, int vid
, int pid
, const char* manuf
, const char* product
, const char* serial
)
75 libusb_set_debug(NULL
, LIBUSB_LOG_LEVEL_WARNING
);
76 *h
= ncusb_find_and_open(NULL
, vid
, pid
, manuf
, product
, serial
);
78 fprintf(stderr
, "No PL2303 USB device %04x:%04x found ;(\n", vid
, pid
);