aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinus Walleij <triad@df.lth.se>2007-09-28 19:21:54 +0000
committerLinus Walleij <triad@df.lth.se>2007-09-28 19:21:54 +0000
commit8e3af0074bac70b91d090fe7e845ae93d3ab9f65 (patch)
treea6ac32cc96aa8293b5f39f02880e4a21e0679aa5 /src
parent29f03bafd5b1664f4caae3db0c9a2dae7b157b35 (diff)
downloadlibmtp-8e3af0074bac70b91d090fe7e845ae93d3ab9f65.tar.gz
Introduce a new device flag for the Creative ZEN 8GB
Diffstat (limited to 'src')
-rw-r--r--src/libusb-glue.c31
-rw-r--r--src/libusb-glue.h12
2 files changed, 29 insertions, 14 deletions
diff --git a/src/libusb-glue.c b/src/libusb-glue.c
index c3fae58..95beb73 100644
--- a/src/libusb-glue.c
+++ b/src/libusb-glue.c
@@ -97,7 +97,7 @@ static const LIBMTP_device_entry_t mtp_device_table[] = {
{ "Creative ZEN V Plus", 0x041e, 0x4152, DEVICE_FLAG_NONE },
{ "Creative ZEN Vision W", 0x041e, 0x4153, DEVICE_FLAG_NONE },
// Reported by Paul Kurczaba <paul@kurczaba.com>
- { "Creative ZEN 8GB", 0x041e, 0x4157, DEVICE_FLAG_NONE },
+ { "Creative ZEN 8GB", 0x041e, 0x4157, DEVICE_FLAG_IGNORE_HEADER_ERRORS },
// Reported by Ringofan <mcroman@users.sourceforge.net>
{ "Creative ZEN V 2GB", 0x041e, 0x4158, DEVICE_FLAG_NONE },
@@ -1294,6 +1294,7 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler)
uint16_t ret;
PTPUSBBulkContainer usbdata;
unsigned long written;
+ PTP_USB *ptp_usb = (PTP_USB *) params->data;
memset(&usbdata,0,sizeof(usbdata));
do {
@@ -1303,14 +1304,19 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler)
if (ret!=PTP_RC_OK) {
ret = PTP_ERROR_IO;
break;
- } else
+ }
if (dtoh16(usbdata.type)!=PTP_USB_CONTAINER_DATA) {
ret = PTP_ERROR_DATA_EXPECTED;
break;
- } else
+ }
if (dtoh16(usbdata.code)!=ptp->Code) {
- ret = dtoh16(usbdata.code);
- break;
+ if (ptp_usb->device_flags & DEVICE_FLAG_IGNORE_HEADER_ERRORS) {
+ ptp_debug (params, "ptp2/ptp_usb_getdata: detected a broken "
+ "PTP header, expect problems! (But continuing)");
+ } else {
+ ret = dtoh16(usbdata.code);
+ break;
+ }
}
if (usbdata.length == 0xffffffffU) {
/* stuff data directly to passed data handler */
@@ -1354,12 +1360,11 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler)
(uint8_t *) &usbdata + packlen, surplen);
params->response_packet_size = surplen;
/* Ignore reading one extra byte if device flags have been set */
- } else if( !(((PTP_USB *)params->data)->device_flags &
- DEVICE_FLAG_NO_ZERO_READS &&
- rlen - dtoh32(usbdata.length) == 1)) {
- ptp_debug (params, "ptp2/ptp_usb_getdata: read %d bytes "
- "too much, expect problems!",
- rlen - dtoh32(usbdata.length));
+ } else if(( !(ptp_usb->device_flags & DEVICE_FLAG_NO_ZERO_READS) &&
+ rlen - dtoh32(usbdata.length) == 1)) {
+ ptp_debug (params, "ptp2/ptp_usb_getdata: read %d bytes "
+ "too much, expect problems!",
+ rlen - dtoh32(usbdata.length));
}
rlen = packlen;
}
@@ -1381,7 +1386,7 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler)
&written
);
- if (((PTP_USB *)params->data)->device_flags & DEVICE_FLAG_NO_ZERO_READS &&
+ if (ptp_usb->device_flags & DEVICE_FLAG_NO_ZERO_READS &&
len+PTP_USB_BULK_HDR_LEN == PTP_USB_BULK_HS_MAX_PACKET_LEN_READ) {
#ifdef ENABLE_USB_BULK_DEBUG
printf("Reading in extra terminating byte\n");
@@ -1389,7 +1394,6 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler)
// need to read in extra byte and discard it
int result = 0;
char byte = 0;
- PTP_USB *ptp_usb = (PTP_USB *)params->data;
result = USB_BULK_READ(ptp_usb->handle, ptp_usb->inep, &byte, 1, ptpcam_usb_timeout);
if (result != 1)
@@ -1400,7 +1404,6 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler)
#endif
int zeroresult = 0;
char zerobyte = 0;
- PTP_USB *ptp_usb = (PTP_USB *)params->data;
zeroresult = USB_BULK_READ(ptp_usb->handle, ptp_usb->inep, &zerobyte, 0, ptpcam_usb_timeout);
if (zeroresult != 0)
diff --git a/src/libusb-glue.h b/src/libusb-glue.h
index 2574b67..85d30f4 100644
--- a/src/libusb-glue.h
+++ b/src/libusb-glue.h
@@ -117,6 +117,18 @@
* Windows behaviour of never releasing interfaces.
*/
#define DEVICE_FLAG_NO_RELEASE_INTERFACE 0x00000040
+/**
+ * This falg was introduced with the advent of Creative ZEN
+ * 8GB. The device sometimes return a broken PTP header
+ * like this: < 1502 0000 0200 01d1 02d1 01d2 >
+ * the latter 6 bytes (representing "code" and "transaction ID")
+ * contain junk. This is breaking the PTP/MTP spec but works
+ * on Windows anyway, probably because the Windows implementation
+ * does not check that these bytes are valid. To interoperate
+ * with devices like this, we need this flag to emulate the
+ * Windows bug.
+ */
+#define DEVICE_FLAG_IGNORE_HEADER_ERRORS 0x00000080
/**
* Internal USB struct.