1 | --- io/hpiod/device.cpp.orig 2006-04-28 20:13:31.000000000 -0400 |
---|
2 | +++ io/hpiod/device.cpp 2006-04-29 17:14:17.000000000 -0400 |
---|
3 | @@ -99,14 +99,60 @@ |
---|
4 | |
---|
5 | int Device::Write(int fd, const void *buf, int size) |
---|
6 | { |
---|
7 | - syslog(LOG_ERR, "error Write: unimplemented (osx) %s %s %d\n", URI, __FILE__, __LINE__); |
---|
8 | - return -1; |
---|
9 | + int r, ep; |
---|
10 | + |
---|
11 | + if (FD[fd].pHD == NULL) |
---|
12 | + { |
---|
13 | + syslog(LOG_ERR, "invalid Device::Write state (osx): %s %s %d\n", URI,__FILE__, __LINE__); |
---|
14 | + return 0; |
---|
15 | + } |
---|
16 | + |
---|
17 | + ep = GetOutEP(dev, FD[fd].Config, FD[fd].Interface, FD[fd].AltSetting, USB_ENDPOINT_TYPE_BULK); |
---|
18 | + |
---|
19 | + if (ep < 0) |
---|
20 | + { |
---|
21 | + syslog(LOG_ERR, "invalid bulk out endpoint (osx) %s %s %d\n", URI, __FILE__, __LINE__); |
---|
22 | + return 0; |
---|
23 | + } |
---|
24 | + |
---|
25 | + r = usb_bulk_write(FD[fd].pHD, ep, (char *)buf, size, LIBUSB_TIMEOUT); |
---|
26 | + |
---|
27 | + if (r < 0) |
---|
28 | + { |
---|
29 | + syslog(LOG_ERR, "error Write (osx) %s: %s %d\n", URI, __FILE__, __LINE__); |
---|
30 | + return r; |
---|
31 | + } |
---|
32 | + |
---|
33 | + return r; |
---|
34 | } |
---|
35 | |
---|
36 | int Device::Read(int fd, void *buf, int size, int usec) |
---|
37 | { |
---|
38 | - syslog(LOG_ERR, "error Read: unimplemented (osx) %s %s %d\n", URI, __FILE__, __LINE__); |
---|
39 | - return -2; |
---|
40 | + int r, ep; |
---|
41 | + |
---|
42 | + if (FD[fd].pHD == NULL) |
---|
43 | + { |
---|
44 | + syslog(LOG_ERR, "invalid Device::Read state (osx): %s %s %d\n", URI,__FILE__, __LINE__); |
---|
45 | + return 0; |
---|
46 | + } |
---|
47 | + |
---|
48 | + ep = GetInEP(dev, FD[fd].Config, FD[fd].Interface, FD[fd].AltSetting, USB_ENDPOINT_TYPE_BULK); |
---|
49 | + |
---|
50 | + if (ep < 0) |
---|
51 | + { |
---|
52 | + syslog(LOG_ERR, "invalid bulk in endpoint (osx) %s %s %d\n", URI, __FILE__, __LINE__); |
---|
53 | + return 0; |
---|
54 | + } |
---|
55 | + |
---|
56 | + r = usb_bulk_read(FD[fd].pHD, ep, (char *)buf, size, usec/1000); |
---|
57 | + |
---|
58 | + if (r < 0) |
---|
59 | + { |
---|
60 | + syslog(LOG_ERR, "error Read bulk (osx) %s: %s %d\n", URI, __FILE__, __LINE__); |
---|
61 | + return r; |
---|
62 | + } |
---|
63 | + |
---|
64 | + return r; |
---|
65 | } |
---|
66 | |
---|
67 | #else |
---|
68 | @@ -118,7 +164,7 @@ |
---|
69 | */ |
---|
70 | int Device::Write(int fd, const void *buf, int size) |
---|
71 | { |
---|
72 | - int len=0, r, ep; |
---|
73 | + int len=-EIO, r, ep; |
---|
74 | |
---|
75 | if (FD[fd].pHD == NULL) |
---|
76 | { |
---|
77 | @@ -145,10 +191,8 @@ |
---|
78 | FD[fd].urb_write.number_of_packets = 0; |
---|
79 | |
---|
80 | if (usb_submit_urb_ex(FD[fd].pHD, &FD[fd].urb_write)) |
---|
81 | - { |
---|
82 | - syslog(LOG_ERR, "invalid submit_urb %s: %m %s %d\n", URI, __FILE__, __LINE__); |
---|
83 | goto bugout; |
---|
84 | - } |
---|
85 | + |
---|
86 | FD[fd].urb_write_active = 1; |
---|
87 | } |
---|
88 | |
---|
89 | @@ -177,7 +221,7 @@ |
---|
90 | int Device::Read(int fd, void *buf, int size, int usec) |
---|
91 | { |
---|
92 | struct timeval t1, t2; |
---|
93 | - int len=0, ep; |
---|
94 | + int len=-EIO, ep; |
---|
95 | int r, total_usec, tmo_usec=usec; |
---|
96 | |
---|
97 | if (FD[fd].pHD == NULL) |
---|
98 | @@ -210,21 +254,17 @@ |
---|
99 | FD[fd].urb_read.number_of_packets = 0; |
---|
100 | |
---|
101 | if (usb_submit_urb_ex(FD[fd].pHD, &FD[fd].urb_read)) |
---|
102 | - { |
---|
103 | - syslog(LOG_ERR, "invalid submit_urb %s: %m %s %d\n", URI, __FILE__, __LINE__); |
---|
104 | goto bugout; |
---|
105 | - } |
---|
106 | |
---|
107 | r = usb_wait_urb_ex(FD[fd].pHD, &FD[fd].urb_read, tmo_usec/1000); |
---|
108 | if (r == -ETIMEDOUT) |
---|
109 | { |
---|
110 | - len = -1; |
---|
111 | + len = -ETIMEDOUT; |
---|
112 | usb_reap_urb_ex(FD[fd].pHD, &FD[fd].urb_read); /* remove urb */ |
---|
113 | goto bugout; |
---|
114 | } |
---|
115 | if (r < 0) |
---|
116 | { |
---|
117 | - len = -2; |
---|
118 | syslog(LOG_ERR, "invalid urb read completion %s: %m %s %d\n", URI, __FILE__, __LINE__); |
---|
119 | usb_reap_urb_ex(FD[fd].pHD, &FD[fd].urb_read); |
---|
120 | goto bugout; |
---|
121 | @@ -239,7 +279,7 @@ |
---|
122 | total_usec += (t2.tv_usec > t1.tv_usec) ? t2.tv_usec - t1.tv_usec : t1.tv_usec - t2.tv_usec; |
---|
123 | if (total_usec > usec) |
---|
124 | { |
---|
125 | - len = -1; /* timeout */ |
---|
126 | + len = -ETIMEDOUT; /* timeout */ |
---|
127 | break; |
---|
128 | } |
---|
129 | tmo_usec = usec - total_usec; /* decrease timeout */ |
---|
130 | @@ -633,7 +673,7 @@ |
---|
131 | pSys->GeneralizeModel(sz, gen, sizeof(gen)); |
---|
132 | |
---|
133 | pSys->GetURIModel(uri, uriModel, sizeof(uriModel)); |
---|
134 | - if (strcmp(uriModel, gen) != 0) |
---|
135 | + if (strcasecmp(uriModel, gen) != 0) |
---|
136 | goto bugout; |
---|
137 | |
---|
138 | if (usb_get_string_simple(hd, dev->descriptor.iSerialNumber, sz, sizeof(sz)) < 0) |
---|
139 | @@ -846,8 +886,6 @@ |
---|
140 | |
---|
141 | int Device::Open(char *sendBuf, int *result) |
---|
142 | { |
---|
143 | - char uriModel[128]; |
---|
144 | - char model[128]; |
---|
145 | int len=0; |
---|
146 | int config, interface, altset; |
---|
147 | |
---|
148 | @@ -910,16 +948,6 @@ |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | - /* Make sure uri model still matches device id model. */ |
---|
153 | - pSys->GetURIModel(URI, uriModel, sizeof(uriModel)); |
---|
154 | - pSys->GetModel(ID, model, sizeof(model)); |
---|
155 | - if (strcmp(uriModel, model) != 0) |
---|
156 | - { |
---|
157 | - *result = R_INVALID_DEVICE_NODE; /* found different device plugged in */ |
---|
158 | - syslog(LOG_ERR, "invalid model %s != %s Device::Open %s %d\n", uriModel, model, __FILE__, __LINE__); |
---|
159 | - goto blackout; |
---|
160 | - } |
---|
161 | - |
---|
162 | blackout: |
---|
163 | pthread_mutex_unlock(&mutex); |
---|
164 | |
---|