Package: acr38 / 1.7.11-1

0003-Also-check-usbfs-under-dev.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
From 9c49e1cca7856a47624c0f7c8b171541b0cbc35d Mon Sep 17 00:00:00 2001
From: Laurent Bigonville <bigon@bigon.be>
Date: Tue, 12 May 2009 16:17:31 +0200
Subject: [PATCH 3/5] Also check usbfs under /dev

---
 src/driver/usblinux.c |   52 +++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/src/driver/usblinux.c b/src/driver/usblinux.c
index 5e72a98..e6c4456 100644
--- a/src/driver/usblinux.c
+++ b/src/driver/usblinux.c
@@ -17,23 +17,33 @@
 #include <usblinux.h>
 #include "config.h"
 
-#define PCSCLITE_USB_PATH      "/proc/bus/usb"
-
+#define PCSCLITE_USB_PATH      "/proc/bus/usb"
+#define UDEV_USB_PATH      "/dev/bus/usb"
+
+static int check_usb_vfs(const char *dirname);
 
 int open_linux_usb_dev ( unsigned int manuID, unsigned int prodID, unsigned int lunNum )
 {
 
 	DIR                         *dir, *dirB;
 	struct dirent               *entry, *entryB;
-	char                         dirpath[150];
+	char                         dirpath[150];
+	char                         dirbase[150];
 	unsigned int				 skip = lunNum;
 	struct usb_device_descriptor usbDescriptor;
 
-	dir = opendir(PCSCLITE_USB_PATH);
 
-	if (!dir)
-	{
-		printf("Cannot Open USB Path Directory\n");
+	if (check_usb_vfs(UDEV_USB_PATH)) {
+		dir = opendir(UDEV_USB_PATH);
+		strcpy(dirbase, UDEV_USB_PATH);
+	}
+	else if (check_usb_vfs(PCSCLITE_USB_PATH)) {
+		dir = opendir(PCSCLITE_USB_PATH);
+		strcpy(dirbase, PCSCLITE_USB_PATH);
+	}
+	else {
+		printf("Cannot Open USB Path Directory\n");
+		return -1;
 	}
   
   
@@ -48,7 +58,7 @@ int open_linux_usb_dev ( unsigned int manuID, unsigned int prodID, unsigned int
 			continue;
 		}
     
-		sprintf(dirpath, "%s/%s", PCSCLITE_USB_PATH, entry->d_name);
+		sprintf(dirpath, "%s/%s", dirbase, entry->d_name);
 		
 		dirB = opendir(dirpath);
 		
@@ -175,3 +185,29 @@ int bulk_linux_usb_dev( int fd, int pipeNum, unsigned char *buffer,
 
   return ret;  
 }
+
+/* Code from libusb to detect if usbfs path is valid */
+static int check_usb_vfs(const char *dirname)
+{
+  DIR *dir;
+  struct dirent *entry;
+  int found = 0;
+
+  dir = opendir(dirname);
+  if (!dir)
+    return 0;
+
+  while ((entry = readdir(dir)) != NULL) {
+    /* Skip anything starting with a . */
+    if (entry->d_name[0] == '.')
+      continue;
+
+    /* We assume if we find any files that it must be the right place */
+    found = 1;
+    break;
+  }
+
+  closedir(dir);
+
+  return found;
+}