static LONG HPAddHotPluggable(int i, unsigned long usbAddr) { /* NOTE: The deviceName is an empty string "" until someone implements * the code to get it */ RFAddReader(bundleTracker[i].readerName, PCSCLITE_HP_BASE_PORT + usbAddr, bundleTracker[i].libraryPath, ""); return 1; } /* End of function */
static LONG HPAddHotPluggable(struct usb_device *dev, const char bus_device[], struct _driverTracker *driver) { int i; char deviceName[MAX_DEVICENAME]; Log2(PCSC_LOG_INFO, "Adding USB device: %s", bus_device); snprintf(deviceName, sizeof(deviceName), "usb:%04x/%04x:libusb:%s", dev->descriptor.idVendor, dev->descriptor.idProduct, bus_device); deviceName[sizeof(deviceName) -1] = '\0'; SYS_MutexLock(&usbNotifierMutex); /* find a free entry */ for (i=0; i<PCSCLITE_MAX_READERS_CONTEXTS; i++) { if (readerTracker[i].fullName == NULL) break; } if (i==PCSCLITE_MAX_READERS_CONTEXTS) { Log2(PCSC_LOG_ERROR, "Not enough reader entries. Already found %d readers", i); SYS_MutexUnLock(&usbNotifierMutex); return 0; } strncpy(readerTracker[i].bus_device, bus_device, sizeof(readerTracker[i].bus_device)); readerTracker[i].bus_device[sizeof(readerTracker[i].bus_device) - 1] = '\0'; #ifdef ADD_SERIAL_NUMBER if (dev->descriptor.iSerialNumber) { usb_dev_handle *device; char serialNumber[MAX_READERNAME]; char fullname[MAX_READERNAME]; int ret; device = usb_open(dev); ret = usb_get_string_simple(device, dev->descriptor.iSerialNumber, serialNumber, MAX_READERNAME); usb_close(device); if (ret < 0) { Log2(PCSC_LOG_ERROR, "usb_get_string_simple failed: %s", usb_strerror()); readerTracker[i].fullName = strdup(driver->readerName); } else { snprintf(fullname, sizeof(fullname), "%s (%s)", driver->readerName, serialNumber); readerTracker[i].fullName = strdup(fullname); } } else #endif readerTracker[i].fullName = strdup(driver->readerName); if (RFAddReader(readerTracker[i].fullName, PCSCLITE_HP_BASE_PORT + i, driver->libraryPath, deviceName) == SCARD_S_SUCCESS) readerTracker[i].status = READER_PRESENT; else { readerTracker[i].status = READER_FAILED; (void)CheckForOpenCT(); } SYS_MutexUnLock(&usbNotifierMutex); return 1; } /* End of function */
/* * Scans the hotplug driver directory and looks in the system for * matching devices. * Adds or removes matching readers as necessary. */ LONG HPSearchHotPluggables(void) { HPDriver *drivers = HPDriversGetFromDirectory(PCSCLITE_HP_DROPDIR); if (!drivers) return 1; HPDeviceList devices = NULL; if (HPDriversMatchUSBDevices(drivers, &devices)) return -1; if (HPDriversMatchPCCardDevices(drivers, &devices)) return -1; HPDevice *a; for (a = devices; a; a = a->m_next) { int found = FALSE; HPDevice *b; for (b = sDeviceList; b; b = b->m_next) { if (HPDeviceEquals(a, b)) { found = TRUE; break; } } if (!found) { char deviceName[MAX_DEVICENAME]; /* the format should be "usb:%04x/%04x" but Apple uses the * friendly name instead */ snprintf(deviceName, sizeof(deviceName), "%s", a->m_driver->m_friendlyName); deviceName[sizeof(deviceName)-1] = '\0'; RFAddReader(a->m_driver->m_friendlyName, PCSCLITE_HP_BASE_PORT + a->m_address, a->m_driver->m_libPath, deviceName); } } for (a = sDeviceList; a; a = a->m_next) { int found = FALSE; HPDevice *b; for (b = devices; b; b = b->m_next) { if (HPDeviceEquals(a, b)) { found = TRUE; break; } } if (!found) { RFRemoveReader(a->m_driver->m_friendlyName, PCSCLITE_HP_BASE_PORT + a->m_address); } } HPDeviceListRelease(sDeviceList); sDeviceList = devices; HPDriverVectorRelease(drivers); return 0; }
static void HPAddDevice(struct udev_device *dev, struct udev_device *parent, const char *devpath) { int i; char deviceName[MAX_DEVICENAME]; char fullname[MAX_READERNAME]; struct _driverTracker *driver, *classdriver; const char *sSerialNumber = NULL, *sInterfaceName = NULL; LONG ret; int bInterfaceNumber; driver = get_driver(parent, devpath, &classdriver); if (NULL == driver) { /* not a smart card reader */ #ifdef DEBUG_HOTPLUG Log2(PCSC_LOG_DEBUG, "%s is not a supported smart card reader", devpath); #endif return; } Log2(PCSC_LOG_INFO, "Adding USB device: %s", driver->readerName); bInterfaceNumber = atoi(udev_device_get_sysattr_value(dev, "bInterfaceNumber")); (void)snprintf(deviceName, sizeof(deviceName), "usb:%04x/%04x:libudev:%d:%s", driver->manuID, driver->productID, bInterfaceNumber, devpath); deviceName[sizeof(deviceName) -1] = '\0'; (void)pthread_mutex_lock(&usbNotifierMutex); /* find a free entry */ for (i=0; i<PCSCLITE_MAX_READERS_CONTEXTS; i++) { if (NULL == readerTracker[i].fullName) break; } if (PCSCLITE_MAX_READERS_CONTEXTS == i) { Log2(PCSC_LOG_ERROR, "Not enough reader entries. Already found %d readers", i); (void)pthread_mutex_unlock(&usbNotifierMutex); return; } #ifdef ADD_INTERFACE_NAME sInterfaceName = udev_device_get_sysattr_value(dev, "interface"); #endif #ifdef ADD_SERIAL_NUMBER sSerialNumber = udev_device_get_sysattr_value(parent, "serial"); #endif /* name from the Info.plist file */ strlcpy(fullname, driver->readerName, sizeof(fullname)); /* interface name from the device (if any) */ if (sInterfaceName) { strlcat(fullname, " [", sizeof(fullname)); strlcat(fullname, sInterfaceName, sizeof(fullname)); strlcat(fullname, "]", sizeof(fullname)); } /* serial number from the device (if any) */ if (sSerialNumber) { /* only add the serial number if it is not already present in the * interface name */ if (!sInterfaceName || NULL == strstr(sInterfaceName, sSerialNumber)) { strlcat(fullname, " (", sizeof(fullname)); strlcat(fullname, sSerialNumber, sizeof(fullname)); strlcat(fullname, ")", sizeof(fullname)); } } readerTracker[i].fullName = strdup(fullname); readerTracker[i].devpath = strdup(devpath); readerTracker[i].status = READER_PRESENT; readerTracker[i].bInterfaceNumber = bInterfaceNumber; ret = RFAddReader(fullname, PCSCLITE_HP_BASE_PORT + i, driver->libraryPath, deviceName); if ((SCARD_S_SUCCESS != ret) && (SCARD_E_UNKNOWN_READER != ret)) { Log2(PCSC_LOG_ERROR, "Failed adding USB device: %s", driver->readerName); if (classdriver && driver != classdriver) { /* the reader can also be used by the a class driver */ ret = RFAddReader(fullname, PCSCLITE_HP_BASE_PORT + i, classdriver->libraryPath, deviceName); if ((SCARD_S_SUCCESS != ret) && (SCARD_E_UNKNOWN_READER != ret)) { Log2(PCSC_LOG_ERROR, "Failed adding USB device: %s", driver->readerName); readerTracker[i].status = READER_FAILED; (void)CheckForOpenCT(); } } else { readerTracker[i].status = READER_FAILED; (void)CheckForOpenCT(); } } (void)pthread_mutex_unlock(&usbNotifierMutex); } /* HPAddDevice */
/* * Scans the hotplug driver directory and looks in the system for * matching devices. * Adds or removes matching readers as necessary. */ LONG HPSearchHotPluggables(void) { HPDriver *drivers = HPDriversGetFromDirectory(PCSCLITE_HP_DROPDIR); if (!drivers) return 1; HPDeviceList devices = NULL; if (HPDriversMatchUSBDevices(drivers, &devices)) return -1; if (HPDriversMatchPCCardDevices(drivers, &devices)) return -1; HPDevice *a; for (a = devices; a; a = a->m_next) { int found = FALSE; HPDevice *b; for (b = sDeviceList; b; b = b->m_next) { if (HPDeviceEquals(a, b)) { found = TRUE; break; } } if (!found) { char deviceName[MAX_DEVICENAME]; /* the format should be "usb:%04x/%04x:libusb:%s" but we do not * know the libusb string. So it is not possible to differentiate * two identical readers :-( */ snprintf(deviceName, sizeof(deviceName), "usb:%04x/%04x", (unsigned int)a->m_driver->m_vendorId, (unsigned int)a->m_driver->m_productId); deviceName[sizeof(deviceName)-1] = '\0'; RFAddReader(a->m_driver->m_friendlyName, PCSCLITE_HP_BASE_PORT + a->m_address, a->m_driver->m_libPath, deviceName); } } for (a = sDeviceList; a; a = a->m_next) { int found = FALSE; HPDevice *b; for (b = devices; b; b = b->m_next) { if (HPDeviceEquals(a, b)) { found = TRUE; break; } } if (!found) { RFRemoveReader(a->m_driver->m_friendlyName, PCSCLITE_HP_BASE_PORT + a->m_address); } } HPDeviceListRelease(sDeviceList); sDeviceList = devices; HPDriverVectorRelease(drivers); return 0; }