YK_KEY *yk_open_first_key(void)
{
- YK_KEY *yk = _ykusb_open_device(YUBICO_VID, YUBIKEY_PID);
- int rc = yk_errno;
+ int pids[] = {YUBIKEY_PID, NEO_OTP_PID, NEO_OTP_CCID_PID};
- if(!yk) {
- yk = _ykusb_open_device(YUBICO_VID, YUBIKEY_NEO_PID);
- rc = yk_errno;
- }
+ YK_KEY *yk = _ykusb_open_device(YUBICO_VID, pids, sizeof(pids));
+ int rc = yk_errno;
if (yk) {
rc = 0;
int _ykusb_start(void);
int _ykusb_stop(void);
-void * _ykusb_open_device(int vendor_id, int product_id);
+void * _ykusb_open_device(int vendor_id, int *product_ids, size_t pids_len);
int _ykusb_close_device(void *);
int _ykusb_read(void *dev, int report_type, int report_number,
return 0;
}
-void *_ykusb_open_device(int vendor_id, int product_id)
+void *_ykusb_open_device(int vendor_id, int *product_ids, size_t pids_len)
{
libusb_device *dev;
libusb_device_handle *h = NULL;
if (ykl_errno != 0)
goto done;
- if (desc.idVendor == vendor_id && desc.idProduct == product_id) {
+ if (desc.idVendor == vendor_id) {
+ size_t j;
+ for(j = 0; j < pids_len; j++) {
+ if (desc.idProduct == product_ids[j]) {
+ break;
+ }
+ }
+ if (j == pids_len) {
+ goto done;
+ }
+
rc = YK_EUSBERR;
ykl_errno = libusb_open(dev, &h);
if (ykl_errno != 0)
return 1;
}
-void *_ykusb_open_device(int vendor_id, int product_id)
+void *_ykusb_open_device(int vendor_id, int *product_ids, size_t pids_len)
{
struct usb_bus *bus;
struct usb_device *dev;
for (bus = usb_get_busses(); bus; bus = bus->next) {
rc = YK_ENOKEY;
for (dev = bus->devices; dev; dev = dev->next)
- if (dev->descriptor.idVendor == vendor_id
- && dev->descriptor.idProduct == product_id) {
+ if (dev->descriptor.idVendor == vendor_id) {
+ size_t j;
+ for (j = 0; j < pids_len; j++) {
+ if (dev->descriptor.idProduct == prduct_ids[j]) {
+ break;
+ }
+ }
+ if(j == pids_len) {
+ goto done;
+ }
+
rc = YK_EUSBERR;
h = usb_open(dev);
#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP
CFArrayAppendValue( ( CFMutableArrayRef ) context, value );
}
-void *_ykusb_open_device(int vendor_id, int product_id)
+void *_ykusb_open_device(int vendor_id, int *product_ids, size_t pids_len)
{
void *yk = NULL;
- CFDictionaryRef dict;
- CFStringRef keys[2];
- CFStringRef values[2];
int rc = YK_ENOKEY;
+ size_t i;
+
+ CFMutableArrayRef matches = CFArrayCreateMutable( kCFAllocatorDefault, pids_len, kCFTypeArrayCallBacks );
+
CFNumberRef vendorID = CFNumberCreate( kCFAllocatorDefault, kCFNumberIntType, &vendor_id );
- CFNumberRef productID = CFNumberCreate( kCFAllocatorDefault, kCFNumberIntType, &product_id );
+ for(i = 0; i < pids_len; i++) {
+ CFDictionaryRef dict;
+ CFStringRef keys[2];
+ CFStringRef values[2];
+
+ CFNumberRef productID = CFNumberCreate( kCFAllocatorDefault, kCFNumberIntType, &product_ids[i] );
- keys[0] = CFSTR( kIOHIDVendorIDKey ); values[0] = (void *) vendorID;
- keys[1] = CFSTR( kIOHIDProductIDKey ); values[1] = (void *) productID;
+ keys[0] = CFSTR( kIOHIDVendorIDKey ); values[0] = (void *) vendorID;
+ keys[1] = CFSTR( kIOHIDProductIDKey ); values[1] = (void *) productID;
- dict = CFDictionaryCreate( kCFAllocatorDefault, (const void **) &keys, (const void **) &values, 1, NULL, NULL);
+ dict = CFDictionaryCreate( kCFAllocatorDefault, (const void **) &keys, (const void **) &values, 1, NULL, NULL);
+ CFArrayAppendValue( matches, dict );
+
+ CFRelease( productID );
+ CFRelease( dict );
+ }
- IOHIDManagerSetDeviceMatching( ykosxManager, dict );
+ IOHIDManagerSetDeviceMatchingMultiple( ykosxManager, matches );
CFSetRef devSet = IOHIDManagerCopyDevices( ykosxManager );
IOHIDManagerScheduleWithRunLoop( ykosxManager, CFRunLoopGetCurrent( ), kCFRunLoopDefaultMode );
IOHIDManagerUnscheduleFromRunLoop( ykosxManager, CFRunLoopGetCurrent( ), kCFRunLoopDefaultMode );
+ CFRelease( vendorID );
CFRelease( array );
CFRelease( devSet );
}
- CFRelease( dict );
- CFRelease( vendorID );
- CFRelease( productID );
+ CFRelease( matches );
if (yk) {
_ykusb_IOReturn = IOHIDDeviceOpen( yk, 0L );
return 0;
}
-void * _ykusb_open_device(int vendor_id, int product_id)
+void * _ykusb_open_device(int vendor_id, int *product_ids, size_t pids_len)
{
yk_errno = YK_ENOTYETIMPL;
return NULL;
return 1;
}
-void * _ykusb_open_device(int vendor_id, int product_id)
+void * _ykusb_open_device(int vendor_id, int *product_ids, size_t pids_len)
{
HDEVINFO hi;
SP_DEVICE_INTERFACE_DATA di;
HIDD_ATTRIBUTES devInfo;
if (HidD_GetAttributes(m_handle, &devInfo)) {
- if (devInfo.VendorID == vendor_id && devInfo.ProductID == product_id) {
+ if (devInfo.VendorID == vendor_id) {
+ size_t j;
+ for (j = 0; j < pids_len; j++) {
+ if (devInfo.ProductID == product_ids[j]) {
+ break;
+ }
+ }
+ if (j == pids_len) {
+ goto done;
+ }
+
ret_handle = m_handle;
free (pi);
goto done;