summaryrefslogtreecommitdiffstats
path: root/packaging/android/patches/libusb-android.patch
blob: bb98743b83a178870a2d24e3e446b5681bbca1d2 (plain) (blame)
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
94
diff -ur libusb-1.0.19.orig/libusb/libusb.h libusb-1.0.19/libusb/libusb.h
--- libusb-1.0.19.orig/libusb/libusb.h	2014-06-13 20:31:35.000000000 +0200
+++ libusb-1.0.19/libusb/libusb.h	2015-08-20 22:26:15.851840655 +0200
@@ -1991,6 +1991,14 @@
 void LIBUSB_CALL libusb_hotplug_deregister_callback(libusb_context *ctx,
 						libusb_hotplug_callback_handle handle);
 
+#ifdef __ANDROID__
+typedef int (*libusb_android_open_callback_func)(uint16_t idVendor, uint16_t idProduct);
+/* Make the darn thing ifdef'able */
+#define libusb_android_open_callback_func libusb_android_open_callback_func
+
+void libusb_set_android_open_callback(libusb_android_open_callback_func aocf);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff -ur libusb-1.0.19.orig/libusb/os/linux_usbfs.c libusb-1.0.19/libusb/os/linux_usbfs.c
--- libusb-1.0.19.orig/libusb/os/linux_usbfs.c	2014-06-13 20:31:35.000000000 +0200
+++ libusb-1.0.19/libusb/os/linux_usbfs.c	2015-08-20 22:24:26.841479417 +0200
@@ -179,6 +179,14 @@
 	int iso_packet_offset;
 };
 
+#ifdef __ANDROID__
+static libusb_android_open_callback_func _android_open_callback = NULL;
+
+void libusb_set_android_open_callback(libusb_android_open_callback_func aocf) {
+	_android_open_callback = aocf;
+}
+#endif
+
 static int _get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent)
 {
 	struct libusb_context *ctx = DEVICE_CTX(dev);
@@ -186,14 +194,25 @@
 	int fd;
 	int delay = 10000;
 
+#ifndef __ANDROID__
 	if (usbdev_names)
 		snprintf(path, PATH_MAX, "%s/usbdev%d.%d",
 			usbfs_path, dev->bus_number, dev->device_address);
 	else
 		snprintf(path, PATH_MAX, "%s/%03d/%03d",
 			usbfs_path, dev->bus_number, dev->device_address);
+#endif
 
+#ifdef __ANDROID__
+	if (_android_open_callback) {
+		fd = _android_open_callback(dev->device_descriptor.idVendor, dev->device_descriptor.idProduct);
+	} else {
+		usbi_err(ctx, "_android_open_callback not set");
+		return LIBUSB_ERROR_OTHER;
+	}
+#else
 	fd = open(path, mode);
+#endif
 	if (fd != -1)
 		return fd; /* Success */
 
@@ -369,11 +388,13 @@
 	struct stat statbuf;
 	int r;
 
+#ifndef __ANDROID__
 	usbfs_path = find_usbfs_path();
 	if (!usbfs_path) {
 		usbi_err(ctx, "could not find usbfs");
 		return LIBUSB_ERROR_OTHER;
 	}
+#endif
 
 	if (monotonic_clkid == -1)
 		monotonic_clkid = find_monotonic_clock();
@@ -469,6 +490,8 @@
 {
 #if defined(USE_UDEV)
 	return linux_udev_start_event_monitor();
+#elif __ANDROID__
+	return LIBUSB_SUCCESS;
 #else
 	return linux_netlink_start_event_monitor();
 #endif
@@ -478,6 +501,8 @@
 {
 #if defined(USE_UDEV)
 	return linux_udev_stop_event_monitor();
+#elif __ANDROID__
+	return LIBUSB_SUCCESS;
 #else
 	return linux_netlink_stop_event_monitor();
 #endif