summarylogtreecommitdiffstats
path: root/0001-Use-usb_bulk_-read-write-instead-of-homemade-handler.patch
blob: 26fa5be49dd17066bd50f0dfc9aca942f4b43e9b (plain)
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
95
From c4586e80dc6f1a92513b466d8d43748ec733b7fd Mon Sep 17 00:00:00 2001
From: Jonathan Dieter <jdieter@lesbg.com>
Date: Mon, 2 Apr 2012 14:35:09 +0300
Subject: [PATCH 1/3] Use usb_bulk_[read|write] instead of homemade handlers. 
 This allows us to run against libusb-compat as well as
 the old libusb.

Signed-off-by: Jonathan Dieter <jdieter@lesbg.com>
---
 src/host/usb-linux.c |   42 ++++++------------------------------------
 1 file changed, 6 insertions(+), 36 deletions(-)

diff --git a/src/host/usb-linux.c b/src/host/usb-linux.c
index 55cc0b5..65f94c4 100644
--- a/src/host/usb-linux.c
+++ b/src/host/usb-linux.c
@@ -49,20 +49,8 @@
 
 #define USBDEVFS_IOCTL_TIMEOUT  2000
 
-struct myusb_dev_handle {
-	int fd;
-
-	// other stuff here
-};
-
 typedef struct {
-	union {
-		usb_dev_handle *handle;
-
-		/* XXX cheezy hack to let us get to the file descriptor hidden in the libusb handle */
-		struct myusb_dev_handle *myhandle;
-	};
-
+	usb_dev_handle *handle;
 	novacom_usbll_handle_t usbll_handle;
 
 	bool shutdown;
@@ -218,7 +206,7 @@ static novacom_usb_handle_t *novacom_usb_open( void )
 					if (!handle) continue;
 
 #if USB_SCAN_TRACE
-					log_printf(LOG_SPEW, "opened usb handle: fd %d\n", ((struct myusb_dev_handle *)handle)->fd);
+					log_printf(LOG_SPEW, "opened usb handle: devnum %d\n", dev->devnum);
 #endif
 
 					int eps[2];
@@ -281,17 +269,10 @@ int novacom_usb_transport_init(void)
 static int novacom_usb_read(novacom_usb_handle_t *handle, void *buf, size_t len)
 {
 //	TRACEF("handle %p, buf %p, len %d, timeout %d\n", handle, buf, len, timeout);
-//	TRACEF("fd %d\n", handle->myhandle->fd);
-
-	struct usbdevfs_bulktransfer bulktransfer;
-
-	bulktransfer.ep = handle->rxep;
-	bulktransfer.len = len;
-	bulktransfer.timeout = handle->rx_timeout;
-	bulktransfer.data = buf;
 
 	int rc;
-	rc = ioctl(handle->myhandle->fd, USBDEVFS_BULK, &bulktransfer);
+
+	rc = usb_bulk_read(handle->handle, handle->rxep, buf, len, handle->rx_timeout);
 	if (rc > 0) { //now check the packet header
 
 		if (novacom_usbll_check_packet_header(buf, rc)) { //bad packet
@@ -303,22 +284,11 @@ static int novacom_usb_read(novacom_usb_handle_t *handle, void *buf, size_t len)
 	return rc;
 }
 
-static int novacom_usb_write(novacom_usb_handle_t *handle, const void *buf, size_t len)
+static int novacom_usb_write(novacom_usb_handle_t *handle, void *buf, size_t len)
 {
 //	TRACEF("handle %p, buf %p, len %d, timeout %d\n", handle, buf, len, timeout);
-//	TRACEF("fd %d\n", handle->myhandle->fd);
-
-	struct usbdevfs_bulktransfer bulktransfer;
 
-	bulktransfer.ep = handle->txep;
-	bulktransfer.len = len;
-	bulktransfer.timeout = handle->tx_timeout;
-	bulktransfer.data = (void *)buf;
-
-	int rc;
-	rc = ioctl(handle->myhandle->fd, USBDEVFS_BULK, &bulktransfer);
-//	TRACEF("rc %d\n", rc);
-	return rc;
+	return usb_bulk_write(handle->handle, handle->txep, buf, len, handle->tx_timeout);	
 }
 
 struct usb_thread_args {
-- 
1.7.10