[Pcsclite-cvs-commit] PCSC/src hotplug_libusb.c,1.18,1.19

sauveron-guest@quantz.debian.org sauveron-guest@quantz.debian.org
Wed, 14 Jan 2004 12:56:42 +0100


Update of /cvsroot/pcsclite/PCSC/src
In directory quantz:/tmp/cvs-serv7474/src

Modified Files:
	hotplug_libusb.c 
Log Message:
Get the device name of the USB device and give it to RFAddReader.

Index: hotplug_libusb.c
===================================================================
RCS file: /cvsroot/pcsclite/PCSC/src/hotplug_libusb.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- hotplug_libusb.c	12 Jan 2004 09:49:17 -0000	1.18
+++ hotplug_libusb.c	14 Jan 2004 11:56:39 -0000	1.19
@@ -321,41 +321,76 @@
 	return 0;
 }
 
+static LONG HPGetDeviceName(LPSTR deviceName, struct usb_device *dev)
+{
+#ifdef __linux__
+#define LINUX_USB_PATH	"/proc/bus/usb"
+
+	struct stat fStatBuf;
+
+	if ((SYS_Stat(LINUX_USB_PATH, &fStatBuf) == 0) && S_ISDIR(fStatBuf.st_mode))
+	{
+		snprintf(deviceName, MAX_DEVICENAME, "%s/%s/%s", LINUX_USB_PATH, dev->bus->dirname, dev->filename);
+	}
+	else
+	{
+		DebugLogA("No USB VFS found");
+		return 1;
+	}
+#else
+#ifdef __FreeBSD__
+	snprintf(deviceName, MAX_DEVICENAME, "%s", dev->filename);
+#else
+	snprintf(deviceName, MAX_DEVICENAME, "%s.00", dev->filename);
+#endif
+#endif
+	DebugLogB("The fullname for this device is: %s", deviceName);
+
+	return 0;
+}
+
 LONG HPAddHotPluggable(struct usb_device *dev, const char bus_device[],
 	struct _driverTracker *driver)
 {
+	LONG rv;
 	int i;
+	char deviceName[MAX_DEVICENAME];
 
 	SYS_MutexLock(&usbNotifierMutex);
 
 	DebugLogB("Adding USB device: %s", bus_device);
 
-	/* find a free entry */
-	for (i=0; i<PCSCLITE_MAX_READERS_CONTEXTS; i++)
-	{
-		if (readerTracker[i].driver == NULL)
-			break;
-	}
-	
-	if (i==PCSCLITE_MAX_READERS_CONTEXTS)
-	{
-		DebugLogB("Not enough reader entries. Already found %d readers", i);
-		return 0;
-	}
+	rv = HPGetDeviceName(deviceName, dev);
 
-	if (RFAddReader(driver->readerName, PCSCLITE_HP_BASE_PORT + i,
-		driver->libraryPath) == SCARD_S_SUCCESS)
-	{
-		strncpy(readerTracker[i].bus_device, bus_device, BUS_DEVICE_STRSIZE);
-		readerTracker[i].bus_device[BUS_DEVICE_STRSIZE - 1] = '\0';
+	if (rv == 0)
+	{	
+		/* find a free entry */
+		for (i=0; i<PCSCLITE_MAX_READERS_CONTEXTS; i++)
+		{
+			if (readerTracker[i].driver == NULL)
+				break;
+		}
+	
+		if (i==PCSCLITE_MAX_READERS_CONTEXTS)
+		{
+			DebugLogB("Not enough reader entries. Already found %d readers", i);
+			return 0;
+		}
 
-		readerTracker[i].status = READER_PRESENT;
-		readerTracker[i].driver = driver;
+		if (RFAddReader(driver->readerName, PCSCLITE_HP_BASE_PORT + i,
+			driver->libraryPath, deviceName) == SCARD_S_SUCCESS)
+		{
+			strncpy(readerTracker[i].bus_device, bus_device, BUS_DEVICE_STRSIZE);
+			readerTracker[i].bus_device[BUS_DEVICE_STRSIZE - 1] = '\0';
+       
+			readerTracker[i].status = READER_PRESENT;
+			readerTracker[i].driver = driver;
+		}
 	}
 
 	SYS_MutexUnLock(&usbNotifierMutex);
 
-	return 1;
+	return rv;
 }	/* End of function */
 
 LONG HPRemoveHotPluggable(int index)